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

vector<int> sort(vector<int> l);

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> x(m);
  for(int i=0;i<m;i++)
    cin >> x.at(i);
  
  //sorting
  //x = sort(x);
  sort(x.begin(), x.end());
  /*for(int i=0;i<x.size();i++)
    cout << x.at(i) << ",";
  cout << endl;//*/

  vector<int> d(m-1);
  for(int i=1;i<m;i++)
    d.at(i-1) = abs(x.at(i) - x.at(i-1));
  //d = sort(d);
  sort(d.begin(),d.end());
  /*for(int i=0;i<d.size();i++)
    cout << d.at(i) << ",";
  cout << endl;//*/

  if(n >= m){
    cout << 0 << endl;
    return 0;
  }

  //counting
  int sum = 0;
  for(int i= 0;i<d.size()-n+1;i++)
    sum+=d.at(i);
  cout << sum << endl;
  return 0;
}

vector<int> sort(vector<int> l){
  for(int i=0;i<l.size();i++){
    for(int j=l.size()-1;j>i;j--){
      if(l.at(j-1) > l.at(j)){
        int temp = l.at(j);
        l.at(j) = l.at(j-1);
        l.at(j-1) = temp;
      }
    }
  }
  return l;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
#define inI(x) scanf("%d",&x)
#define inI2(x,y) scanf("%d %d",&x,&y)
#define inI3(x,y,z) scanf("%d %d %d",&x,&y,&z)
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
long long n,m,ans=INT_MAX,nn,mm,a,b,c,mx,mn,k,cc;
int main()
{
    scanf("%lld %lld",&n,&m);
    for(int i=1;i<=n;i++)
    {
        k=n-i;
        cc=k/2;
        a=i*m;
        if(k>=2)
        {
            b=cc*m;
            c=(n-i-cc)*m;
            mn=min(a,min(b,c));
            mx=max(a,max(b,c));
            ans=min(ans,mx-mn);
        }
        if(m>=2)
        {
            cc=m/2;
            b=cc*k;
            c=(m-cc)*k;
            mn=min(a,min(b,c));
            mx=max(a,max(b,c));
            ans=min(ans,mx-mn);
        }
    }
    for(int i=1;i<=m;i++)
    {
        k=m-i;
        cc=k/2;
        a=i*n;
        if(k>=2)
        {
            b=cc*n;
            c=(m-i-cc)*n;
            mn=min(a,min(b,c));
            mx=max(a,max(b,c));
            ans=min(ans,mx-mn);
        }
        if(m>=2)
        {
            cc=n/2;
            b=cc*k;
            c=(n-cc)*k;
            mn=min(a,min(b,c));
            mx=max(a,max(b,c));
            ans=min(ans,mx-mn);
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 256
prime = [True] * (123456 * 2 + 1)
prime[0] = prime[1] = False
for i in range(2, int(len(prime) ** 0.5) + 1):
    if prime[i]:
        for j in range(i * 2, len(prime), i):
            prime[j] = False
prinum = [0] * len(prime)
for i in range(1, len(prime)):
    prinum[i] = prinum[i - 1] + prime[i]

while True:
    n = int(input())
    if n == 0:
        break
    print(prinum[2 * n] - prinum[n])

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn = 1e6 + 11;

int main() {

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

  int r; cin >> r;

  cout << (3*r*r) << "\n";


  return 0;
}


Measured memory_bytes: 256
Q, H, S, D = list(map(int, input().split()))
N = int(input())

# N が整数なので、1リットルずつしか買えない。
# 0.25リットルと0.5リットルを1リットルあたりの価格に換算して、最小の価格を S とする
S = min(4*Q, 2*H, S)

if D >= 2*S:
    ans = N * S
else:
    ans = N//2 * D + N%2 * S

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int group[15];

int main(){

	int x,y;

	scanf("%d %d",&x,&y);

	group[1]=1;
	group[3]=1;
	group[5]=1;
	group[7]=1;
	group[8]=1;
	group[10]=1;
	group[12]=1;


	group[4]=2;
	group[6]=2;
	group[9]=2;
	group[11]=2;

	group[2]=3;

	if(group[x]==group[y]){printf("Yes\n");}
	else{printf("No\n");}


	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> que;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int h, w, ans;
vector<string> table;
bool inRange(int y, int x)
{
    if(y < 0 or x < 0 or y >= h or x >= w) return false;
    return true;
}
int solve()
{
    int res = 0;
    bool flag;
    while(true)
    {
        flag = false;
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                if(table[i][j] != '.') continue;
                map<char, vector<P>> mp;
                for(int k = 0; k < 4; k++)
                {
                    int ny = i + dy[k], nx = j + dx[k];
                    while(inRange(ny, nx))
                    {
                        if(table[ny][nx] != '.')
                        {
                            mp[table[ny][nx]].push_back(make_pair(ny, nx));
                            break;
                        }
                        ny += dy[k];
                        nx += dx[k];
                    }
                }
                for(auto x : mp)
                {
                    if(x.second.size() == 2)
                    {
                        flag = true;
                        for(int k = 0; k < x.second.size(); k++)
                        {
                            P p = x.second[k];
                            table[p.first][p.second] = '.';
                        }
                        res += x.second.size();
                    }
                }
            }
        }
        if(flag == false) break;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    table.resize(h);
    for(int i = 0; i < h; i++) cin >> table[i];
    cout << solve() << endl;
    return 0;
}





Measured memory_bytes: 3368
def main():
    N = int(input())

    flag = False

    for i in range(1,10):
        for j in range(1,10):
            if(N == i*j):
                flag = True
                break

    if(flag):
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int c2=0;
  for(int i=0;i<=n/2-1+n%2;i++){
      int m=2*i+1;
      int c1=0;
      for(int j=1;j<=m;j++){
          if(m%j==0) c1++;
      }
      if(c1==8) c2++;
  }
  cout<<c2<<endl;
}
    

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

int main(){
  int K,S; cin >> K >> S;
  int sum=0;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
     if(i+j <= S && S-K <= i+j){
       sum++;
       }
      }
    }
  
  cout << sum << endl;
}
  

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int N,M;
    cin >> N >> M;

    vector<vector<int> >a(M, vector<int>(2));
    rep(i,M) cin >> a[i][0] >> a[i][1];

    vector<int> ary(N,1);
    rep(i,N) ary[i] += i;

    int ans = 0;
    
    do
    {
        if( ary[0] != 1 )break;

        // 順序が実行できるか試す
        bool isRight = true;
        rep(i,N-1)
        {
            bool flag = false;
            // パスの探索
            rep(j, M)
            {
                if( ary[i] == a[j][0] && ary[i+1] == a[j][1] ) flag=true;
                else if( ary[i] == a[j][1] && ary[i+1] == a[j][0] ) flag=true;
            }
            if( !flag )
            {
                isRight = false;
                break;
            }
        }
        if(isRight)ans++;
    }
    while(next_permutation(all(ary)));
    
    cout << ans << endl;
}


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

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++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int K; cin >> K;
	vector<vpint> g(K);
	vint dist(K, -1);
	deque<pint> dq;
	rep(i,K) {
		g[i].pb(mp(i * 10 % K, 0));
		g[i].pb(mp((i + 1) % K, 1));
	}
	dq.push_back(mp(1,1));
	for (;;) {
		pint p = dq.front();
		dq.pop_front();
		int v = p.first;
		int d = p.second;
		if (dist[v] == -1 || d < dist[v]) {
			dist[v] = d;
			dq.push_front(mp(g[v][0].first, d));
			dq.push_back(mp(g[v][1].first, d + 1));
			if (v == 0) {
				break;
			}
		}
	}
	cout << dist[0] << endl;
	return 0;
}


