akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

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

  lol n;
  cin >> n;
  vector<lol> ans(n + 5, 2);
  lol nasu = 1;
  for(lol i = 2;i <= n;i ++){
    // cout << ans[i] << " " << i << '\n';
    nasu += (ans[i] * i);
    for(lol j = i * 2;j <= n;j += i){
      ans[j] ++;
    }
  }
  cout << nasu << '\n';
  return 0;
}


Measured memory_bytes: 81324
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll x, n;
    cin >> x >> n;

    bool used[111] = {};
    rep(i, n){
        ll p;
        cin >> p;
        used[p] = true;
    }

    int ans = 100000;
    int dif = 100000;
    for(int i = -1000; i <= 1000; ++i){
        if(i >= 0 && i <= 110 && used[i])continue;

        if(abs(x - i) < dif){
            dif = abs(x - i);
            ans = i;
        }
        else if(abs(x - i) == dif)ans = min(ans, i);


    }

    cout << ans << endl;
}

Measured memory_bytes: 3644
/**
 * @author: Jun
 * @date  : 03-14-2019
 **/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

int g[10] = {0,2,5,5,4,5,6,3,7,6};

int n,m;
int usable[10];

int dp[10005][10];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    for(int i=1;i<=10000;i++){
        for(int j=1;j<=9;j++){
            dp[i][j]=-1;
        }
    }
    memset(usable, 0, sizeof usable);
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        usable[a]=1;
    }
    for(int i=1;i<=9;i++){
        if(usable[i]){
            dp[g[i]][i]=1;
        }
    }
    for(int i=2;i<=n;i++){
        for(int j=1;j<=9;j++){
            if(usable[j]){
                if(i-g[j] > 1){
                    int dmax=-1;
                    int kmax=-1;
                    for(int k=1;k<=9;k++){
                        if(dp[i-g[j]][k]!=-1){
                            if(dp[i-g[j]][k] >= dmax){
                                dmax = dp[i-g[j]][k];
                            }
                            if(k >= kmax){
                                kmax=k;
                            }
                        }
                    }
                    if(dmax!=-1){
                        dp[i][j] = dmax+1;
                    }
                }
            }
        }
    }
    int ha = n;
    while(ha >= 2){
        int valmax=-1;
        for(int i=1;i<=9;i++){
            if(usable[i]){
                valmax = max(valmax, dp[ha][i]);
            }
        }
        int idmax=-1;
        for(int i=1;i<=9;i++){
            if(usable[i]){
                if(dp[ha][i]==valmax){
                    idmax = max(idmax, i);
                }
            }
        }
        cout << idmax;
        ha -= g[idmax];
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

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

int main()
{
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    double sol = 0;
    int mw = a*100;
    int ms = 0;
    for(int i = 0; i <= f/(a*100); ++i){
        for(int j = 0; j <= (f-100*a*i)/(b*100); ++j){
            for(int k = 0; k <= (f-100*b*j-100*a*i)/c; ++k){
                for(int l = 0; l <= (f-c*k-100*b*j-100*a*i)/d; ++l){
                    if(i == 0 && j == 0 && k == 0 && l == 0) continue;
                    double w = 100*a*i + 100*b*j;
                    double s = c*k + d*l;
                    if(100*s/(w+s) <= 100.0*e/(100.0+e)){
                        if(sol < 100*s/(w+s)){
                            mw = static_cast<int>(w);
                            ms = static_cast<int>(s);
                            sol = 100*s/(w+s);
                        }
                    }
                }
            }
        }
    }
    cout << mw+ms << " " << ms << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>

using namespace std;

typedef pair<int,int>P;

int SQ(int x){ return x*x; }

map<P, int>m;
int N;
P crd[3005];

int main(){
  while(scanf("%d", &N) && N){
    for(int i=0;i<N;i++){
      int y,x; scanf("%d%d", &x,&y);
      crd[i] = P(y,x);
      m[P(y,x)] = 1;
    }
    int res = 0;
    for(int i=0;i<N;i++) for(int j=0;j<N;j++){
	if(i==j) continue;
	P s1 = crd[i], s2 = crd[j];
	int sq = SQ(s1.first-s2.first)+SQ(s1.second-s2.second);
	//	printf("%d %d %d\n", i, j, sq);
	int dx = s1.second-s2.second, dy = s1.first-s2.first;
	P n1, n2;
	n1 = P(s1.first-dx, s1.second+dy), n2 = P(s2.first-dx, s2.second+dy);
	//	printf("%d %d %d %d\n", n1.first, n1.second, n2.first, n2.second);
	if(m.find(n1) != m.end() && m.find(n2) != m.end()) res = max(res, sq);
	n1 = P(s1.first+dx, s1.second-dy), n2 = P(s2.first+dx, s2.second-dy);
	if(m.find(n1) != m.end() && m.find(n2) != m.end()) res = max(res, sq);	
      }
    
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1916
//In the Name of Allah Most Gracious, Most Merciful//
/*If you want something you've never had, you have  to do something you never did.*/

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


#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define M 100007
#define INF 1e9
#define INFL 1e18
#define PI acos(-1)
#define mp make_pair
#define fast_in_out ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move





int main()
{
    fast_in_out;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,m;
    cin>>n>>m;
    int arr[m+5];
    ll sum=0;
    for(int i=0;i<m;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    if(n>=sum)
    {
        cout<<n-sum<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
    return 0;
}



Measured memory_bytes: 3680
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <map>
#include <list>
#define pb push_back
using namespace std;

int main(){
  double n,k;

  cin>>n>>k;

  double res=0;
  for(int i=1;i<=n;i++){
    double x=i;
    double y=1.0;
    while(x<k){
      x*=2;
      y*=0.5;
    }
    res+=y;
  }
  printf("%0.10f\n",res/n);
  return 0;
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll A, B; cin >> A >> B;
  int K; cin >> K;
  REP(i, K){
    if(i%2 == 0){
      if(A%2 == 1) A--;
      A /= 2;
      B += A;
    }else{
      if(B%2 == 1) B--;
      B /= 2;
      A += B;
    }
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}


int main(){
    cin.tie(0);
    
    int A, B, C;
    cin >> A >> B >> C;
    int ans = 0;
    while (1){
        if (A % 2 || B % 2 || C % 2){
            break;
        }
        if (A == B && A == C && B == C){
            cout << -1 << endl;
            return 0;
        }
        ans++;
        int tmpa = B/2 + C/2;
        int tmpb = A/2 + C/2;
        int tmpc = B/2 + A/2;
        A = tmpa;
        B = tmpb;
        C = tmpc;
    }
    cout << ans << endl;
    return 0;
} 


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

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

Measured memory_bytes: 256
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def main():
    H, W, K = i2nn()
    nnn = []
    for _ in range(H):
        s = i2s()
        nn = [1 if c == '#' else 0 for c in s]
        nnn.append(nn)
    def rec(ii, jj, ret):
        if len(ii) < W:
            ret = rec(ii + [0], jj, ret)
            ret = rec(ii + [1], jj, ret)
            return ret
        if len(jj) < H:
            ret = rec(ii, jj + [0], ret)
            ret = rec(ii, jj + [1], ret)
            return ret
        nnn2 = [[n for n in nn] for nn in nnn]
        for k, i in enumerate(ii):
            if i == 1:
                for l in range(H):
                    nnn2[l][k] = 0
        for k, j in enumerate(jj):
            if j == 1:
                for l in range(W):
                    nnn2[k][l] = 0
        n = 0
        for i in range(H):
            for j in range(W):
                if nnn2[i][j] == 1:
                    n += 1
        if n == K:
            ret += 1
        else:
            ret += 0
        return ret
    ret = rec([], [], 0)

    print(ret)

main()


Measured memory_bytes: 9408
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;



int main(){
    int N, K;
    float f;
    string s;
    
    cin >> N >> K;
    
    int temp;
    temp = (N+1)/2;
    
    if (temp>=K) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int a,b,x;
	long long int count=0;
	cin >> a >> b >> x;
	count=b/x-a/x;
	if(a%x==0){
		count++;
	}
	cout << count << endl;
	return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef string ST;



void func() {
  LL N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  A--;
  B--;
  C--;
  D--;

  ST S;
  cin >> S;

  ST T;
  T = S;
  T[A] = 'A';
  T[B] = 'B';
  T[C] = 'C';
  T[D] = 'D';
  //cerr << T << endl;;
  //! AとCの間に##があるか確認 
  for (LL i = A + 1; i <= C - 1-1; i++) {
    if (S[i] == '#' && S[i + 1] == '#') {
      cout << "No";
      cerr << "1";
      return;
    }
  }

  //! BとDの間に##があるか確認 
  for (LL i = B + 1; i <= D - 1 - 1; i++) {
    if (S[i] == '#' && S[i + 1] == '#') {
      cout << "No";
      cerr << "2";
      return;
    }
  }

  if (C < D) {
    cout << "Yes";
    cerr << "3";
    return;
  }
  //! BとDの間に...があるか確認 
  for (LL i = B; i <= D; i++) {
    if (S[i] == '.' && S[i + 1] == '.' && S[i -1] == '.') {
      cout << "Yes";
      cerr << "6";
      return;
    }
  }

  cout << "No";
  cerr << "10";


}


#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "\n%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





Measured memory_bytes: 772
#include <iostream>
using namespace std;
typedef long long ll;
ll n,z,w,a[2000];
int main(void){
    cin>>n>>z>>w;
    for(int i=0;i<n;i++)cin>>a[i];
    if(n==1){
        cout<<abs(w-a[n-1])<<endl;
        return 0;
    }
    cout<<max(abs(w-a[n-1]),abs(a[n-1]-a[n-2]))<<endl;
}


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

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

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin >> k;
    queue<ll> Q;
    for (int i = 1; i <= 9; i++) Q.push(i);
    k--;
    while (k--) {
        ll tp = Q.front();
        Q.pop();
        ll d = tp % 10;
        if (d > 0) Q.push(tp * 10 + (d - 1));
        Q.push(tp * 10 + (d));
        if (d < 9) Q.push(tp * 10 + (d + 1));
    }
    cout << Q.front() << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define sp(x) fixed<<setprecision(x)
#define pb push_back
#define eb emplace_back
#define die(x) return cout << x << endl, 0
#define fastio ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define file ifstream cin("input.txt"); ofstream cout("output.txt")
#define int long long
//#define endl '\n'
const int MAXN = 100 * 1000 + 7, MOD = 1000 * 1000 * 1000 + 7;
int dp[MAXN];
int Pow(int a, int b){
    if(b == 0ll) return 1ll;
    int x = Pow(a, b / 2);
    x *= x;
    x %= MOD;
    if(b % 2) x *= a;
    x %= MOD;
    return x % MOD;
}

int32_t main(){
    fastio;
    int n, k;
    cin >> n >> k;
    for(int i = k; i > 0; i --){
        dp[i] = Pow((k / i), n) % MOD;
        for(int j = i * 2; j <= k; j += i)
            dp[i] = (dp[i] - dp[j] + MOD) % MOD;
        dp[i] %= MOD;
    }
    int ans = 0;
    for(int i = 1; i <= k; i ++){
        ans += ((i % MOD) * (dp[i] % MOD)) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4368
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<-1<<endl;return 0
//ios::sync_with_stdio(false);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e12+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
vector<vector<int>>ko;
vector<int>oya;
vector<vector<int>>dp;

void make_tree(int per,int ter)
{//make_tree(-1,root);で木を作れる
	auto itr=find(ko[ter].begin(),ko[ter].end(),per);
	if(per!=-1){oya[ter]=(*itr);ko[ter].erase(itr);}
	for(auto it=ko[ter].begin();it!=ko[ter].end();it++){
		make_tree(ter,*it);
	}
}
//k=5
//0 1 2 3 4 5 最大
//0 1 2 2 1 0 その他
int kotae=999999;
pair<deque<int>,int> solve(int ter,int K,int n){
	int i;
	deque<int>ans(K+1);
	deque<int>mai(K+1);
	int kaz=1;
	for(auto it:ko[ter]){
		auto paret=solve(it,K,n);
		auto ret=paret.fir;
		kaz+=paret.sec;
		ret.puf(ret[0]+1);
		for(i=0;i<=K;i++){ans[i]+=ret[min(i,K-i)];maxeq(mai[i],ret[K-i]-ret[i]);}
	}
	for(i=0;i<=K;i++){ans[i]-=mai[i];}
	for(i=0;i<K;i++){mineq(ans[i+1],ans[i]);}
	mineq(kotae,ans[K]+n-kaz);
	return mp(ans,kaz);
}
int main(void){
	int n,i,j,K;cin>>n>>K;
	ko.res(n);
	oya.res(n);
	dp.res(n);
	for(i=0;i<n-1;i++){
		int a,b;cin>>a>>b;a--;b--;
		ko[a].pub(b);
		ko[b].pub(a);
	}
	make_tree(-1,0);
	solve(0,K,n);
	cout<<kotae<<endl;
	return 0;
}

Measured memory_bytes: 27696
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll mi = min({a, b, c, d, e});
    if(n <= mi) cout << "5" << endl;
    else{
        ll ans = (ll)ceil(n/(double)mi)-1+5;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	int n;
	cin >> n;
	vector<int> a(n+1);
	int rw[n+1][20] = {};
	a[0] = 0;
	REP1(i, n){
		cin >> a[i];
		REP(j, 20){
			if((1<<j) & a[i]) rw[i][j] = 1;
			rw[i][j] += rw[i-1][j];
			//cout << rw[i][j] << " ";
		}
		//cout << endl;
	}	
	bool ch;
	REP1(i, n){
		int he = i, ta = n;
		while(he != ta){
			int now = (he + ta + 1) /2;
			ch = true;
			REP(k, 20){
				if(rw[now][k] - rw[i-1][k] > 1) ch = false;
			}
			if(ch) he = now;
			else ta = now -1;
		}
		//cout << ta << endl;
		ans += ta - i + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 19596
n=int(input())
li=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        ans+=((li[i][0]-li[j][0])**2+(li[i][1]-li[j][1])**2)**0.5
print(ans*2/n)

Measured memory_bytes: 3060
/*input
10
AC
AC
AC
AC
AC
AC
AC
AC
AC
AC
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
// #define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 
 
 
ll n,i,j,k,m;
int r[4]={0,0,1,-1};
int c[4]={1,-1,0,0};



void solve()
{
cin>>n;
map<string,int> mp;
string a;
rep(i,n)
{
    cin>>a;

    mp[a]++;


}

cout<<"AC x "<<mp["AC"]<<endl;

cout<<"WA x "<<mp["WA"]<<endl;

cout<<"TLE x "<<mp["TLE"]<<endl;

cout<<"RE x "<<mp["RE"]<<endl;

}
 
 
 
 
 
 
signed main()
{

    // inputFile;
    // outputFile;
    fast;
    int T = 1;
 // cin >> T;
ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;


int W, H;//H→y軸、W→x軸
vector<vector<char>> s;

// cost[y][x] = スタートから(x, y)までの最短経路
vector<vector<int>> cost;
int bfs(int a,int b,int c,int d){
    cost = vector<vector<int>>(H, vector<int>(W, -1));//-1に初期化
    // 移動可能なマスをループで簡単に列挙
    int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

    // 座標をpair(y, x)でもってqueueに入れる
    queue<pair<int, int>> que;
    // スタートは(a-1, b-1) (0-indexedに読み替える)
    que.push(make_pair(a-1, b-1));
    cost[a-1][b-1] = 0;

    while(!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        if(p == make_pair(c-1, d-1)){
            // ゴールに到達
            return cost[p.first][p.second];
        }
        for(int i = 0; i < 4; i++) {
            int ny = p.first + dy[i], nx = p.second + dx[i];
            // 壁orマスの外
            if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
            if(s[ny][nx] == '#') continue;
            // 既に探索済み
            if(cost[ny][nx] != -1) continue;

            cost[ny][nx] = cost[p.first][p.second] + 1;
            que.push(make_pair(ny, nx));
        }
    }
    return -1;
}

int main() {
    cin >> H >> W;
    s = vector<vector<char>>(H, vector<char>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> s[i][j];
        }
    }

    int max_cost=0;
    for(int a=1;a<=H;a++){
      for(int b=1;b<=W;b++){
        for(int c=1;c<=H;c++){
          for(int d=1;d<=W;d++){
            if(s[a-1][b-1]=='.' && s[c-1][d-1]=='.'){
          int dcost = bfs(a,b,c,d);
          max_cost=max(max_cost,dcost);}
          }
        }
      }
    }
    cout << max_cost << endl;
}

Measured memory_bytes: 3612
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader bf = 
            new BufferedReader(new InputStreamReader(System.in));
        String[] str = bf.readLine().split(" ");
        int A = Integer.parseInt(str[0]),
            B = Integer.parseInt(str[1]);
        int[] sum = {2*A-1, 2*B-1, A+B};
        int max = sum[0];
        for(int i = 1; i < 3; i++){
            if(max < sum[i]){
                max = sum[i];
            }
        }        
        System.out.println(max);
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

int prime[1010];
bool is_prime[1010];

int sieve(int n){
	int p = 0;
	for(int i=0;i<=n;i++)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
		}
	}
	return p;
}


int main() {
    int n;
    cin>>n;
    int num = sieve(n);
    ll cnt=1;
    map<int, ll> c;
    for (int i = 1; i <= n; i++) {
        for(int j=0;j<num;j++){
            if(i<prime[j])break;
            ll t=0;
            int target=i;
            while(target%prime[j]==0&&target!=0){
                t++;
                target/=prime[j];
            }
            c[prime[j]]+=t;
        }
    }

    for(auto i:c){
        (cnt*=(i.second+1LL))%=MOD;
    }

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,b,c[100],top=0,i=0;
  char s[100],m;
  while( scanf("%s",s) != EOF){
    if ( s[i] == '+' ){
      top = top - 1;
      a = c[top+1];
      top = top - 1;
      b = c[top+1];
      top++;
      c[top] = a + b;
    } else if ( s[i] == '-' ){
      top = top - 1;
      a = c[top+1];
      top = top - 1;
      b = c[top+1];
      top++;
      c[top] = b - a;
    } else if ( s[i] == '*' ){
      top = top - 1;
      a = c[top+1];
      top = top - 1;
      b = c[top+1];
      top++;
      c[top] = a * b;
    } else {
      a = atoi(s);
      top++;
      c[top] = a;
    }
  }
  printf("%d\n", c[top]);
  return 0;
}


Measured memory_bytes: 2108
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

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

template <class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
	for (const auto &e : mp) os << "[" << e << "] ";
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	vector<vector<int>> alpha(26);
	string s, t;
	cin >> s >> t;

	for (int i = 0; i < s.size(); i++) {
		alpha[s[i] - 'a'].emplace_back(i + 1);
	}

	DMP(alpha);
	int pre = 0;
	lint ans = 0;
	for (int i = 0; i < t.size(); i++) {

		int idx = t[i] - 'a';
		if (alpha[idx].empty()) {
			cout << -1 << "\n";
			return 0;
		}
		else if (upper_bound(alpha[idx].begin(), alpha[idx].end(), pre) == alpha[idx].end()) {
			
			ans += s.size() - pre;
			pre = alpha[idx][0];
			ans += pre;

		}
		else {
			ans += *upper_bound(alpha[idx].begin(), alpha[idx].end(), pre) - pre;
			pre = *upper_bound(alpha[idx].begin(), alpha[idx].end(), pre);
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1228
#include "bits/stdc++.h"
using namespace std;

vector<int> occ[26];
///
struct BIT{
  int b[2 * 1000 * 105];
  void upd(int pos){for(; pos < 2 * 1000 * 105; pos += pos & -pos) b[pos]++;}
  int sum(int pos, int ans = 0){for(;pos;pos -= pos & -pos)ans += b[pos]; return ans;}
}bR, bL;
int main(){

  string s;
  cin >> s;
  int off = 0;
  for(int i = 0; i < s.size(); i++){
    occ[s[i] - 'a'].push_back(i);
  }
  vector<pair<int, int>> vp;
  int cen;
  bool f = false;
  for(int i = 0; i < 26; i++){

      for(int j = 0; j < occ[i].size() / 2; j++){
        int k = occ[i].size() - j - 1;
        vp.push_back({occ[i][j] + 1, occ[i][k] + 1});
      }
      if(occ[i].size() & 1){
        if(f)return cout << -1 << endl, 0;
        f = 1;
        cen = occ[i][occ[i].size()/2] + 1;
      }

  }

  sort(vp.rbegin(),vp.rend());
  long long ans = 0;
  for(auto x : vp){
    ans += 2 * (bL.sum(s.size()) - bL.sum(x.second));
    ans += bL.sum(x.second) - bR.sum(x.second);
    bL.upd(x.first);
    bR.upd(x.second);
  }
  if(f)
  for(auto x : vp)
    if(!(x.first < cen && cen < x.second))ans++;
  cout << ans << '\n';
}


Measured memory_bytes: 3832
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

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

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let s:Vec<char> = read::<String>().chars().collect();
    let n:usize = s.len();

    let mut csum:Vec<i64> = vec![0;n+1];
    for (i,&ch) in s.iter().enumerate() {
        csum[i+1] = csum[i];
        if ch == 'W' { csum[i+1] += 1}
    }
    let mut ans:i64 = 0;
    for (i,&ch) in s.iter().enumerate() {
        if ch == 'B' {
            ans += csum[n]-csum[i];
        }
    }

    println!("{}", ans);

}


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

int main() {
  int N,L; cin >>N>>L;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());
  for(int i=0;i<N;i++){
    cout<<S.at(i);
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
int N,M;
vi S,C;

auto solve(){
	string T(N,'-');
	rp(i,0,M) T[S[i]-1] = C[i]+'0';
	// ote(T);//
	rp(i,0,M) if(T[S[i]-1] != C[i]+'0') return -1;
	if(N!=1 && T[0]=='0') return -1;

	int ans = INT_MAX;

	rp(i,0,999){
		string A = to_string(i);
		if(A.size() != N) continue;
		// ote(A);//
		int j;
		for(j=0; j<N; ++j){
			if(T[j] != '-' && T[j] != A[j]){
				break;
			}
		}
		if(j == N) ans = min(ans, i);

	}

	return ans;
}

int main(){
	cin>>N>>M;
	S.resize(M);
	C.resize(M);
	rp(i,0,M) cin>>S[i]>>C[i];
	cout<< solve() <<endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(in.hasNextInt()){
			int n = in.nextInt();
			int ns[] = new int[n];
			for(int i=0; i<n; i++)
				ns[i] = in.nextInt();
			Arrays.sort(ns);
			int ans = 0, accum = 0;
			for(int i=0; i<n; i++){
				accum += ns[i];
				ans += accum;
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 12000
n=int(input())
c=0
a=0
b=0
ab=0

for i in range(n):
  s=input()
  c+=s.count("AB")
  if s[0]=="B" and s[-1]=="A":ab+=1
  elif s[0]=="B":b+=1
  elif s[-1]=="A":a+=1

c+=min(a,b)+ab if max(a,b)!=0 else ab-1 if ab>0 else 0
print(c)

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

int main() {
	int h, w;
	string board[60];//多めに６０
	cin >> h >> w;
	for (int i = 0; i < h; i++) cin >> board[i];

	bool can = true;
	const int dx[4] = { 0, -1, 1, 0 };
	const int dy[4] = { -1, 0, 0, 1 };

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			bool can2 = false;
			if (board[i][j] == '.') continue;

			for (int d = 0; d < 4; d++) {
				int ni = i + dy[d];
				int nj = j + dx[d];
				if (ni < 0)continue;
				if (ni >= h)continue;
				if (nj < 0)continue;
				if (nj >= w)continue;
				if (board[ni][nj] == '#') can2 = true;
			}

			if (!can2) {
				can = false;
				//cout << "change" << endl; //これ
			}
		}
	}

	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,t;
	int x,y=0,sum=0;
	cin >>n>>t;
	for(int i=0;i<n;++i){
		cin >>x;
		if(x-y<t) sum+=x-y;
		else sum+=t;
		y=x;
	}
	cout << sum+t << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M;
ll d[101][101]={};
ll a[1001],b[1001],c[1001];
set<P> st;
int main(){
    cin>>N>>M;
    for(ll i=0;i<N;i++) for(ll j=0;j<N;j++){
        if(i==j)continue;
        d[i][j]=INF;
    }
    for(ll i=0;i<M;i++){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;
        b[i]--;
        d[a[i]][b[i]]=c[i];
        d[b[i]][a[i]]=c[i];
    }
    for(ll k=0;k<N;k++)for(ll i=0;i<N;i++)for(ll j=0;j<N;j++)
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    ll ans=0;
    for(ll i=0;i<M;i++){
        if(d[a[i]][b[i]]<c[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
void fail() { puts("-1"); exit(0); }
// const int INF  = 1<<30;
// const ll INFll = 1ll<<62;
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


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

  int x = 7;
  rep2(i, 1, k+2) {
    if (x % k == 0) {
      cout << i << '\n';
      return 0;
    }
    x = 10 * x + 7;
    x %= k;
  }

  cout << -1 << '\n';
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	
	int N;
	int64_t K;
	cin >> N >> K;
	vector<int> A(N);
	vector<int64_t> B(N, -1);
	B[0] = 0;
	int actP = 0;
	int64_t T = 0;
	forn(i, N)
	{
		cin >> A[i];
		--A[i];
	}

	while (true)
	{
		actP = A[actP];
		++T;
		if (K == T)
		{
			cout << actP + 1 << endl;
			return 0;
		}
		if (B[actP] == -1)
			B[actP] = T;
		else
			break;
	}
	uint64_t loop = T - B[actP];
	K -= T;
	K %= loop;

	while (K--)
	{
		actP = A[actP];
	}

	cout << actP + 1 << endl;	
	
	return 0;
}


Measured memory_bytes: 5576
// D.

#include <iostream>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef pair<int, int> II;
typedef pair<int, II> III;

struct UnionFind {
	std::vector<int> _parent;
	std::vector<int> _size;
	UnionFind(int size) : _parent(size, -1), _size(size, 1) { }
	void unite(int a, int b) {
		int ra = root(a), rb = root(b); if (ra == rb) { return; }
		if (_size[ra] >= _size[rb]) { _parent[rb] = ra, _size[ra] += _size[rb]; } else { _parent[ra] = rb, _size[rb] += _size[ra]; }
	}
	int root(int a) {
		int p = _parent[a];
		if (p < 0) { return a; }
		while (_parent[p] >= 0) { p = _parent[p]; }
		return _parent[a] = p;
	}
	int size(int a) { return _size[root(a)]; }
};

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<II> vx, vy;
	for (int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		vx.push_back(II(x, i));
		vy.push_back(II(y, i));
	}
	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());
	priority_queue<III, vector<III> > q;
	for (int i = 1; i < n; ++i) {
		q.push(III(vx[i - 1].first - vx[i].first, II(vx[i - 1].second, vx[i].second)));
		q.push(III(vy[i - 1].first - vy[i].first, II(vy[i - 1].second, vy[i].second)));
	}
	int ans = 0;
	UnionFind uf(n);
	while (q.size()) {
		III top = q.top();
		q.pop();
		if (uf.root(top.second.first) != uf.root(top.second.second)) {
			uf.unite(top.second.first, top.second.second);
			ans -= top.first;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

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

	int n;
	cin >> n;

	int m = 1000001;

	vector<int> a(n);
	vector<int> cnt(m);
	vector<bool> vis(m);

	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		cnt[a[i]] += 1;
	}

	for(int i = 1; i < m; ++i) {
		if(cnt[i] > 0) {
			for(int j = i + i; j < m; j += i) {
				vis[j] = true;
			}
		}
	}

	long long ans = n;

	for(int i : a) {
		if(cnt[i] > 1 || vis[i]) {
			ans -= 1;
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 8248
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

char num2alpha(int n){
  for(char moji='a';moji<='z';++moji){
    if(n==(int)(moji-'a'+1)){
      return moji;
    }
  }
}

int main(){
  ll n; cin>>n;
  vector<int> v;
  while(1){
    ll tmp=n%26;
    if(tmp==0)
      tmp+=26;
    v.push_back(tmp);
    n=n-tmp;
    n/=26;
    if(n==0){
      break;
    }
  }
  for(auto itr=v.end()-1;itr>=v.begin();--itr){
    cout<<num2alpha(*itr);
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

// warshall_floyd
// dは隣接行列(long long intを使うこと)
void warshall_floyd(vector<vector<long long int>>& d) {
    long long int n = d.size();
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (d[i][k] == LLONG_MAX || d[k][j] == LLONG_MAX) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    lint M = LLONG_MAX;
    vector<vector<lint>> d(n, vector<lint>(n, M));
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    for (int i = 0; i < n; i++) {
        d[i][i] = 0;
    }
    warshall_floyd(d);
    vector<vector<lint>> e(n, vector<lint>(n, M));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d[i][j] <= l) {
                e[i][j] = 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        e[i][i] = 0;
    }
    warshall_floyd(e);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        if (e[s][t] == M) {
            cout << -1 << endl;
        } else {
            cout << e[s][t] - 1 << endl;
        }
    }
}

Measured memory_bytes: 1920
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N;
    cin >> N;

    map<vector<char >, ll> mp;

    for(ll i = 1; i <= N; i++){
        string num = to_string(i);
        if(num.length() == 1) mp[vector<char >{num[0],num[0]}]++;
        else mp[vector<char >{num[0],num[num.length()-1]}]++;
    }

    ll ans = 0;

    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        char a = iter->first[0];
        char b = iter->first[1];
        ll num = iter-> second;
        ans += num * mp[vector<char >{b, a}];
        //cout << a << " " << b << " " << num << endl;
    }    

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len=s.length();
    int num,mn=1000000;
    for(int i=0;i<len-2;i++)
       {
           num=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
           mn=min(mn,abs(num-753));
       }
       cout<<mn<<endl;
       return 0;
}


Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())
x = "D"
x += "R"*(tx-sx+1)
x += "U"*(ty-sy+1)
x += "L"
x += "D"*(ty-sy)
x += "L"*(tx-sx)
x += "U"*(ty-sy)
x += "R"*(tx-sx)
x += "U"
x += "L"*(tx-sx+1)
x += "D"*(ty-sy+1)
x += "R"
print(x)

Measured memory_bytes: 61960
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

struct mint {
    ll v;
    ll mod;
    mint() : v(0) {}
    mint(signed v, ll mod = MOD) : v(v), mod(mod) {}
    mint(ll t, ll mod = MOD) : mod(mod) {
        v = t % mod;
        if (v < 0)
            v += mod;
    }

    mint pow(ll k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }

    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }

    mint inv() { return pow(mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += mod - a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = 1LL * v * a.v % mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(MOD - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};

int main() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<mint>> dp(n + 1, vector<mint>(k + 1, 0));     // n-th child, k-candies
    vector<vector<mint>> cumsum(n + 1, vector<mint>(k + 1, 0)); // n-th child, k-candies
    dp[0][0] = 1;
    cumsum[0][0] = 1;
    for (int i = 1; i <= k; ++i) {
        cumsum[0][i] += cumsum[0][i - 1];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= k; ++j) {
            dp[i + 1][j] += cumsum[i][j];
            if (j - a[i] - 1 >= 0)
                dp[i + 1][j] -= cumsum[i][j - a[i] - 1];
        }
        cumsum[i + 1][0] = dp[i + 1][0];
        for (int j = 1; j <= k; ++j) {
            cumsum[i + 1][j] = cumsum[i + 1][j - 1] + dp[i + 1][j];
        }
    }
    cout << dp[n][k].v << "\n";
    return 0;
}

Measured memory_bytes: 317540
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] f = new int[n];
		int sz = 0;
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			if (sz == 0) {
				f[sz] = a[0];
				++sz;
			} else {

				int ok = -1;
				int ng = sz;
				while (ng - ok > 1) {
					int middle = (ok + ng) / 2;
					if (f[middle] < a[i]) {
						ok = middle;
					} else {
						ng = middle;
					}
				}

				f[ok + 1] = a[i];
				if (ok + 1 == sz)
					++sz;
			}
		}
		
		System.out.println(sz);

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 71808