akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mxn=1000010;
int N,M,K,head[mxn],dfn[mxn],low[mxn],stk[mxn],exist[mxn],F[mxn],tot,tp;
struct ed{int to,nxt;}edge[mxn];
void addedge(int u,int v){
	edge[++M]=(ed){v,head[u]},head[u]=M;
}
void dfs(int u){
	dfn[u]=low[u]=++tot;
	stk[++tp]=u,exist[u]=1;
	for (int i=head[u],v;i;i=edge[i].nxt)
		if (!dfn[v=edge[i].to]) dfs(v),low[u]=min(low[u],low[v]);
		else if (exist[v]) low[u]=min(low[u],dfn[v]);
	if (dfn[u]==low[u]){
		++K;
		for (;stk[tp+1]!=u;)
			F[stk[tp]]=K,exist[stk[tp--]]=0;
	}
}
void sat_solve(){
	tot=K=0;
	memset(dfn,0,sizeof(dfn));
	memset(stk,0,sizeof(stk));
	for (int i=1;i<=N;++i)
		if (!dfn[i]) dfs(i);
}
#define ls (i<<1)
#define rs (i<<1|1)
#define mid ((l+r)>>1)
int n,tr[mxn],a[mxn],b[mxn];
void link(int i,int l,int r,int x,int y,int u){
	if (r<x||l>y) return;
	if (l>=x&&r<=y) return addedge(u,tr[i]);
	link(ls,l,mid,x,y,u),link(rs,mid+1,r,x,y,u);
}
void build(int i,int l,int r){
	tr[i]=++N;
	if (l==r) return addedge(tr[i],(a[l]+n-1)%(n<<1)+1);
	build(ls,l,mid),build(rs,mid+1,r);
	addedge(tr[i],tr[ls]),addedge(tr[i],tr[rs]);
}
bool check(int k){
	for (int i=1;i<=n<<1;++i){
		int l=1,r=i-1;
		for (;l<=r;)
			if (b[a[i]]-b[a[i-mid]]<k) l=mid+1;
			else r=mid-1;
		if (r) link(1,1,n<<1,i-r,i-1,a[i]);
		for (l=1,r=(n<<1)-i;l<=r;)
			if (b[a[i+mid]]-b[a[i]]<k) l=mid+1;
			else r=mid-1;
		if (r) link(1,1,n<<1,i+1,i+r,a[i]);
	}
	sat_solve();
	for (int i=1;i<=n;++i)
		if (F[i]==F[n+i]) return 0;
	return 1;
}
bool cmp(const int &x,const int &y){
	return b[x]<b[y];
}
int _N,_M,_head[mxn];
void clr(){
	for (int i=1;i<=N;++i) head[i]=_head[i];
	N=_N,M=_M;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%d%d",&b[i],&b[n+i]);
	for (int i=1;i<=n<<1;++i) a[i]=i;
	sort(a+1,a+(n<<1)+1,cmp);
	N=2*n;
	build(1,1,2*n);
	_N=N,_M=M;
	for (int i=1;i<=N;++i)
		_head[i]=head[i];
	int l=0,r=1e9;
	for (;l<=r;clr())
		if (check(mid)) l=mid+1;
		else r=mid-1;
	printf("%d\n",r);
	return 0;
}

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