Measured memory_bytes: 6912
#include <iostream>
int checked[40000][16];
long long dp[40000][16];
long long esum[40000];
using namespace std;
int eds[16][16];
int n,m;
long long calc(int state,int now);
long long calc_sub(int state_base,int state,int dep,int now,int prev) {
	if(dep==n) {
		return esum[state_base-state]+eds[now][prev]+calc(state,prev);
	}
	long long ret=0;
	if(dep==prev) {
		ret=calc_sub(state_base,state+(1<<dep),dep+1,now,prev);
	} else if(dep==now) {
		ret=calc_sub(state_base,state,dep+1,now,prev);
	} else {
		ret=calc_sub(state_base,state,dep+1,now,prev);
		if(state_base&(1<<dep)) {
			long long temp=calc_sub(state_base,state+(1<<dep),dep+1,now,prev);
			if(ret<temp) ret=temp;
		}
	}
	return ret;
}
long long calc(int state,int now) {
	if(checked[state][now]) return dp[state][now];
	checked[state][now]=1;
	if(now==0) {
		dp[state][now]=esum[state];
	} else {
		dp[state][now]=-1e16;
		for(int i=0;i<n;i++) {
			if((state&(1<<i))>0&&i!=now&&eds[i][now]>0) {
				long long temp=calc_sub(state,1,1,now,i);
				if(dp[state][now]<temp) dp[state][now]=temp;
			}
		}
	}
	return dp[state][now];
}
int main() {
	cin >> n >> m;
	for(int i=0;i<m;i++) {
		int va,vb,vc;
		cin >> va >> vb >> vc;
		va--; vb--;
		eds[va][vb]=vc;
		eds[vb][va]=vc;
	}
	for(int i=0;i<(1<<n);i++) {
		for(int j=0;j<n;j++) for(int k=j+1;k<n;k++) {
			if((i&(1<<j))>0&&(i&(1<<k))>0) esum[i]+=eds[j][k];
		}
	}
	cout << esum[(1<<n)-1]-calc((1<<n)-1,n-1) << endl;
	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
#include<iomanip>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
const int INF = 10000;

int r, n;
bool shade[30][50];

int main() {
  while (cin >> r >> n and r) {
    REP(y,30) REP(x,50) shade[y][x] = false;
    REP(y,30) shade[y][24-r] = shade[y][26+r] = true;
    REP(i,n) {
      int xl,xr,h;
      cin >> xl >> xr >> h;
      xl += 25, xr += 25;
      for (int x = xl; x < xr; ++x) REP(y,h) shade[y][x] = true;
    }
    vector<pair<int,int>> minh;
    for (int x = 25 - r; x < 25 + r; ++x) {
      int y = 0;
      while (shade[y][x] and shade[y][x-1]) y++;
      minh.push_back(make_pair(x,y));
    }
    double ans = INF;
    for (auto p : minh) {
      double x = p.first, y = p.second;
      ans = min(ans, y + (double)r - sqrt(r*r-(25-x)*(25-x)));
    }
    cout << fixed << setprecision(10) << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int calc(int x, int y, int z) {
    return (x * x + y * y + z * z + x * y + y * z + z * x);
}
int contribute(int x, int y, int z) {
    set<int> freq;
    freq.insert(x); freq.insert(y); freq.insert(z);
    if (freq.size() == 3)
        return 6;
    if (freq.size() == 2)
        return 3;
    return 1;
}

int main() {
    //  ios_base::sync_with_stdio(0); 
      //cin.tie(0); 
      //cout.tie(0);
      //freopen("input.txt", "r", stdin);
      //freopen("output.txt", "w", stdout);
    int T = 1;
    int val[100 * 100 + 5] = {};
    for (int x = 1; x < 100; x++) {
        for (int y = x ; y < 100; y++) {
            for (int z = y; z < 100; z++) {
                if (calc(x, y, z) > 100 * 100)
                    break;
              //  cout << x << " " << y << " " << z << " " << calc(x, y, z) << endl;
                val[calc(x, y, z)] += contribute(x, y, z);
            }
        }
    }



        scanf("%d", &T);
        for (int i = 1; i <=T; i++) {

            printf("%d\n", val[i]);
        }

    return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define int long long 
#define double long double 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(a) (a).begin(),(a).end()

using namespace std;

bool palli(string s){
	string temp = s;
	reverse(all(temp));
	return temp == s; 
}

signed main(){
	IOS;
	string s;
	cin >> s;
	if(!palli(s)){
		cout << "No" << endl ;
		return 0;
	}
	int n = (int)s.size() ; 
	string s1 = s.substr(0,n/2) , s2 = s.substr((n+3)/2-1,n-n/2);
       	if(palli(s1) and palli(s2)){
		cout << "Yes" << endl ; 
	}else{
		cout<< "No" << endl;
	}	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

int bal;
void solve(){
	rep(i,0,3){
		char ch;
		cin>>ch;
		if(ch == 'o') bal++;
	}
	cout<<bal*100+700<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(const int argc, const char *argv[])
{
    int64_t input;
    int64_t h, m, s;
    cin >> input;
    if (input < 0 || input >= 86400) {
        return 1;
    }
    h = input / (60 * 60);
    input = input % (60 * 60);
    m = input / 60;
    s = input % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}

Measured memory_bytes: 1164
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  string s;
  cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]=='1') cout<<9;
    else cout<<1;
  }
  cout<<endl;
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N = int(input())
    S = input().strip()
    
    v = 0
    R = 0
    G = 0
    B = 0
    for i in range(N):
        if S[i] == "R":
            R += 1
        elif S[i] == "G":
            G += 1
        else:
            B += 1

        if i == 0 or i == N - 1:
            continue

        for d in range(1, min(i, N - i - 1) + 1):
            if S[i] == S[i - d]:
                continue
            if S[i] == S[i + d]:
                continue
            if S[i - d] == S[i + d]:
                continue
            v += 1

    print(R * G * B - v)

if __name__ == "__main__":
    main()


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

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

struct edge {
    int from, to;
    ll weight;
};

using edges = vector<edge>;
using graph = vector<edges>;

constexpr ll INF = 1e18;

int main() {
    ll N, M, C;
    cin >> N >> M >> C;

    graph g(N);
    ll sum_cost = 0;
    for(int i=0; i<M; ++i) {
        int a, b;
        ll d;
        cin >> a >> b >> d;
        a--; b--;
        g[a].push_back((edge){a, b, d});
        g[b].push_back((edge){b, a, d});
        sum_cost += d;
    }

    vector<P> d(N);
    for(int i=1; i<N; ++i) {
        d[i] = make_pair(INF, i);
    }
    d[0] = make_pair(0, 0);
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(make_pair(0, 0));
    while(!que.empty()) {
        P p = que.top();
        int v = p.second;
        que.pop();
        if(d[v].first > p.first) {
            continue;
        }
        for(auto& e : g[v]) {
            if(d[e.to].first > d[v].first + e.weight) {
                d[e.to].first = d[v].first + e.weight;
                que.push(make_pair(d[e.to].first, e.to));
            }
        }
    }
    sort(d.begin(), d.end());
    ll res = 1e18;
    set<int> S;
    for(int i=0; i<N; ++i) {
        for(auto& e : g[d[i].second]) {
            if(S.count(e.to) == 1) {
                sum_cost -= e.weight;
            }
        }
        res = min(res, sum_cost + C * d[i].first);
        S.insert(d[i].second);
    }
    cout << res << endl;
}


Measured memory_bytes: 21980
using System;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var maxXplusY = long.MinValue;
            var maxXMinusY = long.MinValue;
            var minXplusY = long.MaxValue;
            var minXminusY = long.MaxValue;
            for (int i = 0; i < N; i++)
            {
                var xy = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                var x = xy[0]; var y = xy[1];
                if (x + y > maxXplusY) maxXplusY = x + y;
                if (x + y < minXplusY) minXplusY = x + y;
                if (x - y > maxXMinusY) maxXMinusY = x - y;
                if (x - y < minXminusY) minXminusY = x - y;
            }
            Console.WriteLine(Math.Max(maxXplusY - minXplusY, maxXMinusY - minXminusY));
        }
    }
}


