akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
vector<int> v;
int main(){
	cin >> N;
	int A,B,C;
	if(N==3){
		printf("2 5 63\n");
		return 0;
	}
	if(N<=5002){
		C = 1;
		B = N-3;
		if(B%2==0)B--;
		A = N-B-C;
	}else if(N<=7000){
		B = 4999;
		C = N-2-B;
		if(C%2==0)C--;
		A = N-B-C;
	}else{
		B = 4999;
		C = 1999;
		A = N-B-C;
	}
	int sum = 0;
	for(int i=0;i<B;i++){
		v.pb(3*(2*i+1));
		sum += 3*(2*i+1);
	}
	for(int i=0;i<C;i++){
		if(i%2==0){
			v.pb(15*i+5);
			sum += 15*i+5;
		}else{
			v.pb(15*i+10);
			sum += 15*i+10;
		}
	}
	for(int i=0;i<A;i++){
		v.pb(2*(i+1));
		sum += 2*(i+1);
	}
	sum %= 30;
	v.back() += (30-sum);
	for(int i=0;i<v.size();i++){
		printf("%d ",v[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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 int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main(int argc, char* argv[])
{
  string s;
  cin >> s;
  char tmp = s[0];
  int ans = 0;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != tmp) {
      ans++;
    }
    tmp = s[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  if (a[0] == 0) {
    cout << 0 << endl;
  } else {
    ll res = 1;
    rep(i,n) {
      if (res == -1) continue;
      else if (res > 1000000000000000000 / a[i]) res = -1;
      else res *= a[i];
    }
    cout << res << endl;
  }

  return 0;
}



Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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; }

int bubbleSort(int A[], int N) {
    int sw = 0;
    int flag = 1;
    for(int i = 0; flag; ++i) {
        flag = 0;
        for(int j = N - 1; j >= i + 1; j--) {
            if(A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

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

    int n; cin >> n;
    int A[100];
    rep(i, n) cin >> A[i];
    int ans = bubbleSort(A, n);
    rep(i, n) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << ans << endl;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[303][303];
vector<pair<int, P>> v;
int d[303][303];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
			v.push_back(make_pair(a[i][j],P(i,j)));
		}
	}
	sort(v.begin(),v.end());
	
	for(int i = 0; i < 303; i++) fill(d[i],d[i]+303,INF);
	i64 ans = 0;
	for(int i = 0; i < v.size(); i++){
		int c = v[i].first;
		int x = v[i].second.first, y = v[i].second.second;
		
		for(int j = 0; j < n; j++){
			chmin(d[x][y], d[x][j] + d[y][j]);
		}
		if(chmin(d[x][y], c)) ans += c;
		if(d[x][y] < c){
			cout << -1 << endl;
			return;
		}
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 5108
/*    nya-n   */
#include<stdio.h>
char nyan[30000] = {};
int nyaa = 0;
int main(){
nyaa++;nyan[nyaa]=getchar();nyaa++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;while(nyan[nyaa]){
nyaa--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyaa++;nyan[nyaa]--;
}nyan[nyaa]=getchar();nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;
nyan[nyaa]--;while(nyan[nyaa]){nyaa--;while(nyan[nyaa]){nyaa++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;
nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyaa--;nyan[nyaa]--;}nyaa++;nyan[nyaa]--;nyan[nyaa]--;nyaa++;nyan[nyaa]++;
nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;while(nyan[nyaa]){nyaa--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;
nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyaa++;nyan[nyaa]--;}nyan[nyaa]=getchar();while(nyan[nyaa]){nyan[nyaa]--;}}nyan[nyaa]=getchar();
nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;
while(nyan[nyaa]){nyaa++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;
nyan[nyaa]++;while(nyan[nyaa]){nyaa--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;
nyan[nyaa]--;nyan[nyaa]--;nyaa++;nyan[nyaa]--;}nyan[nyaa]++;nyaa--;nyan[nyaa]++;nyaa--;while(nyan[nyaa]){nyaa++;while(nyan[nyaa]){
nyan[nyaa]++;nyaa++;nyaa++;}nyaa++;while(nyan[nyaa]){nyaa++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;while(nyan[nyaa]){
nyaa--;nyaa--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyaa++;nyaa++;nyan[nyaa]--;}nyaa++;}nyaa--;nyaa--;nyaa--;
nyaa--;nyaa--;nyan[nyaa]++;nyaa++;nyan[nyaa]--;}nyaa--;while(nyan[nyaa]){nyaa++;nyan[nyaa]++;nyaa--;nyan[nyaa]--;}nyaa++;nyaa++;nyaa++;
nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;while(nyan[nyaa]){
nyaa--;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyan[nyaa]++;nyaa++;
nyan[nyaa]--;}nyaa--;putchar(nyan[nyaa]);nyan[nyaa]=getchar();nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;
nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;nyan[nyaa]--;}return 0;}


Measured memory_bytes: 128
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	static long mod = (long)(1e9+7);
	public static void main(String[] args) { //Ball out 
		/*
		 * */
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long N = I.nextLong();
		long ten = 1;
		long nine = 1;
		long eight = 1;
		for (int i = 0; i < N; i++) {
			ten*=10;
			nine*=9;
			eight*=8;
			ten%=mod;
			nine%=mod;
			eight%=mod;
		}
		long ans = ten-2*nine+eight;
		ans%=mod;
		if (ans<0) ans+=mod;
		O.pln(ans);
	}
	public static double max(double a, double b) {return Math.max(a, b);}
	public static double min(double a, double b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x) {return Math.abs(x);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(min(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 25864
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=998244353;
struct BIT{
	int size=1;
	vector<long long> node;
	BIT(int n){
		while(size<n){
			size<<=1;
		}
		node.resize(size+1,0);
	}
	//k番目の値にa加算
	void add(int k,long long a){
		k++;
		while(k<=size){
			(node[k]+=a)%=mod;
			k+=k&-k;
		}
	}
	//[0,k)の範囲内の区間和を求める
	int query(int k){
		long long res=0;
		while(k){
			(res+=node[k])%=mod;
			k-=k&-k;
		}
		return res;
	}
};
int main(){
	int n,k;
	pair<int,int> lr[10];
	cin>>n>>k;
	for(int i=0;i<k;i++){
		cin>>lr[i].first>>lr[i].second;
	}
	sort(lr,lr+k);
	BIT bit(n);
	bit.add(0,1);
	for(int i=1;i<n;i++){
		for(int j=0;j<k;j++){
			if(i-lr[j].first<0){
				break;
			}else if(i-lr[j].second<0){
				bit.add(i,bit.query(i-lr[j].first+1));
			}else{
				bit.add(i,(bit.query(i-lr[j].first+1)-bit.query(i-lr[j].second)+mod)%mod);
			}
		}
	}
	cout<<(bit.query(n)-bit.query(n-1)+mod)%mod<<endl;
	return 0;
}


Measured memory_bytes: 4936
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

ll dp[100005][3];
ll a[100005][3];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    rep(i,n) {
        rep(j,3) {
            cin >> a[i][j];
        }
    }

    rep(i,n) {
        rep(j,3) {
            rep(k,3) {
                if(j!=k) {
                    dp[i+1][k] = max(dp[i+1][k],dp[i][j] + a[i][k]);
                }
            }
        }
    }

    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;


    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,COUNT) for(int i=0;i<(int)(COUNT);i++)
typedef long long ll;
#define MOD 1000000007
double dp[3001][3001];
int main()
{
  ll N;
  double p[3000],sum=0;
  cin >> N;
  REP(i,N)cin >> p[i+1];
  REP(i,3001)REP(j,3001)dp[i][j] = 0;
  dp[0][0] = 1.0;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=i;j++){
      if(j-1 >= 0)
        dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1.0-p[i]);
      else
        dp[i][j] = dp[i-1][j]*(1.0-p[i]);
    
    }
  }
  
  REP(i,N/2+1){
    sum += dp[N][N/2+1+i];
  }
  printf("%.16lf\n",sum);
  return 0;
}



Measured memory_bytes: 70656
n = int(input())
h = list(map(int, input().split(" ")))
count = 0
temp = 0
for i in range(1, n):
  
  if h[i] <= h[i-1]:
    temp += 1
  else:
    count = max(count, temp)
    temp = 0
print(max(temp, count))

Measured memory_bytes: 20508
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int n,k;
int a[200004];
bool check(int x){
    int cop = k;
    for(int i=1;i<=n;i++){
        if(a[i] > x) {
            int v = a[i] / x;
            if(a[i] % x != 0) v ++;
            cop -= (v-1);
            if(cop < 0) return false;
        }
    }
    return true;
}
int main(){
    scanf("%d%d",&n,&k);
    int maxn = 0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]), maxn = max(maxn, a[i]);
    int ans=-1,l=1,r=maxn;
    while(l<=r){
        int mid=(l+r)/2;
        if(check(mid)) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n, t; cin >> n >> t;
  int price;
  int buy = 1e9+1;
  int profit = 0;
  int ans;
  rep(i,n) {
    cin >> price;
    buy = min(buy, price);
    if (price - buy == profit) ++ans;
    else if (price - buy > profit) {
      profit = price - buy;
      ans = 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,popcnt,sse4.1,sse4.2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<20, mod = 119<<23|1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
vi g[maxn];
deque<int> ans;
vi vis;
bool ext(int &v, int a) {
	for(auto u : g[v]) {
		if(!vis[u]) {
			vis[v = u] = 1;
			if(a) ans.push_back(u);
			else ans.push_front(u);
			return true;
		}
	}
	return false;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	vis = vi(n+1, 0);
	for(int f, t, i = 0; i < m; i++) {
		cin >> f >> t;
		g[f].pb(t);
		g[t].pb(f);
	}
	int l = 1, r = g[1][0];
	ans.push_back(l), ans.push_back(r);
	vis[l] = vis[r] = 1;
	while(ext(l, 0) || ext(r, 1));
	cout << ans.size() << '\n';
	for(auto &i : ans) cout << i << " ";
}


Measured memory_bytes: 29696
import itertools

n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
ans=0
for poss in itertools.permutations([i for i in range(n)]):
  for i in range(n-1):
    x1,y1=arr[poss[i]]
    x2,y2=arr[poss[i+1]]
    ans+=((x1-x2)**2+(y1-y2)**2)**0.5
for i in range(1,n+1):
  ans/=i
print(ans)

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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  // 前処理
  COMinit();
  int N,K;
  cin >> N >> K;
  for(int i=1; i<=K; i++){
    if(N-K+1<i){
      cout << 0 << endl;
    }
    else{
      cout << COM(K-1,i-1)*COM(N-K+1,i)%MOD << endl;
    }
  }
}

Measured memory_bytes: 12160
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
using namespace std;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	ll i,n,t,a,ans=0,j;
	cin>>n>>t;
	vector<ll> v(n);
	rep(i,n)cin>>v[i];
	rep(i,n){
		j=i+1;
		while(j<n&&v[j]-v[j-1]<=t){
			j++;
		}
		j--;
//		cout<<v[j]<<endl;
		ans+=v[j]+t-v[i];
		i+=j-i;
	}
	fin(ans);
	
	
	
	
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


Measured memory_bytes: 1792
AX, AY, BX, BY = [int(x) for x in input().split()]

def main():
    x = BX - AX
    y = BY - AY
    cx = BX - y
    cy = BY + x
    dx = cx - x
    dy = cy - y

    print(cx, cy, dx, dy)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, A, S, Goal;

struct Elem {
    int point;
    string s;
};

struct Edge {
    int to;
    string s;
};

signed main() {
    while(cin >> N >> A >> S >> Goal, N) {
        // dp ??????, cnt ???????????????
        vector<string> dp(N, "");

        vector< vector<Edge> > G(N);
        rep(i,0,A) {
            int a, b; string s;
            cin >> a >> b >> s;
            G[b].push_back(Edge{a, s});
        }

        bool ng = false;
        rep(k,0,7*N) {
            bool updated = false;
            rep(i,0,N) {
                if(i != Goal && dp[i] == "") continue;
                for(auto e : G[i]) {
                    int to = e.to; string ss = e.s;
                    if((to != Goal && dp[to] == "") || dp[to] > ss + dp[i]) {
                        updated = true;
                        dp[to] = ss + dp[i];
                    }
                }
            }
            if(!updated) break;
        }

        if(dp[S].length() > 6*N) ng = true;
        if(ng || dp[S] == "") cout << "NO" << endl;
        else cout << dp[S] << endl;
    }
    return 0;
}

Measured memory_bytes: 3492
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Main.MergeSort(a, a.length);
		
		int max = (k - a[n-1]) + a[0];
		for(int i = 1; i < n; i++) {
			if (a[i] - a[i-1] > max) {
				max = a[i] - a[i-1];
			}
		}
		System.out.println(k - max);
	}
	
	
	static void MergeSort(int[] a,int num) {
		int mid = (num+1)/2;
		int[] left = new int[mid];
		int[] right = new int[num-mid];

		
		if(num > 1) {
			
			for(int i = 0; i < mid; i++) {left[i] = a[i];}
			for(int i = 0; i < num-mid; i++) {right[i] = a[mid+i];}
			MergeSort(left, mid);
			MergeSort(right, num-mid);
			Main.merge(a, left, right);
		}
	}
	static void merge(int[] a, int[] left, int[] right) {
		int i = 0, j = 0;
		while( i < left.length || j < right.length) {

			if(j >= right.length || (i < left.length && left[i] < right[j])) {
				a[i+j] = left[i];
				i++;
			}else {
				a[i+j] = right[j];
				j++;
			}
		}
	}
	
}


Measured memory_bytes: 91924
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
 
#define int long long 
#define pb push_back
#define all(s) s.begin(),s.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define bst ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

using namespace std;

const int N = 5e5 + 10, mod = 1e9 + 7, inf = 1e18 + 7;
const double pi = acos(-1);


void solve() {
	//soln
	int a, b, c;
	cin >> a >> b >> c;
	int k;
	cin >> k;
	int res = min(k, a);
	k -= a;
	if(k > 0) {
		k -= b;
	}
	if(k > 0) {
		res -= k;		
	}
	cout << res << endl;
}
main() {
	bst;
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
}
		

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

using namespace std;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	map<int, int> mp;
	mp[0] = 1;
	long long ans = 0;
	int sum = 0;
	rep(i,n) {
		(sum += a[i]) %= m;
		ans += mp[sum] ++ ;
	}
	cout << ans << endl;
}


Measured memory_bytes: 6536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		sc.close();
		long C = 0;
		long pair =((B-A)/2);
		if(pair%2 == 0){
			C = 0;
		}
		else{
			C = 1;
		}

		long ans = 0;

		if(A%2 == 0 && B%2 == 0){
			ans = C^B;
		}
		else if(A%2 != 0 && B%2 == 0){
			ans = A^C^B;
		}
		else if(A%2 == 0 && B%2 != 0){
			if(C == 0){
				ans = 1;
			}
			else{
				ans = 0;
			}
		}
		else if(A%2 != 0 && B%2 != 0){
			ans = A^C;
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


int main(void) {
  ll i, j, k, l;
  
  ll N;
  cin >> N;
  ll s=0;
  ll a[MAX];
  memset(a, 999, sizeof(a));
  for(i=0; i<N; i++) {
    cin >> a[i];
    s+=abs(a[i]);
  }
  sort(a, a+N);
  
  if((a[0]<=0 && a[N-1]>=0)) {
    pt(s);
    for(k=0; a[k]<=0; k++);
    if(a[N-1]==0) k=N-1;
    
    
    for(i=k; i<N-1; i++) {
      pt(a[0]<<" "<<a[i]);
      a[0]-=a[i];
    }
      
    for(i=0; i<k; i++) {
      pt(a[N-1]<<" "<<a[i]);
      a[N-1]-=a[i];
    }
    
  }else if(a[0]>0) {
    pt(s-a[0]*2);
    for(i=1; i<N-1; i++) {
      pt(a[0]<<" "<<a[i]);
      a[0]-=a[i];
    }
    pt(a[N-1]<<" "<<a[0]);
    
  }else {
    pt(s-abs(a[N-1])*2);
    for(i=0; i<N-1; i++) {
      pt(a[N-1]<<" "<<a[i]);
      a[N-1]-=a[i];
    }
      
  }
  
  
}




Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long int H;
cin>>H;
int k = __builtin_clzll(H);
int m= 64-k;
long long ans= 0;
for(int i= 0; i< m; i++){
	ans+= (1LL<<i);
}
		cout<<ans;
	
	

	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  vector<i64> rv(n + 1, 0), gv(n + 1, 0), bv(n + 1, 0);
  REP(i, n + 1) {
    if (i % r == 0) rv[i] = 1;
  }
  REP(i, n + 1) {
    auto j = 0;
    while (true) {
      if (i + j > n) break;
      gv[i + j] += rv[i];
      j += g;
    }
  }
  REP(i, n + 1) {
    auto j = 0;
    while (true) {
      if (i + j > n) break;
      bv[i + j] += gv[i];
      j += b;
    }
  }

  cout << bv[n] << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split(' ')))

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        
# 最大数を計算
max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)

# 辞書Kに関して全探索
for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )

Measured memory_bytes: 24748
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    K = II()
    A,B = MI()
    ans = 0

    for i in range(A, B+1):
        if i % K == 0:
            ans= 1
    if ans == 1:
        print("OK")
    else:
        print("NG")


if __name__ == "__main__":
	main()

Measured memory_bytes: 61792
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var S = ReadText();
            var length = S.Length;
            var answer1 = new string(Enumerable.Range(0, length).Select(x => (x % 2 == 0 ? 0 : 1).ToString()[0]).ToArray());
            var answer2 = new string(Enumerable.Range(0, length).Select(x => (x % 2 == 0 ? 1 : 0).ToString()[0]).ToArray());

            var count1 = NewMethod(S, length, answer1);
            var count2 = NewMethod(S, length, answer2);

            return Math.Min(count1, count2);
        }

        private static long NewMethod(string S, int length, string answer)
        {
            var count = 0L;
            for (int i = 0; i < length; i++)
            {
                if (answer[i] != S[i])
                {
                    count++;
                }
            }
            return count;
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 15356
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll m_cnt = 0;
    ll mi = abs(A[0]);
    ll sum = 0;
    rep(i, N) {
        if (A[i] < 0) {
            m_cnt++;
        }
        mi = min(mi, abs(A[i]));
        sum += abs(A[i]);
    }
    if (m_cnt % 2 == 0) {
        print(sum);
    } else {
        print(sum - 2*mi);
    }
    return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())

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

