akhauriyash/Code-Regression huggingface dataset:
n =int(input())
x = list(map(int, input().split()))
if x.count(0) !=0:
  print('0')
else:  
  ans=x[0]
  for i in range(1,n):
    ans=ans*x[i]
    if ans >10**18:
      print(-1)
      exit()
  print(ans)  
  

Measured memory_bytes: 21484
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define BRK(x) { (x); break; }
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using namespace std;


int N, M;
MII cnt;


bool solve(){
	for(PII p : cnt)
		if(p.second == 2) return true;
	return false;
}


signed main(){
	cin >> N >> M;
	rep(i, 0, M){
		int a, b;
		cin  >> a >> b;
		if(a == 1) cnt[b]++;
		else if(b == N) cnt[a]++;
	}
	
	if(solve()) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	
	return 0;
}

Measured memory_bytes: 9600
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from itertools import accumulate

def resolve():
    it = map(int, sys.stdin.read().split())
    N, K = next(it), next(it)
    A = [next(it) for i in range(N)]

    for k in range(K):
        B = [0]*(N+1)
        for i, di in enumerate(A):
            lhs = max(0, i-di)
            rhs = min(i+di+1, N)

            B[lhs] += 1
            B[rhs] -= 1

        if B[0] == N:
            print(*[N]*N)
            return
        A = accumulate(B)

    print(*list(A)[:-1])

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 159716
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse = True)
ans = 1
if a[-1] == 0:
    ans = 0
else:
    for i in range(n):
        ans *= a[i]
        if ans > 10**18:
            ans = -1
            break
print(ans)
    
    

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

int main()
{
    int n,k,i;
    char s[51]={};
    scanf("%d %d ",&n,&k);
    for(i=1;i<=n;i++){
        scanf("%c",&s[i]);
    }
    s[k]=s[k]-'A'+'a';
    for(i=1;i<=n;i++){
        printf("%c",s[i]);
    }
}

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