int main(void) {
    int H,A; cin >> H >> A;
    int ans=0;
    while(H>0) {
        H-=A;
        ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

int main(){
	int n;

	cin >> n;
	
	map<string, ll> sv;
	ll cnt = 0;

	for (size_t i = 0; i < n; ++i) {
		string s;
		cin >> s;

		sort(begin(s), end(s));


		if (sv.count(s) != 0) {
			sv.at(s) += 1;
		} else {
			sv.insert(make_pair(s, 1));
		}
	}
	
	for (auto p : sv) {
		if (p.second > 1) {
			cnt += p.second * (p.second - 1) / 2;
		}
	}
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 11136
from collections import defaultdict
from fractions import gcd
#from math import factorial
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
class UnionFindNode(object):
    """
    Union-Find構造
    ノードのグループ併合や、所属グループ判定を高速に処理する
    """

    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.size_ = 1

    def __str__(self):
        template = "UnionFindNode(group_id: {}, \n\tparent: {}, value: {}, size: {})"
        return template.format(self.group_id_, self.parent_, self.value, self.size_)

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        parent = self.root()
        return parent.group_id_

    def size(self):
        parent = self.root()
        return parent.size_

    def unite(self, unite_node):
        parent = self.root()
        unite_parent = unite_node.root()

        if parent.group_id_ != unite_parent.group_id_:
            if parent.size() > unite_parent.size():
                unite_parent.parent_ = parent
                parent.size_ = parent.size_ + unite_parent.size_
            else:
                parent.parent_ = unite_parent
                unite_parent.size_ = parent.size_ + unite_parent.size_


N,K,L=map(int,input().split())
inf1=[]
for _ in range(K):
    inf1.append(list(map(int,input().split())))
inf2=[]
for _ in range(L):
    inf2.append(list(map(int,input().split())))
U=[UnionFindNode(i) for i in range(N+1)]
for i in range(K):
    x=inf1[i][0]
    y=inf1[i][1]
    U[x].unite(U[y])
U_=[UnionFindNode(i) for i in range(N+1)]
for i in range(L):
    x=inf2[i][0]
    y=inf2[i][1]
    U_[x].unite(U_[y])
d=defaultdict(int)
for i in range(1,N+1):
    k=(U[i].find(),U_[i].find())
    d[k]+=1
ans=[]
for i in range(1,N+1):
    k=(U[i].find(),U_[i].find())
    ans.append(d[k])
print(" ".join(map(str,ans)))


Measured memory_bytes: 139644
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<pll> X;   //要素、添え字
vector<ll> ans;

int main() {
	cin >> N;
	X.resize(N);
	for (ll n = 0; n < N; n++) {
		cin >> X[n].first;
		X[n].second = n;
	}
	sort(X.begin(), X.end(), [](pll a, pll b) {
		return a.first < b.first;
	});
	ans.resize(N, 0);
	for (ll n = 0; n < N/2; n++) {
		ans[X[n].second] = X[N / 2].first;
	}
	for (ll n = N / 2; n < N; n++) {
		ans[X[n].second] = X[N / 2 - 1].first;
	}
	for (ll n = 0; n < N; n++)cout << ans[n] << endl;
	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;
typedef pair<ll, ll> PL;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}

ll n, m;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin >> n>>m;
	vector<PL> a(n + m);
	rep(i,0,n){
		ll temp;
		cin >> temp;
		a.push_back(PL(temp, 1));
	}
	rep(i,0,m){
		ll b, c;
		cin >> b >> c;
		a.push_back(PL(c, b));
	}
	sort(a.begin(), a.end(), greater<PL>());
	ll ans = 0;
	ll cnt = 0;
	rep(i, 0, n){
		ll b = a[i].first;
		ll c = a[i].second;
		if(cnt+c>=n){
			ans += b * (n - cnt);
			break;
		}
		cnt += c;
		ans += c * b;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 8448
a, b = map(int, input().split())

n = int(a/float(0.08))
m = int(b/float(0.10))

if int(n*float(0.08)) == a:
  n = n
else:
  n += 1

if int(m*float(0.10)) == b:
  m = m
else:
  m += 1
  
if int(n*float(0.10)) == b and int(m*float(0.08)) != a:
  print(n)
elif int(n*float(0.10)) != b and int(m*float(0.08)) == a:
  print(m)
elif int(n*float(0.10)) == b and int(m*float(0.08)) == a:
  print(min(n, m))
else:
  print('-1')

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (b - a == c - b) System.out.println("YES");
        else System.out.println("NO");
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

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

const ll mod = 1e9 + 7;

void makedist(map<pll,ll> &dist,ll i,ll j,ll k){
    dist[mp(min(i, j), max(i, j))] =
        min(dist[mp(min(i, j), max(i, j))],
            dist[mp(min(i, k), max(i, k))] + dist[mp(min(j, k), max(j, k))]);
    return;
}

int main(){
    ll N, M;
    ll inf = 1e15;
    cin >> N >> M;
    ll a, b, c;
    vector<vector<ll>> branch(M, vector<ll>(3, 0));
    rep(i,M){
        cin >> a >> b >> c;
        branch[i][0] = a - 1;
        branch[i][1] = b - 1;
        branch[i][2] = c;
    }
    map<pll, ll> dist;
    rep(i,N){
        repf(j,i,N){
            if (i==j){
                dist[mp(i,j)] = 0;
            }
            else{
                dist[mp(i, j)] = inf;
            }
        }
    }
    rep(m,M){
        ll i, j, d;
        i = min(branch[m][0], branch[m][1]);
        j = max(branch[m][0], branch[m][1]);
        d = branch[m][2];
        dist[mp(i, j)] = min(dist[mp(i, j)], d);
    }
    rep(k,N){
        rep(i,N){
            rep(j,N){
                makedist(dist,i,j,k);
            }
        }
    }
    ll ans = 0;
    /* 
    rep(i,N){
        rep(j,N){
            cout << min(i, j) << " " << max(i, j) << endl;
            cout << dist[mp(min(i, j), max(i, j))] << endl;
        }
    }*/
    rep(m, M)
    {
        ll i, j, d;
        i = min(branch[m][0], branch[m][1]);
        j = max(branch[m][0], branch[m][1]);
        d = branch[m][2];
        if (dist[mp(i,j)]<d){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N;
    cin >> N;
    vector<int> A(N, 0);
    int tmp;
    vector<vector<pair<int, int> > > hon;
    int tmp1, tmp2;
    rep(i, N) {
        cin >> tmp;
        vector<pair<int, int> > x(tmp);
        rep(j, tmp) {
            cin >> tmp1 >> tmp2;
            x[j] = make_pair(--tmp1, tmp2);
        }
        hon.push_back(x);
    }
    int ans = 0;
    int tmp3;
    rep(i, 1 << N) {
        tmp3 = 0;
        rep(j, N) {
            A[j] = (i & (1 << j)) >> j;
            tmp3 += A[j];
            //cout << A[j] << '\t';
        }
        //cout << endl;
        bool flag = true;
        // check if valid
        rep(j, hon.size()) {
            if(A[j] == 0) continue;
            rep(k, hon[j].size()) {
                tmp1 = hon[j][k].first;
                tmp2 = hon[j][k].second;
                if (A[tmp1] != tmp2) {
                    //cout << A[tmp1] << ' ' << tmp2 << endl;
                    flag = false;
                }
            }
        }
        if (flag) ans = max(ans, tmp3);
    }
    cout << ans << endl;


	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int a, b, p = 0;
      cin >> a >> b;
      int ans = 1;
      for (int i = 0; i < a; i++) {
        int t; cin >> t;
        p += t;
        if (p <= b) ans++;
      }
      cout << ans << endl;
    }

Measured memory_bytes: 256
#include <stdio.h>

int main(){
   char number[1001];
   int i, sum;
   while(1){
       scanf("%s", number);
       if(number[0]=='0')break;
       sum=0;
       for(i=0;number[i]!='\0';i++){
           sum+=number[i]-'0';
       }
       printf("%d\n", sum);
   }

   return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}


#define MAX_N 200005

class UnionFind
{
public:
  int par[MAX_N];
  int depth[MAX_N];
  int nGroup[MAX_N];

  UnionFind(int n) {
    init(n);
  }

  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }

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

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

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
  }
  int ans = 0;
  rep(i, n) {
    chmax(ans, uf.nGroup[uf.root(i)]);
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 5936
n = int(input())
uv = [tuple(map(int, input().split())) for _ in range(n-1)]

ans = 0
for nn in range(1, n+1):
    ans += nn * (n-nn+1)

for u, v in uv:
    if u > v:
        u, v = v, u
    ans -= u * (n - v + 1)
print(ans)


Measured memory_bytes: 36048
import java.util.*;
public class Main {
     public static void main(String [] args){
        Scanner input = new Scanner(System.in);
       
        int mount[] = new int[10];
        
        for(int i = 0; i <mount.length; i++)
            mount[i] = input.nextInt();
         
        Arrays.sort(mount);
        //System.out.println(Arrays.toString(mount));
        
        int max1 = mount[mount.length-1];
        int max2 = mount[mount.length-2];
        int max3 = mount[mount.length-3];
        
        //System.out.println(Arrays.toString(mount));
        //System.out.println(Arrays.sort(mount));
        /*       
        for(int i = 0; i <mount.length; i++){
            if(mount[i]>max1)
                max1=mount[i];
        }
        */
        
           System.out.println(max1);
           System.out.println(max2);
           System.out.println(max3);
      }
}



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

int main()
{
	int a, b;
	while(cin >> a >> b){
		if(a % 10 != a || b % 10 != b){
			cout << "-1" << endl;
			continue;
		}
		else
		    cout << a * b << endl;
	}
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1'000'000'007LL;
const ll M = 128;
const ll X = 32768; // >= sqrt(N)

ll a[M][X], b[M][X];
int main(){
	int N, K; scanf("%d%d", &N, &K);
	for(int i=1; i<X; i++){
		a[1][i] = min(i, N);
		b[1][i] = N/i;
	}
	for(int m=2; m<=K; m++){
		a[m][0]=0;
		for(int i=1; i<X; i++){
			a[m][i] = ( a[m][i-1] + b[m-1][i] ) % MOD;
		}
		b[m][X-1]= a[m][N/(X-1)];
		for(int i=X-2; i>=1; i--){
			b[m][i] = ( b[m][i+1] + a[m-1][i] * (N/i - N/(i+1)) ) % MOD;
		}
	}
	printf("%lld\n", b[K][1]);
}


Measured memory_bytes: 53248
a,b,k = [int(i) for i in input().split()]
jougen = a+k-1
kagen = b-k+1

if jougen>=kagen:
  for i in range(a,b+1):
    print(i)
    
else:
  for i in range(a,jougen+1):
    print(i)
  for i in range(kagen,b+1):
    print(i)
    
 

Measured memory_bytes: 3060
n, k = map(int, input().split())
mod0 = []
mod2 = []
for i in range(1, n + 1):
    if i % k == 0:
        mod0.append(i)
    elif k % 2 == 0 and i % k == k // 2:
        mod2.append(i)
print(len(mod0) * len(mod0) * len(mod0) + len(mod2) * len(mod2) * len(mod2))


Measured memory_bytes: 10940
/*
*
*   Bismillah Hir Rahman Nir Raheem
*   Name: Jaied Al Sabid
*
*/
#include <bits/stdc++.h>

using namespace std;

#define pf printf
#define sf scanf
#define elif else if
#define unint unsigned int
#define sint short int
#define lint long long int
#define Size 100000

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    double x,y;
    cin>>x>>y;
    cout<<(int)ceil(x/y)<<endl;
    return 0;
}


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

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

struct State {
  int var, x, y, dir;
  State(int v, int _x, int _y, int d) : var(v), x(_x), y(_y), dir(d) {}
};

string s[22];
int row, col, dp[22][22][6];

inline int c2dir(char c) {
  return c == '^' ? 0 : ( c == '>' ? 1 : ( c == 'v' ? 2 : 3 ) );
}

inline int c2i(char c) { return 0 + (c - '0'); }

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

int main() {
  cin >> row >> col;
  rep (i,row) cin >> s[i];
  memset(dp, 0, sizeof dp);
  bool will_be_stopped = false;
  
  queue<State> q;
  q.push(State(0, 0, 0, 1));

  while (!q.empty()) {
    State i = q.front(); q.pop();
    if (dp[i.y][i.x][i.dir] >> i.var & 1) continue;
    dp[i.y][i.x][i.dir] |= (1 << i.var);
    char c = s[i.y][i.x];

    if (c == '>' || c == '<' || c == '^' || c == 'v') {
      i.dir = c2dir(c);
    } else if (c == '_' || c == '|') {
      i.dir = c == '_' ? (i.var == 0 ? 1 : 3 ) : (i.var == 0 ? 2 : 0);
    } else if (c == '?') {
      rep (j,4) {
        int tx = i.x + dx[j], ty = i.y + dy[j];
        if (tx == -1) { tx = col-1; } else if (tx == col) { tx = 0; }
        if (ty == -1) { ty = row-1; } else if (ty == row) { ty = 0; }
        if (tx < 0 || ty < 0 || tx >= col || ty >= row) continue;
        q.push(State(i.var, tx, ty, j));
      }
      continue;
    } else if (c == '@') {
      will_be_stopped = true; break;
    } else if (c == '+' || c == '-') {
      c == '+' ? i.var++ : i.var--;
      if (i.var == -1) i.var = 15;
      else if (i.var == 16) i.var = 0;
    } else if (c == '.') {
    } else if (c >= '0' && c <= '9') {
      i.var = c2i(c);
    }
    
    int nx = dx[i.dir] + i.x, ny = dy[i.dir] + i.y;
    if (nx == -1) { nx = col-1; } else if (nx == col) { nx = 0; }
    if (ny == -1) { ny = row-1; } else if (ny == row) { ny = 0; }
    q.push(State(i.var, nx, ny, i.dir));
  }
  
  printf("%s\n", (will_be_stopped) ? "YES" : "NO" );
  
  return 0;
}

Measured memory_bytes: 0
import itertools

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def main():
    A, B = map(int, input().split())
    a = set(make_divisors(A))
    b = set(make_divisors(B))
    ans = 0
    union_ab = a & b
    #print(union_ab)
    tmp = [1]
    for s in union_ab:
        if s >= 4 and s%2 == 0:
            continue
        if len(make_divisors(s)) == 2:
            tmp.append(s)
    #print(tmp)
    ans = len(tmp)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5176
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	string S;
	cin >> S;

	if (S.length() == 2) {
		cout << S << endl;
	}
	else {
		reverse(S.begin(), S.end());
		cout << S << endl;
	}

}






Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {
  int count = 0;
  public static void main(String[] args) {
    new Main().run();
  }
  public void run() {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int Z = sc.nextInt();
    X = X - Z;
    while(X >= 0){
      X = X - (Y + Z);
      count++;
    }
    if(count == 0){
      System.out.println(0);
    }else{
      System.out.println(count - 1);
    }
  }
}


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

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.size() / 2) {
        if (s[i] != s[s.size() - 1 - i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main() {

    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> v(n);
    for(int i=0;i<n;i++)
     cin>>v[i];
     vector<int> dp(n,-1);
     dp[0]=0;
     for(int i=1;i<n;i++)
     {
    for(int j=1;j<=min(i,k);j++)
      {
          if(dp[i]==-1)
           {
               dp[i]=dp[i-j]+abs(v[i]-v[i-j]);
           }
          else
          {
           dp[i]=min(dp[i-j]+abs(v[i]-v[i-j]),dp[i]);   
          }
      }
         
     }
    cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 4000
N = int(input())
h = [int(c) for c in input().split()]

dp=[0]*N
dp[1]=abs(h[1]-h[0])

for i in range(2,N):
    dp[i] = min([dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])])

print(dp[N-1])

Measured memory_bytes: 20524
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a > b) System.out.println("a > b");
        else if(a == b) System.out.println("a == b");
        else System.out.println("a < b");
    }
}


Measured memory_bytes: 26096
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
using ll = long long;
using P = pair<int,int>;

int main(void) {
  int a, b;
  cin >> a >> b;

  if(b%a==0) {
    cout << a+b << endl;
  } else {
    cout << b-a << endl;
  }
  return 0;
}

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

int main(){
  int N, x, ans=0;
  cin >> N;
  
  for(int i=1; i<=N; i++){
    cin >> x;
    if(x!=i){
      ans++;
      i--;
      N--;
    }
  }
  if(N==0)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

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

typedef pair<int, int> pii;

int main()
{	
	int n, m;

	while (cin >> n >> m, n || m){
		int c;
		int point[100] = {0};
		vector <pii> p(m);

		for (int i = 0; i < n; i++){
			for (int j = 0; j <	m; j++){
				cin >> c;
				if (c == 1){
					point[j]++;
				}
			}
		}

		for (int i = 0; i < m; i++){
			p[i] = make_pair(-point[i], i + 1);
		}

		sort(p.begin(), p.end());
		
		cout << p[0].second;
		for (int i = 1; i < m; i++){
			cout << ' ' << p[i].second;
		}
		cout << endl;
	}
	return (0);
}

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

#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
const ll INF = 1LL << 60;
vector<vector<P>> tree;
int h = 0;
vector<ll> height;
int mx = 0;
int node = 0;
P dfs(int cur, int parent) {
    height[cur] = h;
    h = 0;
    REP(i, tree[cur].size()) {
        if (tree[cur][i].first != parent) {
            h = height[cur] + tree[cur][i].second;
            if (h > mx) {
                mx = h;
                node = tree[cur][i].first;
            }
            dfs(tree[cur][i].first, cur);
        }
    }
    h = 0;
    // height.assign(height.size(), 0);
    return {node, mx};
}
int treediameter() { return dfs(dfs(0, -1).first, -1).second; }
int main() {
    int n;
    cin >> n;
    tree.resize(n);
    height.resize(n);
    REP(i, n - 1) {
        int s, t, w;
        cin >> s >> t >> w;
        tree[s].push_back({t, w});
        tree[t].push_back({s, w});
    }
    cout << treediameter() << endl;
}


Measured memory_bytes: 15240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 4e5 + 7;
const double pi = acos(-1);

int main(){
	string s;
	cin >> s;
	int f1 = 0,f2 = 0;
	for(int i = 0;i < s.size();i++){
		if(s[i] == 'A') f1 = 1;
		else f2 = 1;
	}
	if(f1 && f2) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
import sys
import itertools

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

K = ni() - 1

for le in range(1, 11):
    for h in range(1, 10):
        for a in itertools.product((-1, 0, 1), repeat=le-1):
            cur = h
            ok = True
            for u in a:
                cur += u
                if cur > 9 or cur < 0:
                    ok = False
                    break
            if ok:
                if K == 0:
                    ret = [h] + [_ + h for _ in itertools.accumulate(a)]
                    print("".join(map(str, ret)))
                    sys.exit(0)
                K -= 1

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

int m[1000001] = {} ;

void cal(){
	m[0] = 1 ;
	m[1] = 1 ;
	for( int i=2 ; i<=1000000 ; i++ ){
		for( int j=2 ; j<=1000000  ; j++ ){
			if( i*j <= 1000000 ) m[i*j] = 1 ;
			else break ;
		}
	}
}

int main(){
	
	int a , d , n ;
	int count , p ;
	cal();
	
	while(1){
		cin >> a >> d >> n ;
		if( a==0 && d==0 && n==0 ) break ;
		
		count = 0 ;
		p=0 ;
		while( count < n ){
			if( a+d*p <= 1000000 && m[a+d*p] == 0 ) count++ ;
			p++;
		}
		
		cout << a+d*(p-1) << endl ;
	}
	
return 0 ;
}

Measured memory_bytes: 5064
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;
int main(void){
    long long int a,b;
    cin >> a;
    b = 0;
    for(int i=1; i<=a; i++){
        for(int j=1; j<=a; j++){
            for(int k=1; k<=a; k++){
                b += gcd(i,gcd(j,k));
            }
        }
    }
    cout << b << endl;
}

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

using namespace std;

int main(void)
{
	int n,ans;//過半数を占める文字をしらべる
	string a,b,c;
	ans=0;
	cin>>n>>a>>b>>c;
	for(int i=0;i<n;i++){
		if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]){
			if(a[i]==b[i]&&b[i]==c[i]){
				
			}else{
				ans++;
			}
		}else{
			ans=ans+2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

inf = float('inf')

n, m = map(int, sys.stdin.readline().split())
g = [[] for _ in range(n+1)]
for _ in range(m):
    u, v = map(int, sys.stdin.readline().split())
    g[u].append(v)

s, t = map(int, sys.stdin.readline().split())

def main():
    dist = [inf] * (n + 1)
    can_reach = [[False] * 3 for _ in range(n + 1)]
    queue = deque([(0, s)])
    can_reach[s][0] = True
    while queue:
        d, x = queue.popleft()
        if d % 3 == 0:
            dist[x] = min(dist[x], d // 3)
        d += 1
        for y in g[x]:
            if not can_reach[y][d%3]:
                can_reach[y][d%3] = True
                queue.append((d, y))

    return dist[t] if dist[t] != inf else -1

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 32472
open Batteries
open Tuple
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (n,k) = scan "%d %d" Tuple2.make
let arr = scan_array ~sep:' ' Int.of_string

let memo = Array.make_matrix (succ k) 2 None

let rec solve k t =
  match memo.(k).(if t then 1 else 0) with
  | Some v -> v
  | None ->
    let v = if t then
        if k < arr.(0) then false
        else ArrayL.exists arr ~f:(fun a ->
            if k - a >= 0 then solve (k-a) false else false)
      else
      if k < arr.(0) then true
      else not @@ ArrayL.exists arr ~f:(fun a ->
          if k - a >= 0 then solve (k-a) true  = false else false) in
    memo.(k).(if t then 1 else 0) <- Some v; v

let () =
  solve k true
  |> (fun b -> Printf.printf "%s\n" (if b then "First" else "Second"))


Measured memory_bytes: 25856
#include <iostream>
#include <string>

int main(){
  int fx=0;
  std::string str_num;
  std::cin >> str_num;
  int n = atoi(str_num.c_str());
  
  for(int i=0; i<str_num.length(); i++){
    const char s = str_num[i];
    fx += str_num[i] - '0';
  }
  if(n%fx)std::cout << "No" << std::endl;
  else std::cout << "Yes" << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
int N;
bool isprime[105];
int prime_cnt[105];


void eratosthenes_seive(int n) {

  for (int i = 2; i <= n+1; i++) isprime[i] = true;

    for (int i = 2; i <= n+1; i++) {
      if ( isprime[i] == true ) {
        for (int j = i + i; j <= n+1; j += i) isprime[j] = false;
      }
    }
    return;
}

void prime_factrization(int n) {

  for (int i = 2; i <= n; i++) {
    if (isprime[i]) {
      while (n % i == 0) {
        prime_cnt[i]++;
        n /= i;
      }
    }
  }
  if (n > 1) prime_cnt[n]++;
  
  return;
}



int main(void) {
    scanf("%d", &N);

   
    eratosthenes_seive(N);

    rep(i, 2, N+1) prime_factrization(i);
    
    /*
    75になる組み合わせ
    1 * 75
    3 * 25
    5 * 15
    3 * 5 * 5  
    */
    
    int four = 0, two = 0;
    int sf = 0, tf = 0, fourty = 0;

    rep(i, 2, N+1) {
       if (prime_cnt[i] >= 4) four++;
       if (prime_cnt[i] >= 2) two++;
       if (prime_cnt[i] >= 74) sf++;
       if (prime_cnt[i] >= 24) tf++;
       if (prime_cnt[i] >= 14) fourty++;
    }
    ans += sf;
    ans += tf * (two-1);
    ans += fourty * (four-1);
    if (four >=2 && two >= 3) ans += four * (four-1) / 2 * (two - 2);
    

     
    
    

   

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

	return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
long int n,k,i,j,temp,s=0;
scanf("%ld %ld",&n,&k);
long int h[n];
for(i=0;i<n;i++)
{
    scanf("%ld",&h[i]);
}
if(n>k)
{
sort(h,h+n);

for(i=0;i<n-k;i++)
{
    s+=h[i];
}
printf("%ld",s);
}
else
    printf("0");
}



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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	long long int n, maxx, a;
	cin >> n;
	cin >> maxx;
	long long int ans = 0;
	for(long long int i = 1; i < n; i++) {
		cin >> a;
		if(maxx > a) {
			ans += (maxx - a);
		}
		else {
			maxx = a;
		}
	}
	cout << ans;
	return 0;
}

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

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

Measured memory_bytes: 256
N = int(input())
s = input()
MOD = 10**9+7

#A1 ... AnのBIT(1-indexed)
BIT = [0]*(N+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= N:
        BIT[idx] += x
        idx += idx&(-idx) #BIT_update(0, )をすると while が終わらない
    return


dp = [[0]*N for _ in range(N)] # dp[i][k]：i番目まで見た時に，i番目の要素より小さい値の個数がkの時のパターン数 
for k in range(N): dp[0][k] = 1

for i in range(1, N):
    BIT = [0]*(N+1)
    for k in range(N): BIT_update(k+1, dp[i-1][k]) #BIT_update(0, )をすると while が終わらない
    if s[i-1] == '<':
        for k in range(N-i): dp[i][k] = BIT_query(k+1) % MOD #sum([dp[i-1][j] for j in range(k+1)])
    else:
        for k in range(N): dp[i][k] = (BIT_query(N) - BIT_query(k+1)) % MOD #sum([dp[i-1][j] for j in range(k+1, N)])

print(dp[-1][0])

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

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


Measured memory_bytes: 3068
#include <stdio.h>
int main(void){
	int a,cnt=0;
  	scanf("%d",&a);
  	int d[a];
  	for(int i=0; i<a; i++){
		scanf("%d",&d[i]);
    }
  	for(int i=0; i<a; i++){
		for(int j=i+1; j<a; j++){
          cnt = cnt + (d[i] * d[j]);
        }
    }
  	printf("%d\n",cnt);
  	return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DSummerVacation {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, M;
	    in >> N >> M;
	    vector<pair<int,int>> works(N);
	    REP(i,0,N) in >> works[i].first >> works[i].second;
	    sort(all(works));

	    priority_queue<int> queue;

	    int answer = 0;
	    int top = 0;
	    REP(i,1,M+1) {
	        while (top < works.size() && works[top].first <= i) {
	            queue.push(works[top].second);
	            top++;
	        }
	        if (queue.size() == 0) continue;
	        answer += queue.top();
	        queue.pop();
	    }
	    out << answer << "\n";
	}
};


int main() {
	DSummerVacation solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1660
S=input()
Q=int(input())

flag=0
forward=""
back=""
for i in range(Q):
    #query[i]=input()
    b=input()

    if(len(b)==1):
        #S=S[::-1]
        flag+=1
    else:
        a=b.split(" ")
        if(flag==0):
            if(a[1]=="1"):
                #S=a[2]+S
                forward=a[2]+forward
            else:
                #S+=a[2]
                back=back+a[2]
        else:
            if(a[1]=="1"):
                #S=a[2]+S
                back=back+a[2]
            else:
                #S+=a[2]
                forward=a[2]+forward
                
    flag=flag%2

S=forward+S+back
if(flag==1):
    S=S[::-1]
print(S)



Measured memory_bytes: 4424
#include<stdio.h>
#include<math.h>

#define N 15

int main(){
  const int n, a[N], x[N][N-1], y[N][N-1];
  scanf("%d",&n);
  for(int i=0; i<n; i++){
    scanf("%d",&a[i]);
    for(int j=0; j<a[i]; j++){
      scanf("%d %d", &x[i][j], &y[i][j]);
//      printf("%d %d\n",y[i][j], x[i][j]);
    }
  }
  
  int isHonest[n], sumHonest, maxSumHonest=0, isContra=0;
  for(int k=0; k<pow(2,n); k++){
    isContra=0;
    for(int i=0; i<n; i++){
      isHonest[i] = (k>>i)&1;   // decide whether person i is honest or not
    }
    for(int i=0; i<n; i++){
      if(isHonest[i]==1){
//        for(int l=0; l<n; l++) { printf("%d ",isHonest[l]); } printf("\n");
        for(int j=0; j<a[i]; j++){
//          printf("%d %d\n",y[i][j], x[i][j]);
          if(y[i][j]!=isHonest[x[i][j]-1]){  // if 'honest i' isn't honest 
            isContra=1;
//            printf("%d ",isContra);
//            for(int l=0; l<n; l++) { printf("%d ",isHonest[l]); } printf("\n");
            break;
          }
        }
        if(isContra==1){
//          for(int l=0; l<n; l++) { printf("%d ",isHonest[l]); } printf("\n");
          break;
        }
      }
    }
    if(isContra==0){
//      for(int l=0; l<n; l++) { printf("%d ",isHonest[l]); } printf("\n");
      sumHonest=0;
      for(int i=0; i<n; i++){
        sumHonest += isHonest[i];
        if(sumHonest>maxSumHonest){
          maxSumHonest = sumHonest;
        }
      } 
    }
  }
  printf("%d",maxSumHonest);
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
    int N=0;
    int L=0;
    int taberu=10000;
    int temp=0;
    int temp2=0;
    long sum=0;
    scanf("%d %d",&N,&L);
    for(int i=1;i<=N;i++){
        sum+=L+i-1;
       
        temp=L+i-1;
        if(temp<0) temp*=-1;
        temp2=taberu;
        if(temp2<0) temp2*=-1;
        if(temp2>temp) taberu=L+i-1;
       
    }
    printf("%ld\n",sum-taberu);
    
     return 0;
}


Measured memory_bytes: 128
/* author   : mpily :-()
title : Competing.cpp
time :Sun Oct 27 15:09:11 2019

*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	long long lim = sqrt(n);
	long long ans = 0;
	for(int i = lim; i >=1;i--){
		if(n%i == 0){
			ans = n/i;
			break;
		}
	}
	cout<<(ans-1)+((n/ans)-1)<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>

struct vertex {
  int num;
  std::vector<int> adjacent;
  int cost;
  int counter;
};
std::vector<struct vertex> tree;

void recur(struct vertex *v, int from, int costsum) {
  v->counter = costsum + v->cost;
  for (unsigned j = 0; j < v->adjacent.size(); ++j) {
    if (v->adjacent[j] == from) continue;
    recur(&tree[v->adjacent[j]], v->num, v->counter);
  }
};

int main(void) {
  int N, Q;
  scanf("%d %d", &N, &Q);
  tree.reserve(N);
  for (int i = 0; i < N; ++i) {
    tree[i].num = i;
    tree[i].cost = 0;
  }
  for (int i = 0; i < N-1; ++i) {
    int a, b;
    scanf("%d %d", &a, &b); --a; --b;
    tree[a].adjacent.push_back(b);
    tree[b].adjacent.push_back(a);
  }
  for (int i = 0; i < Q; ++i) {
    int p, x;
    scanf("%d %d", &p, &x); --p;
    tree[p].cost += x;
  }
  recur(&tree[0], -1, 0);
  printf("%d", tree[0].counter);
  for (int i = 1; i < N; ++i) {
    printf(" %d", tree[i].counter);
  }
  puts("");
}


Measured memory_bytes: 22656
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = Integer.MIN_VALUE;
		int maxIdx = 0;
		int min = Integer.MAX_VALUE;
		int minIdx = 0;
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    if (max < x) {
		        max = x;
		        maxIdx = i + 1;
		    }
		    if (min > x) {
		        min = x;
		        minIdx = i + 1;
		    }
		}
		StringBuilder sb = new StringBuilder();
		if (Math.abs(max) >= Math.abs(min)) {
		    for (int i = 1; i <= n; i++) {
		        sb.append(maxIdx).append(" ").append(i).append("\n");
		    }
		    for (int i = 1; i < n; i++) {
		        sb.append(i).append(" ").append(i + 1).append("\n");
		    }
		} else {
		    for (int i = 1; i <= n; i++) {
		        sb.append(minIdx).append(" ").append(i).append("\n");
		    }
		    for (int i = n; i > 1; i--) {
		        sb.append(i).append(" ").append(i - 1).append("\n");
		    }
		}
		System.out.println(n * 2 - 1);
		System.out.print(sb);
    }
}



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

using namespace std;

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

    string s;
    cin>>s;

    k =k-1;
    if(s[k] == 'A')
    {
        s[k] = 'a';
    }

    else if(s[k] == 'B')
    {
        s[k] = 'b';
    }

    else if(s[k] == 'C')
    {
        s[k] ='c';
    }

    cout <<s<< endl;
    return 0;
}


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll l, r;
    cin >> l >> r;
    ll tmp = 2019;
    if(r - l > 2020){
        cout << 0 << endl;
        return 0;
    }
    for(ll i = l; i < r; ++i){
        for(ll j = i + 1; j <= r; ++j){
            tmp = min(tmp, (i*j) % 2019);
        }
    }
    cout << tmp << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long Int;


int main() {
    Int H, W, A, B;
    cin >> H >> W >> A >> B;

    vector<string> s(H);

    if (B > 0) {
        rep(i,B) {
            if (A > 0) {
                rep(j,A) {
                    s[i] += '1';
                }
            }
            rep(j,W-A) s[i] += '0';
        }
    }
    for (int i = B; i<H; i++) {
        if (A > 0) {
                rep(j,A) {
                    s[i] += '0';
                }
            }
            rep(j,W-A) s[i] += '1';
    }

    rep(i,H) cout << s[i] << endl;
}

Measured memory_bytes: 2304
#include <stdio.h>

int selection_sort(int A[], int N)
{
    int i, j, t, sw = 0, minj;
    for (int i = 0; i < N - 1; i++) {
        minj = i;
        for ( j = i; j < N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if (i != minj) sw++;
    }
    return sw;
}


int main(int argc, char const *argv[])
{
    int A[100], N, i, sw;

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }

    sw = selection_sort(A, N);

    for (i = 0; i < N; i++) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);

    return 0;
}



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

int main(){
    int n, x, ans;
    while (1){
        cin >> n >> x;
        if (n==0 && x==0) break;
        ans = 0;
        for (int i = 1; i <= n-2; i++){
            for (int j = i+1; j <= n-1; j++){
                for (int k = j+1; k <= n; k++){
                    if (i+j+k == x) ans += 1;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

constexpr ll MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;



int main()
{
	double A, B, H, M;
	cin >> A >> B >> H >> M;

	double angleA = 2 * PI*(H * 60 + M) / (12 * 60);
	double xA = A*cos(angleA);
	double yA = A*sin(angleA);

	double angleB = 2 * PI*M / 60;
	double xB = B*cos(angleB);
	double yB = B*sin(angleB);

	double ans = sqrt((xA - xB)*(xA - xB) + (yA - yB)*(yA - yB));

	printf("%.20f\n", ans);

	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define foru(i,a,n) for(ll i=(a); i<=(n); ++i)
#define ford(i,n,a) for(ll i=(n); i>=(a); --i)
using namespace std;
const int M = 101010;
const ll inf = 1e17;
ll n, m, w[111], v[111], dp[111][M];

int main(){
	//freopen("a.in","r",stdin);
	cin >>n >>m;
	foru(i,1,n) cin >>w[i] >>v[i];

	dp[0][0] = 0;
	foru(i,1,M-1) dp[0][i] = inf;
	foru(i,1,n) foru(j,1,M-1){
		if(j < v[i])
			dp[i][j] = dp[i-1][j];
		else
			dp[i][j] = min(dp[i-1][j], dp[i-1][j - v[i]] + w[i]);
	}
	
	ll ans = 0;
	foru(j, 1, M-1) if(dp[n][j] <= m) ans = j;
	cout <<ans;
	return 0;
}


Measured memory_bytes: 80128