#AB = [tuple(map(int, input().split())) for i in range(M)]

#丸暗記。隣接リストの初期化
graph = [[] for _ in range(N)]

for _ in range(M):
  a, b = map(int, input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

  ans = 0

for n in range(N):
  flag = True
  for to in graph[n]:
    if H[n] <= H[to]:
      flag = False
    
  if flag:
    ans += 1
  
print(ans)

Measured memory_bytes: 29416
def main():
    N, X, Y = map(int, input().split())
    ans = [0] * (N-1)
    for i in range(N):
        for j in range(i+1, N):
            dst = min(j-i, abs(X-1-i) + abs(Y-1-j) + 1)
            ans[dst-1] += 1
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

struct UnionFind {
	int s, num; // [0, s) の s 個の要素がある。num は非空集合の個数。
	vector<vector<int>> v;
	vector<int> find;
	
	UnionFind() { s = 0; }
	UnionFind(int s) { init(s); }
	void init(int arg_s) {
		num = s = arg_s;
		v.clear();
		find.clear();
		inc(i, s) { v.PB({i}); find.PB(i); }
	}
	bool unite(int x, int y) {
		assert(inID(x, 0, s) && inID(y, 0, s));
		if(find[x] == find[y]) { return false; }
		num--;
		if(v[find[x]].size() > v[find[y]].size()) { swap(x, y); }
		int fx = find[x];
		for(auto && e: v[find[x]]) { v[find[y]].PB(e); find[e] = find[y]; }
		v[fx].clear();
		return true;
	}
};

// ---- ----

int n, k[2];
UnionFind uf[2];
map<pair<int, int>, int> mp;

int main() {
	cin >> n >> k[0] >> k[1];
	int p, q;
	inc(i, 2) {
		uf[i].init(n);
		inc(j, k[i]) {
			cin >> p >> q;
			p--; q--;
			uf[i].unite(p, q);
		}
	}
	
	inc(i, n) { mp[MP(uf[0].find[i], uf[1].find[i])]++; }
	inc(i, n) { cout << (i == 0 ? "" : " ") << mp[MP(uf[0].find[i], uf[1].find[i])]; }
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 36780
#include <iostream>
using namespace std;
int main(void){
    int N,M;
    cin >> N >>M;
    int L=0;
    int R=N;
    int l,r;
    for(int i = 0;i<M;i++){
        cin >> l >> r;
        L = max(L,l);
        R = min(r,R);
    }
    int ans = R-L+1;
    if(R-L+1<0)ans = 0;
    
    cout << ans<<endl;
    
    
    
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int [] a = new int[n];
		for (int i = 0 ; i < n; i++) {
			a[i] = scan.nextInt();
		}
		for (int i = n-1; i >= 0; i--) {
		    if ( i  != 0) {
		        System.out.print(a[i] + " ");
		    }else {
		        System.out.print(a[i]);
		    }
			
			
		}
		System.out.println();
	}
}


Measured memory_bytes: 26260
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
//#define bint int1024_t
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define pi 3.1415926536
#define mod int(1e9+7)
#define mp make_pair
//ios_base::sync_with_stdio(false);cin.tie(NULL);
#define testcases ll t; cin>>t; while(t--)

using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // int k=0;
    // testcases
    // {
        

    //     cout<<"Case #"<<++k<<": "<<ans<<"\n";
    // }

    ll n;
    cin>>n;
    vect v(n+1,0);
    for(int i=1;i<n;i++)
    {
        int x;
        cin>>x;
        v[x]++;
    }
    for(int i=1;i<=n;i++) cout<<v[i]<<"\n";

    return 0;
}