signed main(void)
{
	int n, m;
	map<int, int> mp;
	cin >> n >> m;
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		mp[a]++;
		mp[b]++;
	}
	for(auto p : mp)
	{
		auto k = p.first;
		auto v = p.second;
		if (v % 2 != 0)
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 4352
#include<stdio.h>
 
int max(int a,int b){
  if(a>=b)return a;
  return b;
}
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  int keep = max(a+b,a-b);
  printf("%d",max(keep,a*b));
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#define print(n) std::cout << n << std::endl
#define print_no_indention(n) std::cout << n
using namespace std;


int main() {
   long long int h;
   cin >> h;
   long long int fanctorial_2 = 2;
   while (h >= fanctorial_2)fanctorial_2 *= 2;
   print(fanctorial_2 - 1);
}

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

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


int main() {

string s;
cin >> s;

bool match = false;

rep(j,s.size())rep(i,s.size()){
    if(s.at(i)==s.at(j) and i!=j)match = true;
}
if(match)cout << "no" << endl;
else cout << "yes" << endl;

return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

const int MAX_N = 55556;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
void sieve(int n){
   int p = 0;
   for(int i = 0; i <= n; i++) is_prime[i] = true;
   is_prime[0] = is_prime[1] = false;
   for(int i = 2; i <= n; i++){
   if(is_prime[i]){
           prime[p++] = i;
           for(int j = 2*i; j <= n; j += i) is_prime[j] = false;
       }
   }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    sieve(MAX_N);
    vector<int> ans;
    rep(i, 0, MAX_N) if(is_prime[i] && i % 5 == 1) ans.push_back(i);
    int n;
    cin >> n;
    for(int ii = 0; ii < n; ii++){
        if(ii) cout << ' ';
        cout << ans[ii];
    }
    cout << endl;
}

Measured memory_bytes: 384
#include <iostream>

int main() {
    int t;
    std :: cin >> t;
    long double ans = 0;

    while(t--) {
        long double val;
        std :: string cur;

        std :: cin >> val >> cur;

        if(cur == "BTC") ans += val * 380000.0f;
        else ans += val;
    }

    std :: cout << ans << '\n';
}

Measured memory_bytes: 3832
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>

#define INF (long long)1000000000
#define MOD 1000000007
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	int n;
	cin>>n;
	vector<vector<P> > d(n);
	REP(i,n-1) {
		ll a, b, c;
		cin>>a>>b>>c;
		--a;
		--b;
		d[a].pb(P(b,c));
		d[b].pb(P(a,c));
	}
	int Q,k;
	cin>>Q>>k;
	--k;
	vector<ll> dist(n,INF*INF);
	dist[k]=0;
	priority_queue<P, vector<P>, greater<P> > q;
	q.push(P(0,k));
	while(!q.empty()) {
		P buf = q.top();
		q.pop();
		ll di = buf.first;
		ll p = buf.second;
		if(dist[p]<di) continue;
		REP(i,d[p].size()) {
			ll np = d[p][i].first;
			ll nd = d[p][i].second;
			if(dist[np]>dist[p]+nd) {
				dist[np]=dist[p]+nd;
				q.push(P(dist[np],np));
			}
		}
	}
	REP(i,Q) {
		ll x, y;
		cin>>x>>y;
		--x;
		--y;
		cout<<dist[x]+dist[y]<<endl;
	}
}


Measured memory_bytes: 11120
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <stdio.h>
#include <numeric>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("input.txt", "rt", stdin);
	//freopen("out.txt", "wt", stdout);
	int n;
	cin >>n;
	vector<int> as(n + 1);
	vector<int> bs(n);
	for (int i = 0; i < n + 1; ++i) {
		cin >> as[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> bs[i];
	}
	vector<int> mas(n);
	long long cnt = 0;
	vector<bool> busy(n);
	for (int i = 0; i < n; ++i) {
		auto def = min(as[i], bs[i]);
		cnt += def;
		bs[i] -= def;
		def = min(bs[i], as[i + 1]);
		cnt += def;
		as[i + 1] -= def;
	}
	cout << cnt << endl;
	/*int n, m, k;
	cin >> n >> m >> k;
	vector <tuple<int, int, int>> edges(m);
	for (int i = 0; i < m; ++i) {
		int x, y, w;
		cin >> x >> y >> w;
		if (x > y) swap(x, y);
		edges[i] = make_tuple(w, x, y);
	}
	sort(edges.begin(), edges.end());
	vector <tuple<int, int, int>> paths;
	int curmin = get<0>(edges[0]);
	int ind = 0;
	int cnt = 0;
	while (get<0>(edges[ind]) == curmin && cnt < k) {
		paths.push_back(edges[ind]);
		++ind;
		++cnt;
	}
	while (cnt < k) {
		curmin = get<0>(edges[ind]);
		bool added = false;
		for (int i = 0; i < paths.size(); ++i)
			for (int j = i + 1; j < paths.size(); ++j) {
				int xi = get<1>(paths[i]);
			}

	}*/
	/*int n, m;
	cin >> n >> m;
	vector<vector<int>> graph(n);
	vector<int> powers(n);
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
		++powers[a];
		++powers[b];
	}
	vector<pair<int, int>> sorted(n);
	for (int i = 0; i < n; ++i) {
		sorted[i].first = powers[i];
		sorted[i].second = i;
	}
	sort(sorted.begin(), sorted.end());
	if (m % 2) {
		cout << -1 << endl;
		return 0;
	}*/
	//cout << get<0>(paths[k - 1]);
	return 0;
}


Measured memory_bytes: 1408
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] data = br.readLine().split(" ");
    
    long k = Long.parseLong(data[0]);
    long s = Long.parseLong(data[1]);
  
    long result = 0;
    
    for (int i=0; i<=k; i++){
      result += getNumAllocation(s-i, k);
    }
    
    System.out.println(result);
  }
  public static long getNumAllocation(long sum, long max){
    if (sum < 0){
      return 0;
    } else if (sum <= max){
      return sum+1;
    } else if (sum <= max*2){
      return 2*max-sum+1;
    } else {
      return 0;
    }
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
int main(){
    int n,m;
    cin>>n>>m;
    vector<int64_t> a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    vector<int64_t> c(m),d(m);
    rep(i,m){
        cin>>c[i]>>d[i];
    }
    rep(i,n){
        int64_t mamin=big;
        int cp;
        rep(j,m){
            int64_t dis = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(dis<mamin){
                mamin = dis;
                cp=j;
            }
        }
        cout<<cp+1<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int f[12][12];
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };

void fill(int x, int y, int c) {
    f[y][x] = c;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || nx > 11 || ny < 0 || ny > 11) {
            continue;
        }
        if (f[ny][nx] == 1) {
            fill(nx, ny, c);
        }
    }
}

int main() {
    char ch;
    while (1) {
        for (int i = 0; i < 12; i++) {
            for (int j = 0; j < 12; j++) {
                if (!(cin >> ch)) {
                    return 0;
                }
                f[i][j] = ch - '0';
            }
        }
        int color = 2;
        bool success = true;
        while (success) {
            success = false;
            for (int i = 0; i < 12; i++) {
                for (int j = 0; j < 12; j++) {
                    if (f[i][j] == 1) {
                        fill(j, i, color);
                        color++;
                        success = true;
                    }
                }
            }
        }
        cout << color - 2 << endl;
    }

    return 0;
}

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

