akhauriyash/Code-Regression huggingface dataset:
#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>;

struct Edge {
	int to; // 辺の行き先
	ll cost; // その辺を通るコスト
	Edge(int t, ll c) : to(t), cost(c) { }
};

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int N; cin >> N;
	vector<int> a(N), b(N);
	vector<ll> c(N); REP(i, N - 1) cin >> a[i] >> b[i] >> c[i];
	REP(i, N - 1) {
		a[i]--;
		b[i]--;
	}
	int Q; cin >> Q;
	int K; cin >> K; K--;
	vector<int> x(Q), y(Q); REP(i, Q) cin >> x[i] >> y[i];
	REP(i, Q) {
		x[i]--;
		y[i]--;
	}

	// 最短距離を初期化
	vector<ll> d(N, (ll)1e18);
	d[K] = 0;
	// グラフを隣接リストでセットする
	vector<vector<Edge> > G(N);
	REP(i, N - 1) {
		G[a[i]].push_back(Edge(b[i], c[i]));
		G[b[i]].push_back(Edge(a[i], c[i]));
	}
	// 距離が小さい順に取り出せるようgreater<P>を指定
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, K));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second; // 更新した頂点の中で距離が最小の頂点v
        if (d[v] < p.first) continue;
        for (auto e : G[v]) { // 頂点vから出る辺eを走査
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }

	REP(i, Q)
		cout << d[x[i]] + d[y[i]] << '\n';
    return 0;
}


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


using namespace std;
using ll = long long;

ll N;

