akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  cout << a.at(n-1) - a.at(0) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int cardn, cutn; 

  while(1){

  scanf("%d %d", &cardn, &cutn);

  if(cardn==0 && cutn==0)
    break;

  int card[50];
  int save[50];
  int i, j, p, c;

  for(i=0; i<cardn; i++)
    card[i]=cardn-i;

  for(i=0; i<cutn; i++){

    scanf("%d %d", &p, &c);

    for(j=0; j<c; j++)
      save[j]=card[p-1+j];

    for(j=0; j<p-1; j++)
      card[p+c-2-j]=card[p-2-j];

    for(j=0; j<c; j++)
      card[j]=save[j];



  }
  
    printf("%d\n", card[0]);

  }


  return 0;

}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
long long int coins(long int x)
{
    long int rem;
    rem = x%500;
    x = x/500;
    rem = rem/5;
    return (x*1000+rem*5);
}
int main()
{
    long int x;
    long long res;
    cin>>x;
    res = coins(x); 
    cout<<res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;


int main(){
  vector<int> a(3);
  for(int i=0; i<3; i++)  cin >> a.at(i);
  sort(a.begin(), a.end());
  ll ans = 0;
  if(a[0]%2==a[1]%2 && a[1]%2==a[2]%2) ans = (a[2]-a[0])/2+(a[2]-a[1])/2;
  else if(a[0]%2==a[1]%2) ans = (a[2]-a[0])/2+(a[2]-a[1])/2+1;
  else if(a[0]%2==a[2]%2) ans = (a[2]+1-a[0]+1)/2+(a[2]+1-a[1])/2;
  else ans = (a[2]+1-a[0])/2+(a[2]+1-a[1]+1)/2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

static long long int merge(int A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    int i, j, k;
    int *L, *R;
    long long int c = 0;

    L = malloc(sizeof(int) * n1 + sizeof(int));
    R = malloc(sizeof(int) * n2 + sizeof(int));
    for ( i = 0; i < n1; i++ ) {
        L[i] = A[left + i];
    }
    L[i] = INT_MAX;
    for ( i = 0; i < n2; i++ ) {
        R[i] = A[mid + i];
    }
    R[i] = INT_MAX;    
    
    for ( i = 0, j = 0, k = left; k < right; k++ ) {
        if ( L[i] <= R[j] ) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            c += n1 - i;        /* 飛び越えたR側の個数 */
            j++;
        }
    }
    free(L);
    free(R);

    return c;
}

static long long int MergeSort(int A[], int left, int right) {
    long long int c = 0;
    
    if ( left + 1 >= right ) {
        return 0;
    }

    int mid = (left + right) / 2;
    c += MergeSort(A, left, mid);
    c += MergeSort(A, mid, right);
    c += merge(A, left, mid, right);

    return c;
}

int main(void) {
    int * A;
    int n;
    long long int c;

    scanf("%d\n", &n);
    A = malloc(sizeof(int) * n);

    for ( int i = 0; i < n; i++ ) {
        int a;
        scanf("%d", &a);
        A[i] = a;
        (void)fgetc(stdin);
    }

    c = MergeSort(A, 0, n);

    printf("%lld\n", c);

#if 0
    for (int i = 0; i < n; i++ ) {
        printf("%d ", A[i]);
    }
    printf("\n");
#endif

    return 0;
}



Measured memory_bytes: 2980
package main

import (
        "fmt"
        "sort"
)

func solution(n int, d []int) int {
        sort.Ints(d)
        l := len(d)
        return d[l/2] - d[l/2-1]
}

func main() {
        var n int
        fmt.Scan(&n)
        d := make([]int, n)
        for i := 0; i < n; i++ {
                var t int
                fmt.Scan(&t)
                d[i] = t
        }
        fmt.Println(solution(n, d))
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  string s[3];
  char u[3] = {'A', 'B', 'C'};
  cin >> s[0] >> s[1] >> s[2];
  int next = 0, tmp;
  while(1) {
    if(s[next].length() == 0)
      break;
    tmp = s[next][0] - 'a';
    s[next].erase(0, 1);
    next = tmp;
  }
  cout << u[next] << endl;
  return 0;
}


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

using std::cin;
using std::cout;
using std::cerr;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using std::sort;
using std::reverse;

using ll = long long;

#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())
#define endl '\n'

struct __init {
    __init() {
        cin.tie(nullptr);
        std::iostream::sync_with_stdio(false);
        cout << std::fixed << std::setprecision(10);
        cerr << std::fixed << std::setprecision(5);
        std::mt19937 rand(300);
    }

    ~__init() {
        #ifdef SEREZHKA
            cerr << "Time elapsed: " << static_cast<double>(clock()) / CLOCKS_PER_SEC << endl;
        #endif
    }
} init;

const ll inf = (ll) 1e9 + 7ll;
const int maxn = (int) 1e6 + 17;

ll n;

bool read() {
    if (!(cin >> n))
        return false;

    return true;
}

vector<int> getv(ll n) {
    vector<int> v;

    while (n > 0)
        v.push_back(n % 10), n /= 10;

    reverse(v.begin(), v.end());
    return v;
}

void solve() {
    auto v = getv(n);
    int ans = accumulate(v.begin(), v.end(), 0);

    for (int i = 0; i < sz(v); ++i) {
        auto u = v;
        
        if (v[i] > 0) {
            u[i] = v[i] - 1;

            for (int j = i + 1; j < sz(u); ++j)
                u[j] = 9;

            ans = max(ans, accumulate(u.begin(), u.end(), 0));
        }
    }

    cout << ans << endl;
}

int main() {
#if SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    //連結チェック

    int n,m;cin>>n>>m;
    vector<vector<int>> g(n);
    rep(i,m){
        int u,v;cin>>u>>v;u--,v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    vector<bool> check(n,false);
    vector<int> pre(n,-1);

    queue<int> que;
    check[0]=true;
    que.push(0);pre[0]=0;
    while(!que.empty()){
        int now=que.front();que.pop();
        for(auto to:g[now]){
            if(check[to]) continue;
            pre[to]=now;
            check[to]=true;
            que.push(to);
        }
    }

    if(*min_element(ALL(pre))<0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
        for(int i=1;i<n;i++) cout<<pre[i]+1<<endl;
    }

    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

ll l[300003],r[300003];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    for(ll i = 0; i < n; i++)
    {
        if(i>0)l[i]+=l[i-1];
        if(s[i]=='E')l[i]++;
    }
    r[n-1] = 0;
    for(ll i = n-1; i >= 0; i--)
    {
        if(i<n-1)r[i]+=r[i+1];
        if(s[i]=='W')r[i]++;
    }
    ll ans = 3e5;
    for(ll i = 0; i < n; i++)
    {
        //cout << l[i] << " " << r[i] << endl;
        ans = min(ans, n-l[i]-r[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;
    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }
    int s[D][26];
    rep(i, 0, D) {
        rep(j, 0, 26) {
            cin >> s[i][j];
        }
    }
    int t[D];
    rep(i, 0, D) {
        cin >> t[i];
        t[i]--;
    }
    int m;
    cin >> m;
    rep(i, 0, m) {
        int d, q;
        cin >> d >> q;
        d--;
        q--;
        t[d] = q;

        ll score[D] = {};
        vector<int> last_day(26, -1);
        rep(i, 0, D) {
            if (i != 0) score[i] = score[i - 1];
            score[i] += s[i][t[i]];
            last_day[t[i]] = i;
            int decrease = 0;
            rep(j, 0, 26) {
                decrease += c[j] * (i - last_day[j]);
            }
            score[i] -= decrease;
        }
        cout << score[D - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pii;
int getId(int a, int b, int N) {
  if (a > b) {
    swap(a, b);
  }
  return a * (N + 1) + b;
}

void dfs(vector<vector<int>> &adj, unordered_map<int, int> &edge_map, int parent, int parent_color, int v, vector<int>& res, int &max_color) {
  int N = adj.size() - 1;
  int color = 1;
  for (int u : adj[v]) {
    if (u == parent) {
      continue;
    }
    int id = getId(u, v, N);
    int idx = edge_map[id];
    if (color == parent_color) {
      color++;
    }
    res[idx] = color;
    max_color = max(max_color, color);
    dfs(adj, edge_map, v, color, u, res, max_color);
    color++;
  }
  return;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> adj(N + 1);
  vector<int> res(N - 1);
  unordered_map<int, int> edge_map;
  int max_degree = 0;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    int id = getId(a, b, N);
    edge_map[id] = i;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int max_color = 0;
  dfs(adj, edge_map, 0, 0, 1, res, max_color);
  cout << max_color << endl;
  for (int i = 0; i < N - 1; i++) {
    cout << res[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 14220
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <map>

#define INF 100000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using P = pair<int, int>;

const int MAX = 1000000;
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;
        //そのまま計算すると負の値になるので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;
}

//二分累乗法
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
*/

/*
//UnionFind木
struct UnionFind{
   vector<long long int> par; //par[i] : iの親の番号
   vector<long long int> rnk; //root[i] : iの木のサイズ

   //コンストラクタ
   UnionFind(long long int n): par(n), rnk(n){
       //木の初期化
       for(long long int i = 0; i < n; i++){
           par[i] = i;
           rnk[i] = 1;
       }
   }

   //データxが属する木の根を再帰で取得
   long long int root(long long int x){
       if(par[x] == x){
           return x;
       }else{
           return par[x] = root(par[x]);
       }
   }

   //xとyが同じ木に属しているかを判定
   bool same(long long int x, long long int y){
       return root(x) == root(y);
   }

   //xとyの木を併合
   void unite(long long int x, long long int y){
       long long int rx = root(x); //xの根
       long long int ry = root(y); //yの根
       if(rx == ry) return; //根が同じならそのまま

       //併合するときにサイズを足し合わせる
       if(rnk[rx] < rnk[ry]){
           par[rx] = ry;
           rnk[ry] += rnk[rx];
       }else{
           par[ry] = rx;
           rnk[rx] += rnk[ry];
       }
   }

   //属している木のサイズを取得
   long long int size(long long int x){
       return rnk[root(x)];
   }
};
*/


/*
typedef struct edge{
   int to;
   int cost;
} edge;

vector<edge> graph[2010];
long long int d[2010];

void dijkstra(int s){
   priority_queue<P, vector<P>, greater<P> > que;
   for(int i = 0; i < 2010; i++){
       d[i] = INF;
   }
   d[s] = 0;
   que.push(P(s, 0));

   while (!que.empty()) {
       P p = que.top();
       que.pop();
       int v = p.first;
       if (d[v] < p.second) continue;

       for (int i=0; i<graph[v].size(); ++i) {
           edge e = graph[v][i];
           if (d[e.to] > d[v] + e.cost) {
               d[e.to] = d[v] + e.cost;
               que.push(P(e.to, d[e.to]));
           }
       }
   }
}
*/

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '+') ans++;
        else ans--;
    }

    cout << ans << endl;
}


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

#define west 0
#define east 1

int main()
{
	int n;
	int cmin = INT_MAX;
	int wcou = 0, ecou = 0;
	char c;
	bool ew[300000];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> c;
		if(c == 'W'){
			ew[i] = west;
		}
		else{
			ew[i] = east;
			ecou += 1;
		}
	}
	for(int i = 0; i < n; i++){
		if(ew[i] == east){
			ecou -= 1;
			cmin = min(ecou + wcou, cmin);
			continue;
		}
		else{
			wcou += 1;
			cmin = min(ecou + wcou - 1, cmin);
		}
	}
	cout << cmin << endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

long long waru2(long long count , long long a){
  if(a%2 != 0){
    return count;
  }
  else{
    count ++;
    a /= 2;
  }
   waru2(count , a);
}


int main(void){
  
  int n;
  scanf("%d",&n);
    
 long long a[n];
  for(int i = 0;i <n;i ++){
    scanf("%lld",&a[i]);
  }
  
  long long count = 0;
  long long ans = 0;
  for(int i = 0;i < n;i ++){
    ans += waru2(count , a[i]);
   
  }
  
  printf("%lld\n",ans);
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
typedef long long ll;
int n,k;
const int N=2e5+10;
int num[N];
int main()
{
	scanf("%d %d",&n,&k);
	register ll ans=0;
	register ll ret=n/k;
	ans=ret*ret*ret;
	if((k&1)==0) {
		if(n>=k/2) ret=(n-k/2)/k+1;
		else ret=0;
		ans+=ret*ret*ret;
	}
	printf("%lld\n",ans);
}


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

int main() {
  int N, M; cin >> N >> M;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  map<long long, long long> nums;
  long long sum = 0;
  nums[sum]++;
  for (int i = 0; i < N; ++i) {
	sum += A[i];
	nums[sum % M]++;
  }
  long long res = 0;
  for (map<long long, long long>::iterator it = nums.begin(); it != nums.end(); ++it) {
	res += it->second * (it->second - 1) / 2;
  }
  cout << res << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(){
    ll n, m;
    cin >> n >> m;
    ll a[n];
    ll ans = 0;
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    ll sum[n];
    sum[0] = a[0]%m;
    for(ll i = 1; i < n; i++){
        sum[i] = (sum[i-1]+a[i])%m;
    }
    sort(sum, sum+n);
    ll count = 1;
    if(sum[0]==0) ans++;
    for(ll i = 1; i < n; i++){
        if(sum[i]==0) ans++;
        if(sum[i]==sum[i-1]) count++;
        else{
            //cout << count << endl;
            ans+=count*(count-1)/2;
            count=1;
        }
        if(i==n-1){
            ans+=count*(count-1)/2;
            //cout << i << " " << count*(count-1)/2 << endl;
        }
        //cout << i << " " << ans << " " << sum[i] << endl;
        //cout << sum[i] << endl;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	long long int *b;
	int k = n / 2;
	int var = 0;
	var = n - 2 * k;
	b = new long long int[n];
	for (int i = 1; i <= n; i++) {
		cin >> b[k];
		if (var == 0) {
			k -= i;
			var++;
		}
		else {
			k += i;
			var--;
		}
	}
	cout << b[0];
	for (int i = 1; i < n; i++) {
		cout << " " << b[i];
	}
	return 0;
}



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

typedef long long ll;

int main() {
    // input
    ll a, b, x;
    cin >> a >> b >> x;

    // solve & output
    if (a != 0) {
        cout << b / x - (a - 1) / x << endl;
    } else {
        cout << b / x + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T> 
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}
template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
const int inf = 1e9+10;
const ll INF = 1e18+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;

void solve()
{
	ll a,b,l;
	cin>>a>>b;
	l = (a*b)/__gcd(a,b);
	cout<<l<<endl;
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;

}
    

Measured memory_bytes: 256
l = [str(x) for x in input().split()] 
S = []
top = 1

for i in range(len(l)):
    S.append(l[i])

    if(l[i] == "+"):
        S.pop()
        x = int(S.pop()) + int(S.pop())
        S.append(x)
    if(l[i] == "-"):
        S.pop()
        x = - int(S.pop()) + int(S.pop())
        S.append(x)
    if(l[i] == "*"):
        S.pop()
        x = int(S.pop()) * int(S.pop())
        S.append(x)

print(*S)



Measured memory_bytes: 5604
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
mod = 10**9+7
print((pow(10,N,mod)-2*pow(9,N,mod)+pow(8,N,mod)) % mod)


Measured memory_bytes: 61788
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		var h1=new Dictionary<int,int>();
		var h2=new Dictionary<int,int>();
		for(int i=0;i<n;i++){
			if(i%2==0){
				if(h1.ContainsKey(s[i])){h1[s[i]]++;}
				else{h1.Add(s[i],1);}
			}
			else{
				if(h2.ContainsKey(s[i])){h2[s[i]]++;}
				else{h2.Add(s[i],1);}
			}
		}

		int[][] a=new int[h1.Count+1][];
		int[][] b=new int[h2.Count+1][];

		int j=0;
		foreach(KeyValuePair<int,int> e in h1){
			a[j]=new int[]{e.Value,e.Key};
			j++;
		}
		a[j]=new int[]{0,0};
		j=0;
		foreach(KeyValuePair<int,int> e in h2){
			b[j]=new int[]{e.Value,e.Key};
			j++;
		}
		b[j]=new int[]{0,0};
		Array.Sort(a,ca);
		Array.Sort(b,ca);
		if(a[0][1]==b[0][1]){
			Console.WriteLine("{0}",Math.Min(n-a[1][0]-b[0][0],n-a[0][0]-b[1][0]));
		}
		else{Console.WriteLine("{0}",n-a[0][0]-b[0][0]);}
	}
	static int ca(int[] a,int[] b){
		if(a[0]<b[0]){return 1;}
		else if(a[0]>b[0]){return -1;}
		else{return 0;}
	}
}

Measured memory_bytes: 30300
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            int n = int.Parse(s);

            n = (int)Math.Pow(n, 3);

            Console.WriteLine(n);
        }
    }
}

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

typedef long long ll;
typedef pair<int, int> P;
const int N = (int)1e5 + 50;
const ll INF = (ll)1e18;

vector<int> in[N], out[N];
int n, m;
P p[N];

int get_len(int i) {
    int res = p[i].second - p[i].first;
    if(res < 0) res += m;
    return res;
}

int main() {
    cin >> n >> m;
    cin >> p[0].first;
    for(int i = 0; i < n - 1; i++) {
        cin >> p[i].second;
        p[i+1].first = p[i].second;
    }
    n--;

    int cnt = 0;
    ll sum = 0, res = INF;
    for(int i = 0; i < n; i++) {
//        cout << p[i].first << "," << p[i].second << endl;
        int f1 = p[i].first;
        if(f1 > m) f1 -= m;
        in[f1].push_back(i);
        out[p[i].second].push_back(i);
        if(p[i].first > p[i].second) {
            cnt++;
            sum += p[i].second - 1;
        }
        else {
            sum += p[i].second - p[i].first;
        }
    }
//    cout << sum << endl;
    for(int i = 1; i <= m; i++) {
        res = min(res, sum + cnt);
//        cout << i << ", " << sum << " " << cnt << endl;
        cnt += in[i].size();
        cnt -= out[i].size();
        for(auto x : out[i]) {
            sum += get_len(x);
//            cout << get_len(x) - 1 << endl;
        }
        sum -= cnt;
    }
    cout << res << endl;

}

Measured memory_bytes: 10368
from collections import deque
N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    #treeに(繋がっている頂点, 辺の番号)を加える
    tree[a-1].append((b-1,i))
    tree[b-1].append((a-1,i))
ans = [0]*N #それぞれの辺に対する答え
q = deque()
q.append((0,0))
ma = 0  #最大の値、１行目
while q:    #これ以下を書けるように、bfsの典型
    ape1, color1 = q.popleft()    #親
    color2 = 1
    for ape2, h in tree[ape1]:  #子
        if ans[h] != 0: #既に値がある=親ならスキップ
            continue
        if color1 == color2:    #親と同じ色なら+1
            color2 += 1
        ans[h] = color2
        q.append((ape2,color2))
        ma = max(ma,color2)
        color2 += 1
print(ma)
for i in range(N-1):
    print(ans[i])


Measured memory_bytes: 40140
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int maxn=18;
int n;
int a[maxn+5],b[maxn+5];
int dp[maxn+5][(1<<maxn)+5],id[maxn+5];
int p2[maxn+5];
void chm(int &x,int y)
{
	if(x==-1||x>y) x=y;
	return;
}
int count(int num)
{
	int cnt=0;
	for(int i=num;i>0;i-=lowbit(i)) cnt++;
	return cnt;
}
int main()
{ 
	p2[0]=1;
	for(int i=1;i<=maxn;i++) p2[i]=p2[i-1]*2;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n;i++) scanf("%d",&b[i]);
	int full=(1<<n)-1;
	for(int i=0;i<n;i++) for(int mas=0;mas<=full;mas++) dp[i][mas]=-1;
	for(int i=0;i<n;i++) dp[i][1<<i]=i;
	for(int mas=0;mas<=full;mas++)
	{
		int cnt=count(mas);
		for(int i=0;i<n;i++) 
		{
			if(!(mas&p2[i])) continue;
			if(dp[i][mas]==-1) continue;
			int tot=cnt-1;
			for(int j=0;j<n;j++) if(!(mas&p2[j])) id[j]=++tot;
			int na=(cnt-1)%2==i%2?a[i]:b[i];
			for(int j=0;j<n;j++)
			{
				if(mas&p2[j]) continue;
				int nb=cnt%2==j%2?a[j]:b[j];
				if(na>nb) continue;
				chm(dp[j][mas|p2[j]],dp[i][mas]+id[j]-cnt);
			}
		}
	}
	int ans=-1;
	for(int i=0;i<n;i++) if(dp[i][full]!=-1) chm(ans,dp[i][full]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 20864
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout << x << endl;
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;


signed main(){
    string s; cin >> s;
    int n=s.size();
    int dp[n][2];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    dp[0][1]=0;
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]) chmax(dp[i][0],dp[i-1][0]+1);
        chmax(dp[i][0],dp[i-1][1]+1);
        if(i==1){
            dp[1][1]=1;
        }
        else{
            chmax(dp[i][1],dp[i-2][0]+1);
            chmax(dp[i][1],dp[i-2][1]+1);
        }
    }
    cout << max(dp[n-1][0],dp[n-1][1]) << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    bool t = true;
    if(a.size() > b.size()){
        cout << "GREATER";
    }
    else if(a.size() < b.size()){
        cout << "LESS";
    }
    else{
        for(int i = 0; i < a.size(); i++){
            if(a[i] < b[i]){
                cout << "LESS";
                t = false;
                break;
            }
            else if(a[i] > b[i]){
                cout << "GREATER";
                t = false;
                break;
            }          
        }
        if(t){
            cout << "EQUAL";
        }
    }
    
    cout << endl;
}


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

using namespace std;

int i, j, k, p, q, r, n, m, a, b, c, cost[101], t, dc[101][101], dt[101][101];

int dic(const int d[101][101]) {
  cost[p] = 0;
  int min, f[101] = {};
  for(i = 0; i < m; i++) {
    f[p] = 1;
    for(j = 0; j <= m; j++) {
      if(f[j]) continue;
      if(cost[j] > cost[p] + d[p][j]) cost[j]  = cost[p] + d[p][j];
    }
    min = 200000000;
    for(j = 0; j <= m; j++ ) {
      if(f[j]) continue;
      if(min > cost[j]) min = cost[p = j];
    }
  }
  return cost[q];
}


int main() {
  while(cin >> n >> m, n != 0 || m != 0) {
    for(i = 0; i <= 100; i++)
      for(j = 0; j <= 100; j++) {
	dc[i][j] = 100000000;
	dt[i][j] = 100000000;
      }
    while(n--) {
      cin >> a >> b >> c >> t;
      dc[a][b] = dc[b][a] = c;
      dt[a][b] = dt[b][a] = t;
    }
    cin >> k;
    while(k--) {
      cin >> p >> q >> r;
      for(i = 0; i <= 100; i++) cost[i] = 100000000;
      if(r) cout << dic(dt) << endl;
      else cout << dic(dc) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1240
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,h=get_i
ab=array(N)
max_a=0
N.times do|i|
    ab[i]=get_i
    max_a=ab[i][0] if max_a<ab[i][0]
end
ans=0
ab.sort!{|x,y| y[1]<=>x[1]}
ab.each do|a,b|
    if max_a<b
        h-=b
        ans+=1
    end
    break if h<=0
end
if h>0
    ans+=(h+max_a-1)/max_a
end
puts ans

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

int main(){
    int N, count=0;
    cin >> N;
    for(int i=1;i<=N;i++){
        int digit=0, num=i;
        while(num!=0){
            num/=10;
            digit++;
        }
        if(digit%2!=0){
            count++;
        }
    }
    cout << count;
    return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

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

void hawawa()
{
	int a, b;
	cin >> a >> b;
	cout << (a + b + 1) / 2 << "\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  string s;
  if (a == b) {
    s = "==";
  } else if (a > b) {
    s = ">";
  } else {
    s = "<";
  }

  // output
  cout << "a " << s << " b" << endl;
  return 0;
}



Measured memory_bytes: 3144
X,N=map(int,input().split())
p=map(int,input().split())
P=sorted(p)
PS=[abs(X-y) for y in P]
if N==0:
    print(X)
else:
    if not 0 in PS:
        print(X)
    else:
        for n in range(1,100):
            if PS.count(n)==1:
                place=PS.index(n)
                answer=0
                break
            elif PS.count(n)==0:
                answer=1
                break
        if answer==0:
            if P[place] - X < 0:
                print(X + n)
            else:
                print(X - n)
        else:
            print(X-n)
            

Measured memory_bytes: 62020
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//#define MOD 1000000007

using namespace std;

const long long MOD=998244353;

ll dp[90005];
ll dp2[90005];

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> a(n);
    long i;
    long sum=0;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
        sum += a[i];
    }
    long sum2=(sum+1)/2;

    long j;
    dp[0]=1;
    dp2[0]=1;
    for(i=1; i<=n; i++) {
        for(j=sum; j>=0; j--) {
            dp2[j] = dp2[j]*2%MOD;
            if(j>=a[i-1]) {
                dp[j]=(dp[j]+dp[j-a[i-1]])%MOD;
                dp2[j]=(dp2[j]+dp2[j-a[i-1]])%MOD;
            }
        }
    }

    ll val0=0;
    for(i=sum2; i<sum-1; i++) {
        val0 = (val0 + (dp2[i]-2*dp[i]+2*(ll)MOD))%MOD;
    }

    ll ans = mpow(3, n);
    ans -= (mpow(2, n)*3);
    ans = (ans+3*(ll)MOD)%MOD;
    ans += 3;
    ans %= MOD;
    ans -= (val0*3);
    ans = (ans+MOD*3)%MOD;
    printf("%lld\n", ans);


    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const int N = 1e5 + 5;
int a[N];
    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int n, k;
  cin>>n>>k;
  int M = 0;
  int g = 0;
  RE (i, n) {
    cin>>a[i];
    maxi(M, a[i]);
    g = __gcd(g, a[i]);
  }
  if (k <= M && k % g == 0) {
    cout<<"POSSIBLE\n";
  } else {
    cout<<"IMPOSSIBLE\n";
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>

int main()
{
  long long n;
  scanf("%lld", &n);
  long long a[100000];
  long long b[100000];
  long long sum = 0;
  for (long long i = 0; i < n; ++i)
  {
    scanf("%lld", a + i);
    sum += *(a + i);
  }
  b[0] = sum;
  for (long long i = 1; i < n; i += 2)
  {
    b[0] -= 2 * a[i];
  }
  printf("%lld", *b);
  for (long long i = 1; i < n; ++i)
  {
    b[i] = 2 * a[i - 1] - b[i - 1];
    printf(" %lld", b[i]);
  }
  putchar('\n');
  return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>


int main(){

	int a,b;
	char op;

	
	
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		
		if(op=='?'){break;}
		else if(op=='+'){printf("%d\n",a+b);}
		else if(op=='-'){printf("%d\n",a-b);}
		else if(op=='*'){printf("%d\n",a*b);}
		else if(op=='/'){printf("%d\n",a/b);}
	
	}
	
	return 0;
}

Measured memory_bytes: 600
def getlist():
	return map(int, input().split())

N, A, B, C, D = getlist()
S = list(input())

a = A - 1
b = B - 1
c = C - 1
d = D - 1

if c < b:
	judge1 = "YES"
	j = 0
	val = 0
	for i in range(a, c):
		if S[i] == ".":
			val = 0
		else:
			val += 1
			if val > j:
				j = val
	if j >= 2:
		judge1 = "NO"

	judge2 = "YES"
	j = 0
	val = 0
	for i in range(b, d):
		if S[i] == ".":
			val = 0
		else:
			val += 1
			if val > j:
				j = val
	if j >= 2:
		judge2 = "NO"

	if judge1 == "YES" and judge2 == "YES":
		print("Yes")
	else:
		print("No")


elif c < d:
	judge = "Yes"
	j = 0
	val = 0
	for i in range(a, d):
		if S[i] == ".":
			val = 0
		else:
			val += 1
			if val > j:
				j = val
	if j >= 2:
		judge = "No"
	print(judge)

else:
	judge1 = "YES"
	j = 0
	val = 0
	for i in range(a, c):
		if S[i] == ".":
			val = 0
		else:
			val += 1
			if val > j:
				j = val
	if j >= 2:
		judge1 = "NO"

	judge2 = "YES"
	j = 0
	val = 0
	for i in range(b - 1, d + 2):
		if S[i] == "#":
			val = 0
		else:
			val += 1
			if val > j:
				j = val
	if j <= 2:
		judge2 = "NO"

	if judge1 == "YES" and judge2 == "YES":
		print("Yes")
	else:
		print("No")



Measured memory_bytes: 5044
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;


int main() {
	string s, t;
	ll ans = 0;
	cin >> s >> t;
	
	rep(i, s.size()){
		if (s[i] != t[i]) {
			ans++;
		}
	}

	cout << ans;

	return 0;
}


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

template <typename T, typename U>
T power(T x, U y)
{
    T ret = 1;
    while (y > 0)
    {
        if ((y & 1) > 0)
        {
            ret *= x;
        }
        x *= x;
        y >>= 1;
    }
    return ret;
}

int main()
{
    long long M, K;
    cin >> M >> K;

    if (K >= power(2ll, M))
    {
        cout << -1;
    }
    else if (K == 0)
    {
        for (long long i = 0; i < power(2ll, M); i++)
        {
            cout << i << " ";
        }
        for (long long i = power(2ll, M) - 1; i >= 0; i--)
        {
            cout << i << " ";
        }
    }
    else if (K == 1 && M == 1)
    {
        cout << -1;
    }
    else
    {
        cout << K << " ";
        for (long long i = 0; i < power(2ll, M); i++)
        {
            if (i != K)
            {
                cout << i << " ";
            }
        }
        cout << K << " ";
        for (long long i = power(2ll, M) - 1; i >= 0; i--)
        {
            if (i != K)
            {
                cout << i << " ";
            }
        }
    }

    cout << endl;
}


Measured memory_bytes: 1792
/*
 * main.cpp
 *
 *  Created on: 2019/03/19
 *      Author: maleicacid
 */

#include <climits>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
class UnionFind
{
public:
	gp_hash_table<T, long> sz;
	gp_hash_table<T, long> rank;
	UnionFind()
	{

	}
	~UnionFind()
	{
		sz.clear();
		rank.clear();
		m.clear();
	}
	void makeSet(long value)
	{
		m[value] = value;
		sz[value] = 1;
		rank[value] = 0;
	}

	T findSet(T x)
	{
		auto tmp = m.find(x);

		if (tmp != m.end())
		{
			if (x != (*tmp).second)
			{
				return (*tmp).second = findSet((*tmp).second);
			}
			return (*tmp).second;
		}
	}
	bool isEqual(T x, T y)
	{
		return findSet(x) == findSet(y);
	}

	pair<const long, const long> link(T x, T y)
	{
		pair<const long, const long> tmp(sz[x], sz[y]);
		if (sz[x] > sz[y])
		{
			m[y] = x;
			sz[x] += sz[y];
			sz.erase(y);
		}
		else
		{
			m[x] = y;
			if (sz[y] == sz[x])
				rank[y]++;
			sz[y] += sz[x];
			sz.erase(x);
		}
		return tmp;
	}
	long unite(T x, T y)
	{
		auto p = pair<T,T>(findSet(x), findSet(y));
		if (p.first != p.second)
		{
			auto t = link(p.first, p.second);
			return t.first * t.second;
		}
		else
			return 0;
	}

private:
	gp_hash_table<T, T> m;
};


int main()
{
	int n, m;
	scanf("%d",&n);
	scanf("%d",&m);

	stack<pair<long, long>> g;
	for (int i = 0; i < m; i++)
	{
		long a, b;
		scanf("%ld", &a);
		scanf("%ld",&b);

		pair<long, long> p(a,b);
		g.push(p);
	}

	UnionFind<long> graph;
	for (int i = 1; i <= n; i++)
	{
		graph.makeSet(i);
	}

	vector<long> inconvenience;
	inconvenience.push_back(0);
	for (int i = 0; i < m; i++)
	{
		auto p = g.top();
		g.pop();

		auto a = graph.unite(p.first, p.second);
		inconvenience.push_back(a +inconvenience[i]);
	}

	for (int i = m-1; i >= 0; i--)
	{
		printf("%ld\n", inconvenience[m] - inconvenience[i]);
	}
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n+2); a.front()=0; for(int i=1;i<=n;++i)cin>>a.at(i); a.back()=0;
	int sum=0;
	for(int i=1;i<=n+1;++i){
		sum+=abs(a.at(i)-a.at(i-1));
	}
	sum+=abs(a.back());
	for(int i=1;i<=n;++i){
		int ans=sum+abs(a.at(i-1)-a.at(i+1))-(abs(a.at(i-1)-a.at(i))+abs(a.at(i)-a.at(i+1)));
		cout<<ans<<"\n"s;
	}
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 2000009
#define MOD 1000000007
#define endl '\n'
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);
#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
#endif
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=(i*(i+1))/2;
    }
    //cout<<ans<<endl;
    for(ll i=1;i<=n-1;i++){
        ll a,b;
        cin>>a>>b;
        if(a>b){
            swap(a,b);
        }
        ans-=(a*(n-b+1));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <functional>

using namespace std; using ll=long long; using ld=long double; using P=pair<ll,ll>; const int INF=1e9; const ll LINF=1e18;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494459;

int main(){
  int n,k; cin>>n>>k;
  int a[n]; int fi=n; // I'm at the left of the fi.
  for(int i=0;i<n;i++) {
    cin>>a[i];
    if (a[i]==0) k--, i--, n--;
    if (fi==n&&a[i]>0) fi=i;
  }
  //cout<<fi<<endl;
  int an=INF;
  // go left
  for(int i=0;i<fi;i++) {
    int l = k - (fi-i);
    int sm = -a[i];
    if (l>0) {
      if (fi+l-1>=n) sm=INF;
      else sm += a[fi+l-1]-a[i];
    }
    //cout<<sm<<" "<<l<<endl;
    an=min(an,sm);
  }
  for(int i=fi;i<n;i++) {
    int l = k - (i-fi+1);
    int sm = a[i];
    if (l>0) {
      if (fi-l<0) sm=INF;
      else sm += a[i]-a[fi-l];
    }
    //cout<<sm<<endl;
    an=min(an,sm);
  }
  cout<<an<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main() {
	double n, m, k;
	while (cin >> n >> m >> k) {
		double sum = 0;
		double p = n;
		while (n <= (k + 0.5)) {
			sum += m;
			n += p;
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int k, a, b;
    cin >> k >> a  >> b;
    reps(a, i, b+1) {
        if (i % k == 0) {
            cout << "OK" << endl;
            exit(0);
        }
    }
    cout << "NG" << endl;
}


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

//  x/y < p  を満たす最大の既約分数を　x<=n y<=n で返す

void SBT_MAX(ll n,ll p,ll &x,ll&y,ll pl=0,ll ql=1,ll pr=1,ll qr=0){
	ll pm = pl + pr , qm = ql + qr ;
	if( pm > n || qm > n ) return ;
	if( p*qm >= pm ){
		x=pm,y=qm;
		SBT_MAX( n , p , x , y , pm , qm , pr , qr );
	}
	if( p*qm < pm ){
		SBT_MAX( n , p , x , y , pl , ql , pm , qm );
	}
}
//   p < x/y を満たす最小の既約分数を　x<=n y<=n で返す

void SBT_MIN(ll n,ll p,ll &x,ll&y,ll pl=0,ll ql=1,ll pr=1,ll qr=0){
	ll pm = pl + pr , qm = ql + qr ;
	if( pm > n || qm > n ) return ;
	if( p*qm > pm ){
		SBT_MIN( n , p , x , y , pm , qm , pr , qr );
	}
	if( p*qm <= pm ){
		x=pm,y=qm;
		SBT_MIN( n , p , x , y , pl , ql , pm , qm );
	}
}

//  x/y < √p  を満たす最大の既約分数を　x<=n y<=n で返す

void SBT_MAX_Sqrt(ll n,ll p,ll &x,ll&y,ll pl=0,ll ql=1,ll pr=1,ll qr=0){
	ll pm = pl + pr , qm = ql + qr ;
	if( pm > n || qm > n ) return ;
	if( p*qm*qm > pm*pm ){
		x=pm,y=qm;
		SBT_MAX_Sqrt( n , p , x , y , pm , qm , pr , qr );
	}
	if( p*qm*qm < pm*pm ){
		SBT_MAX_Sqrt( n , p , x , y , pl , ql , pm , qm );
	}
}
//   √p < x/y を満たす最小の既約分数を　x<=n y<=n で返す

void SBT_MIN_Sqrt(ll n,ll p,ll &x,ll&y,ll pl=0,ll ql=1,ll pr=1,ll qr=0){
	ll pm = pl + pr , qm = ql + qr ;
	if( pm > n || qm > n ) return ;
	if( p*qm*qm > pm*pm ){
		SBT_MIN_Sqrt( n , p , x , y , pm , qm , pr , qr );
	}
	if( p*qm*qm < pm*pm ){
		x=pm,y=qm;
		SBT_MIN_Sqrt( n , p , x , y , pl , ql , pm , qm );
	}
}

int main(){
	ll n,p;
	while(cin>>p>>n,p){
		ll a1,b1,a2,b2;
		SBT_MIN_Sqrt(n,p,a1,b1);
		SBT_MAX_Sqrt(n,p,a2,b2);
		cout<<a1<<'/'<<b1<<' '<<a2<<'/'<<b2<<endl;
	}
}


Measured memory_bytes: 3048