int main(){
	int n;
	while ( cin >> n ){
		if ( !n ) break;
		int* a = new int[ n ];
		for ( int i = 0; i < n; ++i ){
			cin >> a[ i ];
		}
		int sum, max = a[ 0 ];
		for ( int i = 0; i < n; ++i ){
			sum = 0;
			for ( int j = i; j < n; ++j ){
			sum += a[ j ];
			if ( sum > max ) max = sum;
			}
		}
		cout << max << endl;
		delete[] a;
	}

	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C){
    set<int> se;
    se.insert(A);
    se.insert(B);
    se.insert(C);
    if(se.size() == 2){
        cout<<YES<<endl;
    }else{
        cout<<NO<<endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    cout << ((c-b-1)%2==0 ? "Borys" : "Alice") << endl;

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
cntm = cntz = 0
for i in range(n):
    if a[i] < 0:
        cntm += 1
    elif a[i] == 0:
        cntz += 1
ans = 0
for i in range(n):
    ans += abs(a[i])
if cntm%2 == 0 or cntz > 0:
    print(ans)
else:
    abmin = 10**15
    for i in range(n):
        if abs(a[i]) < abmin:
            abmin = abs(a[i])
    print(ans - 2*abmin)

Measured memory_bytes: 14468
#include "bits/stdc++.h"
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;

    vector<vector <char>> a(H, vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> a[i][j];
        }
    }
    
    vector<int> ansH(H);
    vector<int> ansW(W);
    for (int i = 0; i < H; i++) {
        ansH[i] = i;
    }
    for (int i = 0; i < W; i++) {
        ansW[i] = i;
    }

    for (int i = 0; i < H; i++) {
        bool flag = true;
        for (int j = 0; j < W; j++) {
            if (a[i][j] == '#') {
                flag = false;
            }
        }
        if (flag) {
            for (int k = 0; k < ansH.size(); k++) {
                if (ansH[k] == i) {
                    ansH.erase(ansH.begin() + k);
                    break;
                }
            }
        }
    }
    for (int j = 0; j < W; j++) {
        bool flag = true;
        for (int i = 0; i < H; i++) {
            if (a[i][j] == '#') {
                flag = false;
            }
        }
        if (flag) {
            for (int k = 0; k < ansW.size(); k++) {
                if (ansW[k] == j) {
                    ansW.erase(ansW.begin() + k);
                    break;
                }
            }
        }
    }

    for (int i = 0; i < ansH.size(); i++) {
        for (int j = 0; j < ansW.size(); j++) {
            cout << a[ansH[i]][ansW[j]];
        }
        cout << endl;
    }
}

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

using namespace std;

bool check(int num, int arr[]) {
    while(num > 0) {
        int tmp = num % 10;
        num /= 10;
        if (arr[tmp] == 1)
            return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    int arr[10] = {0};

    for (int i = 0; i < k; i ++) {
        int tmp;
        cin >> tmp;
        arr[tmp] ++;
    }
    int i;
    for ( i = n; ; i++) {
        if (check(i, arr))
            break; 
    }

    cout << i ;

    return 0;
}

Measured memory_bytes: 256
/*input
4 3
1 2 3 4
1 3
2 3
2 4
*/
#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 ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<long long>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mod         998244353
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repi(i,a,b) for(ll i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define fIO         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define tr(it, a)   for(auto it = a.begin(); it != a.end(); it++)
#define clr(x)      memset(x, 0, sizeof(x))
#define debug(x)      cerr << #x << "=" << x << endl
#define debug2(x, y)  cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define TIME        cerr << "\nTime elapsed: "<<1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; 
//#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update>;

ll sub(ll a, ll b){return (a-b+hell)%hell;}
ll add(ll a, ll b){return (a+b)%hell;}
ll mul(ll a, ll b){return (a*b)%hell;}
/*vector<ll>adj[100005];
bool vis[100005];
ll siz,edges;
void dfs(ll i)
{
    vis[i]=1;
    //siz++;
    for(ll j=0;j<adj[i].size();j++)
    {        
        edges++;
        if(!vis[adj[i][j]])
            dfs(adj[i][j]);
    }
}
ll mpow(ll base, ll exp) {
  base %= hell;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % hell;
    base = ((ll)base * base) % hell;
    exp >>= 1;
  }
  return result;
}*/
int main()
{
fIO;
ll n,sum=0,t=1,m,ans=0;

//cin >> t;
while(t--){
  //string s;
  cin>>n>>m;
  vi a(n+1),b(n+1,1);
  rep(i,1,n+1)cin>>a[i];
  //vector<vi>v(n+1,vi(n+1));
  map<pii,ll>ma;

  rep(i,0,m){
    ll aa,bb;
    cin>>aa>>bb;
    ma[{aa,bb}]=1;
    
  }
  tr(it,ma){
    if(a[it->x.x]<a[it->x.y]){b[it->x.x]&=0;b[it->x.y]&=1;}
    else if(a[it->x.x]==a[it->x.y]){b[it->x.x]&=0;b[it->x.y]&=0;}
    else if(a[it->x.x]>a[it->x.y]){b[it->x.x]&=1;b[it->x.y]&=0;}


  }
  rep(i,1,n+1)if(b[i]==1)ans++;
  cout<<ans<<endl;













}
TIME;
    
}

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        do {
            int z = x % y;
            x = y;
            y = z;
        } while (y != 0);
        System.out.println(x);
        sc.close();
    }
}


