akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;
typedef pair<int, int> pii;

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

        vector<pii> a(m);
        for(int i=0; i<m; i++){
            int x,y;
            cin >> x >> y;
            a[i] = pii(x, y);
        }

        int n;
        cin >> n;
        set<pii> b;
        for(int i=0; i<n; i++){
            int x,y;
            cin >> x >> y;
            b.insert(pii(x, y));
        }
        int ansx,ansy;
        for(auto bb: b){
            int dx = bb.first -a[0].first;
            int dy = bb.second -a[0].second;
            bool ok = true;
            for(int i=0; i<m; i++){
                if(b.find(pii(a[i].first+dx, a[i].second+dy)) == b.end()){
                    ok = false;
                    break;
                }
            }
            if(ok){
                ansx = dx;
                ansy = dy;
                break;
            }
        }
        cout << ansx << " " << ansy << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int solve(int x){
    int i = 1;
    while(i*(i+1)/2 <=x)
        ++i;
    if(i*(i+1)/2==x) return i;
    return i-1;
}


vl primeFactorization(ll n){
    vl fact;

    for(ll d=2; d*d<=n; d++){
        while(n%d==0){
            fact.pb(d);
            n/=d;
        }
    }
    if(n>1)
        fact.pb(n);
    return fact;
}


