akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

                    
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    char c;
    cin >> c;
    char b = c + 1;
    cout << b << endl;
}


Measured memory_bytes: 3552
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
using namespace std;
int main(void){
    int ans=1;
    string s;
    cin>>s;
    string t="AKIHABARA";
    for(int i=0;i<t.length();i++){
        if(s[i]!=t[i]){
            s.insert(s.begin()+i,'A');
        }
    }
    if(s.length()!=t.length())ans=0;
    for(int i=0;i<t.length();i++){
        if(s[i]!=t[i])ans=0;
    }
    cout<<(ans?"YES":"NO")<<endl;
}
    
  

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

vector<int>devisor(int n) {
	vector<int>value;
	FOR(i, 1, pow(n, 0.5) + 1) {
		if (n % i == 0) {
			value.push_back(i);
			if (i * i != n) {
				value.push_back(n / i);
			}
		}
	}
	return value;
}

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(all(a));

	int b = a[0];
	int c = a[1];
	vector<int>devisor_b,devisor_c;
	devisor_b = devisor(b);
	devisor_c = devisor(c);
	rep(i, devisor_b.size()) {
	//	cout << devisor_b[i] << endl;
	}
	sort(all(devisor_b));
	reverse(all(devisor_b));
	sort(all(devisor_c));
	reverse(all(devisor_c));
	bool flag = true;
	int i = 0;
	int gcd = 1;

	while(flag) {
		int count = 0;
		//cout << devisor_c[i];
		rep(j, n) {
			if (a[j] % devisor_c[i] != 0) {
				count++;
			}
			if (count >= 2) {
				break;
			}
		}
		//cout <<" " <<count << endl;

		if (count <= 1) {
			gcd = max(gcd, devisor_c[i]);
			//cout << gcd << endl;
			flag = false;
		}
		else {
			i++;
		}
	}
	flag = true;
	i = 0;
	while (flag) {
		int count = 0;
		//cout << devisor_b[i] << endl;
		rep(j, n) {
			if (a[j] % devisor_b[i] != 0) {
				count++;
			}
			if (count >= 2) {
				break;
			}
		}
		//cout << " " << count ;
		if (count <= 1) {
			gcd = max(gcd, devisor_b[i]);
			//cout << gcd << endl;

			flag = false;
		}
		else {
			i++;
		}
	}
	cout << gcd << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
int s[100005];
map<int, LL> dp1[100005], dp2[100005];
map<int, LL>::iterator its;
int main(){
    int n;
    scanf("%d", &n);
    for(int i=0;i<=n-1;i++) scanf("%d", &s[i]);
    for(int i=1;i<=n-1;i++){
        for(int j=i;j<=n-1;j+=i){
            dp1[j][i] = dp1[j-i][i] + s[j];
        }
    }

    for(int i=1;i<=n-1;i++){
        LL sum = 0;
        int cnt = 1;
        for(int j=(n-1)-i;j>=1;j-=i){
            if(j%i == 0 && cnt >= j/i) sum = -1e18;
            sum += s[j];
            dp2[i][cnt] = sum;
            cnt++;
        }
    }
    LL ans = 0;
    for(int A=1;A<=n-1;A++){
        for(its = dp1[n-1-A].begin();its != dp1[n-1-A].end();its++){
            int d = its->first;
            LL val = its->second;
            if(A <= d) continue;

            int cnt = (n-1-A)/d;
            val += dp2[d][cnt];

            ans = max(ans, val);
        }
    }
    printf("%lld\n", ans);      
}

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

#include <bits/stdc++.h>

using namespace std;

#include <bits/stdc++.h>

using namespace std;

template<typename T>
struct Dinic{
    //辺
    struct edge
    {
        //行先と逆辺、revはid参照されているので、
        //追加された順に1,2,3,...となっている
        int to,rev;
        //cap は capacityの略
        T cap;
        edge(int to,T cap,int rev):to(to),cap(cap),rev(rev){};
    };

    const T INF;

    //グラフと探索済みかの配列
    vector<vector<edge>> graph;
    vector<int> iter,level;

    Dinic(int n):INF(numeric_limits<T>::max()){
        graph.resize(n);
    }

    void add_edge(int from, int to, T cap){
        //from ~ toにcapの辺を通す
        graph[from].emplace_back(to,cap,int(graph[to].size()));
        //to~from　に0容量の辺を通す
        graph[to].emplace_back(from,0,int(graph[from].size())-1);
    }