Measured memory_bytes: 26352
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

bool dict_min(string &l, string &r){
  return l < r;
}

int main(void){
  string s;cin >> s;
  int K;cin >> K;
  vector<string> v;
  int i,j,N=s.length();
  REP(i,N){
    REP(j,min(K+1,N-i+1)) v.push_back(s.substr(i,j));
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  cout << v[K] << endl;
  return 0;
}


Measured memory_bytes: 1660
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}
const int INF=1e6;
const ll int MOD=998244353;

main(){
    char a,b;
    cin>>a>>b;
    cout<<(a^b?"D":"H");
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.HashSet;

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

        int n = sc.nextInt();
        List<Integer> d = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            d.add(sc.nextInt());
        }
        List<Integer> d_new = new ArrayList<>(new HashSet<>(d));
        System.out.println(d_new.size());
    }
}





Measured memory_bytes: 21332
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 100000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int cnt[2][100050];
int main() {
	int N, i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		int t;
		scanf("%d", &t);
		cnt[i % 2][t]++;
	}

	vector <pii> Vl[2];
	for (i = 0; i < 2; i++) for (j = 0; j <= 100000; j++) Vl[i].emplace_back(cnt[i][j], j);
	sort(all(Vl[0]));
	reverse(all(Vl[0]));
	sort(all(Vl[1]));
	reverse(all(Vl[1]));
	
	int ans = N;
	for (i = 0; i < 2; i++) {
		for (j = 0; j < 2; j++) {
			if (Vl[0][i].second == Vl[1][j].second) continue;
			ans = min(ans, N - Vl[0][i].first - Vl[1][j].first);
		}
	}
	return !printf("%d\n", ans);
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n, m;

const int MAX_N = 200000;
//Quick Find Weighted
class QuickFindWeighted{
    public:
        int i2g[MAX_N];//i2g[i] := 頂点iが所属するグループ
        vector<int> g2i[MAX_N];//g2i[g]:= グループgに所属する頂点番号

        void init(int n){
            for (int i = 0; i < n; ++i){
                i2g[i] = i;
                g2i[i].push_back(i);
            }
        }
        // 座標iaと座標ibは同じグループに所属しているか？
        bool issame(int ia, int ib){
            return i2g[ia] == i2g[ib];
        }
        // 座標iaの所属するグループと座標ibの所属するグループを1つにする(異なるグループに属するものに)
        void merge(int ia, int ib){
            if(issame(ia, ib)) return;
            //iaの所属するグループがibの所属するグループより小さくならないようにする(一般的マージテク)
            if(g2i[i2g[ia]].size() < g2i[i2g[ib]].size()){
                swap(ia, ib);
            }
            int ga = i2g[ia], gb = i2g[ib];//グループgbの方が要素数が少ない
            for(auto u : g2i[gb]){//uには頂点の番号はいる
                i2g[u] = ga;//グループの番号を更新
            }
            g2i[ga].insert(g2i[ga].end(), g2i[gb].begin(), g2i[gb].end());//つなげる
            g2i[gb].clear();
        }
};