int main(){
    ll n;
    while(cin>>n){
        vl facts = primeFactorization(n);
        map<ll,ll> m;
        for(auto f: facts)
            m[f]++;
        
        int ans = 0;
        for(auto p: m){
            ans+=solve(p.second);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
    string S;
    cin >> S;
    int ans = 0;
    for(auto e:S){
      if(e== '+')ans++;
      else ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
 
  while(1) {
  int n,k;
  cin >> n >> k;
  if(n==0 && k==0) break;
 
  int a[100001] = {};
 
  for(int i=0;i<n;i++) cin >> a[i];
 
  
  int maxsum = 0;
  int sum;
  for(int i=0;i<k;i++) maxsum += a[i];
 
  sum = maxsum;
  for(int i=k;i<n;i++) {
    sum =sum + a[i] - a[i-k];
      if(sum > maxsum) maxsum = sum;
  }
 
  cout << maxsum <<endl;
  }
 
  return 0;
}

Measured memory_bytes: 1556
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M,S;
//i->jの運賃がAで、移動時間がBの時
//集合adj[i]はtuple<j,A,B>を含む
vector<vector<tuple<LL,LL,LL>>> adj;
LL C[51],D[51];

LL ans[51];

void solve(){
	S = min(S,2500LL);
	//頂点1からiのわかってる中で最短距離、i、残り銀貨枚数j
	priority_queue<tuple<LL,LL,LL>,vector<tuple<LL,LL,LL>>,greater<tuple<LL,LL,LL>>> q;
	q.push(tuple<LL,LL,LL>(0,1,S));
	vector<vector<LL>> dist(N+1,vector<LL>(2501,INF));
	dist[1][S] = 0;
	while(!q.empty()){
		LL d = get<0>(q.top());//頂点1からiのわかってる中で最短距離
		LL i = get<1>(q.top());//今見ている頂点の番号
		LL j = get<2>(q.top());//残り銀貨枚数
		q.pop();
		if(dist[i][j]<d) continue;
		for(auto next:adj[i]){
			LL ni = get<0>(next);
			LL silver_required = get<1>(next);
			LL time_required = get<2>(next);
			LL nj = j - silver_required;
			if(nj<0) continue;
			if(dist[ni][nj]<=dist[i][j]+time_required) continue;
			dist[ni][nj] = dist[i][j]+time_required;
			q.push(tuple<LL,LL,LL>(dist[ni][nj],ni,nj));
		}
		if(j<2500){
			LL nj = min(j+C[i],2500LL);
			if(dist[i][nj]<=dist[i][j]+D[i]) continue;
			dist[i][nj] = dist[i][j]+D[i];
			q.push(tuple<LL,LL,LL>(dist[i][nj],i,nj));
		}
	}
	for(int i=2;i<=N;i++){
		ans[i] = INF;
		for(int j=0;j<=2500;j++){
			ans[i] = min(ans[i],dist[i][j]);
		}
	}
}

int main(){
    cin >> N >> M >> S;
    adj = vector<vector<tuple<LL,LL,LL>>>(N+1);
    for(int i=0;i<M;i++){
    	LL u,v,a,b;cin >> u >> v >> a >> b;
    	adj[u].push_back(tuple<LL,LL,LL>(v,a,b));
    	adj[v].push_back(tuple<LL,LL,LL>(u,a,b));
    }
    for(int i=1;i<=N;i++) cin >> C[i] >> D[i];

    solve();

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

Measured memory_bytes: 6788
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
		  #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
		   ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
			   # #  # # #                   # #      ###### #    # #    # #      #####
		  #    # #   #  #              #    # #      #    # #    # #    # #      #   #
		   ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
	*/
	 
	#include<bits/stdc++.h>
	using namespace std;
	 
	typedef long long LL;
	typedef vector<LL> VLL;
	typedef vector<string> VS;
	typedef vector<pair<LL, LL> > VP;
	 
	 
	#define For(in) for (LL i = 0; i < (n); i++)
	#define FOR(in) for(LL i=1; i <= (n); i++)
	#define pb push_back
	#define sr(v) sort(v.begin(), v.end())
	#define rev(v) reverse(v.begin(), v.end())
	#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
	#define exit(); return 0;
	#define no "NO"
	#define yes "YES"
	#define con continue;
	 
	 
	LL concate(LL a, LL b)
	{
		ostringstream os;
		os <<a <<b;
		istringstream is(os.str());
		LL c;
		is>> c;
		return c;
	}
	 
	 
	LL check(char c)
	{
		return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
	}
	 
	 
	int main()
	{
		LL q,t;
		//cin>>t;
		//while(t--)
		//{
		   LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
			LL aa[1000];
			LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
			LL ma=0, mi=100000000;
			LL mid=0, temp=0, stop=0, start=0;
			double pi= 3.141592653589793;
			double d1=0.0, d2, d3, d4;
			VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
			VS vs, vs1, vs2, vs3, vs4;
			VP vp, vp1,vp2;
			char ch, ch1, ch2[1001];
			string str, str1, str2, str3, str4, str5;
			pair<LL, LL> pa;
			list<LL> li, li1;
			map<LL, LL> mp, mp1;
			set<LL> st;
			map<LL ,LL> :: iterator imll;
			VLL :: iterator ivll;
			set<LL> :: iterator isll;
			VP :: iterator ivp;
	 
			
			cin>>a>>b>>x;
			if(a%x==0)d=(a/x)-1;
			else d = a/x;
			e = b/x;
			cout<<e-d<<endl;
	 
		 //}
	 
		exit()
	 
	 
	}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
signed main() {
	int h, r; cin >> h >> r;
	if (-r == h)cout << 0 << endl;
	else if (-r<h)cout << 1 << endl;
	else cout << -1 << endl;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int mod = 998244353;

map<string,int> dp;

int rec(string s) {
	if (dp.find(s) != dp.end()) return dp[s];
	int res = rec(s.substr(1));
	if (s[0]=='1') res *= 2;
	if (res >= mod) res -= mod;
	int n = SZ(s);
	for (int len = 1; len*2 <= n; len++) {
		string v = s.substr(0, len);
		for (int k = 2; k*len <= n; k++) {
			int fst = len*(k-1);
			FOR(i,len) if (s[fst+i]=='0') v[i] = '0';
			//printf("%s asking for %s and %s\n", s.c_str(), v.c_str(), s.substr(len*k).c_str());
			res = (1LL * rec(v) * rec(s.substr(len*k)) + res) % mod;
		}
	}
	//printf("dp[%s] = %d\n", s.c_str(), res);
	return dp[s] = res;
}

char s[111];
int main() {
	scanf("%s", s);
	dp[""] = 1;
	printf("%d\n", rec(s));
	return 0;
}


Measured memory_bytes: 5632
#include<iostream>
using namespace std;
int main(){
    int n,x,count;
    while (true){
        cin>>n>>x;
        if(n==0 && x==0) break;
        else{
            count=0;
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                        if(i+j+k==x) count+=1;
                        else{
                            continue;
                        }
                    }
                }
            }cout<<count<<endl;
        }
    }
}


Measured memory_bytes: 3088
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;
struct Node{Node *parent, *left, *right; int key;};
Node T[10000];
int D[10000];
int H[10000];

Node *root, *NIL;


void print_preorder(Node *r){
    if(r==NIL) return;
    cout<<" "<<r->key;
    print_preorder(r->left);
    print_preorder(r->right);
}

void print_inorder(Node *r){
    if(r==NIL) return;
    print_inorder(r->left);
    cout<<" "<<r->key;
    print_inorder(r->right);
}

//void print_postorder(int r){
//    if(r==-1) return;
//    print_postorder(T[r].left);
//    print_postorder(T[r].right);
//    cout<<" "<<r;
//}

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z=(Node *)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NIL){
        root = z;
    }else{
        if(z->key<y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}

void find(int k){
    Node *x = root;
    while(x!=NIL){
        if(x->key==k){
            cout<<"yes"<<endl;
            return;
        }else if(x->key>k){
            x=x->left;
        }else if(x->key<k){
            x=x->right;
        }
    }
    cout<<"no"<<endl;
    return;
}

int main()
{
    int n,i,x;
    string com;

    cin>>n;
    for(i=0;i<n;i++){
        cin>>com;
        if(com=="insert"){
            cin>>x;
            insert(x);
        }else if(com=="print"){
            print_inorder(root);
            cout<<endl;
            print_preorder(root);
            cout<<endl;

        }else if(com=="find"){
            cin>>x;
            find(x);
        }
    }

    return 0;
}


Measured memory_bytes: 21900
#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() {
  int N;
  string S;
  cin >> N >> S;

  map<char, vector<int> > counts;
  vector<char> colors = {'R', 'G', 'B'};
  for (auto color : colors) {
    counts[color].resize(N);
  }

  // init (i = N - 1)
  for (auto color : colors) {
    counts[color][N - 1] = 0;
  }
  counts[S[N - 1]][N - 1]++;

  // iterate
  for (int i = N - 2; i >= 0; --i) {
    for (auto color : colors) {
      counts[color][i] = counts[color][i + 1];
    }
    counts[S[i]][i]++;
  }
  
  ll ans = 0;
  for (int i = 0; i < N - 2; ++i) {
    for (int j = i + 1; j < N - 1; ++j) {
      if (S[i] != S[j]) {
	char color;
	if (S[i] != 'R' and S[j] != 'R') {
	  color = 'R';
	} else if (S[i] != 'G' and S[j] != 'G') {
	  color = 'G';
	} else {
	  color = 'B';
	}
	ans += counts[color][j + 1];
	int k = j + (j - i);
	if (k < N and S[k] == color) {
	  --ans;
	}
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3164
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

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

int ans1=0,ans2=0,N,sum;

int main(){
    cin>>N;
    int X[N];
    rep(i,N){
        cin>>X[i];
        sum+=X[i];
    }
    int ave=sum/N;
    int ave1=ave+1;
    rep(i,N){
        ans1+=(ave-X[i])*(ave-X[i]);
        ans2+=(ave1-X[i])*(ave1-X[i]);
    }
    out(min(ans1,ans2));
    
    
}

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

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

    int main()
    {
        int m, n;
        int a[202] = {0};
        scanf("%d%d", &n, &m);
        int sum = 0;
        for(int i = 1; i <= n; i++){
            scanf("%d", &a[i]);
            sum += a[i];
        }
        sort(a + 1, a + n + 1, cmp);
        if(a[m] < sum * 1.0 / (4 * m))
            printf("No\n");
        else
            printf("Yes\n");
        return 0;
    }
    /*
    4 2
    5 4 4 3
    */


Measured memory_bytes: 256
/*
@Date    : 2019-10-10 21:43:24
@Author  : Adscn (adscn@qq.com)
@Link    : https://www.cnblogs.com/LLCSBlog
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IL inline
#define RG register
#define gi geti<int>()
#define gl geti<ll>()
#define gc getchar()
#define File(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
template<typename T>IL bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
template<typename T>IL bool chkmin(T &x,const T &y){return x>y?x=y,1:0;}
template<typename T>
IL T geti()
{
	RG T xi=0;
	RG char ch=gc;
	bool f=0;
	while(!isdigit(ch))ch=='-'?f=1:f,ch=gc;
	while(isdigit(ch))xi=xi*10+ch-48,ch=gc;
	return f?-xi:xi;
}
template<typename T>
IL void pi(T k,char ch=0)
{
	if(k<0)k=-k,putchar('-');
	if(k>=10)pi(k/10);
	putchar(k%10+'0');
	if(ch)putchar(ch);
}
const int N=2e5+7;
struct edge{
	int v,nxt,w;
}e[N<<1];
struct Edge{
	int u,v;
	ll w;
	Edge(){}
	explicit Edge(int _u,int _v,ll _w):u(_u),v(_v),w(_w){}
	bool operator < (const Edge &b)const{return w<b.w;}
};
vector<Edge>G;
int head[N],cnt;
inline void init(){memset(head,cnt=-1,sizeof head);}
inline void add(int u,int v,int w){e[++cnt]=(edge){v,head[u],w},head[u]=cnt;}
inline void link(int u,int v,int w){add(u,v,w),add(v,u,w);}
#define For_tree(x) for(int i=head[x],v=e[i].v;~i;i=e[i].nxt,v=e[i].v)
int siz[N],hson[N],total,Hrt,n,vis[N];
ll dep[N],W[N];
pair<ll,int> Min;
inline void grt(int x,int p=0)
{
	hson[x]=0,siz[x]=1;
	For_tree(x)
		if(v^p&&!vis[v])
			grt(v,x),siz[x]+=siz[v],chkmax(hson[x],siz[v]);
	chkmax(hson[x],total-siz[x]);
	if(hson[x]<hson[Hrt])Hrt=x;
}
inline void gdis(int x,int p=0)
{
	G.push_back(Edge(Min.second,x,dep[x]+W[x]+Min.first));
	For_tree(x)
		if(v^p&&!vis[v])
			gdis(v,x);
}
inline void gmin(int x,int p=0)
{
	chkmin(Min,decltype(Min)(dep[x]+W[x],x));
	For_tree(x)
		if(v^p&&!vis[v])
			dep[v]=dep[x]+e[i].w,gmin(v,x);
}
inline void work(int x){
	Min=decltype(Min)(W[x],x),dep[x]=0;
	gmin(x),gdis(x);
}
inline void solve(int x)
{
	vis[x]=1,work(x);
	For_tree(x)
		if(!vis[v])
		{
			Hrt=0,total=siz[v];
			grt(v),solve(Hrt);
		}
}
int fa[N];
inline int find(int x){return fa[x]==x?x:(fa[x]=find(fa[x]));}
inline int join(int x,int y){
	x=find(x),y=find(y);
	if(x==y)return 0;
	return fa[x]=y,1;
}
int main(void)
{
	n=gi;init();
	for(int i=1;i<=n;++i)W[i]=gi,fa[i]=i;
	for(int i=1,u,v,w;i<n;++i)u=gi,v=gi,w=gi,link(u,v,w);
	total=hson[Hrt=0]=n;
	grt(1),solve(Hrt);
	sort(G.begin(),G.end());
	ll ans=0,cnt=0;
	for(auto i:G)
		if(join(i.u,i.v))
			ans+=i.w,++cnt;
	pi(ans);
	return 0;
}

Measured memory_bytes: 84320
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String line = br.readLine();
			String[] str = line.split(" ");
			int h = Integer.parseInt(str[0]);
			int w = Integer.parseInt(str[1]);
			if ( h == 0 && w == 0 ){ //??\????????¨??????0
				break;
			}

			for (int i = 0; i < h ; i++ ) {
				for (int k = 0; k < w ; k++ ) {
					if ( i == 0 || i == (h-1)) {
						System.out.print("#");
					}else{
						if ( k == 0 || k == (w-1)) {
							System.out.print("#");
						}else{
							System.out.print(".");
						}
					}
				}
					System.out.print("\n");
			}
			System.out.print("\n");
		}
	}
}

Measured memory_bytes: 35836
#include <bits/stdc++.h>
using namespace std;
const int sz=1e5+9;
int n,m;
int f[sz],t[sz];
vector<long long> v;
int p[sz],s[sz];
long long ans,cnt;

int findp(int a){
    return (a==p[a]?a:p[a]=findp(p[a]));
}

bool same(int a,int b){
    return findp(a)==findp(b);
}

long long unite(int a,int b){
    long long ret;
    a=findp(a);
    b=findp(b);
    ret=s[a];
    s[a]+=s[b];
    p[b]=a;
    ret*=s[b];
    return ret;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++) scanf("%d %d",&f[i],&t[i]);
    for(int i=1;i<=n;i++){
        p[i]=i;
        s[i]=1;
    }
    ans=n;
    ans*=(n-1);
    ans>>=1;
    for(int i=m-1;i>=0;i--){
        v.push_back(ans);
        if(!same(f[i],t[i])){
            cnt=unite(f[i],t[i]);
            ans-=cnt;
        }
    }
    for(int i=v.size()-1;i>=0;i--) printf("%lld\n",v[i]);
    return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

__int128 n, a, b, c, d, res;

string to_string (__int128 n) {
	string res;
	while (n) {
		res.pb(n % 10 + '0');
		n /= 10;
	}
	reverse(all(res));
	return res;
}

map<ll, __int128> mem;

__int128 dp (ll n) {
	if (n == 0) return 0;

	if (mem.count(n)) return mem[n];
	__int128 &res = mem[n];
	res = d * n;

	ll to = n - n % 2;
	res = min(res, d * (n - to) + a * bool(to) + dp(to / 2));

	to += 2;
	res = min(res, d * (to - n) + a * bool(to) + dp(to / 2));

	to = n - n % 3;
	res = min(res, d * (n - to) + b * bool(to) + dp(to / 3));

	to += 3;
	res = min(res, d * (to - n) + b * bool(to) + dp(to / 3));

	to = n - n % 5;
	res = min(res, d * (n - to) + c * bool(to) + dp(to / 5));

	to += 5;
	res = min(res, d * (to - n) + c * bool(to) + dp(to / 5));

	return res;
}

void solve () {
	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	n = N;
	a = A;
	b = B;
	c = C;
	d = D;

	mem.clear();
	cout << to_string(dp(n)) << endl;	
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int t;
	cin >> t;
	while (t--)
		solve();

	return 0;
}


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

int main(){
  string s;
  cin >> s;
  if(s=="Sunny"){
    cout << "Cloudy" << endl;
  }
  else{
    if(s=="Cloudy"){
      cout << "Rainy" << endl;
    }
    else{
      cout << "Sunny" << endl;
    }
  }
  
  return 0;
}

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

using namespace std;

struct BIT{
  vector<int>node;
  int sz;
  BIT(int sz):sz(sz){
    node.resize(sz,0);
  }
  int sum(int i){
    int res=0;
    for(i--;i>=0;i=(i&(i+1))-1)res+=node[i];
    return res;
  }
  void add(int i,int x){
    for(;i<sz;i|=i+1)node[i]+=x;
  }
  int sum(int l,int r){
    return sum(r)-sum(l);
  }
};

signed main(){
  int N;
  string S;
  cin>>N>>S;
  vector<BIT>bits;
  for(int i=0;i<26;i++)bits.push_back(BIT(N));
  for(int i=0;i<N;i++){
    bits[S[i]-'a'].add(i,1);
  }
  int Q;
  cin>>Q;
  for(int i=0;i<Q;i++){
    int q;
    cin>>q;
    if(q==1){
      int index;
      char c;
      cin>>index>>c;
      index--;
      bits[S[index]-'a'].add(index,-1);
      bits[c-'a'].add(index,1);
      S[index]=c;
    }
    if(q==2){
      int l,r;
      cin>>l>>r;
      l--,r--;
      int ans=0;
      for(int j=0;j<26;j++){
        ans+=min(bits[j].sum(l,r+1),1);
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 51716
#include <iostream>

void BubbleSort(char* A, char* a, int N)
{
  for(int i=0; i<N-1; ++i){
    for(int j=N-1; j>i; --j){
      if( a[j] < a[j-1] ){
        std::swap(A[j], A[j-1]);
        std::swap(a[j], a[j-1]);
      }
    }
  }
}

void SelectionSort(char* B, char* b, int N)
{
  for(int i=0; i<N-1; ++i){
    int minj = i;
    for(int j=i+1; j<N; ++j){
      if( b[j] < b[minj] ){
        minj = j;
      }
    }
    if(i != minj){
      std::swap(B[i], B[minj]);
      std::swap(b[i], b[minj]);
    }
  }
}


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

  char A[n], a[n];
  char B[n], b[n];
  char IN[n], in[n];

  for(int i=0; i<n; ++i){
    std::cin >> A[i] >> a[i];
  }

  for(int i=0; i<n; ++i){
    IN[i] = B[i] = A[i];
    in[i] = b[i] = a[i];
  }

  /*------------ BubbleSort -----------*/
  BubbleSort(A, a, n);
  for(int i=0; i<n; ++i){
    if(i != 0) std::cout << " ";
    std::cout << A[i] << a[i];
  }
  std::cout << std::endl;
  std::cout << "Stable" << std::endl;

  /*------------ SelectionSort -----------*/
  SelectionSort(B, b, n);
  for(int i=0; i<n; ++i){
    if(i != 0) std::cout << " ";
    std::cout << B[i] << b[i];
  }
  std::cout << std::endl;

  int i;
  for(i=0; i<n; ++i){
    if(a[i] != b[i] || A[i] != B[i]) break;
  }
  if(i == n){
    std::cout << "Stable" << std::endl;
  }else{
    std::cout << "Not stable" << std::endl;
  }


  return 0;
}



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

int main() {
    int N, T;
	cin >> N >> T;
    
    long long t[N];
	
    for (int i = 0; i < N; ++i){
		cin >> t[i];
	}
	
    long long now, end;
    long long sums = 0;
    now = t[0];
    end = t[0] + T;
    for (int i = 0; i < N; ++i){
        if(end < t[i+1]){
            sums += (end - now);
            now = t[i+1];
            end = t[i+1] + T;
        }else if(end >= t[i+1]){
            sums += t[i+1] - t[i];
            now = t[i+1];
            end = t[i+1] + T;
        }
	}
    cout << sums << endl;
}

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

int main(void){

  int l,a,b,c,d,res1,res2;

  cin >> l >> a >> b >> c >> d;

  res1 = a / c;
  res2 = b / d;
  
  res1 += (a % c != 0)? 1 : 0;
  res2 += (b % d != 0)? 1 : 0;

  l -= (res1 < res2)? res2 : res1;

  cout << l << endl;
  return 0;
}

Measured memory_bytes: 3108
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  const r = Number(lines[0]);
  console.log(3 * (r ** 2));
});


Measured memory_bytes: 7628
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define F first
#define S second


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n; cin >> n;
	VI a(n); rep(i, n)cin >> a[i];
	int m; cin >> m;
	VI b(m); rep(i, m)cin >> b[i];
	puts(includes(all(a), all(b)) ? "1" : "0");
}


Measured memory_bytes: 4328
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}

		w := 512
		weights := make([]int, 10)
		for i := 9; i >= 0; i-- {
			if n >= w {
				weights[i] = w
				n -= w
			}
			w /= 2
		}

		output := []int{}
		for i := 0; i < 10; i++ {
			if weights[i] > 0 {
				output = append(output, weights[i])
			}
		}
		outputStr := fmt.Sprint(output)
		fmt.Println(outputStr[1:(len(outputStr) - 1)])
	}
}