Measured memory_bytes: 4780
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
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; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int H, W, h, w;
    in2(H, W);
    in2(h, w);

    outl((H - h) * (W - w));

    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
typedef long long ll;
using namespace std;

class union_find {
public:
	vector<int>parent;
	union_find(int n) {
		parent = vector<int>(n, -1);
	}
	int root(int a) {
		if (parent[a] <  0) {
			return a;
		}
		else {
			return parent[a] = root(parent[a]);
		}
	}
	int size(int a) {
		return -parent[root(a)];
	}
	bool connect(int a, int b) {
		a = root(a); b = root(b);
		if (a == b) {
			return false;
		}
		else {
			if (size(a) > size(b)) {
				swap(a, b);
			}
			parent[a] += parent[b];
			parent[b] = a;
			return true;
		}
	}
};


int main() {
	int n, m; cin >> n >> m;
	vector<int>a(m), b(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}
	vector<ll>ans(m);
	ans[m - 1] = (ll)n * (n - 1) / 2;
	union_find uf(n);
	for (int i = m - 1; i >= 1; i--) {
		a[i]--; b[i]--;
		if (uf.root(a[i]) != uf.root(b[i])) {
			ans[i - 1] = ans[i] - (long long)uf.size(a[i]) * uf.size(b[i]);
			uf.connect(a[i], b[i]);
		}
		else {
			ans[i - 1] = ans[i];
		}
	}
	for (int i = 0; i < m; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n;
    cin >> n;
	
  	if(n <= 999){
      cout << "ABC" << endl;
    }
  	else{
      cout << "ABD" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def mm(str, arr, c)
    str[arr[0]] = c
    arr = arr[1..-1]
    x = arr.size

    return [str] if x == 0
    re = mm(str.clone, arr, c.next)
    s = str.clone
    arr.each {|k| s[k] = c}
    re << s

    1.upto(x-1) do |j|
        arr.combination(j) do |a|
            s = str.clone
            a.each {|k| s[k] = c}
            re += mm(s, arr - a, c.next)
        end
    end
    re
end

n = gets.to_i
str = Array.new(n)
arr = (0..n-1).to_a

puts mm(str, arr, "a").map(&:join).sort

Measured memory_bytes: 121744
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int dy[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
const ll MOD = 1000000007;
const ll INF = 1000000000;
const int MAX = 10000000;


int main() {
    string s;
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            char c; cin >> c;
            if (i == j) s += c;
        }
    }
    cout << s << endl;
   
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>

using namespace std;

struct card{
	char s;
	int n;
	int o;
}C[100000];


int partition(card *a, int p, int r)
{
	int x=a[r].n;
	int i=p-1;
	for(int j=p; j<r; j++) {
		if(a[j].n<=x) {
			i++;
			swap(a[i], a[j]);
		}
	}
	swap(a[i+1], a[r]);
	return i+1;
}

void quicksort(card *a, int p, int r)
{
	if(p<r) {
		int q=partition(a, p, r);
		quicksort(a, p, q-1);
		quicksort(a, q+1, r);
	}
}

bool isStable(card *a, int n)
{
	for(int i=1; i<n; i++) if(a[i-1].n==a[i].n && a[i-1].o>a[i].o) return false;

	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	char str[16];
	cin.getline(str, 16);
	int n=atoi(str);

	for(int i=0; i<n; i++) {
		cin.getline(str, 16);
		C[i]=card{str[0], atoi(str+2), i};
	}
	quicksort(C, 0, n-1);

	cout<<(isStable(C, n) ? "Stable\n": "Not stable\n");
	for(int i=0; i<n; i++) cout<<C[i].s<<' '<<C[i].n<<'\n';
	return 0;
}



Measured memory_bytes: 4304
#include<iostream>
#include <string.h>
#include<stdio.h>
#include <math.h>

using namespace std;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main(){
	
	const double PI = 3.14159265358979323846;

	int R;
	cin >> R;

	const double ans = 2 * R * PI;
    printf("%.16f", ans);

return 0;
}


Measured memory_bytes: 3748
import sys
input = sys.stdin.readline

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

k = 10**15
s = 0
for i in range(N):
    a, b = AB[i]
    s += b
    if a > b:
        k = min(k, b)

if k == 10**15:
    print(0)
else:
    print(s-k)

Measured memory_bytes: 7796
#include<bits/stdc++.h>
#define rep(i,b) for(int i=1;i<=b;i++)
#define drep(i,b) for(int i=b;i>=1;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pr pair<int,int>
#define ff first
#define ss second
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
int n,m,k,t,x,y,z;
int a[200],b[200][200],c[200],sum;

void dfs(int i,int &ans) {
    if(i==n+1) {
        rep(j,m) if(c[j]<k) return ;
        ans=min(ans,sum);
        return ;
    }
    dfs(i+1,ans);
    rep(j,m) c[j]+=b[i][j];
    sum+=a[i];
    dfs(i+1,ans);
    rep(j,m) c[j]-=b[i][j];
    sum-=a[i];
}

void solve(int ans=mod) {
    cin>>n>>m>>k;
    rep(i,n) {
        cin>>a[i];
        rep(j,m) cin>>b[i][j];
    }
    dfs(1,ans);
    if(ans!=mod) cout<<ans<<endl;
    else cout<<-1<<endl;
}

#undef int
int main() {
    ios::sync_with_stdio(false);
    //int T;cin>>T;
    //while(T--)
        solve();
}


Measured memory_bytes: 3680
from operator import add

n, m = map(int, input().split())
li = []
for i in range(n):
    li.append(list(map(int, input().split())))
    del li[i][0]
li = sum(li, [])
li_2 = list(set(li))
count = 0
for num in li_2:
    if n == li.count(num):
        count += 1
print(count)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int,input().split()))

# 0
# 1, 0
# 2, 0, 1
# 3, 1, 0, 2
# 4, 2 ,0, 1, 3

ans = None
if N % 2 == 1:
  ans = A[::2][::-1] + A[1::2]
else:
  ans = A[1::2][::-1] + A[::2]
print(*ans)

Measured memory_bytes: 31008
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
b,c = [], []
bb,cc = a[0], a[-1]

for i in range(n):
  bb, cc = gcd(bb, a[i]), gcd(cc, a[-i-1])
  b.append(bb)
  c.append(cc)

ans = 1
c = c[::-1]
for i in range(1,n-1):
  ans = max(ans, gcd(b[i-1], c[i+1]))
print(max([ans, b[-2], c[1]]))



Measured memory_bytes: 16612
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void solve(){
  int n;
  cin >> n;
  int ans = 1e9;
  forn(i,n){
    int a;
    cin >> a;
    int cnt = 0;
    while (a % 2 == 0){
      a /= 2;
      cnt++;
    }
    setmin(ans, cnt);
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

6
1 1
7 1
2 2
6 2
1 3
7 3

 */

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int flag=1;
    while(flag){
        int a,b;
        scanf("%d %d",&a,&b);
        if(a==0 && b==0){
            flag=0;
            break;
        }
        
        int i,j;
        for(i=0;i<a;i++){
            for(j=0;j<b;j++){
                if(i>0 && i<a-1 && j>0 && j<b-1){
                    printf(".");
                }else{
                    printf("#");
                }
                
                if(j==b-1){
                    printf("\n");
                }
            }
        }
        printf("\n");
    }
}


Measured memory_bytes: 2072
L, R = map(int, input().split())
if R >= L+2019:
    print(0)
    quit()
L %= 2019
R %= 2019
ans = 2020
if L > R:
    t = L
    L = R
    R = t
if L == R:
    print(L*L%2019)
    quit()
ans = 2020
for i in range(L, R):
    for j in range(i+1, R+1):
        ans = min(ans, i*j%2019)
print(ans % 2020)


Measured memory_bytes: 3060