int main(void){
	cin >> n >> m;
	QuickFindWeighted uf;
	uf.init(n + m);
	rep(i, n){
		int k; cin >> k;
		rep(j, k){
			int l; cin >> l;
			uf.merge(i, n + l - 1);
		}
	}
	int g = uf.i2g[0];
	sort(all(uf.g2i[g]));
	rep(i, n){
		if(uf.g2i[g][i] != i){
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 12732
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

void func(void)
{
//DEBUG_OUT("----\n");
    uint32 n, m;
    cin >> n >> m;

    cout << ((n-1)*(m-1)) << endl;
    
    return;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define int long long
int ifPrime(int n){
    if(n==1)return false;
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin>>x;
    while(!ifPrime(x))x++;
    cout<<x<<endl;
}

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

bool dp(vector<int> dx, int X, int inix){
    int n = dx.size();
    int M = 8000;
    vector<vector<bool>> dp = vector<vector<bool>>(2*M+2, vector<bool>(n+1,false));
    dp[M+1+inix][0] = true;
    for(int i=1; i<=n; i++){
        for(int x=0; x<=2*M+1; x++){
            //cout << i << " " << x << " " << dp[x][i-1] << endl;
            if(dp[x][i-1]){
                dp[x+dx[i-1]][i] = true;
                dp[x-dx[i-1]][i] = true;
                // cout << i << ":" << x << " --> " << x+dx[i-1] << ", " << x-dx[i-1] << endl;
            }
        }
    }
    // cout << M << " " << X << " " << n << endl;
    // cout << X << " " << M+1+X << " " << dp[M+1+X][n] << endl;
    return dp[M+1+X][n];
}

int main(){
    string s;
    int x, y;
    cin >> s >> x >> y;
    int N = s.length();

    vector<int> dx, dy;
    dx.push_back(0);
    dy.push_back(0);
    bool goX = true;
    bool cntxini = true;
    int xini = 0;
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(s[i]=='T' || i==N-1){
            if(s[i]=='F') cnt++;
            if(cntxini){
                xini = cnt;
                cntxini = false;
                cnt = 0;
                goX = false;
                continue;
            }
            if(goX) dx.push_back(cnt);
            else dy.push_back(cnt);
            cnt = 0;
            goX = !goX;
        }else{
            cnt++;
        }
    }

    // for(int i=0; i<dx.size()-1; i++){
    //     cout << dx[i] << " ";
    // }cout << dx[dx.size()-1] << endl;
    // for(int i=0; i<dy.size()-1; i++){
    //     cout << dy[i] << " ";
    // }cout << dy[dy.size()-1] << endl;
    // cout << xini << endl;

    if(dp(dx,x,xini) && dp(dy,y,0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

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

int main(){
    ll N,a[5];
    cin>>N;
    rep(i,5) cin>>a[i];
    ll m=1000000000000000;
    rep(i,5) m=min(m,a[i]);
    rep(i,5){
        if(N%m!=0) m=N/m+1;
        else m=N/m;
    }
    int b;
    rep(i,5){
        if(a[i]==m){
            b=i;
            break;
        }
    }
    cout<<m+4-b<<endl;
}

Measured memory_bytes: 256
# coding: utf-8

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

class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, n):
        if self.parent[n] == n:
            return n
        else:
            self.parent[n] = self.root(self.parent[n])
            return self.parent[n]

    def union(self, x, y):
        x_root = self.root(x)
        y_root = self.root(y)
        if x_root == y_root:
            pass
        else:
            self.parent[x_root] = y_root

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

ans = 0

input_ = []
for _ in range(m):
    a, b = list(map(int, input().split(" ")))
    a -= 1
    b -= 1
    input_.append((a, b))

for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if i == j:
            continue
        a, b = input_[j]
        uf.union(a, b)
    for k in range(1, n):
        if not uf.same(0, k):
            ans += 1
            break
print(ans)


Measured memory_bytes: 75972
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;

int main() {
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i,h) {
        cin >> c[i];
    }
    int ans = 0;
    for (int bh = 0; bh < (1<<h); bh++)
    {
        for (int bw = 0; bw < (1<<w); bw++)
        {
            int cnt = 0;
            rep(i,h) {
                rep(j,w) {
                    // 塗らないマスが黒なら
                    if ( bh&(1<<i) && bw&(1<<j) ) {
                        if (c[i][j] == '#') cnt++;
                    }
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(void){
  int h, w;
  cin >> h >> w;
  for(int i=0;i<h+2;++i){
    if(i==0||i==h+1){
      for(int j=0;j<w+2;++j){
        cout << "#";
      }
      cout << endl;
    }else{
      cout << "#";
      string s;
      cin >> s;
      cout << s << "#\n";
    }
  }
}

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

using namespace std;

const int inf = 1000000000;

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

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

	long long m = 1000;
	for(int i = 0; i + 1 < n; ++i) {
		if(a[i] < a[i + 1]) {
			long long x = m / a[i];
			long long y = m % a[i];
			m = x * a[i + 1] + y;
		}
	}

	cout << m << '\n';

	return 0;
}


Measured memory_bytes: 3624
t = ord("t")
z = ord("z")
a = ord("a")
 
def _decode(tv, v):
    spam = ord(v)
    if not (a <= spam <= z):
        return v
 
    x = t - ord(tv)
    y = spam + x
 
    if y > z:
        y = a + (y % z) - 1
    elif y < a:
        y = z - (a - y - 1)
 
    return chr(y)
 
while 1:
    try:
        txt = input()
        for s in [x for x in txt.split() if 3 <= len(x) <= 4]:
            tv = s[0]
            dec_val = ''.join(list(map(lambda x:_decode(tv,x),s)))
 
            if (dec_val in ('this', 'the', 'that')):
                print(''.join(list(map(lambda x:_decode(tv,x),txt))))
                break
    except:
        break

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

int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; cin >> a[i] >> b[i]; ++i) {
  }
  sort(a, a + n);
  sort(b, b + n);
  if (n % 2 == 0) {
    cout << b[n / 2] + b[n / 2 - 1] - a[n / 2] - a[n / 2 - 1] + 1;
  } else {
    cout << b[n / 2] - a[n / 2] + 1;
  }
  return 0;
}

Measured memory_bytes: 4640
// Shift-JIS（シフトジス）

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int A, B, C = 0;
    cin >> A >> B;
    if (A > B) {
        C += A;
        A--;
    } else {
        C += B;
        B--;
    }
    if (A > B) {
        C += A;
        A--;
    } else {
        C += B;
        B--;
    }
    cout << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long N, long long M, std::vector<long long> H, std::vector<long long> A, std::vector<long long> B){
    char dat[N];
    REP(i, N) {dat[i] = 1;}
    REP(i, M){
        if(H[A[i]-1] >= H[B[i]-1]){
            dat[B[i] - 1] = 0;
        }
        if(H[A[i]-1] <= H[B[i]-1]){
            dat[A[i] - 1] = 0;
        }
    }
    int res = 0;
    REP(i, N){
        if (dat[i] == 1) { res++; }
    }
    cout << res << endl;
}

int main(){

    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(H), std::move(A), std::move(B));
    return 0;
}



Measured memory_bytes: 5504
s=list(input())
N=len(s)
for i in range(int((N-1)/2)):
  if s[i]!=s[N-1-i]:
    print("No")
    exit()
for i in range(int(((N-1)/2-1)/2+1)):
  if s[i]!=s[int((N-1)/2)-1-i]:
    print("No")
    exit()
for i in range(int(((N-1)/2-1)/2+1)):
  if s[int((N-1)/2)+1+i]!=s[N-1-i]:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3064
n,k = map(int,input().split())
a = input().split()
b = [0]*n
d = {}
ind = 1
num = 0
loop = 1
sup =0

while num != k:
  if b[ind-1] == 0:
    b[ind-1] = -1
    d[ind] = num
    num += 1
    ind = int(a[ind-1])
  else:
    loop = num-d[ind]
    sup = d[ind]
    break

if k-sup >=0:
  for i in range((k-sup)%loop):
    ind = int(a[ind-1])

print(ind)

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

const int MAXN = 100010;
void bye() { std::cout << -1 << std::endl; exit(0); }
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], tot;
int deg[MAXN], n;
void addedge(int b, int e) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e;
	nxt[++tot] = head[e]; to[head[e] = tot] = b;
	++deg[b]; ++deg[e];
}
typedef std::pair<int, int> pi;
int son[MAXN], fa[MAXN], ind[MAXN], li[MAXN], bak;
pi diameter(int u) {
	pi res(0, u); son[u] = 0;
	for (int i = head[u]; i; i = nxt[i])
		if (to[i] != fa[u]) {
			fa[to[i]] = u;
			pi ret = diameter(to[i]); ++ret.first;
			if (ret > res) {
				son[u] = to[i];
				res = ret;
			}
		}
	return res;
}
int ansl[MAXN], tmp[MAXN];
void solve() {
	int now = 0, tl = 0;
	for (int i = 1; i <= bak; ++i) {
		for (int j = now + 2; j <= now + deg[li[i]] - (i != 1); ++j)
			tmp[++tl] = j;
		tmp[++tl] = now + 1;
		now += deg[li[i]] - (i != 1);
	}
	if (std::lexicographical_compare(tmp + 1, tmp + 1 + n, ansl + 1, ansl + 1 + n))
		memcpy(ansl, tmp, n + 1 << 2);
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1, t1, t2; i < n; ++i)
		std::cin >> t1 >> t2, addedge(t1, t2);
	int rtl = diameter(1).second;
	memset(fa, 0, n + 1 << 2);
	diameter(rtl).second;
	ind[li[++bak] = rtl] = true; int now = rtl;
	ind[0] = true;
	while (son[now]) ind[li[++bak] = son[now]] = true, now = son[now];
	for (int i = 1; i <= n; ++i) if (!ind[fa[i]]) bye();
	ansl[1] = 123456789;
	solve(); std::reverse(li + 1, li + 1 + bak); solve();
	for (int i = 1; i <= n; ++i) std::cout << ansl[i] << ' ';
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 10240
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int A;
  int B;
  int C;
  int D;
  cin >>A>>B>>C>>D;
  int x=A+B;
  int y=C+D;
  if(x>y) {
cout << "Left" << endl;
  }
else if (x==y) {
cout << "Balanced" << endl;
}
  else if (x<y) {
cout << "Right" << endl;
  }
}
    

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    static PrintStream out = System.out;

    static int[] parent;
    static int[] sz;     // sz[i]表示以i为根的集合中元素个数

    static int findRoot(int p) {
        while (p != parent[p]) {
            parent[p] = parent[parent[p]];
            p = parent[p];
        }
        return p;
    }

    static void union(int a, int b) {
        int aRoot = findRoot(a);
        int bRoot = findRoot(b);
        if (aRoot == bRoot)
            return;
        /**
         * 根据两个元素所在树的元素个数不同判断合并方向, 将元素个数少的集合合并到元素个数多的集合上
         */
        if (sz[aRoot] < sz[bRoot]) {
            parent[aRoot] = bRoot;
            sz[bRoot] += sz[aRoot];
            sz[aRoot] = sz[bRoot];
        } else {
            parent[bRoot] = aRoot;
            sz[aRoot] += sz[bRoot];
            sz[bRoot] = sz[aRoot];
        }
    }

    static int n, m;

    static void solve(Scanner in) {
        n = in.nextInt();
        m = in.nextInt();
        parent = new int[n + 1];
        sz = new int[n + 1];
        /** 初始化, 每一个parent[i]指向自己, 表示每一个元素自己自成一个集合 */
        for (int i = 1; i <= n; i++) {
            parent[i] = i;
            sz[i] = 1;
        }
        int[] a = new int[m+1];
        int[] b = new int[m+1];
        for(int i = 0; i < m; i++){
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }

        long cur = ((long)n * (long)(n-1)) / 2L;

        long[] res = new long[m+1];
        int p = m;
        res[p--] = cur;
        for(int i = m - 1; i >= 0; i--){
            int aR = findRoot(a[i]);
            int bR = findRoot(b[i]);
            if(aR == bR ){ //如果 a[i]和b[i]已经在同一个集合了，则不需要-了
                res[p--] = cur;
                continue;
            }
            cur -= (long)sz[aR] * (long)sz[bR];
            res[p--] = cur;
            union(a[i], b[i]);
        }
        for(int i = 1; i <= m; i++) out.println(res[i]);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedInputStream(System.in));
        solve(in);
    }
}

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