Measured memory_bytes: 1112
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <assert.h>
#include <time.h>
#include <memory.h>
#include <set>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <unordered_map>

using namespace std;

const int mod = 1000000007;

int a[211111];

int cmp(int a, int b) {
	return abs(b) > abs(a);
}

int main() {
	ios::sync_with_stdio(0);
	int t, sn = 0;
	t = 1; // assert(1 <= t && t <= 1e5);
	while (t --) {
		int n, k;
		cin >> n >> k;
		sn += n;
		bool zero = 0;
		for (int i = 0; i < n; ++i) {
			cin >> a[i];

			zero |= (a[i] == 0);
		}
		sort(a, a + n, cmp);

//        for(int i = 0; i < n; ++i) {
//            cout << a[i] << " ";
//            if (i == n-k-1)
//                cout << "\n";
//        }
//        cout << "\n";

		int sn = 1;
		vector<int> nums;
		int gneg = -1e9 - 1, gpos = 1e9 + 1;
		for (int i = 0, id = n - 1; i < k; ++i, id--) {
			if (a[id] < 0) sn *= -1;
			nums.push_back(a[id]);
			if (a[id] < 0)
				gneg = max(gneg, a[id]);
			else
				gpos = min(gpos, a[id]);
		}

		if (sn > 0) {
			int ans = 1;
			for (auto x : nums)
				ans = (ans * 1ll * x) % mod;
			cout << (ans + mod) % mod << "\n";
		} else {
			int mn = 1, mx = -1;
			for (int i = 0; i < n - k; ++i) {
				mn = min(mn, a[i]);
				mx = max(mx, a[i]);
			}

			//cout << gneg << " " << mx << "\n";
			//cout << gpos << " " << mn << "\n";

			bool g1 = gneg != -1e-9 - 1 && mx != -1;
			bool g2 = gpos != 1e9 + 1 && mn != 1;
			if (g1 && g2) {
				int val, repl;
				if (mx * 1ll * gpos > mn * 1ll * gneg)
					val = gneg, repl = mx;
				else
					val = gpos, repl = mn;

				for (int i = 0; i < k; ++i)
					if (nums[i] == val) {
						nums[i] = repl;
						break;
					}
				int ans = 1;
				for (auto x : nums)
					ans = (ans * 1ll * x) % mod;
				cout << (ans + mod) % mod << "\n";
			} else if (g1) {
				for (int i = 0; i < k; ++i)
					if (nums[i] == gneg) {
						nums[i] = mx;
						break;
					}
				int ans = 1;
				for (auto x : nums)
					ans = (ans * 1ll * x) % mod;
				cout << (ans + mod) % mod << "\n";
			} else if (g2) {
				for (int i = 0; i < k; ++i)
					if (nums[i] == gpos) {
						nums[i] = mn;
						break;
					}
				int ans = 1;
				for (auto x : nums)
					ans = (ans * 1ll * x) % mod;
				cout << (ans + mod) % mod << "\n";
			} else {
				if (zero)
					cout << "0\n";
				else {
					int ans = 1;
					for (int i = 0; i < k; ++i)
						ans = (ans * 1ll * a[i]) % mod;
					cout << (ans + mod) % mod << "\n";
				}
			}


		}
	}
	return 0;
}