    //容量がある条件で最短距離の検索
    bool bfs(int s, int t){
        level.assign(graph.size(),-1);
        queue<int> que;
        level[s] = 0;
        que.push(s);

        while(!que.empty() and level[t] == -1){
            int p = que.front();
            que.pop();

            for(auto &e : graph[p]){
                if(e.cap > 0 and level[e.to] == -1){
                    que.push(e.to);
                    level[e.to] = level[p] + 1;
                }
            }
        }

        return level[t] != -1;

    }

    //ただのdfs探索
    //これは一本のパスについてflowを返していく
    T dfs(int v, const int t, T flow){
        //終了地点にきたらflowを返す
        if(v == t) return flow;
        for(int &i = iter[v]; i < graph[v].size(); i++){
            //流す余地があって未探索
            auto &e = graph[v][i];
            if(e.cap > 0 and (level[v] < level[e.to])){
                //このノード以降のフローを求める
                T d = dfs(e.to,t,min(flow,e.cap));
                if(d > 0){
                    e.cap -= d;
                    graph[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        //ここにたどり着くのは増加パスがない時
        return 0;
    }

    T max_flow(int s,int t){
        T flow = 0;
        //
        //cout << " bfs?" << " " << bfs(s,t) << endl;
        while(bfs(s,t)){
            //探索回数のリセット
            iter.assign(graph.size(),0);
            
            T f = 0;
            //dfsで見つかる限りflowを追加
            
            while((f = dfs(s,t,INF)) > 0){
                
                flow += f;
            }
            
        }
        return flow;
    }
};

int main(){
  int N; cin>>N;
  Dinic<int> pokemon(N*2+2);
  vector<pair<int,int>> ken(N,pair<int,int>()), tate(N,pair<int,int>());
  rep(i,N){
    cin>>ken[i].first>>ken[i].second;
  }
  rep(i,N){
    cin>>tate[i].first>>tate[i].second;
  }
  rep(i,N){
    rep(j,N){
      if(ken[i].first<tate[j].first&&ken[i].second<tate[j].second){
        pokemon.add_edge(i,N*2-1-j,1);
      }
    }
  }
  rep(i,N) pokemon.add_edge(N*2,i,1);
  rep(i,N) pokemon.add_edge(N*2-1-i,N*2+1,1);
  ll ans=0;
  ans=pokemon.max_flow(N*2,N*2+1);
  cout<<ans<<endl;
}


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

int main(){
  string s, t;	cin >> s >> t;
  int a, b;		cin >> a >> b;
  string u;		cin >> u;
  if(s == u) a--;
  else b--;
  cout << a << " " << b;
  return 0;
}

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

#define llint long long int

using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  int n = s.length();
  bool flag  = false;
  for(int i = 0; i < n; i++){
    if(flag)
      break;
  	if(s[0] == t[i]){
      char temp[n];
      int j = 0;
      for(j = 0; i+j < n; j++){
        temp[j] = t[i+j];
      }
      int k = 0;
      for(;j < n; j++){
        temp[j] = t[k];
        k++;
      }
      int l = 0;
      for(l = 0; l < n; l++){
        if(s[l] != temp[l])
          break;
      }
      if(l == n)
        flag = true;
    }
  }
  if(flag)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int main() {

	int N, K, X, Y;
	cin >> N >> K >> X >> Y;

	long long ans = 0;

	for (int i = 1; i <= N; i++) {
		if (K < i) {
			ans += Y;
		}
		else {
			ans += X;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef struct _player{
	int num;
	double time;
}player;

bool lesstime(const player&l,const player&r){return l.time<r.time;}

vector<player> nokori;

void pr(player&p){
	printf("%d %.2f\n",p.num,p.time);
}

int main(){
	for(int i=0;i<3;i++){
		vector<player> rane;
		for(int j=0;j<8;j++){
			int n;
			double t;
			cin>>n>>t;
			player tp={n,t};
			rane.push_back(tp);
		}
		sort(rane.begin(),rane.end(),lesstime);
		pr(rane[0]);
		pr(rane[1]);
		for(int j=2;j<8;j++){
			nokori.push_back(rane[j]);
		}
	}
	
	sort(nokori.begin(),nokori.end(),lesstime);
	pr(nokori[0]);
	pr(nokori[1]);
}

Measured memory_bytes: 0
N,X=map(int,input().split())
blu=[list(map(int,input().split())) for i in range(N)]

S=0
data=[]

low=0
high=0

for i in range(N):
    b,l,u=blu[i]
    high+=b
    data.append([u*(X-b)+l*b,i])
    S-=b*l
data.sort(reverse=True)

lst=[data[0][0]]
lsls=[data[0][1]]
for i in range(1,N):
    lst.append(lst[-1]+data[i][0])
    lsls.append(data[i][1])

while high-low>1:
  
    mid=(high+low)//2
    ppp=mid//X
    qqq=mid%X
    
    SS=S
    if ppp>0:
        SS+=lst[ppp-1]
    num=0
    for i in range(ppp,N):
        b,l,u=blu[lsls[i]]
        if qqq>=b:
            num1=b*l+(qqq-b)*u
        else:
            num1=qqq*l
        num=max(num,num1)
    SS+=num
    
    SSS=S+lst[ppp]
    num=-float("inf")
    for i in range(ppp):
        zzz,ind=data[i]
        b,l,u=blu[ind]
        if qqq>=b:
            num1=-zzz+b*l+(qqq-b)*u
        else:
            num1=-zzz+qqq*l
        num=max(num,num1)
    SSS+=num
    
    SS=max(SS,SSS)
    if SS>=0:
        high=mid
    else:
        low=mid

print(high)

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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int num[10][10] = {}, ans = 0;
    int n;
    cin >> n;
    FOR(i, 1, n + 1) {
        int a, b = i % 10;
        int x = i;
        while(x) {
            a = x;
            x /= 10;
        }
        num[a][b]++;
    }
    FOR(i, 1, 10) FOR(j, 1, 10) { ans += num[i][j] * num[j][i]; }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int gcd(int x, int y) {
    if (x == 0) return y;
    if (y == 0) return x;
    return gcd(y, x%y);
}
int main(void){
  int N,X;
  cin >> N >> X;
  
  vector<int>point(N,0);
  for(int i=0;i<N;i++){
    cin >> point[i];
  }
  
  int ans = 0;
  if(N == 1){
    ans = abs(X - point[0]);
  }
  else{
    ans = gcd(abs(X - point[0]),abs(X - point[1]));
  for(int i=2;i<N;i++){
    ans = gcd(abs(X - point[i]),ans);
  }
  }
  cout << ans << endl;
  
  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

template<typename T> ostream& operator << (ostream& r, const vector<T> t){vrep(v,t)r<<*v<<(v+1==t.end()?"":" ");return r;}
template<typename T> ostream& operator << (ostream& r, const pair<vector<T>, int> p){int n=p.second;minup(n,p.first.size());rep(i,n-1)r<<p.first[i]<<' ';r<<p.first[n-1];return r;}
template<typename T> ostream& operator << (ostream& r, const pair<T*, int> p){int n=p.second-1;rep(i,n)r<<p.first[i]<<' ';return r<<p.first[n];}
template<typename T, size_t S> ostream& operator << (ostream& r, const T (&a)[S]){rep(i,S-1)r<<a[i]<<' ';return r<<a[S-1];}

string str;

int main()
{
  while(getline(cin, str)){
    vector<string> s;
    istringstream stream(str);
    while(getline(stream, str, ' ')) s.pb(str);
    bool ok = false;
    rep(k, 26){
      vrep(v, s) rep(i, v->size()) if((*v)[i] >= 'a' && (*v)[i] <= 'z') (*v)[i] = 'a' + ((*v)[i] - 'a' + 1) % 26;
      vrep(v, s) if(*v == "the" || *v == "this" || *v == "that") ok = true;
      if(ok){
        cout << s << endl;
        break;
      }
    }
  }

 return 0;
}

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

vector<tuple<int,int,int>> stx;
set<pair<int,int>> D;
 
int ans[200000];
 
void solve(){
	for(int i=0;i<Q;i++) ans[i] = -1;
    sort(stx.begin(),stx.end());
 
    for (int i=0;i<N;i++) {
    	int x = get<0>(stx[i]);
    	int s = get<1>(stx[i]);
    	int t = get<2>(stx[i]);
        auto first = D.lower_bound(make_pair(s-x,0));
        auto end = D.upper_bound(make_pair(t-x-1,Q));
 
        for(auto it=first;it!=end;it++) ans[it->second] = get<0>(stx[i]);
 
        D.erase(first, end);
    }
}
 
int main(){
	cin >> N >> Q;
	for(int i=0;i<N;i++){
		int s,t,x;
		cin >> s >> t >> x;
		stx.push_back(tuple<int,int,int>(x,s,t));
	}
	for(int i=0;i<Q;i++){
		int d;
		cin >> d;
		D.insert(make_pair(d,i));
	}
 
	solve();
 
	for(int i=0;i<Q;i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 14320
N = int(input())
D_list = []
for _ in range(N):
    D1, D2 = map(int, input().split())
    D_list.append([D1, D2])

sequence_doublet = 0
for D in D_list:
    if D[0] == D[1]:
        sequence_doublet += 1
    else:
        sequence_doublet = 0
    
    if sequence_doublet == 3:
        break

if sequence_doublet == 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define maxn 102333
using namespace std;
int ans[maxn];
int main() {
	for(int i = 1; i <= 100; ++i) {
		for(int j = 1; j <= 100; ++j) {
			for(int k = 1; k <= 100; ++k) {
				++ans[i*i + j*j + k*k + i*j + j*k + k*i];
			}
		} 
	}
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3876
package main

import (
  "fmt"
)

func main(){
  
  var day string
  fmt.Scan(&day)
 
  if day == "SUN"{
    fmt.Println("7")
  }else if day == "MON"{
    fmt.Println("6")
  }else if day == "TUE"{
    fmt.Println("5")
  }else if day == "WED"{
    fmt.Println("4")
  }else if day == "THU"{
    fmt.Println("3")
  }else if day == "FRI"{
    fmt.Println("2")
  }else{
    fmt.Println("1")
  }
  
  
  
}


Measured memory_bytes: 512
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, P = mapint()
As = list(mapint())
bit = [a%2 for a in As]

pos = {}
pos[0] = 1
for i in range(1, N+1):
    pos[i] = pos[i-1]*i
dic = {}
dic[0] = 0
dic[1] = 0
for i in bit:
    dic[i] += 1

ans = 2**dic[0]
if P==1:
    if dic[1]<1:
        print(0)
        exit(0)
    else:
        pass
        # ans*=dic[1]
        # dic[1] -= 1
val = 0
for i in range(dic[1]//2+1):
    val += pos[dic[1]]//pos[i*2]//pos[dic[1]-i*2]
print(val*ans)

Measured memory_bytes: 61976
#include <bits/stdc++.h>
#define int long long
#define all(c) (c).begin(),(c).end()
#define pii pair<long long,long long>
#define endl '\n'

using namespace std;

signed main(){
    std::ios::sync_with_stdio(false);
    vector <char> s(6,'a');
    for(int i=0;i<6;i++){
        cin>>s[i];
    }
    //cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout << "Yes\n";
    }
    else cout << "No\n";
    
}

Measured memory_bytes: 256
# coding: utf-8
N = int(input())
H = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(N):
    if i == 0:
        tmp = H[i]
    else:
        if tmp >= H[i]:
            cnt += 1
        else:
            ans = max(ans, cnt)
            cnt = 0
        tmp = H[i]
    ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 14224
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, M = sc.nextInt()

    val prefectures = Array.fill(N+1)(
      scala.collection.mutable.ArrayBuffer.empty[Int])
    val result = new Array[String](M)
    val year = new Array[Int](M)

    (0 until M) foreach { i =>
      val p = sc.nextInt()
      year(i) = sc.nextInt()
      prefectures(p).append(i)
    }

    val format = (n: Long) => "%012d".format(n)

    (1 to N). foreach { p =>
      val prefecture = prefectures(p).sortBy(i => year(i))
      val l = prefecture.size
      var i = 1
      while (i <= l) {
        val city = prefecture(i-1)
        result(city) = format(p * 1000000L + i)
        i += 1
      }
    }

    println(result.mkString("\n"))

  }

}


Measured memory_bytes: 131724
import sys


class AlgUnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    uf = AlgUnionFind(n)
    t = n * (n - 1) // 2
    ans = []
    for i in range(m):
        a, b = ab[-i-1]
        ans.append(t)
        if not uf.same(a-1, b-1):
            t -= uf.size(a-1) * uf.size(b-1)
            uf.union(a-1, b-1)
    ans.reverse()
    print(*ans, sep="\n")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 107356
#include <stdio.h>
#include <string.h>

using ll = long long;

const ll MAX = 1000000000000001LL;

int main()
{
	ll N;
	scanf("%lld", &N);

	ll offset = 0;
	ll base = 1;
	int keta = 1;
	while (1) {
		base *= 26;
		if (offset + base > N - 1) {
			break;
		}
		offset += base;
		keta++;
	}

	N -= offset;
	N--;
	char str[256];
	base = 1;
	for (int i = 0; i < keta - 1; i++) {
		base *= 26;
	}
	for (int i = 0; i < keta; i++) {
		//printf("!%d\n", N / base);
		str[i] = 'a' + (N / base);
		N %= base;
		base /= 26;
	}
	str[keta] = '\0';
	puts(str);

	return 0;
}


Measured memory_bytes: 1656
#include <stdio.h>
#include <stdlib.h>

int main(void){
    char str[3];
    scanf("%s",str);

    int price = 700;
    for(int i = 0;i < 3;i++){
        if(str[i] == 'o'){
            price += 100;
        }
    }

    printf("%d",price);
    
}

Measured memory_bytes: 128
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
*/
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int H=sc.nextInt(),W=sc.nextInt();
        int h=sc.nextInt(),w=sc.nextInt();
        out.println(H*W-(h*W+w*H-h*w));
    }
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a, b;
  ll K;
  cin >> a >> b >> K;
  for(ll i=min(a,b);i>=1;i--){
    if(a%i==0 and b%i==0)K--;
    if(K==0){cout << i;break;}
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "stdc++.h"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = max(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

bool	check(vector<pii> s)
{
	int h = 0;
	for (pii p : s) {
		int b = h + p.first;
		if (b < 0) return false;
		h += p.second;
	}
	return true;
}

void	solve()
{
	int n;
	cin >> n;
	vector<pii> ls, rs;
	int total = 0;
	while (n--) {
		string s;
		cin >> s;
		int h = 0, b = 0;;
		for (char c : s) {
			if (c == '(') 
				h++;
			else
				h--;
			b = min(b, h);
		}
		if (h > 0) ls.emplace_back(b, h);
		else rs.emplace_back(b - h, -h);
		total += h;
	}
	sort(rall(ls));
	sort(rall(rs));
	if (check(ls) && check(rs) && !total)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	solve();
}

Measured memory_bytes: 18888
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> oset;

// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

const int mod = 1e9 + 7;
const int inf = 9e18;
const int N = 1e5 + 5;

int i,n,m,a[N];
string s;

void solve(){
	cin>>n>>m>>s;
	vi pos,ans;
	for(i=0;i<n+1;++i){
		if(s[i]=='0'){
			pos.pb(i);
		}
	}
	int j=0;
	for(i=1;i<n+1;++i){
		if(s[i]=='0'){
			if(i-pos[j]<=m){
				a[i]=pos[j];
			}
			else{
				while(i-pos[j]>m){
					++j;
				}
				if(i==pos[j]){
					cout<<-1;
					return;
				}
				a[i]=pos[j];
			}
		}
	}
	i=n;
	while(i>0){
		ans.pb(i-a[i]);
		i=a[i];
	}
	reverse(all(ans));
	for(auto &i:ans){
		cout<<i<<" ";
	}
}

signed main(){
	fastio;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3524
n, a, b = map(int, input().split())
ls = [int(input()) for _ in range(n)]
m = max(ls)
lo = (m + a - 1) // a
hi = (m + b - 1) // b + 1
mi = (hi + lo) // 2
while hi > lo + 1:
    mi = (hi + lo) // 2
    if sum([(max(x - mi * b, 0) + a - b - 1) // (a - b) for x in ls]) <= mi:
        hi = mi
    else:
        lo = mi
if sum([(max(x - lo * b, 0) + a - b - 1) // (a - b) for x in ls]) <= lo:
    print(lo)
else:
    print(hi)

Measured memory_bytes: 11064
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int n,k;
    while(cin>>n>>k){
        int arr[n];
        f0(n)cin>>arr[i];
        for(int i=0,j=k;j<n;i++,j++){
            if(arr[i]<arr[j]){
                cout << "Yes\n";
            }
            else{
                cout << "No\n";
            }
        }
    }
    return 0;
}
///Alhamdulillah


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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define md (ll)(1e9+7)

const int M=1e6+6;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}
ll n,i,dp[M],h[M];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	cin >> h[1] >> h[2];
	dp[2] = abs(h[2]-h[1]);
	for(i=3;i<=n;++i)
	{
		cin >> h[i];
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout << dp[n] << endl;
	return 0;
}

	


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
#define qmin(a,b) ((a)<(b)?(a):(b))

int a[N],n,k;
long long dp[N];

int main() {
	scanf("%d%d",&n,&k);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	for (int i = 1; i <= n; i++) dp[i] = 1LL*INT_MAX;
	dp[1] = 0;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i - j >= 1) {
				dp[i] = qmin(dp[i], dp[i-j] + abs(a[i-j] - a[i]));
			}
		}
	}
	printf("%lld\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1408
def main():
    from fractions import gcd

    n, m = map(int, input().split())
    s, t = input(), input()
    l = n * m // gcd(n, m)
    a = [l // n * i + 1 for i in range(n)]
    b = [l // m * i + 1 for i in range(m)]
    c = set(a) & set(b)
    for x in list(c):
        i = a.index(x)
        j = b.index(x)

        if s[i] != t[j]:
            print(-1)
            exit()
    else:
        print(l)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81828
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s, n) for(int i = s; i < (int)(n); i++)
#define co(x) cout<<x<<endl
#define SQvec(i,j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000000+7
typedef long long int lint;

int main() {
  int ans = 0;
  string S;
  cin >> S;
  rep(i,0,S.size()){
    if(S[i] == '+'){ans++;}
    if(S[i] == '-'){ans--;}
  }
  co(ans);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class CAKE implements Comparable<CAKE>{
	int w,d,surface,ar,number;
	CAKE(int w,int d){
		this.w=w;
		this.d=d;
		this.surface=(w*d);
		this.ar=(w+d);
	}

	@Override
	public int compareTo(CAKE c1) {
		if (this.surface < c1.surface) {
			return -1;
		} else if (this.surface > c1.surface) {
			return 1;
		} else {
			return 0;
		}
	}
}

public class Main {
	static int p,s,k;
	static CAKE c[];

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,w,d,i;

		while(true){
			k=0;
			n=sc.nextInt();
			w=sc.nextInt();
			d=sc.nextInt();
			if(n==0 && w==0 && d==0) break;
			c=new CAKE[n+1];
			c[k]=new CAKE(w,d);
			c[k].number=1;
			k++;
			for(i=0;i<n;i++){
				p=sc.nextInt();
				s=sc.nextInt();

				cut_position();
			}
			Arrays.sort(c);
			boolean f=true;
			for(i=0;i<k;i++){
				if(f){
					System.out.print(c[i].surface);
				}
				else{
					System.out.print(" "+c[i].surface);
				}
				f=false;
			}
			System.out.println();
		}
	}//main

	static void cut_position(){
		int i,n=-1,temp;


		for(i=0;i<k;i++){
			if(c[i].number==p){
				n=i;
				break;
			}
		}
		
		for(int j=0;j<k;j++){
			if(p<c[j].number){
				c[j].number--;
			}
		}
		
		temp=s%c[n].ar;
		if(c[n].w<temp){
			cut1(n,temp-c[n].w);
		}
		else{
			cut2(n,temp);
		}
	}

	static void cut1(int n,int posi){
		//System.out.println("posi="+posi+" s="+s+" ar="+c[n].ar);
		int w=c[n].w;
		int n0=c[n].d;
		c[n]=new CAKE(w,n0-posi);
		c[k]=new CAKE(w,posi);
		
//		for(int i=0;i<=k;i++){
//			System.out.println(i+" c[i]="+c[i].w+" "+c[i].d+" "+c[i].ar);
//		}
		
		if(c[k].surface<c[n].surface){
			c[k].number=k;
			c[n].number=k+1;
		}
		else{
			c[k].number=k+1;
			c[n].number=k;
		}
		k++;
	}
	static void cut2(int n,int posi){
		int w=c[n].w;
		int n0=c[n].d;
		//System.out.println("posi="+posi+" s="+s+" ar="+c[n].ar);

		c[n]=new CAKE(w-posi,n0);
		c[k]=new CAKE(posi,n0);
		
//		for(int i=0;i<=k;i++){
//			System.out.println(i+" c[i]="+c[i].w+" "+c[i].d+" "+c[i].ar);
//		}
		
		if(c[k].surface<c[n].surface){
			c[k].number=k;
			c[n].number=k+1;
		}
		else{
			c[k].number=k+1;
			c[n].number=k;
		}
		k++;
	}
}

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

using namespace std;
using ll = long long int;

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

    vector<bool> have(n, false);
    for (int i = 0; i < k; i++)
    {
        int d;
        cin >> d;

        for (int j = 0; j < d; j++)
        {
            int a;
            cin >> a;
            a--;
            have[a] = true;
        }
    }

    int ans = 0;
    for (size_t i = 0; i < have.size(); i++)
    {
        if (!have[i])
        {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3628
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]


def main():
    a,b,k = inpm()
    a,k = a-k,k-a
    if a < 0:
        a = 0
    if k > 0:
        b -= k
    if b < 0:
        b = 0
    print(a,b)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 39532
#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

int main()
{
    vi a(500000, 0);
    REP(i,400)
    {
        a[i * i] = 1;
    }
    cin >> n >> m;
    if (m < 10)
    {
        ans = n * 10 + m;
    }
    else if (m < 100)
    {
        ans = n * 100 + m;
    }
    else if(m==100)
    {
        ans = n * 1000 + m;
    }
    cout << (a[ans] == 1 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 4096
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 12 18:50:46 2019
KeyenceD
@author: maezawa
"""
import bisect

h, w = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

n = h*w
arr = [0]*(n+1)

a.sort()
b.sort()
aset = set(a)
bset = set(b)

for i in reversed(range(1,n+1)):
    if i in aset and i in bset:
        arr[i] = 1
    elif i in aset:
        idx = bisect.bisect_right(b, i)
        arr[i] = w - idx
    elif i in bset:
        idx = bisect.bisect_right(a, i)
        arr[i] = h - idx
    else:
        idxa = bisect.bisect_right(a, i)
        idxb = bisect.bisect_right(b, i)
        arr[i] = (h - idxa) * (w - idxb) - (n - i)

ans = 1
for i in range(1, n+1):
    ans = (ans * arr[i]) % (10**9 + 7) 
if ans < 0 or len(aset) != len(a) or len(bset) != len(b):
    ans = 0
print(ans)
        
            
    

Measured memory_bytes: 44120
import sys
prm = sys.stdin.readline()
prm = prm.split()
W = int(prm[0])
H = int(prm[1])
x = int(prm[2])
y = int(prm[3])
r = int(prm[4])

if r <= x and x <= (W-r) and r <= y and y <= (H-r) :
    print 'Yes'
else :
    print 'No'

Measured memory_bytes: 6452
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>
#include <string.h>         // memset()
#include <math.h>           // sqrt()

#define MAX_N 100000
#define MAX_P 10000

int p;
bool f[MAX_N + 1];
int primes[MAX_P];

bool
isprime(int x)
{
	int i;

	if (x <= MAX_N)
		return f[x];

	for (i = 0; i < p && primes[i] <= sqrt(x); ++i)
	{
		if (x % primes[i] == 0)
			return false;
	}

	return true;
}

void
init_primes()
{
	int i, j;

	memset(f, 0xff, sizeof(f));
	p = 0;
	for (i = 2; i <= MAX_N; ++i)
	{
		if (f[i]) // is i prime number?
		{
			primes[p++] = i;
			for (j = i + i; j <= MAX_N; j += i) // j isn't prime number
				f[j] = false;
		}
	}
}

int
main(int argc, char** argv)
{
	int count;
	int x;
	int n;

	init_primes();
	scanf("%d", &n);

	count = 0;
	while (n--)
	{
		scanf("%d", &x);
		if (isprime(x))
			count++;
	}

	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 740
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
//#define cin fin
//#define cout fout
using namespace std;


const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;

int n,m,x,y,z,ans,viz[100005];
vector<int>nod[100005];

void dfs(int s){
    viz[s]=1;
    for(int i=0;i<nod[s].size();i++) if(viz[nod[s][i]]==0) dfs(nod[s][i]);
}

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
    cin >> n >> m;
    for(int i=1;i<=m;i++){
        cin >> x >> y >> z;
        nod[x].push_back(y);
        nod[y].push_back(x);
    }
    for(int i=1;i<=n;i++){
        if(viz[i]==0){ans++; dfs(i);}
    }
    rc(ans);
}


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

int main(){
  int N,K; cin >> N >> K;
  if(K>=N){
    cout << 0 << endl;
  }else{
    multiset<long long> H;
    for(int i=0; i<N; i++){
      long long tmp; cin >> tmp;
      H.insert(tmp);
    }
    auto itr=H.begin();
    long long sum=0;
    for(int i=0; i<N-K; i++){
      sum+=*(itr);
      itr++;
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


int main(){
  int n,k,s;
  cin >> n >> k >> s;
  if(s == 1000000000){
    REP(i,k){
      cout << s << " ";
    }
    REP(i,n-k){
      cout << 1 << " ";
    }
    cout << "\n";
  }
  else{
  REP(i,k){
    cout << s << " ";
  }
  REP(i,n-k){
    cout << s+1 << " ";
  }
  cout << "\n";
  }
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#define int long long
using namespace std;

signed main()
{
	int a;
	cin >> a;
	map<int, int>m;
	for (int b = 0; b < a; b++) {
		int c; cin >> c; m[c]++;
	}
	if (a & 1) {
		bool k = (m[0] == 1);
		for (int i = 2; i < a; i += 2) {
			if (m[i] != 2)k = false;
		}
		if (k) {
			int s = 1;
			for (int l = 0; l < a / 2; l++) {
				s = s * 2 % 1000000007;
			}
			cout << s << endl;
		}
		else puts("0");
	}
	else {
		bool k = true;
		for (int i = 1; i < a; i += 2) {
			if (m[i] != 2)k = false;
		}
		if (k) {
			int s = 1;
			for (int l = 0; l < a / 2; l++) {
				s = s * 2 % 1000000007;
			}
			cout << s << endl;
		}
		else puts("0");
	}
}

Measured memory_bytes: 5376
#include<iostream>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  int i;
  int l,r;
  if(N%2==0) {
    l = 1;
    r = N/2-1;
    for(i=0;i<M&&l<r;i++) {
      cout << l << " " << r << endl;
      l++;
      r--;
    }
    l = N/2+1;
    r = N;
    for(;i<M&&l<r;i++) {
      cout << l << " " << r << endl;
      l++;
      r--;
    }
  }
  else {
    l=2;
    r=N;
    for(i=0;i<M;i++) {
      cout << l << " " << r << endl;
      l++;
      r--;
    }
  }
}

Measured memory_bytes: 3636
n = int(input())
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

plslst = [x - y for (x, y) in zip(v, c)]
ans = []
for i in plslst:
    if i > 0:
        ans.append(i)
    else:
        pass
print(sum(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>

int main()
{
	int n;
	int min, max;
	long long sum;
	std::cin >> n;
	for (int i = 0; i < n; i++)
	{
		int temp;
		std::cin >> temp;
		if (i == 0)
		{
			min = temp;
			max = temp;
			sum = temp;
		}
		else
		{
			if (temp < min)
			{
				min = temp;
			}
			if (temp > max)
			{
				max = temp;
			}
			sum += temp;
		}
	}
	printf("%d %d %ld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e10
#define mod 1000000007
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
#define lcm(x,y)  (x*y)/__gcd(x,y)

int  fact(int n)
{
	if (n == 0 || n == 1)
		return 1;
	else
		return n * fact(n - 1);
}
int nCr(int n, int r)
{
	if (r == 0)
		return 1;
	else
		return fact(n) / (fact(n - r) * fact(r));
}

int32_t main()
{
	//c_p_c();
	int n, k;
	cin >> n >> k;
	vector<int>graph[n + 1];
	int i = 1;
	while (k--)
	{
		int d;
		cin >> d;
		while (d--)
		{
			int x;
			cin >> x;
			graph[x].pb(i);
		}
		i++;
	}
	int c = 0;
	for (i = 1; i <= n; i++)
		if (graph[i].size() == 0)
			c++;
	cout << c << endl;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define int long long 
typedef vector<int> vi;

signed main()
{
    string s;
    cin >> s;
    int mod = 2019;
    reverse(s.begin(), s.end());
    vi rem(mod);
    rem[0]++;
    int p = 1, suf = 0;
    int ans = 0;
    for (auto c:s)
    {
        (suf += (c-'0') * p) %= mod;
        ans += rem[suf];
        (p *= 10) %= mod;
        rem[suf]++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3724
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <ctime>
#include <set>
#include <sstream>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int i,a,b,n;int ans=0;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	cin>>a>>b;
	n-=a;
	i=(n/b)*b;
	n-=i;
	printf("%d\n",n); 
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> a >> b;
    string s = "", t = "";
    for(i = 0; i < a; i++){
        s.pb(b + '0');
    }
    for(i = 0; i < b; i++){
        t.pb(a + '0');
    }
    if(s < t){
        cout << s;
    }
    else{
        cout << t;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n-1);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n-1) cin >> c[i];

	int res = 0;
	rep(i, n) {
		res += b[a[i]-1];
	}
	rep(i, n - 1) {
		if (a[i + 1] - a[i] == 1) res += c[a[i]-1];
	}

	cout << res << endl;
	return 0;
}

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

void  cal(int t)
{
	int answer[50];
	for (int i = 0;i < t;++i) {
		int n, k, a[1000000], b[1000000], sum = 0;
		cin >> n >> k;
		for (int j = 0;j < n;++j) {
			cin >> a[j];
		}
		for (int j = 0;j < n - 1;++j) {
			b[j] = a[j + 1] - a[j];
		}
		sort(b, b + n - 1);
		for (int j = n - 2;n - k - 1 < j;--j) {
			sum += b[j];
		}
		answer[i] = a[n - 1] - a[0] - sum;
	}
	for (int i = 0;i < t;++i) {
		cout << answer[i] << endl;
	}
}

int main()
{
	int t;
	cin >> t;
	cal(t);
}

Measured memory_bytes: 5632
#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;


int main(){

	int n,tmp_id,max_id,max=-1,tmp;

	scanf("%d",&n);

	for(int i=0; i < n; i++){
		scanf("%d %d",&tmp_id,&tmp);
		if(tmp > max){
			max = tmp;
			max_id = tmp_id;
		}else if(tmp == max){
			if(max_id > tmp_id){
				max_id = tmp_id;
			}
		}
	}

	printf("%d %d\n",max_id,max);

    return 0;
}

Measured memory_bytes: 2736