const int MOD = 1e9 + 7;

ll power(ll a, ll b)
{
    ll ans = 1;
    while (b > 0)
    {
        if (b % 2)
        {
            ans *= a;
            ans %= MOD;
        }
        a *= a;
        a %= MOD;
        b /= 2;
    }
    return ans;
}

int main()
{
    int n;
    cin >> n;
    // cout << MOD << ' ' << n << '\n';

    ll p10 = power(10, n) % MOD;
    ll p9 = power(9, n) % MOD;
    ll p8 = power(8, n) % MOD;
    ll ans = (p10 - ((2 * p9) % MOD - p8) % MOD) % MOD;
    ans = (ans + MOD) % MOD;
    cout << ans << '\n';
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);

  string s;
  cin >> s;

  int ss = s.size();
  int frt = 0, bck = 0;
  for (int i = 0; i < ss; ++i) {
    if (s[i] == 'A') {
      frt = i;
      break;
    }
  }
  for (int i = frt + 1; i < ss; ++i) {
    if (s[i] == 'Z') {
      bck = max(i, bck);
    }
  }

  cout << bck - frt + 1 << '\n';

  return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int n;
	cin >> n;
	string s,t;
	cin>>s>>t;
	for (int i = 0; i < n; ++i) cout << s[i] << t[i];
	cout << '\n';
}


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