Measured memory_bytes: 5116
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s[0] == 'S'){
        cout << "Cloudy" << endl;
    }
    else if (s[0] == 'C'){
        cout << "Rainy" << endl;
    }
    else {
        cout << "Sunny" << endl;
     }
}


Measured memory_bytes: 256
#include<iostream>
#define r(n) for(int i=0;i<(n);i++)
#define p(a) std::cout<<a
main(){int a,b,c,d;std::cin>>a>>b>>c>>d;c-=a;d-=b;r(d)p("U");r(c)p("R");r(d)p("D");c++;d++;r(c)p("L");r(d)p("U");r(c)p("R");p("DR");r(d)p("D");r(c)p("L");p("U");}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
ans = []    
for i in range(n-1, -1, -1):
    if sum(b[i::i+1])%2 != a[i]:
        b[i] = 1
        ans.append(i+1)
print(len(ans))
if len(ans):
    print(*ans)

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

/**
 *
 * @author k16069kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        int H = 0;
        int W = 0;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                H = Integer.parseInt(st.nextToken());
                W = Integer.parseInt(st.nextToken());
                for (int i = 0; i < H; i++) {
                    for (int j = 0; j < W; j++) {
                        if (i == 0 || j == 0 || i == H-1 || j == W-1) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                        
                    }
                    System.out.println();
                }
                if(H == 0 && W == 0) break;
                System.out.println("");
                
            }
            if(H == 0 && W == 0) break;
        }
    }
    
}



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

int n;
string s[55];

int main() {
  // 入力
  cin >> n;
  for (int i=0; i<n; i++) cin >> s[i];
  // aから順に全部の文字列に共通してある個数を数えて、それを結合したものが答え
  string ans = "";
  for (char c='a'; c<='z'; c++) {
    int mini = 100;
    for (int i=0; i<n; i++) {
      int cnt = 0;
      for (int j=0; j<s[i].size(); j++) {
        if (s[i][j] == c) cnt++;
      }
      mini = min(mini, cnt);
    }
    for (int i=0; i<mini; i++) {
      ans += c;
    }
  }
  // 解答
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n;
  int x, y;
  cin >> n;
  scanf("%d.%2d", &x, &y);
  ll m = 100*x+y;
  cout << (ll)n*m/100 << endl;

}


Measured memory_bytes: 3772
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int[] sum = new int[n + 1];
		sum[0] = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'E') {
				sum[i + 1] = sum[i] + 1;
			} else {
				sum[i + 1] = sum[i];
			}
		}
		int ans = Integer.MAX_VALUE;
		for(int i = 1; i < n + 1; i++) {
			int tmp = 0;
			tmp += i - 1 - sum[i - 1] + sum[n] - sum[i];
			ans = Math.min(ans, tmp);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 28844
import heapq

N = int(input())

a = list(map(int, input().split()))

n1 = a[:N]

heapq.heapify(n1)

sum1 = sum(n1)

arr1 = [sum1]

for i in range(N, 2*N):
    heapq.heappush(n1, a[i])
    sum1 += a[i]
    sum1 -= heapq.heappop(n1)
    arr1.append(sum1)

n2 = [-i for i in a[2*N:]]

heapq.heapify(n2)
sum2 = sum(n2)

arr2 = [sum2]

for i in range(1, N+1):
    heapq.heappush(n2, -a[2*N-i])
    sum2 += -a[2*N-i]
    sum2 -= heapq.heappop(n2)
    arr2.append(sum2)

ans = -10**17

for i, j in zip(arr1, reversed(arr2)):
    ans = max(ans, i+j)

print(ans)


Measured memory_bytes: 38144
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;cin>>n;int a[n];
	int ans=INT_MIN;
	vector<int>x[n],y[n];
	 for(int j=0;j<n;j++)
   	 {
   	 		cin>>a[j];
		for(int k=0;k<a[j];k++)
			{
				int r ,s;cin>>r>>s;
				x[j].push_back(r);y[j].push_back(s);
				}
		}
	for(int i=0;i<(1<<n);i++)
	{
		int flag=1;
		bitset<15>b(i);
	 for(int j=0;j<n;j++)
   	 {
		if(b.test(j))
		{
			for(int k=0;k<a[j];k++)
			{
				if(y[j][k]==1)
				{
					if(!b.test(x[j][k]-1))
					{
						flag=0;
						break;
					}
				}
				else
				{
					if(b.test(x[j][k]-1))
					{
						flag=0;
						break;
					}
				}
			}
		}
	 }
	 if(flag)
	 {
	 	int f=b.count();
		ans=max(ans,f);
	 }
	}
	cout<<ans;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 1000000007LL;
const int Maxn = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 21;

vector<ll> A, B;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	str s;
	cin >> s;
	for(int i = 0; i< n + n;i++){
		int al = (s[i] == 'B') + i;
		al &= 1;
		if(al == 1) A.pb(i);
		else B.pb(i);
	}
	ll ans = 1;
	if(A.size() != B.size()) return cout << 0, 0;
	for(int i = n - 1; i >= 0; i--){ 
		int cn = n - (lower_bound(all(B), A[i]) - B.begin());
		ans *= (cn - (n - 1 - i));
		ans%=Mod; 
	}
	for(int i = 1; i <= n; i++) ans = (ans*i)%Mod;
	cout << ans;
	return 0;
}

/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/



Measured memory_bytes: 3340
s = input()
Q = int(input())

qs = list()
for i in range(Q):
    qs.append(input().split())

# ns = s
cnt_r = 0
bs, es = '', ''
# for i in range(Q):
#     q = input().split()
for q in qs:
    if len(q) == 1:
        cnt_r += 1
    else:
        f, c = int(q[1]), q[2]
        if f == 1:
            if cnt_r % 2 == 1:
                es += c
                # ns = ns + c
            else:
                bs = c + bs
                # ns = c + ns
        else:
            if cnt_r % 2 == 1:
                bs = c + bs
                # ns = c + ns
            else:
                es += c
                # ns = ns + c

ns = bs + s + es
if cnt_r % 2 == 1:
    print(ns[::-1])
else:
    print(ns)


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

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define V 100000

int v, e;
vector<int> g[V];
int ord[V], low[V];
int cnt;
vector<int> ans;

int dfs(int v, int f) {
  ord[v] = ++cnt;
  int res = cnt;
  bool a = false;
  int d = 0;
  rep(i, g[v].size()) {
    int t = g[v][i];
    if(v == t) continue;
    if(!ord[t]) {
      ++d;
      int r = dfs(t, v);
      if(f != -1 && ord[v] <= r) {
        a = true;
      }
      res = mind(res, r);
    } else {
      res = mind(res, ord[t]);
    }
  }
  low[v] = res;
  if(f == -1 && d > 1) ans.push_back(v);
  if(a) {
    ans.push_back(v);
  }
  return res;
}

int main() {
  cin >> v >> e;
  rep(i, e) {
    int s, t;
    cin >> s >> t;
    g[s].push_back(t);
    g[t].push_back(s);
  }
  dfs(0, -1);
  sort(ALL(ans));
  rep(i, ans.size()) {
    cout << ans[i] << endl;
  }
  return 0;
}

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

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

template <class T = int>
int in() {
  T x;
  cin >> x;
  return x;
}
int bpm(int x, int y) {
  if (x == 0)
    return 0;
  else if (y == 0) {
    return 1;
  }
  int ans = 1;
  x %= MOD;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) {
      ans *= x;
      ans %= MOD;
    }
    x = x * x;
    x %= MOD;
  }
  return ans;
}

class EAlmostEverywhereZero {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    vector<vector<vector<int>>> dp(110, vector<vector<int>>(5, vector<int>(2, 0)));
    string S;
    int K;
    cin >> S >> K;
    dp[0][1][1] = max(0, (S[0] - '0') - 1);
    dp[0][1][0] = 1;
    rep(i, S.size() - 1) {
      dp[i + 1][1][1] += 9;
      rep(j, 4) {
        dp[i + 1][j + 1][1] += dp[i][j][1] * 9 + dp[i][j][0] * max(0, (S[i + 1] - '0' - 1));
        dp[i + 1][j][1] += dp[i][j][1] + (S[i + 1] == '0' ? 0 : dp[i][j][0]);
        dp[i + 1][j + 1][0] += (S[i + 1] == '0' ? 0 : dp[i][j][0]);
        dp[i + 1][j][0] += (S[i + 1] == '0' ? dp[i][j][0] : 0);
      }
    }
    cout << dp[S.size() - 1][K][0] + dp[S.size() - 1][K][1] << endl;
  }
};


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

ll dp[405][405];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  vector<ll> b(a);
  FOR(i, 1, n) b[i] += b[i-1];
  REP(i, n) REP(j, n) dp[i][j] = LLINF;
  REP(i, n) dp[i][i] = 0;

  FOR(w, 2, n+1) {
    REP(l, n) {
      ll r = l + w - 1;
      if(r >= n) break;
      FOR(i, l, r) {
        chmin(dp[l][r], dp[l][i] + dp[i+1][r] + b[r] - (l==0?0:b[l-1]));
      }
    }
  }
  cout << dp[0][n-1] << endl;

  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

//aのp乗を求めるアルゴリズム。計算量はO(logp)
ll modpow(ll a, int p) {

    if(p == 0) {
        return 1;
    }
    if(p%2 == 0) {
        //pが偶数の時
        int halfP = p/2;
        ll half = modpow(a, halfP);
        //a^(p/2)をhalfとして、half*halfを計算
        return half * half % mod;
    }
    else {
        //pが奇数の時は、pを偶数にするために1減らす
        return a * modpow(a, p-1) % mod;
    }
}

ll Comb(int a, int b) {

    if(b > a-b) {
        return Comb(a, a-b);
    }

    ll ansMul = 1LL, ansDiv = 1LL;
    rep(i, b) {
        ansMul *= (a-i);
        ansDiv *= (i+1);
        ansMul %= mod;
        ansDiv %= mod;
    }
    
    // ansMul/ansDivをやりたい
    // ansDivの逆元を使って求めよう
    ll ans = ansMul * modpow(ansDiv, mod-2) % mod;

    return ans; 
}

int main() {
    int x, y;
    cin >> x >> y;

    int z = x+y;

    if(z%3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int n = z/3;

    if(x < n || y < n) {
        cout << 0 << endl;
        return 0;
    }

    cout << Comb(n, x-n) << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    r = 0
    for i in range(1, N+1):
        r += i * (N + 1 - i)
    for i in range(N-1):    
        u, v = map(int, input().split())
        u, v = min(u, v), max(u, v)
        r -= u * (N + 1 - v)
    return r
print(main())


Measured memory_bytes: 9204
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val cityList = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    val heroList = readLine()!!.split(" ").map { it.toLong() }
    var ans = 0L
    for(i in heroList.indices) {
        var remain = heroList[i]
        var kill = Math.min(remain, cityList[i])
        ans += kill
        remain -= kill
        cityList[i] -= kill
        if(remain > 0) {
            kill = Math.min(remain, cityList[i+1])
            ans += kill
            cityList[i+1] -= kill
        }
    }
    println(ans)
}


Measured memory_bytes: 83400
import java.util.*;

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

    static void read(){
        array = new int[10];
        for(int i = 0; i < 10; i++){
            array[i] = sc.nextInt();
        }
    }

    static void solve(){
        Arrays.sort(array);
        System.out.println(array[9]);
        System.out.println(array[8]);
        System.out.println(array[7]);
    }

}

Measured memory_bytes: 26284
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    //vector<int> an(1e9 + 1, 0);
    map<int, int> an;
    int n, a;
    cin >> n;
    bool flag = true;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (an[a] != 0){
            flag = false;
        }
        an[a]++;
    }
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 9600
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

ans = 0
t = n - 1
for i in range(n):
    lim = 2
    if i == 0:
        lim = 1
    for j in range(lim):
        if t > 0:
            ans += a[i]
            t -= 1

print(ans)


Measured memory_bytes: 105484