Measured memory_bytes: 40608
# coding: utf-8


# def prime_set(limit=10**5):
#     """
#     2020/04/10
#     https://atcoder.jp/contests/abc084/tasks/abc084_d
#     """

#     ret = [2]
#     for x in range(3, limit+1, 2):
#         is_prime = True
#         sqrtx = int(pow(x, 0.5))

#         for p in ret:
#             if p > sqrtx:
#                 break

#             if x % p == 0:
#                 is_prime = False
#                 break

#         if is_prime:
#             ret.append(x)

#     return ret


def soinsubunkai(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def main():
    N = int(input())
    if N == 1:
        return 0
    # N = 148
    N_ = N

    # primes = prime_set(int(N**0.5)+1)
    # print(primes)

    # primes = prime_set(10**6)  # 1.3 sec
    # print(len(primes))  # 78498

    # soinsu = {}
    # for p in primes:
    #     print("="*10)
    #     print(p)
    #     if N == 1:
    #         break

    #     if N % p == 0:
    #         soinsu[p] = 1
    #         N = N // p
    #         while True:
    #             print(N)
    #             if N % p == 0:
    #                 soinsu[p] += 1
    #                 N = N // p
    #             else:
    #                 break

    soinsu_ = soinsubunkai(N)
    soinsu = {}
    for k, v in soinsu_:
        soinsu[k] = v
    
    # if len(soinsu.keys()) == 0 and N_ != 1:
    #     soinsu[N_] = 1
    # print(soinsu)

    counts = {}
    for cnt in soinsu.values():
        if cnt not in counts:
            counts[cnt] = 1
        else:
            counts[cnt] += 1
    # print(counts)

    ans = 0
    for k, v in counts.items():
        for n in range(int((2*k+0.25)**0.5) + 1, -1, -1):
            if n*(n+1) <= 2*k < (n+1)*(n+2):
                ans += n*v
                break
    
    return ans


print(main())


Measured memory_bytes: 9524
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

int main() {
  int n;
  long long h;
  cin >> n >> h;
  vector<long long> a(n), b(n);
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  auto it = upper_bound(b.begin(), b.end(), a[n - 1]);
  if(it == b.end()) {
    cout << (h + a[n - 1] - 1) / a[n - 1] << endl;
    return 0;
  }
  long long ans = 0;
  if(it == b.begin()) {
    for(int i = n - 1; i >= 0; i--) {
      ans++;
      h -= b[i];
      if(h <= 0) {
        cout << ans << endl;
        return 0;
      }
    }
  } else {
    it--;
    auto it2 = b.end();
    it2--;
    while(it2 != it) {
      ans++;
      h -= *it2;
      it2--;
      if(h <= 0) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << ans + (h + a[n - 1] - 1) / a[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;
const int mod = 1e9+7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(1000005);

int main()
{
    int x, y;
    cin >> x >> y;
    if((x + y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    int n = 0, m = 0;
    if( (2*x-y) < 0 || (2*y-x) < 0){
        cout << 0 << endl;
        return 0;
    }
    n = (2*x-y) / 3;
    m = (2*y-x) / 3;

    mint ans = 0;
    ans = comb(n + m, m);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18644
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    ll n,k;
    cin >> n >> k;
    ll x = n % k;
    ll y = k - x;
    ll ans = min(x,y);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

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

    vector<int> v(n);
    for(auto& i : v) cin >> i;

    sort(all(v));
    ll ans = 1;

    if(n%2 == 0){
        for(int i=0; i<n; i+=2){
            if(v[i] == i+1 && v[i+1] == i+1){
                ans *= 2;
                ans %= MOD;
            }else{
                ans = 0;
                break;
            }
        }
    }else{
        if(v[0] != 0){
            ans = 0;
        }else{
            for(int i=1; i<n; i+=2){
                if(v[i] == i+1 && v[i+1] == i+1){
                    ans *= 2;
                    ans %= MOD;
                }else{
                    ans = 0;
                    break;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

nums = divisor(n)
total = []
for i in range(len(nums)):
    s = int(n/nums[i])
    total.append(s-1 + nums[i]-1)

print(min(total))

Measured memory_bytes: 39664
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,m,s,t,ans,tot,gap[21000],dis[21000];
char a[110][110];
struct edge
{
    int v,f;
    edge *nxt,*rev;
} pool[100100],*tp=pool,*fst[21000],*cur[21000];

void addedge(int u,int v,int f)
{
    *tp=(edge){v,f,fst[u],tp+1},fst[u]=tp++;
    *tp=(edge){u,0,fst[v],tp-1},fst[v]=tp++;
}

int sap(int x,int flow)
{
    if (x==t)
        return flow;
    int sum=0,f;
    for (edge *i=cur[x]; i; i=i->nxt)
        if (i->f && dis[x]==dis[i->v]+1)
        {
            f=sap(i->v,min(i->f,flow));
            i->f-=f,i->rev->f+=f,cur[x]=i;
            if ((sum+=f)==flow || dis[s]==tot)
                return sum;
        }
    if (!--gap[dis[x]])
        dis[s]=tot;
    ++gap[++dis[x]],cur[x]=fst[x];
    return sum;
}

int main()
{
    scanf("%d%d",&n,&m);
    repu(i,1,n)
        scanf("%s",a[i]+1);
    repu(i,1,n)
        repu(j,1,m)
            if (a[i][j]!='.')
            {
                int p=(i-1)*m+j;
                addedge(p,p+n*m,1);
                addedge(n*m*2+i,p,1<<30);
                addedge(n*m*2+n+j,p,1<<30);
                addedge(p+n*m,n*m*2+i,1<<30);
                addedge(p+n*m,n*m*2+n+j,1<<30);
                if (a[i][j]=='S')
                    s=p+n*m;
                if (a[i][j]=='T')
                    t=p;
            }
    gap[0]=tot=n*m*2+n+m;
    repu(i,1,tot)
        cur[i]=fst[i];
    for (; dis[s]<tot; ans+=sap(s,1<<30));
    printf("%d\n",ans<1<<30?ans:-1);
    return 0;
}

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

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;

		vector<bool> a(2*n, false), b(2*n);
		for(int i=0; i<n; i++){
			int num;
			cin >> num;
			a[num-1] = true;
		}
		for(int i=0; i<2*n; i++){
			b[i] = !a[i];
		}
		int an=n, bn=n;
		int turn=0, curr=0;
		while(an!=0 and bn!=0){
			bool skip = true;
			for(; curr<2*n; curr++){
				if(a[curr]){
					an--;
					a[curr] = false;
					skip = false;
					break;
				}
			}
			if(skip){
				curr = 0;
			}
			swap(a, b);
			swap(an, bn);
			turn++;
		}
		if(turn%2==1){
			swap(an, bn);
		}
		cout << bn << endl << an << endl;
	}
	return 0;
}



Measured memory_bytes: 3096
N = gets.to_i
S = gets.chomp

A = ["A", "B", "C", "D", "E", "F", "G", \
     "H", "I", "J", "K", "L", "M", "N", \
     "O", "P", "Q", "R", "S", "T", "U", \
     "V", "W", "X", "Y", "Z"]

ans = []

S.length.times do |i|
  j = A.index(S[i])
  if j + N < A.length then
    ans << A[j + N]
  else
    ans << A[j + N - A.length]
  end
end

puts ans.join


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

map<string,int>mp;
int mx; string ans[200050]; int lans = 0;
int n; string S[200050];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for (int i = 1; i <= n; ++i){
		cin>>S[i];
		if (!mp.count(S[i])) mp[S[i]] = 1; else mp[S[i]]++;
		mx = max(mx,mp[S[i]]);
	}
	for (int i = 1; i <= n; ++i) if (mp[S[i]]==mx){
		ans[++lans] = S[i]; mp[S[i]] = 0;
	}
	sort(ans+1,ans+lans+1);
	for (int i = 1; i <= lans; ++i) cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 27008
import collections

n=int(input())
li = list(map(int,input().split()))
cli = collections.Counter(li)
cli_values = tuple(cli.values())

count = 0

for cli_value in cli_values:
    if cli_value > 1:
        count += (cli_value * (cli_value-1))//2

for k in range(n):
    tmp = cli[li[k]]
    answer = count - (tmp * (tmp-1))//2 + ((tmp-1) * (tmp-2))//2
    print(answer)


Measured memory_bytes: 26780
#include <cstdio>
#include <cmath>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(val) cout << "!!!" << #val << ": " << val << endl
#define mod 1000000007
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {

    LL n, k;
    cin >> n >> k;

    vector<LL> v(n);
    rep(i, n) {
        cin >> v[i];
    }
    LL ans = LLONG_MAX;
    rep(i, n - k + 1) {
        LL l = i;
        LL r = i + k - 1;
        ans = min (ans, min(abs(v[l]) + abs(v[r] - v[l])
                            , abs(v[r]) + abs(v[r] - v[l])));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
    int n;
    cin >> n;
    vector<int> v;
    
    for (int i = 0; i < n; i++){
	  int x;
	  cin >> x;
	  v.push_back(x);	
	}	
	int mx = 0;
	int cnt = 0;
	for (int i = 0; i + 1 < n; i++){
	  if (v[i] >= v[i + 1]) cnt++;
	  else cnt = 0;
	  mx = max(mx, cnt);
	}
   cout << mx << endl;
 }

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };

signed main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a+b+c>=22) cout << "bust" << endl;
  else cout << "win" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  // d = n - a - b - c
  int n,cnt;
  while(cin >> n){
    cnt=0;
    for(int a=0;a<10;a++){
      for(int b=0;b<10;b++){
	for(int c=0;c<10;c++){
	  if(a+b+c>n)break;
	  for(int d=0;d<10;d++){
	    if(a+b+c+d == n)cnt++;
	  }
	}
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1160
#include <stdio.h>
int main()
{
	int i,n,k,a[100000],c=0;
	scanf("%d",&n);
	scanf("%d",&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	
		if(a[i]>=k)
		{
			c = c+1;
		}
    }
	printf("%d",c);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<cmath>
using namespace std;
long long N = 10000, Debug = 0;
bool okiniiri(long long p1, long long p2) {
	string S1 = to_string(p1), S2 = to_string(p2);
	if (p1 <= p2 && S1 <= S2)return true;
	if (p1 > p2 && S1 > S2)return true;
	return false;
}
bool solve(long long pos) {
	cout << "? " << pos << endl;
	if (Debug == 1) {
		bool V = okiniiri(pos, N);
		if (V == true) { cout << "Y" << endl; }
		else cout << "N" << endl;
		return V;
	}
	else {
		char c; cin >> c;
		if (c == 'Y')return true;
	}
	return false;
}
int main() {
	long long E = 1, F = -1;
	for (int i = 1; i <= 11; i++) {
		if (solve(E) == false) { F = i - 1; break; }
		E *= 10;
	}
	if (F == -1) {
		E = 1;
		for (int i = 1; i <= 11; i++) {
			E *= 10;
			if (solve(E - 1) == true) {
				cout << "! " << E / 10 << endl;
				return 0;
			}
		}
	}
	long long P = 1;
	for (int i = 1; i < F; i++)P *= 10;
	long long L = P * 10, R = P * 100, M, maxn = P * 10 - 1;
	for (int i = 0; i < 42; i++) {
		M = (L + R) / 2;
		bool p1 = solve(M);
		if (p1 == false) { maxn = max(maxn, M); L = M; }
		else { R = M; }
	}
	cout << "! " << (maxn + 1) / 10 << endl;
	return 0;
}

Measured memory_bytes: 656
var
	n,i,x:Longint;
	ans,a,b:int64;
begin
	read(n,x,a);
	if a>x then begin
		ans:=a-x;
		a:=x;
	end;
	for i:=2 to n do begin
		read(b);
		if a+b>x then begin
			inc(ans,a+b-x);
			dec(b,a+b-x);
		end;
		a:=b;
	end;
	writeln(ans);
end.


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

int main() {
	int n;
	cin >> n;
	vector<int> d1(n),d2(n);
	rep(i,n) cin >> d1[i] >> d2[i];
	for(int i=0; i <= n-3;i++) {
		if (d1[i] == d2[i] && d1[i+1] == d2[i+1] && d1[i+2] == d2[i+2]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


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

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<ll> t(n);
    for (int i = 0; i < n; i++)
        cin >> t[i];

    ll ans = t[0];
    for (int i = 1; i < n; i++)
    {
        ans = lcm(ans, t[i]);
    }

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int n,a,b,t,ans;
int main()
{
    scanf("%d %d %d",&n,&a,&b);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&t);
        if(t<a || t>=b)++ans;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 1e6+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}

int dp[N];
vector <int> G[N];

int cmp(int a,int b){
	return dp[a]<dp[b];
}

void dfs(int i){
	REP(j,G[i].size()){
		dfs(G[i][j]);
	}
	int cnt = 1;
	sort(all(G[i]),cmp);
	for(int j=(int)G[i].size()-1;j>=0;j--){
		dp[i] = max(dp[i],dp[G[i][j]]+cnt); cnt++;
	}
}


int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	int n;
	scanf("%d",&n);
	REPP(i,1,n){
		int x; scanf("%d",&x); x--;
		G[x].pb(i);
	}
	dfs(0);
	printf("%d\n",dp[0]);
	return 0;
}




Measured memory_bytes: 31872
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  int n;
  cin >> n;
  REP(i,n) {
    double xa,ya,ra,xb,yb,rb;
    cin>>xa>>ya>>ra>>xb>>yb>>rb;
    double d2 = (xa-xb)*(xa-xb) + (ya-yb)*(ya-yb);
    if((ra+rb)*(ra+rb) < d2) {
      cout << 0 << endl;
    } else if(ra > sqrt(d2) + rb) {
      cout << 2 << endl;
    } else if(rb > sqrt(d2) + ra) {
      cout << -2 << endl;
    } else {
      cout << 1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1240
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

int N;

vector<string> ans;

void add_string(string now,int ns){//nsはすでに出てきた文字の種類数
	if(now.size()==N){
		ans.push_back(now);
		return;
	}
	string ret = now;
	for(int i=0;i<=ns;i++){
		add_string(now+char(i+'a'),max(ns,i+1));
		//add_string(now+char(i+'a'),i+1);
		//これだと例えばN=4の時
		//abac　のような文字列が生成できない
		//1. add_string("ab",3) が呼び出される
		//2. この時for(int i=0;i<=ns(この時ns=3);i++)内でi=0の時
		//3. add_string("aba",1)が呼ばれるが、
		//4. add_string("aba",3)としないとcがくっつかなくなってしまう
	}
}

void solve(){
	add_string("a",1);
}
 
int main(){
	cin >> N;
 
	solve();

	for(int i=0;i<ans.size();i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define  mx 100005
#define  ll long long
#define  pii pair<int,int>
#define  debug printf("%d\n", bug++);
#define  For(i,n) for(ll i = 0; i < (n); ++i)
#define  INF 1 << 30
#define pb(x) push_back(x)
#define  mod  1000000007
#define PI acos(-1)
#define line printf("\n");
using  namespace std;
vector<int>g[mx] , blck[mx] , visited ;
int ans[mx] , vis[mx] , curr_vis[mx];
int cnt = 0 ;
void dfs(int u){
    visited.push_back(u);
    cnt++;
    vis[u]++;
    curr_vis[u]++;
    for(auto i : g[u]){
        ans[u]--;
        if(!vis[i])
            dfs(i);

    }
}
int main(){
    int n ,m, k;
    cin >> n >> m >> k;
    for(int i = 0 ; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for(int i = 0 ; i < k ;++i){
        int x,y;
        cin >> x >>y;
        blck[x].push_back(y);
        blck[y].push_back(x);
    }
    for(int i = 1 ; i <= n; ++i){
        if(!vis[i]){
            cnt = 0 ;
            dfs(i);
            for(auto  j : visited) {
                ans[j] += (cnt - 1);
            }
            for(auto j : visited){
                for(auto item : blck[j]){
                    if(curr_vis[item])
                        ans[j]--;
                }
            }
            for(auto j : visited)
                curr_vis[j] = 0;
            visited.clear();

        }
    }
    for(int i = 1; i <= n; ++i)
        cout << ans[i] << " ";
    line
}


Measured memory_bytes: 13820
from collections import deque

try:
    while True:
        a = list(sorted(map(int, input())))
        result = []

        for i in range(1, 10):
            if a.count(i) == 4:
                continue

            _a = sorted(a+[i])
            dq = deque([(_a, 0)])
            while dq:
                hand, mentu = dq.popleft()
                if mentu == 5:
                    if not hand:
                        result.append(i)
                        break
                    continue
                elif mentu > 5:
                    continue

                current = hand[0]
                if hand.count(current) >= 2:
                    dq.append((hand[2:], mentu+1))
                if hand.count(current) >= 3:
                    dq.append((hand[3:], mentu+1))
                if current+1 in hand and current+2 in hand:
                    _hand = hand[:]
                    del _hand[0]
                    del _hand[_hand.index(current+1)]
                    del _hand[_hand.index(current+2)]
                    dq.append((_hand, mentu+1))

        print(" ".join(map(str, result)) if result else 0)


except EOFError:
    exit()



Measured memory_bytes: 6008
from heapq import heappush, heappop

def solve():
    N, M = map(int, input().split())
    A = []
    for _ in range(N):
        a, b = list(map(int, input().split()))
        if a > M:
            continue
        A.append((a, b))
    A.sort(reverse=True)
    
    q = []
    count = 0
    for i in range(1, M+1):
        while A and A[-1][0] <= i:
            a, b = A.pop()
            heappush(q, -b)
        if q:
            c = -heappop(q)
            count += c
    
    return count

print(solve())

Measured memory_bytes: 17188
mod = 10 ** 9 + 7

SIZE = 10 ** 5 + 5
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
fact[0], fact[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1
for i in range(2, SIZE):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def nCr(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod


from collections import Counter


n = int(input())
A = list(map(int, input().split()))
counterA = Counter(A)
duplicate = 0
for num, count in counterA.items():
    if count == 2:
        duplicate = num
        break

duplicate_pos = []
for i, a in enumerate(A):
    if a == duplicate:
        duplicate_pos.append(i)

first, second, *_ = duplicate_pos

for k in range(1, n+2):
    base = nCr(n+1, k)
    duplicate_pattern = nCr(first + n-second, k-1)
    print((base - duplicate_pattern) % mod)



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N,P;
  string S;
  cin>>N>>P>>S;
  vector<ll>s(N);
  for(int i=0;i<N;i++)s[i]=S[i]-'0';
  if(P==2){
    ll ans=0;
    for(int i=0;i<N;i++)if(s[i]%2==0)ans+=i+1;
    cout<<ans<<endl;
    return 0;
  }
  if(P==5){
    ll ans=0;
    for(int i=0;i<N;i++)if(s[i]==5||s[i]==0)ans+=i+1;
    cout<<ans<<endl;
    return 0;
  }
  reverse(rng(s));
  vector<ll>a(N);
  a[0]=s[0]%P;
  ll memo=10;
  for(int i=1;i<N;i++){
    a[i]=(a[i-1]%P+(s[i]*memo)%P)%P;
    memo=(memo*10)%P;
  }
  map<int,ll>m;
  m[0]++;
  for(int i=0;i<N;i++)m[a[i]]++;
  ll ans=0;
  for(int i=0;i<P;i++)ans+=(m[i]*(m[i]-1))/2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4116
import java.util.Scanner;

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

		// 入力値の取得
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		
		int count = 0;
		
		// 結果の出力
		for (int i = 0; i < S.length; i++) {
			if (S[i] != T[i]) {
				count++;
			}
		}
		System.out.println(count);
		
		sc.close();
	}
}


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

int main() {
  IN (int, N);
  IN (int, X);
  IN (int, K);
  int ans = N / X;
  if (N % X != 0) ans++;
  cout << ans * K << endl;

  return 0;
}


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

int main(){
  string a;
  cin >> a;
  int q;
  cin >> q;
  bool is_reverse = false;
  deque<char> fr,ba;
  for(int i=0; i<q; i++){
    int ti; cin >> ti;
    if(ti==1){
      is_reverse = !is_reverse;
      continue;
    }
    int fi; cin >> fi;
    char ci; cin >> ci;
    if((fi==2&&!is_reverse)||(fi==1&&is_reverse)) a.insert(a.end(), ci);
    else a.insert(a.begin(), ci);
  }
  if(is_reverse) reverse(a.begin(), a.end());
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 904
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;

bool cmp(pair<lli,lli> & a, pair<lli,lli> & b)
{
    return a.first > b.first;
}

lli solve(vector<pair<lli, lli>> & v, lli n)
{
    set<lli> free;
    lli ans = 0;
    
    for(int i=1;i<=n;i++) free.insert(i);
    
    for(auto [val, pos] : v)
    {
        auto it = free.upper_bound(pos);
        
        if(it != free.begin())
        {
            it--;
            ans += val;
            free.erase(*it);
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli t;
    cin>>t;
    while(t--)
    {
        lli n;
        cin>>n;
        lli i, k[n+1], l[n+1], r[n+1], ans=0;
        vector<pair<lli,lli>> v1, v2;
        
        for(i=1;i<=n;i++) cin>>k[i]>>l[i]>>r[i];
        
        for(i=1;i<=n;i++)
        {
            if(l[i] > r[i]) v1.push_back({l[i] - r[i], k[i]}), ans += r[i];
            else            v2.push_back({r[i] - l[i], n - k[i]}), ans += l[i];
        }
        
        sort(v1.begin(), v1.end(), cmp);
        sort(v2.begin(), v2.end(), cmp);
        
        
        cout<<ans + solve(v1, n) + solve(v2, n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 20380