int main(){
    long long a_i, b_i, n, temp, lo, hi, ans = 0;

    cin>>lo>>hi>>n;

    if( lo%n != 0 ){
        temp = lo%n;
        temp = n-temp;
        lo += temp;
    }
    
    if( lo <= hi ){
        ans = (hi-lo)/n;
        ans ++;
    }
    
    cout<<ans<<endl;
    
    //main();
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int x,y,z,temp;
 
 scanf("%d%d",&x,&y);

 if(x < y){
   temp = x;
   x = y;
   y = temp;  
}

 z = x % y;
 while(z != 0) {
   x = y;
   y = z;
   z = x % y;
 }

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

 return 0;
}



Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
  
int Merge(int A[],int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int i,j,k;
  int L[n1+1],R[n2+1];
    
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=1000000000;
  R[n2]=1000000000;
    
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      j++;
    }
  }
  return right-left;
}
  
int Merge_Sort(int A[],int left,int right){
  int mid,res=0;
  if(left+1<right){
    mid=(left+right)/2;
  
    res+=Merge_Sort(A,left,mid);
    res+=Merge_Sort(A,mid,right);
    res+=Merge(A,left,mid,right);
      
  }
  return res;
}
  
int main(){
  int i,x,n,S[500000]; 
  cin>>n;

  int cnt=0;
  
  for(i=0;i<n;i++){
    cin>>S[i];
    if(S[i]==1e9)cnt++;  
  }

  assert(cnt<2);
  
  x=Merge_Sort(S,0,n);
    
  for(i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<S[i];
  }
  cout<<endl;
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	vector<int> V(N), C(N);
	for (int i = 0; i < N; i++) cin >> V[i];
	for (int i = 0; i < N; i++) cin >> C[i];

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int v, c;
		v = V[i];
		c = C[i];
		if (v > c) ans += v - c;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3536
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val k = sc.nextInt()

    //    val one = (1 to k).map { x => gcd(x, x, x) }
    //    val two = (1 to k).combinations(2).map(v => gcd(v(0), v(1), v(1)) + gcd(v(0), v(1), v(1)))
    //    val three = (1 to k).combinations(3).map(v => gcd(v(0), v(1), v(2)))
    //    println(one.sum + 3 * two.sum + 6 * three.sum)
    //

    val sum = (1 to k).flatMap { a =>
      (1 to k).flatMap { b =>
        (1 to k).map { c =>
          gcd(a, b, c)
        }
      }
    }.sum
    println(sum)
  }

  def gcd(a: Int, b: Int, c: Int): Int = gcd(gcd(a, b), c)

  def gcd(x: Int, y: Int): Int = y match {
    case 0 => x
    case _ => gcd(y, x % y)
  }

}