int main()
{
	cin >> N;
	vector<ll> a(N);
	vector<vector<pair<ll, ll>>> account(N);
	for (ll i = 0; i < N; i++)
	{
		cin >> a[i];
		for (ll j = 0; j < a[i]; j++)
		{
			ll x, y;
			cin >> x >> y;
			account[i].push_back(make_pair(x - 1, y));
		}
	}
	ll ans = 0;
	bool flag = true;
	// 正直者嘘つきを仮定する
	for (ll i = 0; i < (1 << N); i++)
	{
		for (ll j = 0; j < N; j++)
		{
			//正直者の発言の確認
			if ((1 << j) & i)
			{
				for (auto word : account[j])
				{
					//正しいとき
					if ((((1 << word.first) & i) && word.second == 1) || (!((1 << word.first) & i) && word.second == 0))
					{
						continue;
					}
					else
					{
						flag = false;
						break;
					}
				}
			}
		}
		//発言が整合したら人数をカウント
		if (flag)
		{
			ll temp = 0;
			for (ll j = 0; j < N; j++)
			{
				if ((1 << j) & i)
				{
					temp++;
				}
			}
			ans = max(ans, temp);
		}
		flag = true;
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
import sys
readline=sys.stdin.readline
read=sys.stdin.read

def main():
    n,k=map(int,readline().split())
    ab=[list(map(int,l.split())) for l in read().splitlines()]
    
    ek=0
    while k>>ek:
        ek+=1

    cand=[]
    for i in range(ek):
        if k>>i&1:
            m=(k>>(i+1))<<(i+1)|((1<<i)-1)
            cand.append(sum([e[1] for e in ab if e[0]|m==m]))
    cand.append(sum([e[1] for e in ab if e[0]|k==k]))
    print(max(cand))

if __name__=='__main__':
    main()


Measured memory_bytes: 35812
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();
    vector<int> a(2019, 0);
    a[0] = 1;
    int t = 1, b = 0;
    int ans = 0;
    for(int i=n-1;i>=0;i--){
    	b += (s[i] - '0') * t;
    	b %= 2019;
    	ans += a[b]; 
    	a[b]++;
    	t *= 10;
    	t %= 2019;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i,n) for(size_t i=0, i##_len=(n); i<i##_len; ++i)


void solve(ll A, ll B) {
  int ans = A+B;
  cout << (ans < 10 ? to_string(ans) : "error") << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(A, B);
  return 0;
}


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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int count = 0;
    while(0 < a && 0 < c){
        if(count % 2 == 0){
            c -= b;
        }
        else{
            a -= d;
        }
        count++;
    }

    if(a <= 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n + 1; i++) {
    char tp = getchar();
    if (i == k) {
      char tpx = tp - (-'a' + 'A');
      putchar(tpx);
    } else {
      putchar(tp);
    }
  }
  printf("\n");

  return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

map<pll, ll> cnt;
map<ll, ll> ans;

int main()
{
  ll h, w, n;
  cin >> h >> w >> n;

  rep(i, n){
    ll a, b;
    cin >> a >> b;

    for(int j = max(1LL, a-2); j <= min(h-2, a); j++){
      for(int k = max(1LL, b-2); k <= min(w-2, b); k++){
        cnt[mp(j, k)]++; 
      }
    }
  }

  for(auto u : cnt){
    ans[u.second]++;
  }

  ll sum = 0;
  for(int i = 1; i < 10; i++) sum += ans[i];

  cout << (h-2)*(w-2)-sum << endl;
  for(int i = 1; i < 10; i++) cout << ans[i] << endl;
  
  return 0;
}


Measured memory_bytes: 56448
#include<stdio.h>
#include<math.h>
int main()
{    int n;
	 double s=0,d,i;
	 scanf("%d",&n);
	 
	 s=n/1.08;
	 d=floor(s);
	 for(i=d;i<=d+2;i++)
	 {
	 	if(fabs(n-floor(i*1.08))==0)
	 	{
		 s=1;break;}
	 }
	 if(s==1)
	 printf("%d\n",(int)i);
	 else
	 printf(":(\n");
	 
	 
 } 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
signed main(){
char a[100];
scanf("%s",a);
char b=a[0];
int c=0;
int d=strlen(a);
for(int e=0;e<d;e++){
    if(a[e]!=b){c++;b=a[e];}
    }
    if(a[0]=='o'&&a[d-1]=='o')c++;
    if(c&1)printf("o\n");
    else printf("x\n");
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	vector<string> s(n), ans;
	rep(i, n) cin >> s[i];
	rep(i, n) {
		if (s[i] == "AB") {
			if (a == 0 and b == 0) {
				cout << "No" << endl;
				return 0;
			} else if (a < b) {
				a++, b--;
				ans.push_back("A");
			} else if (a > b) {
				a--, b++;
				ans.push_back("B");
			} else {
				if (i == n - 1)
					ans.push_back("A");
				else {
					if (s[i + 1] == "AB" or s[i + 1] == "AC") {
						a++, b--;
						ans.push_back("A");
					} else {
						a--, b++;
						ans.push_back("B");
					}
				}
			}
		} else if (s[i] == "BC") {
			if (b == 0 and c == 0) {
				cout << "No" << endl;
				return 0;
			} else if (b < c) {
				b++, c--;
				ans.push_back("B");
			} else if (b > c) {
				b--, c++;
				ans.push_back("C");
			} else {
				if (i == n - 1)
					ans.push_back("B");
				else {
					if (s[i + 1] == "AB" or s[i + 1] == "BC") {
						b++, c--;
						ans.push_back("B");
					} else {
						b--, c++;
						ans.push_back("C");
					}
				}
			}
		} else {
			if (a == 0 and c == 0) {
				cout << "No" << endl;
				return 0;
			} else if (a < c) {
				a++, c--;
				ans.push_back("A");
			} else if (a > c) {
				a--, c++;
				ans.push_back("C");
			} else {
				if (i == n - 1)
					ans.push_back("A");
				else {
					if (s[i + 1] == "AB" or s[i + 1] == "AC") {
						a++, c--;
						ans.push_back("A");
					} else {
						a--, c++;
						ans.push_back("C");
					}
				}
			}
		}
	}
	cout << "Yes" << endl;
	for (auto p : ans) cout << p << endl;
	return 0;
}

Measured memory_bytes: 10564
S = input()

ATCG = ['A','T','C','G']
ans = [0, 0]
for s in S:
    if s in ATCG:
        ans[0] += 1
    else:
        if ans[1] < ans[0]:
            ans[1] = ans[0]
        ans[0] = 0

if ans[1] < ans[0]:
    ans[1] = ans[0]
print(ans[1])

Measured memory_bytes: 3060
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
    int r , D , x ; 
    cin >> r >> D >> x ; 
    int cur = x ; 
    for(int i=0;i<10;i++){
    	int ans = r * cur - D ; 
    	cout << ans << endl;
    	cur = ans ; 
    }
    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[10000];
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	double sum=0;
	for(int i=0;i<n;i++){
		sum+=1.0/a[i];
	}
	cout << 1/sum << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n,A,B;
	cin>>n>>A>>B;
	lli C = A-B;
	vector<lli> h(n);

	REP(i,0,n)cin>>h[i];
	lli small=1,large=1e9;

	while(small<large){
		lli middle = (small+large)/2;
		lli cnt=0;
		REP(i,0,n){
			lli t = h[i]-B*middle;
			if(t>0)cnt += (t-1)/C + 1;
		}

		if(cnt<=middle){
			large = middle;
		}
		else{
			small = middle+1;
		}
	}

	cout<<large<<endl;

	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<queue>
#include <cmath>
#include <complex>
#include<map>
#include <string>
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include<bits/stdc++.h>


/*
#define x real()
#define y imag()
#define angle(a)                (atan2((a).imag(), (a).real()))
#define vec(a,b)                ((b)-(a))
#define same(p1,p2)             (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define dp(a,b)                 ( (conj(a)*(b)).real() )	// a*b cos(T), if zero -> prep
#define cp(a,b)                 ( (conj(a)*(b)).imag() )	// a*b sin(T), if zero -> parllel
#define length(a)               (hypot((a).imag(), (a).real()))
#define normalize(a)            (a)/length(a)
//#define polar(r,ang)            ((r)*exp(point(0,ang)))  ==> Already added in c++11
#define rotateO(p,ang)          ((p)*exp(point(0,ang)))
#define rotateA(p,ang,about)  (rotateO(vec(about,p),ang)+about)
#define reflectO(v,m)  (conj((v)/(m))*(m))
*/

//#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
#define NOT(x) (1^x)

const double PI  = acos(-1.0);
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
typedef complex<double> point;

//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//const int N=500009,M=1000000;
const double EPS= 1e-9,eps=-1e9;
//const int N =300005;
int n;
string s;
ll ans;
map<pair<string,string>,int>cnt;
void bk1(int i=0,string a="",string b="")
{
    if(i==n)
    {
        cnt[{a,b}]++;
        return ;
    }
    bk1(i+1,a+s[i],b);
    bk1(i+1,a,b+s[i]);
}


void bk2(int i=n*2-1,string a="",string b="")
{
    if(i==n-1)
    {
        ans+=cnt[{b,a}];
        return ;
    }
    bk2(i-1,a+s[i],b);
    bk2(i-1,a,b+s[i]);
}
 int main()
{
//freopen("travel.in","r",stdin);
//freopen("travel.out","w",stdout);
//__builtin_popcount()
input;

    cin>>n;
    cin>>s;
    bk1();
    bk2();
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 88544
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 300005
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
int s[MAXN],ans,n,w[MAXN],e[MAXN];
char a[MAXN];
int main() 
{
	cin>>n;
    for(re int i=1;i<=n;i++)
        cin>>a[i];
    for(re int i=1;i<=n;i++){
        if(a[i]=='W') w[i]=w[i-1]+1;
        else w[i]=w[i-1]; 
    }
    for(re int i=n;i>=1;i--){
        if(a[i]=='E') e[i]=e[i+1]+1;
        else e[i]=e[i+1];
    }
    ans=10000000;
    for(re int i=1;i<=n;i++)
        ans=min(ans,w[i]+e[i]-1);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2944
import java.util.*

fun main(args : Array<String>) {
    val scanner = Scanner(System.`in`)
    println(inOutExec(scanner))
}

fun inOutExec(scanner: Scanner): String {
    val numOfPref = scanner.nextInt()
    val numOfCity = scanner.nextInt()

    val citiesIn = mutableListOf<Pair<Int, Int>>()
    repeat(numOfCity) {
        citiesIn.add(Pair(scanner.nextInt(), scanner.nextInt()))
    }

    val cityCodeMap = citiesIn
            .groupByTo(mutableMapOf()) { it.first }
            .flatMap { entry ->
                entry.value
                        .sortedBy { info -> info.second }
                        .mapIndexed { index, pair ->
                            pair to "%06d%06d".format(pair.first, index + 1) } } // Pair<Pair<Int, Int>, String>
            .toMap()

    return citiesIn.joinToString(separator = "\n", postfix = "\n") { cityCodeMap[it]!! }
}

Measured memory_bytes: 155036
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

template<typename T>
struct UnionFind {
	vector<T> Parent;
 
	UnionFind(T N) {
		Parent = vector<T>(N, -1);
	}
 
	T root(T A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	T size(T A) {
		return -Parent[root(A)];
	}
 
	bool connect(T A, T B) {
		A = root(A);
		B = root(B);
		if (A == B) return false;
		if (size(A) < size(B)) swap(A, B);
		Parent[A] += Parent[B];
		Parent[B] = A;
 
		return true;
	}

    bool same(T A,T B){
      return root(A)==root(B);
    }
};

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  VV<ll> y(100010,V<ll>(0));
  V<ll> a(n),b(n);

  rep(i,0,n){
    cin>>a[i]>>b[i];
  }

  UnionFind<ll> u(100001);
  rep(i,0,n){
    if(y[b[i]].size())u.connect(y[b[i]].back(),a[i]);
    else y[b[i]].pb(a[i]);
  }


  ll ans=-n;
  V<set<ll>> se(100001);
  rep(i,0,n){
    se[u.root(a[i])].insert(b[i]);
  }

  rep(i,0,100001){
    ans+=u.size(i)*siz(se[i]);
  }

  cout<<ans<<ENDL;
  
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
using llong = long long;

void fnInput(llong& rnLow, llong& rnHigh, llong& rnDivsor1, llong& rnDivsor2)
{
  cin >> rnLow >> rnHigh >> rnDivsor1 >> rnDivsor2;
}
  
llong fnAntiDivCnt(llong nLow, llong nHigh, llong nDivsor1, llong nDivsor2)
{
  llong nDividend = max(nDivsor1, nDivsor2);
  llong nDivisor = min(nDivsor1, nDivsor2);

  while (nDividend % nDivisor)
  {
    int nRemndr = nDividend % nDivisor;
    nDividend = nDivisor;
    nDivisor  = nRemndr;
  }
  llong nDivLcm = nDivsor1 * (nDivsor2 / nDivisor);
  llong nLowLessDiv1Cnt = (nLow - 1) / nDivsor1;
  llong nLowLessDiv2Cnt = (nLow - 1) / nDivsor2;
  llong nLowLessDLcmCnt = (nLow - 1) / nDivLcm;

  llong nHighDev1Cnt = nHigh / nDivsor1;
  llong nHighDev2Cnt = nHigh / nDivsor2;
  llong nHighDLcmCnt = nHigh / nDivLcm;
  
  llong nDivsible = (nHighDev1Cnt + nHighDev2Cnt - nHighDLcmCnt) -
                    (nLowLessDiv1Cnt + nLowLessDiv2Cnt - nLowLessDLcmCnt);
  return (nHigh - nLow + 1) - nDivsible;
}
  
int main()
{
  llong nLow, nHigh, nDivsor1, nDivsor2;

  fnInput(nLow, nHigh, nDivsor1, nDivsor2);
  cout << fnAntiDivCnt(nLow, nHigh, nDivsor1, nDivsor2) << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <atcoder/all>
// #include <bits/stdc++.h> 
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;
using namespace atcoder;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln '\n'
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 101
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zero ll(0)
#define set_bits(x) __builtin_popcountll(x)
 
ll mpow(ll a, ll b){
	if(a==0) return 0;
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}
 
ll mpow(ll a, ll b, ll p){
	if(a==0) return 0;
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);
	t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
 
ll modinverse(ll a, ll m){
	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; 
}

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
 
ll range(ll l, ll r){
	return l + mt()%(r-l+1);
}
 
ll rev(ll v){
	return mpow(v,MOD-2);
}

ll n,m;
ll f(ll i, ll j){
	return i*m+j;
}


void solve(){
	cin >> n >> m;
	string s[n];
	forn(i,n) cin >> s[i];
	mcf_graph<int, int> g(n * m + 2);
	int s1 = n*m, t = n*m+1;
	ll ans = 0;
	forn(i,n){
		forn(j,m){
			if(s[i][j]=='o') {
				ans += (INF-i-j);
				g.add_edge(s1, f(i,j), 1, 0);
			}
			if(s[i][j]!='#' && i+1<n && s[i+1][j]!='#') g.add_edge(f(i,j), f(i+1,j), INF, 0);
			if(s[i][j]!='#' && j+1<m && s[i][j+1]!='#') g.add_edge(f(i,j), f(i,j+1), INF, 0);
			g.add_edge(f(i,j), t, 1, INF-i-j);
		}
	}
	auto result = g.flow(s1, t);
	cout << ans-result.se << ln;
}
 
int main()
{
	fast_cin();
	ll t=1;
    // cin >> t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 4244
#include <stdio.h>

int n, i, i_mod, num_div, div_max = -1, div_max_i = -1;

int main(void) {
    scanf("%d", &n);
    
    for (i = 1; i <= n; ++i) {
        i_mod = i;
        num_div = 0;
        
        while (i_mod % 2 == 0) {
            ++num_div;
            i_mod /= 2;
        }
        
        if (num_div > div_max) {
            div_max = num_div;
            div_max_i = i;
        }
        
        //printf("%d, %d\n", i, num_div);
    }
    
    //printf("%d times at %d.\n", div_max, div_max_i);
    printf("%d\n", div_max_i);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
int binary_search(int* a,long long k,int n){
    int R = n,L = 0;
    while(L < R){
        int mid = (L+R)/2;
        if (a[mid] == k) return 1;
        else if (k < a[mid]) R = mid;
        else L = mid+1;
    }
    return 0;
}

int main(){
    int n; cin >> n; 
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        long long k; cin >> k;
        cout << binary_search(a,k,n) << endl;
    }
}
  




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define sz(x) ((long long)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define oo 1e15;
const ld eps = 1e-9;
const ld pi = acosl(-1);
const int mod = 998244353;
const int mod1 = 1e9 + 7;


mt19937_64 rnd(time(0));

void faster()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
}

signed main() {
    faster();
    // freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
    //______________________________________
    /*__*/double start = clock();/*__*/
    //_____________________________________
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector <int> dp(n);
    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        dp[i] = oo;
        for (int j = i - 1; j >= 0 && abs(i - j) <= k; j--)
            dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]);
    }
    cout << dp[n - 1];
    //______________________________________
    //  cerr << "Time " << (clock() - start)  * 1.0 / CLOCKS_PER_SEC << "s\n";
    return 0;
}

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

const int maxn = 2e5+5;
int N, Q;
vector<int> adj[maxn];
int pre[maxn];
int tin[maxn], tout[maxn], t = 0;

void dfs(int i, int p) {
    tin[i] = t++;
    for (int j: adj[i]) {
        if (j == p) continue;
        dfs(j,i);
    }
    tout[i] = t;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> Q;
    for (int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1,1);
    for (int i = 0; i < Q; i++) {
        int p, x; cin >> p >> x;
        pre[tin[p]] += x;
        pre[tout[p]] -= x;
    }
    for (int i = 1; i <= N; i++) {
        pre[i] += pre[i-1];
    }
    for (int i = 1; i <= N; i++) {
        cout << pre[tin[i]] << ' ';
    }
    cout << '\n';
}



Measured memory_bytes: 25088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
    	String S = ns();
    	int[] cnt = new int[4];

    	for (int i=0; i<S.length(); i++) {
    		switch(S.charAt(i)) {
    		case 'N':
    			cnt[0]++;
    			break;
    		case 'W':
    			cnt[1]++;
    			break;
    		case 'E':
    			cnt[2]++;
    			break;
    		case 'S':
    			cnt[3]++;
    			break;
    		}
    	}

    	if (cnt[0] == 0 && cnt[3] != 0
    			|| cnt[0] != 0 && cnt[3] == 0
    			|| cnt[1] == 0 && cnt[2] != 0
    			|| cnt[1] != 0 && cnt[2] == 0) {
    		out.println("No");
    	} else {
    		out.println("Yes");
    	}
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}


Measured memory_bytes: 8020
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	int n;
	cin>>n;
	vector<int> D;
	int d;
	rep(i,n){
		cin>>d;
		D.push_back(d);
	}
	sort(D.begin(),D.end());
	int ans = 1;
	rep(i,n-1){
		if(D[i] != D[i+1]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int n;
int plus(int m){
	int c=0,i;
	for(i=0;1;i++){
		if(n/m){
			c++;
			n-=m;
		}
		else break;
	}
	return c;
}
int main(){
	int i,c=0;
	while(1){
		c=0;
		scanf("%d",&n);
		if(!n)break;
		n=1000-n;
		c+=plus(500);c+=plus(100);c+=plus(50);c+=plus(10);c+=plus(5);c+=plus(1);
		printf("%d\n",c);
	}
	exit( 0);
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  if (N % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll x = N / 2;
  ll ans = 0;
  while (x / 5 > 0) {
    ans += x / 5;
    x /= 5;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

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

    int n, k;cin>>n>>k;
    int h[100005];
    _fi(n) cin>>h[i];

    int dp[100005] = {};
    dp[1] = abs(h[0]-h[1]);
    for(int i = 2;i < n;i++){
        dp[i] = abs(h[i]-h[i-1])+dp[i-1];
        for(int j = 2;j <= k && i-j >= 0;j++){
            dp[i] = min(dp[i], abs(h[i]-h[i-j])+dp[i-j]);
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}


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

int main()
{
  int a,b,c,n;
  cin>>n>>a>>b;
  c=n*a;

  if(c<=b)
  {
    cout<<c<<endl;
  }
  else
  {
    cout<<b<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

    for (int i = 0; i < n; ++i)
      p[i] = sc.nextInt();

    int res = 0;

    for (int i = 1; i < n - 1; ++i) {
      if (p[i] > p[i - 1] && p[i] < p[i + 1] ||
          p[i] < p[i - 1] && p[i] > p[i + 1])
        ++res;
    }

    System.out.println(res);

  }
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  int res=0;
  std::vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
    res += v[i];
  }
  sort(v.begin(), v.end());
  if(res%10!=0){
    cout<<res<<endl;
    return 0;
  }
  for(int i=0;i<n;i++){
    int t = res - v[i];
    if(t % 10 != 0){
      cout<<t<<endl;
      return 0;
    }
  }

  cout<<0<<endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using static System.Math;

class Program {
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        int k = int.Parse(Console.ReadLine());
        var count = 1L;
        for (int i = 0; i < n; i++) {
            count = Min(count * 2, count + k);
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 11092
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 1000000 + 9;
int n,vis[N],p[N],x;


 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        forr(i,2,1000000)
        {
            if(!p[i]){
            for(int j=i;j<=1000000;j+=i)
            {
                p[j] = i;
            }}
        }

        int ck = 1,g=0;
        cin>>n;
        forr(i,1,n)
        {
            cin>>x;
            g = __gcd(g,x) ;
            if(!ck)continue;

            while(x != 1)
            {
                if(vis[p[x]]){ck=0;break;}
                else
                {
                    vis[p[x]]=1;
                    int t = p[x];
                    while(x%t==0)x/=t;
                }
            }
        }

        if(ck)cout<<"pairwise coprime"<<endl;
        else if(g == 1)cout<<"setwise coprime"<<endl;
        else cout<<"not coprime"<<endl;







return 0;
}


Measured memory_bytes: 11412
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
int main()
{
  int A,B;
  cin >> A;
  cin >> B;
  cout << (A-1)*(B-1) << endl;
  return 0;
}



Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main() {
    int n, flag[101] = {0};
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;
        flag[d] = 1;
    }

    int ans = 0; 
    for (int i = 1; i <= 100; i++) 
        ans += flag[i];

    cout << ans << endl;

    return 0;
}

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

int main(){
    int n;cin>>n;
    vector<int> p(n);
    for(int i=0;i<n;i++)cin>>p[i];
    bool res=false;
    bool check0=1;
    for(int i=0;i<n-1;i++){
        if(p[i]>p[i+1])check0=0;
        if(i==n-2&&check0)res=true;
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            vector<int> q=p;
            int c=q[j];
            q[j]=q[i];
            q[i]=c;
            bool check=1;
            for(int k=0;k<n-1;k++){
                if(q[k]>q[k+1])check=0;
                if(k==n-2&&check){
                  res=true;
                }
                }
        }
    }
    if(res)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 3596
temp_S = (input().split("/"))
S = []
for i in range(3):
	S.append(int(temp_S[i]))
	
if S[0] > 2020:
	print('TBD')
elif S[0] < 2018:
	print('Heisei')
elif S[1] > 4:
	print('TBD')
elif S[1] < 4:
	print('Heisei')
elif S[2] > 30:
	print('TBD')
else:
	print('Heisei')

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

struct UnionFind{
	vector<int> rnk,par,num;
	UnionFind(int N) : rnk(N),par(N),num(N){
		init();
	}
	void init(){
		for(int i = 0;i < rnk.size();i++){
			rnk[i] = 0;
			par[i] = i;
			num[i] = 1;
		}
	}
	int find(int x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]){
			par[x] = y;
			num[y] += num[x];
		}
		else{
			par[y] = x;
			num[x] += num[y];
			if(rnk[x] == rnk[y]) rnk[x]++;
		}
	}
	bool same(int x,int y){
		return (find(x) == find(y));
	}
	int size(int x){
		return num[find(x)];
	}
};

int main(){
	int n, m; scanf("%d %d", &n, &m);
	UnionFind tree(n);
	for(int i = 0; i < m; i++){
		int a, b; scanf("%d %d", &a, &b);
		--a; --b;
		tree.unite(a, b);
	}
	int ans = 0;
	for(int i = 0; i < n; i++) ans = max(ans, tree.size(i));
	printf("%d\n", ans);
}

Measured memory_bytes: 5628
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]


def solve():
    n = int(input())
    s = [x for x in input()]
    ans = 0
    for i in range(n - 1):
        a = set(s[:i+1])
        b = set(s[i+1:])
        ans = max(ans, len(a & b))
    print(ans)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()

"""

"""



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

int h, w, cnt;
string s[8];

int main() {
    cin >> h >> w;
    for(int i = 0; i < h; i++) cin >> s[i];

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') cnt++;
        }
    }

    if (cnt == (h + w - 1)) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import pdb
input = sys.stdin.readline

N, W = map(int, input().split())
ws = []
vs = []
for _ in range(N):
  w, v = map(int, input().split())
  ws.append(w)
  vs.append(v)

inf = 1e10

# Value[i番目までの品番][重さj以下]
Value = [[-inf for _ in range(W+1)] for __ in range(N)]

for load in range(W+1):
  if load < ws[0]:
    # 1番目の品物を入れようがなければスキップ
    Value[0][load] = 0
  else:
    Value[0][load] = vs[0]

for num in range(1, N):
  for load in range(W+1):
    if load >= ws[num]:   # 新しい品物を入れられるとき
      # 本来はこれ。負の価値の品物があるならばこれが正しい
      Value[num][load] = max(Value[num][load], Value[num-1][load], Value[num-1][load-ws[num]] + vs[num])
      # すべての品物の価値が正なので、入れられるなら入れた方が良い
      # Value[num][load] = max(Value[num][load], Value[num-1][load-ws[num]] + vs[num])
    else:   # 新しい品物を入れられないとき
      # 価値を変えることはできない
      Value[num][load] = Value[num-1][load]
      # Value[num][load] = max(Value[num][load], Value[num-1][load])

print(Value[N-1][W])


Measured memory_bytes: 287844
maxn = 100000

n , m = map(int, input().split())

par = [0] * n
rank = [0] * n
siz = [1] * n

#初期化
for i in range(n):
    par[i] = i
    rank[i] = 0

#判定(一番上野根を求める)
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
#結合
def unite(x , y):
    rx = find(x)
    ry = find(y)
    
    if rx == ry:
        return
    
    if rank[rx] < rank[ry]:
        par[rx] = ry
        siz[ry] += siz[rx]
        siz[rx] = 0
    elif rank[rx] > rank[ry]:
        par[ry] = rx
        siz[rx] += siz[ry]
        siz[ry] = 0
    else:
        par[ry] = x
        siz[rx] += siz[ry]
        siz[ry] = 0
        rank[rx] += 1

a = [0] * m
b = [0] * m
for i in range(m):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    
nn = [0]*(maxn+1)
for i in range(maxn+1):
    nn[i] = i * (i-1) // 2
    
dis = [0]*m
ans = n*(n-1) // 2
dis[m-1] = ans
for i in range(m-1,0,-1):
    if find(a[i]) == find(b[i]):
        dis[i-1] = ans
    else:
        ans -= (siz[find(a[i])] * siz[find(b[i])])
        dis[i-1] = ans
        
    unite(a[i],b[i])
    
for i in range(m):
    print(dis[i])

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

using namespace std;

int const maxn = 2e5 + 5;
int dp[maxn][2], inf = 1e9;

inline int f(int x, int y) {
    return x == 0 && y == 1;
}

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    for (int j = 0; j <= 1; ++j) dp[0][j] = -inf;
    if (s[0] == 'D') dp[0][1] = 1;
    else if (s[0] == 'P') dp[0][0] = 0;
    else {
        dp[0][1] = 1, dp[0][0] = 0;
    }
    vector < char > t = {'P', 'D'};
    for (int i = 1; i < (int)s.size(); ++i) {
        for (int j = 0; j <= 1; ++j) {
            dp[i][j] = -inf;
            if (s[i] == t[j] || s[i] == '?') {
                for (int lst = 0; lst <= 1; ++lst) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][lst] + j + f(lst, j));
                }
            }
        }
    }
    int i = (int)s.size() - 1, j = 0;
    if (dp[i][0] < dp[i][1]) j = 1;
    string ans = "";
    while (i >= 0) {
        ans += t[j];
        if (i == 0) break;
        for (int lst = 0; lst <= 1; ++lst) {
            if (dp[i][j] == dp[i - 1][lst] + j + f(lst, j)) {
                i--, j = lst;
                break;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

#define int int64_t
//#define stress

int g;

void out(int x)
{
    cout << "! " << x;
#ifdef stress
    assert(x == g);
    cout << " OK" << endl;
#endif
}

int cn = 0;

bool query(int x)
{
    assert(1 <= x && x <= 1e18);
#ifdef stress
    //cout << "? " << x << endl;
    cn++;
    int ans = (x <= g && to_string(x) <= to_string(g)) || (x > g && to_string(x) > to_string(g));
    //cout << ans << endl;
    return ans;
#else
cn++;
    cout << "? " << x << endl;
    char ans;
    cin >> ans;
    return ans == 'Y';
#endif
}

signed main()
{

    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef stress
    for(g = 1; g <= 100; g++)
    #endif
    {
        cn = 0;
        int r = 9999999999LL, l = 1000000000LL;

        while(query(r) == query(r / 10) && query(l) == query(l / 10))
        {
            r /= 10;
            l /= 10;
            if(r == 9)
            {
                out(1);
                goto nxt;
            }
        }
        if(query(r) != query(r / 10))
        {
            l *= 10;
            r = r * 10 + 9;
        }
        while(r - l > 10)
        {
            int m = (l + r) / 2 / 10 * 10 + 5;
            if(query(m))
                r = m;
            else
                l = m;
        }
        assert(cn <= 64);
        out(r / 10);
        nxt:;
    }
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,D;
    cin >> N >> D;
    int ans = 0;
    for(int i=0;i<N;i++){
        ll a,b;
        cin >> a >> b;
        ans += a*a+b*b<=D*D;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n = 0;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	cout << n * n * n << "\n";
	return 0;
}

Measured memory_bytes: 256
def fa(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




n=int(input())
if n==1:
  print(0)
  exit()
A=fa(n)
ans=0
for i in range(len(A)):
  x=int((2*A[i][1])**(0.5))
  if (x-2)*(x-1)<=2*A[i][1]<x*(x-1):
    a=x-2
  if (x-1)*x<=2*A[i][1]<x*(x+1):
    a=x-1
  if (x+1)*x<=2*A[i][1]<(x+2)*(x+1):
    a=x
  if (x+1)*(x+2)<=2*A[i][1]<(x+2)*(x+3):
    a=x+1
  if (x+3)*(x+2)<=2*A[i][1]<(x+4)*(x+3):
    a=x+2
  ans=ans+a
print(ans)

Measured memory_bytes: 63540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr int mod = 1000000007;
constexpr int inf = 1e9;
const int maxn = 100005;
long double x;
int u;
int main(){
	cin>>x;
	u = 0;
	long double y = 100.0;
	long double rate = 1.01;
	while(y < x){
		y *= rate;
		y = floor(y);
		u++;
	}
	cout<<u<<endl;	
	return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int n, m;
  cin >> n >> m;
  int x = 0, y = 1;
  while (x < m) {
    y *= 2;
    x++;
  }
  int ans = (1900*m+100*(n-m))*y;
  cout << ans << endl;
}
  

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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

ll a, b;

vector<ll> A, B;

void prime_factor(vector<ll>& res, ll n) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			res.push_back(i);
			n /= i;
		}
	}
	if (n != 1) res.push_back(n);
	res.erase(unique(res.begin(), res.end()), res.end());
}

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

	prime_factor(A, a);
	prime_factor(B, b);

	ll cnt = 1;
	for (int i = 0; i < A.size(); i++) {
		for (int j = 0; j < B.size(); j++) {
			if (A[i] == B[j]) {
				cnt++;
				break;
			}
		}
	}

	cout<< cnt <<endl;
	
	return 0;
}

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

int N, M;
int d[5010][5010];

int main() {
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int a, b, x;
    cin >> a >> b >> x;
    a--;
    b--;
    d[a][b]   += 1;
    d[a][b+1] -= 1;
    d[a+x+1][b]   -= 1;
    d[a+x+2][b+1] += 1;
    d[a+x+1][b+x+2] += 1;
    d[a+x+2][b+x+1+1] -= 1;
  }

  for (int i=1; i<=N; i++) {
    for (int j=1; j<=N; j++) {
      d[i][j] += d[i-1][j-1];
    }
  }
  for (int i=1; i<=N; i++) {
    for (int j=0; j<=N; j++) {
      d[i][j] += d[i-1][j];
    }
  }
  for (int i=0; i<=N; i++) {
    for (int j=1; j<=N; j++) {
      d[i][j] += d[i][j-1];
    }
  }

  int ans = 0;
  for (int i=0; i<N; i++) {
    for (int j=0; j<=i; j++) {
      if (d[i][j] > 0) ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 100928
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <iomanip>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long


int main(){
	int n;
	cin >> n;
	double ans=0;
	int array[]={1,2,3,4,5,6,7,8};
	P pos[n+1];
	int cnt=0;
	LOOP(i,n){
		int x,y;
		cin >> x >> y;
		pos[i+1]=P(x,y);
	}
	do{cnt++;
		// LOOP(i,n){
		// 	cerr << array[i] << " ";
		// }cerr << endl;
		LOOP1(i,n-1){
			int d = array[i-1];
			int f = array[i];
			double dis =
			sqrt(
				(pos[d].first - pos[f].first)*(pos[d].first - pos[f].first)
				+(pos[d].second - pos[f].second)*(pos[d].second - pos[f].second)
			);
			ans += dis;
			// cerr << dis << "+" << endl;
		}
	}while(next_permutation(array,array+n));
	ans/=cnt;
	cout << fixed << setprecision(15) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
def yakusu(x):
    cnt=0
    for i in range(1,x+1):
        if x%i==0:
            cnt+=1
#    print('x=',x,'cnt=',cnt)
    return cnt

cnt=0
for i in range(1,n+1,2):
    if yakusu(i)==8:
        cnt+=1

print(cnt)

Measured memory_bytes: 3060