Measured memory_bytes: 103688
#include<stdio.h>
main(){
  int a,b,c,tmp;
  scanf("%d %d %d",&a,&b,&c);
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  if(b>c){
    tmp=b;
    b=c;
    c=tmp;
  }
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    char B[2][36];
    char S[2][36];
    char card[2];
    for(int i=0; i<n; i++){
        cin >> card;
        B[0][i] = card[0];
        B[1][i] = card[1];
        S[0][i] = card[0];
        S[1][i] = card[1];
    }
    
    //bouble
    int flag = 1;
    while(flag == 1){
        flag = 0;
        for(int j=n-1; j>0; j--){
            char v[2];
            if(int(B[1][j]) < int(B[1][j-1])){
                v[0] = B[0][j];//柄
                v[1] = B[1][j];//数字
                B[0][j] = B[0][j-1];
                B[1][j] = B[1][j-1];
                B[0][j-1] = v[0];
                B[1][j-1] = v[1];
                flag = 1;
            }
        }
    }
    
    for(int k=0; k<n; k++){
        if(k>0) cout << " ";
        cout << B[0][k] << B[1][k];
    }
    cout << endl;
    cout << "Stable" << endl;
    
    //select
    for(int l=0; l<n; l++){
        int minj = l;
        for(int m=l; m<n; m++){
            if(int(S[1][m]) < int(S[1][minj])) minj = m;
        }
        char w[2];
        w[0] = S[0][minj];
        w[1] = S[1][minj];
        S[0][minj] = S[0][l];
        S[1][minj] = S[1][l];
        S[0][l] = w[0];
        S[1][l] = w[1];
    }

    for(int p=0; p<n; p++){
        if(p>0) cout << " ";
        cout << S[0][p] << S[1][p];
    }
    cout << endl;

    int F=0;
    for(int q=0; q<n; q++){
        if(B[0][q] != S[0][q]) F=1; 
    }

    if(F==1) cout << "Not stable" <<endl;
    else cout << "Stable" <<endl;

    return 0;
}


Measured memory_bytes: 3096