akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 100
#define WHITE 0
#define BLACK 2
#define INF 10000001
#define NIL -1

int A[N][N],color[N],t,min,d[N],pi[N];

void prim(int G,int r){
  int i,j,u=0;
  
  for(i=0;i<G;i++){
    d[i]=INF;
    pi[i]=NIL;
  }
  d[r]=0;
  while(1){
    min = INF;
    for(i=0;i<G;i++){
      if(color[i]!=BLACK && d[i]<min){
	min =d[i];
	u=i;
      }
    }
    
    if(min == INF) break;
    
    color[u]=BLACK;
    
    for(i=0;i<G;i++){
      if(color[i] != BLACK && A[u][i]<d[i] && A[u][i]!=-1){
	pi[i]=u;
	d[i] = A[u][i]; 
      }
      
    }
  }
  for(i=0;i<G;i++){
  
      t+=d[i];
    
  }
  
  
  
}

int main(){

  int x,i,j;

  scanf("%d",&x);

  for(i=0;i<x;i++){
    for(j=0;j<x;j++){
      scanf("%d",&A[i][j]);
      color[i]   =WHITE;
    }
  }
  prim(x,0);

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

  return 0;
}



Measured memory_bytes: 2112
import math
s = list(input())
ss = s[:]
k = int(input())
cnt = 0

if len(set(s)) == 1:
    cnt = math.floor(len(s) * k / 2)
else:
    cnt = 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
            s[i + 1] = '*'
    cnt *= k
    if ss[0] == ss[-1]:
        a = 1
        for i in range(len(ss) - 1):
            if ss[i] == ss[i + 1]:
                a += 1
            else:
                break
        b = 1
        for j in range(len(ss) - 1, 0, -1):
            if ss[j] == ss[j - 1]:
                b += 1
            else:
                break
        cnt -= (k - 1) * (math.floor(a / 2) + math.floor(b / 2) - math.floor((a + b) / 2))
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int count = 0;
  for(int i=0;i<3;i++){
    if(s.at(i)=='1'){
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S = list(input())
T = list(input())
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

L = lcm(N, M)
d1 = L//N
d2 = L//M
if S[::d2] == T[::d1]:
    print(L)
else:
    print(-1)

Measured memory_bytes: 4704
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
  int N, K;
  char S[51];
  scanf("%d %d", &N, &K);
  scanf("%s", S);
  S[K-1]=S[K-1]+0x20;
  printf("%s\n", S);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long ncrmodp(long n,long r,long p){
    long ans = 1;
    for(long i=n-r+1;i<=n;i++){
        ans *= i;
        ans %= p;
    }
    long tmp = 1;
    for(long i=2;i<=r;i++){
        tmp *= i;
        tmp %= p;
    }
    for(long i=1;i<=p-2;i*=2){
        if(i & p-2){
            ans *= tmp;
            ans %= p;
        }
        tmp *= tmp;
        tmp %= p;
    }
    return ans;
}
int main(){
    long n,k;
    cin >> n >> k;
    long const mod = 1e9+7;
    long ans = 0;
    for(long i=k;i<=n+1;i++){
        ans += i*(n+n-i+1)/2 - i*(i-1)/2 + 1;
        ans %= mod;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,q;
int v[500000];
int w[500000];
int dp[513][100005];
int ans=0;
int lm=0;
int nm;

void dfs(int pos,int cv,int cw){
	if(pos<=nm){
		ans=max(ans,dp[pos][lm-cw]+cv);
		return;
	}
	dfs(pos/2,cv,cw);
	if(cw+w[pos]<=lm){
		dfs(pos/2,cv+v[pos],cw+w[pos]);
	}
}

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&v[i],&w[i]);
	}
	nm=min(512,n);
	for(int i=1;i<=nm;i++){
		int p=i/2;
		for(int j=0;j<=100000;j++){
			dp[i][j]=max(dp[i][j],dp[p][j]);
			if(j+w[i]<=100000){
				dp[i][j+w[i]]=max(dp[i][j+w[i]],dp[p][j]+v[i]);
			}
		}
		for(int j=1;j<=100000;j++){
			dp[i][j]=max(dp[i][j],dp[i][j-1]);
		}
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int a;
		scanf("%d%d",&a,&lm);
		ans=0;
		dfs(a,0,0);
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 205896
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define sort(v)     sort((v).begin(),(v).end())
#define rall(v)     (v).rbegin(),(v).rend()
#define rsort(v)     sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)      *min_element(v.begin(), v.end());
#define maxx(v)      *max_element(v.begin(), v.end());

typedef pair<int,int> pii;  
typedef vector<int> vi;

signed main() 
{
    fastio;
    int a,b,m;
    cin>>a>>b>>m;
    vi A(a),B(b);
    f(i,a)cin>>A[i];
    f(i,b)cin>>B[i];
    int ans=1e10;
    int x=minn(B);
    int y=minn(A)
    ans=x+y;
    f(i,m)
    {
        int x,y,c;
        cin>>x>>y>>c;
        x-=1;
        y-=1;
        ans=min(ans,A[x]+B[y]-c);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<cstdio>
int main()
{
	int a,b,c=0;
	scanf("%d",&a);
    while(a>=10)
    {
    	if(a%10==9)
    	{
    		c=1;
    		break;
		}
    	a=a/10;
	}
	if((a==9)||(c==1))
   		printf("Yes");
	else 
		printf("No");
    return 0;
}

Measured memory_bytes: 128
x = int(input())
prime = [2]
for i in range(3,320,2):
    flag = True
    for j in prime:
        if i%j==0:
            flag = False
            break
    if flag:
        prime.append(i)
if x<=317:
    for i in range(len(prime)):
        if x<=prime[i]:
            print(prime[i])
            break
else:
    for i in range(x,x+100):
        flag = True
        for j in prime:
            if i%j==0:
                flag = False
                continue
        if flag:
            print(i)
            break

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

int main() {
  int x, y, N;
  cin >> x >> y >> N;
  vector<int> kind(N);
  for (int &e : kind) cin >> e;
  vector<vector<int>> color(x,vector<int>(y));
  int print_c = 0;
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      int k = j;
      if (i % 2 != 0) k = y-1-j;
      if (kind[print_c] == 0) print_c += 1;
      color[i][k] = print_c + 1;
      kind[print_c] -= 1;
    }
  }
  
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      cout << color[i][j];
      if (j < y-1) cout << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
from fractions import gcd

N,M = map(int,input().split())
S = input()
T = input()

G = gcd(N, M)
L = N * M // G
ng = N//G
mg = M//G

for i in range(0,L,ng*mg):
    Nnum = i//mg
    Mnum = i//ng
    if S[Nnum] != T[Mnum]:
        print(-1)
        exit()

print(L)


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

int main() {
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; ++i) {
		cin >> d.at(i);
	}
	set<int> st(d.begin(), d.end());
	cout << st.size() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<n;i++)
int main(){
  int k,a,b;
  bool exist = false;
  int i,j;
  
  cin >> k >> a >> b;
  
  rep1(i,1000){
    if(a<=k*i &&k*i<=b){
      exist = true;
      break;
    }
  }
  if(exist == true)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
    
  
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
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 nextInt() { int x; scanf("%d", &x); return x;}

string dp[11234];

int W[] = {0,2,5,5,4,5,6,3,7,6};

int main2() {
  int N = nextInt();
  int M = nextInt();
  vector<int> A(M); 
  REP(i, M) A[i] = nextInt();

  REP(i, N+1) dp[i] = "$";
  dp[0] = "";
  for (int i = 1; i <= N; i++) {
    for (int a : A) if (i - W[a] >= 0) {
      string t = string(1, '0' + a) + dp[i - W[a]];
      if (t.back() != '$') {
        const string &cur = dp[i];
        if (cur.size() < t.size() || (cur.size() == t.size() && cur < t)) {
          dp[i] = t;
        }
      }
    }
  }
  cout << dp[N] << endl;

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 26368
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        
        // 上下左右
        int[] dx = new int[]{1, 0, -1, 0};
        int[] dy = new int[]{0, 1, 0, -1};
        
        char[][] board = new char[h][w];
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                board[i][j] = str.charAt(j);
            }
        }
        
        Queue<int[]> que = new ArrayDeque<int[]>();
        que.add(new int[]{0, 0, 1});
        
        boolean[][] visited = new boolean[h][w];
        visited[0][0] = true;
        
        int steps = 1;
        while (!que.isEmpty()) {
            int[] cur = que.poll();
            int x = cur[0];
            int y = cur[1];
            int depth = cur[2];
            
            // 移動可能なら現在地までの距離+1を代入
            for (int k = 0; k < 4; k++) {
                int nx = x + dx[k];
                int ny = y + dy[k];
                int ndepth = depth + 1;
                
                if (0 <= nx && nx < h && 0 <= ny && ny < w &&
                    board[nx][ny] == '.' && !visited[nx][ny]) {
                    que.add(new int[]{nx, ny, ndepth});
                    visited[nx][ny] = true;
                    
                    if (nx == h-1 && ny == w-1) steps = ndepth;
                }
            }
        }
        if (steps == 1) {
            System.out.println(-1);
            return;
        }
        
        int sharp = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (board[i][j] == '#') sharp++;
            }
        }
        
        System.out.println((h*w) - steps - sharp);
    }
}

Measured memory_bytes: 23892
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


void solve(long long H, long long N, std::vector<long long> A, std::vector<long long> B){
	vector<LL> dp(H+1);
	for(int i=1;i<=H;i++){
		LL v=1LL<<60;
		for(int j=0;j<N;j++){
			v=min(v,dp[max(0LL,i-A[j])]+B[j]);
		}
		dp[i]=v;
	}
	cout << dp[H] << endl;
}

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


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int n; cin>>n;
    int tmp,ans=1;
    for(int i=2;i<=sqrt(n);i++){
        tmp=i*i;
        while(tmp*i<=n){
            tmp*=i;
        }
        if(ans<tmp) ans=tmp;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
    string s;
    cin>>s;

    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  long long a,b,k;
  cin >> a >> b >> k;
  if(a>=k){
    cout << a-k << ' ' << b << endl;
  }
  else if(k-a<b){
    cout << 0 << ' ' << a+b-k << endl;
  }else{
    cout << 0 << ' ' << 0 << endl;
  }
}

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

int main(){
  size_t n, X;
  cin >> n >> X;
  size_t ans{0};
  for(int i = 0; i < n; ++i){
    size_t a;
    cin >> a;
    ans = __gcd(ans, max(a, X) - min(a, X));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static int  count = 0;
	static long n;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		n = Long.parseLong(s);
		Main main = new Main();
		main.countk(3, true, false, false);
		main.countk(5, false, true, false);
		main.countk(7, false, false, true);
		System.out.println(count);
	}
	public static void countk(long k,boolean r3,boolean r5,boolean r7) {
		if(k>n)
			return;
		
		Main.countk(k*10+3, true, r5, r7);
		Main.countk(k*10+5, r3, true, r7);
		Main.countk(k*10+7, r3, r5, true);
		if(r3&&r5&&r7)
			count++;
	}
	
}


Measured memory_bytes: 22868
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    
    vector<vector<ll> > cnt(10, vector<ll>(10));
    REP(i, N+1) {
        if(i%10 != 0) {
            int low = i%10, high = 0;
            int j = i;
            while(1) {
                if(j/10 == 0) {
                    high = j;
                    break;
                } else {
                    j /= 10;
                }
            }
            cnt[low][high]++;
        }
    }
    ll ans = 0;
    FOR(i, 1, 9)
        FOR(j, 1, 9) {
            if(i != j) ans += cnt[i][j] * cnt[j][i];
            else ans += cnt[i][i] * cnt[i][i];
        }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
l_0 = 2
l_1 = 1
A = int(input())
if A == 0:
  print(l_0)
elif A == 1:
  print(l_1)
else:
  for i in range(A-1):
    if i%2 != 0:
      p = l_1
      l_1 = l_0 + l_1
      l_0 = p
    else:
      p = l_1
      l_1 = l_0 + l_1
      l_0 = p
  print(max(l_0,l_1))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    int res = 0;
    for (int i = 0; i * r <= n; i++) {
        for (int j = 0; j * g <= n; j++) {
            if (n - i * r - j * g >= 0 && (n - i * r - j * g) % b == 0) {
                res++;
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
a, b = map(int, input().split())
flag = True
cnt = 0
sum_ = 0
while b > sum_:
    if flag:
        sum_ += a
        flag = False
        cnt += 1
    else:
        sum_ += (a - 1)
        cnt += 1
if b == 1:
    print(0)
else:
    print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int N;
    double D;
    cin >> N >> D;
    int ans = 0;
    rep(i, N){
        double x, y;
        cin >> x >> y;
        if(sqrt(x*x + y*y) <= D) ans++;
    }
    cout << ans << endl;
}

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

int a, b, k;

void abc120b() {
  vector<int> array;
  for (int i = 1; i <= max(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      array.push_back(i);
    }
  }
  sort(array.rbegin(), array.rend());
  cout << array[k - 1] << '\n';
  return;
}

int main() {
  cin >> a >> b >> k;
  abc120b();
  return 0;
}

Measured memory_bytes: 256
from collections import deque
k = int(input())
stack = deque([x for x in range(1, 10)])
cnt = 9
flag = False
while len(stack) > 0:
    if k < 10:
        print(stack[k - 1])
        break
    now_num = stack.popleft()
    if now_num % 10 == 0:
        for x in [0, 1]:
            next_num = str(now_num) + str(x)
            next_num = int(next_num)
            stack.append(next_num)
            cnt += 1
            if cnt == k:
                print(stack.pop())
                flag = True
                break
    elif now_num % 10 == 9:
        for x in [8, 9]:
            next_num = str(now_num) + str(x)
            next_num = int(next_num)
            stack.append(next_num)
            cnt += 1
            if cnt == k:
                print(stack.pop())
                flag = True
                break
    else:
        for x in range(now_num % 10 - 1, now_num % 10 + 2):
            next_num = str(now_num) + str(x)
            next_num = int(next_num)
            stack.append(next_num)
            cnt += 1
            if cnt == k:
                print(stack.pop())
                flag = True
                break
    if flag:
        break


Measured memory_bytes: 5864
#include<iostream>
#include<cmath>
#include <cstdlib>
#include <climits>
using namespace std;

int main()
{
  int A,B;
  string S;
  cin>>A>>B;
  cin>>S;
  bool correct = true;
  if(S.length() != A + B + 1)
  {
    correct = false;
  }else{
  	for(int i = 0;i<S.length(); i++)
  	{
    	if(i == A)
        {
          if(S[i] != '-')
    		{
     	 		correct = false;
      			break;
    		}
        }else{
    
    		if(0 > S[i] - '0' || S[i] - '0' > 9)
    		{
      			correct = false;
      		    break;
    		}
        }
  	}
  }
  if(correct)
  {
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
} 

Measured memory_bytes: 256
h,w=map(int,input().split())
ans=[['' for i in range(w+2)] for j in range(h+2)]
ans[0] = ['#' for i in range(w+2)]
ans[-1] = ['#' for i in range(w+2)]
for i in range(h):
  ans[i+1][1:w+1] = list(input())
  ans[i+1][0] = '#'
  ans[i+1][-1] = '#'
for i in range(h+2):
  print(*ans[i],sep='')

Measured memory_bytes: 4596
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-6
#define MOD 998244353ll
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;

bool is_pal(string s)
{
	int n = s.size();
	fore(i,0,n/2)
	{
		if (s[i] != s[n - i - 1])
			return 0;
	}
	return 1;
}

inline void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	string t = s.substr(0, (n - 1) / 2), f = s.substr((n + 3) / 2 - 1, n - ((n + 3) / 2) + 1);

	if (is_pal(t) && is_pal(f) && is_pal(s))
		cout << "Yes";
	else
		cout << "No";
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	while (q--)
	{
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 256
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""
t=1
#t=ii()
for _ in range(t):
    n=ii()
    a=ll()
    i=n-1;
    while(i>-1):
        print(a[i],end=" ")
        i-=2
    for i in range(n%2,n,2):
        print(a[i],end=" ")

Measured memory_bytes: 106080
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 1e9
for i in range(M):
    x,y,c = map(int,input().split())
    wari = max(a[x-1]+b[y-1]-c,0)
    ans = min(ans,wari)
ans = min(ans,min(a)+min(b))
print(ans)

Measured memory_bytes: 18608
///                    بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
///                   لآ اِلَهَ اِلّا اللّهُ مُحَمَّدٌ رَسُوُل اللّهِ




#include <bits/stdc++.h>

using namespace std;
#define endl "\n"

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
    string x;
    cin >> x;
    if(x == "ABC") cout << "ARC" << endl;
    else cout<< "ABC" << endl;
    
    

	return 0;
}



Measured memory_bytes: 3584
#include <stdio.h>

int main(){
  int i,j,temp,a[3];
  for(i=0;i<3;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<3;i++){
    for(j=i+1;j<3;j++){
      if(a[j]<a[i]){
        temp = a[j];
        a[j] = a[i];
        a[i] = temp;
      }
    }
  }
  printf("%d %d %d\n",a[0],a[1],a[2]);
  return 0;
}

Measured memory_bytes: 596
import java.util.Scanner


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val h = for (_ <- 0 until n) yield sc.nextInt()
    (n, h)
  }
  
  // O(n)解法(maxを先に求める)
  def solve5(n: Int, h: IndexedSeq[Int]): Int = {
    // maxHeightList(i) = max[ h(i) | i<- 0 to i]
    val maxHeightList = h.tail.scanLeft(h.head)(Math.max)
    //  #[k <- 0 until n | max[ h(i) | i<- 0 to k] <= h(k)]
    (h, maxHeightList).zipped.count { case (currentHeight, maxHeight) => currentHeight >= maxHeight }
  }


  def main(args: Array[String]): Unit = {
    val (n, h) = read()
    println(solve5(n, h))
  }

}

Measured memory_bytes: 27204
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        var s = long.Parse(Console.ReadLine().Trim());
        if (n == s) { Console.WriteLine(n + 1);  goto end; }
        var imax = (int)Math.Sqrt(n);
        var ok = false;
        for (int i = 2; i < imax; i++)
            if (f(i, n) == s) { Console.WriteLine(i); ok = true; break; }
        if (!ok)
        {
            var t2 = n - s;
            var t = (int)Math.Sqrt(n - s);
            var ret = new List<long>();
            for (long i = 1; i <= t; i++)
                if (t2 % i == 0)
                {
                    ret.Add(i);
                    ret.Add(t2 / i);
                }
            ret.Sort();
            var ok2 = false;
            foreach (var x in ret)
                if (f(x + 1, n) == s) { Console.WriteLine(x + 1); ok2 = true; break; }
            if (!ok2) Console.WriteLine(-1);
        }
        end:;
    }
    public static long f(long b, long n)
    {
        if (b == 1) return n;
        if (b > n) return n;
        return f(b, n / b) + n % b;
    }
}



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

typedef long long ll;
typedef unsigned long long ull;

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

  vector<ll> v;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      v.push_back((i-1) + (n/i-1));
      if(i * i != n) {
        v.push_back((n / i -1)*2);
      }
    }
  }
  sort(v.begin(), v.end());

  cout << v[0] << endl;
 
  return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    map<char, char> mp;
    mp['A'] = 'T';
    mp['T'] = 'A';
    mp['C'] = 'G';
    mp['G'] = 'C';
    for (int i = 0; i < (int) s.size(); i++) {
        cout << mp[s[i]];
    }
    cout << '\n';
    return 0;
}


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


int main(){
  int n; cin>>n;
  int h[n];
  rep(i,n)cin>>h[i];
  rep(i,10000){//水やりの回数
    int left=-1;
    int right=n-1;
    for(int l=0;l<n;l++){
      if(h[l]!=0){
          left=l; break;
      }
    }

    if(left==-1){ cout<<i<<endl; break;} //水やりの終了
    else{
      for(int r=left;r<n;r++){
        if(h[r]==0){
          right=r-1; break;
        }
      }

      for(int j=left;j<=right;j++)h[j]--;
    }
  
  }

}

Measured memory_bytes: 256
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()

i = 0
m = [0] * N
m[0] = i

tmp = m[-1]
m[-1] -= i // 2
for j in range(1, N):
    c = m[j - 1] // 2
    t = (L[j] - c) * 2

    m[j] = t

a = sum(m)
b = sum(L)
if a == b:
    print(m[-1], *m[:-1])
    exit()

m[-1] = tmp

i = b - a
m = [0] * N
m[0] = i

m[-1] -= i // 2
for j in range(1, N):
    c = m[j - 1] // 2
    t = (L[j] - c) * 2

    m[j] = t
print(m[-1], *m[:-1])

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N; cin >> N;
  string S, T; cin >> S >> T;
  int ans = (S + T).size();
  rep(i, N) rep(j, N) {
    if(i + N - j < N) continue;
    bool ok = 1;
    string W = S.substr(0, i) + T.substr(j);
    assert(W.size() == i + N - j);
    rep(k, N) {
      ok &= W[k] == S[k];
      ok &= W[W.size() - 1 - k] == T[T.size() - 1 - k];
    }
    if(ok) {
      int k = W.size();
      ans = min(ans, k);
    }
  }

  cout << ans << endl;
  
  return 0;
}

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

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

		int sum = 0;
		int d = n;
		while (d>0) {
			sum = sum + (d%10);
			d/=10;
		}

		System.out.println (n%sum == 0 ? "Yes" : "No");
	}
}


Measured memory_bytes: 35648
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };



void solve() {
    ll a, b, c, d, e , m, n, k, x, y, l,r,t, h, w;
    string s;
    ll ans = 0;
    double dans = 0;
    string sans = "Yes";
    vector<ll> ar;
    vector<string> sr;
    vector<vector<char>> arr;

    cin >> h >> w;

    rep(i,h){
        vector<char> line;
        rep(j,w){
            char hoge;
            cin >> hoge;
            line.push_back(hoge);
        }
        arr.push_back(line);
    }

    int flag=1;

    while(flag==1){

        flag = 0;

        rep(i,h){
            auto it = find(all(arr[i]), '#');
            if(it == arr[i].end()){
                flag=1;
                arr.erase(arr.begin() + i);
                h--;
            }
        }

        rep(j,w){
            int _flg = 0;
            rep(i,h){
                if(arr[i][j] == '#') _flg = 1;
            }

            if(_flg == 0){
                flag = 1;
                rep(i,h){
                    arr[i].erase(arr[i].begin() + j);
                }
                w--;
            }
        }
    }

    rep(i,h){
        rep(j,w){
            cout << arr[i][j];
        }
        cout <<  "\n";
    }

    // std::cout << ans << endl;

    // std::cout << sans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
const double PI = acos(-1.0);
const string ALP = "abcdefghijklmnopqrstuvwxyz";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  int a,b;
  cin >> a >> b;
  cout << ((a+b<10)?to_string(a+b):"error") << endl;
  return 0;
}

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

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(b/a>=c) printf("%d",c);
	else printf("%d\n",b/a);
 	return 0;
 }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
using namespace std;
#define rep(p,q) for(int i = p;i < q; i++)

int main(void) {
	vector<int> takahashi, aoki;
	bool check = false;
	int num = 0;
	cin >> num;
	vector<int> height(num,0),pattern(num,0);

	rep(0, num) {
		int mt = 0;
		cin >> mt;
		takahashi.push_back(mt);
	}

	rep(0, num) {
		int mt = 0;
		cin >> mt;
		aoki.push_back(mt);
	}

	rep(0, num) {
		int a_now = i;
		int a_before = i + 1;
		if (takahashi[num - 1] != aoki[0]) {
			check = true;
			break;
		}
		if (i == 0 ) {
			height[i] = takahashi[i];
			pattern[i] = 1;
			continue;
		}
		if (i == num - 1) {
			height[i] = aoki[i];
			pattern[i] = 1;
			continue;
		}
		
			bool t_change = false,a_change = false;
			if (takahashi[i] > takahashi[i - 1])t_change = true;
			if (aoki[a_before] < aoki[a_now])a_change = true;
			if (t_change && a_change) {
				if (takahashi[i] != aoki[i]) {
					check = true;
					break;
				}
				else {
					height[i] = aoki[i];
					pattern[i] = 1;
					continue;
				}
			}

			if (t_change) {
				if (takahashi[i] <= aoki[i]) {
					height[i] = takahashi[i];
					pattern[i] = 1;
					continue;
				}
				else {
					check = true;
					break;
				}
				
			} 

		    if (a_change) {
				if (aoki[i] <= takahashi[i]) {
					height[i] = takahashi[i];
					pattern[i] = 1;
					continue;
				}
				else {
					check = true;
					break;
				}
			
				
			}
			
			if(takahashi[i] < aoki[i]){
				pattern[i] = takahashi[i];
			}
			else {
				pattern[i] = aoki[i];
			}
		

	}
	long long int ans = 1;
	rep(0, pattern.size()) {
		ans *= pattern[i];
		ans %= 1000000000 + 7;
	}
	if (check) {
		cout << 0 << endl;
	}
	else {
		cout << ans << endl;
	}
}

Measured memory_bytes: 2296
#include <stdio.h>

#ifndef DEBUG_PRINT
#define DEBUG_PRINT 0
#endif

int main(void) {
	int N, M;
	int i;
	static int kaeru[1000000];
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < N; i++) {
		int l, r;
		int d = 1;
		if (scanf("%d%d", &l, &r) != 2) return 1;
#if DEBUG_PRINT
		printf("debug meisan = [%d, %d]\n", l, r);
#endif
		while (r >= d) {
			int a, nextd;
			/* 次に変化するdを求める */
			if (l <= d && d <= r) {
				/* 自明に買える */
				nextd = r;
				/* いもす */
				kaeru[d]++;
				kaeru[nextd + 1]--;
			} else if ((l - 1) / d < r / d) {
				/* 買える */
				a = r / d;
				nextd = (r + a) / a - 1;
				/* いもす */
				kaeru[d]++;
				kaeru[nextd + 1]--;
#if DEBUG_PRINT
				printf("can buy [%d, %d]\n", d, nextd);
#endif
			} else {
				/* 買えない */
				a = (l - 1) / d;
				nextd = ((l - 1) + a) / a - 1;
#if DEBUG_PRINT
				printf("cannot buy [%d, %d]\n", d, nextd);
#endif
			}
			/* 次の区間を処理する */
			d = nextd + 1;
		}
	}

	/* いもす */
	for (i = 1; i <= M; i++) {
		kaeru[i] += kaeru[i - 1];
		printf("%d\n", kaeru[i]);
	}

	return 0;
}

/*
名産品を買える幅が1 (l == r)の場合は
l % d == 0 のとき、かつそのときに限り買える

一般に、名産品は r % d <= r - l のとき、かつその時に限り買える

-----

x / d < a のとき d > x / a

*** TLE ***

1個の電車で1個の名産品を買えるか判定するには
(l-1)/d < r/d のとき、かつそのときに限り買える
この式はl～rの中にdの倍数があるため、l-1のときよりrの時の方がブロック数が増えていることを示す。

各電車について1個の名産品を買えるか判定するには？
二分探索的な感じで
電車d=1なら絶対買える
dを増やすと、(l-1)/dもr/dも減る (少なくとも、増えない)
買える -> 次にr/dが減るまでは買える、減ったらまた買えるか判定
買えない -> 次に(l-1)/dが減るまでは買えない、減ったらまた買えるか判定

いもす
*/


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

int main()
{
    int n;
    cin >> n;
    ll x = 1;
    for (int i = 1; i <= n; i++)
    {
        x = (x * i) % 1000000007;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
res = 0
for i, a in enumerate(A[1:], 1):
    if A[i - 1] <= a:
        continue
    else:
        A[i] = A[i - 1]
        res += A[i - 1] - a
print(res)

Measured memory_bytes: 32312
using namespace std;

#include <cstdio>
#include <cstdint>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>

int main(
){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int     ans = 0;
    int     N = 0;
    int     K = 0;
    cin >> N >> K;

    int     d[K] = {0};
    int     k = 0;
    int     l = 0;
    int     tmp = 0;
    set<int>    s;
    for(k = 0; k < K; k++){
        cin >> d[k];
        for(l = 0; l < d[k]; l++){
            cin >> tmp;
            s.insert(tmp);
        }
    }
    ans = N-s.size();


    cout << ans << "\n";
    return 0;
    
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if(c =='a') cout << "vowel" <<endl;
  else if(c =='i') cout << "vowel" <<endl;
  else if(c =='u') cout << "vowel" <<endl;
  else if(c =='e') cout << "vowel" <<endl;
  else if(c =='o') cout << "vowel" <<endl;
  else cout << "consonant" << endl;
 
}

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

using namespace std;

int main()
{
  int n, m;
  while(cin >> n >> m, n || m){
    int sum[101] = {0};
    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
	int res; cin >> res;
	sum[j] += res;
      }
    }
    vector< pair<int, int> > ans;
    for(int i = 0; i < m; i++) ans.push_back(make_pair(sum[i], -i));
    sort(ans.rbegin(), ans.rend());
    for(int i = 0; i < m; i++){
      if(i) cout << " ";
      cout << -ans[i].second + 1;
    }
    cout << endl;
  }
  return 0;
}

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

#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define REP(i, n) FOR((i), 0, (n))

#define RFOR(i, b, a) for (int(i) = (b); (i) >= (a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair

using namespace std;

const int INF = INT_MAX / 4;
const int MOD = 1000000007;
const double EPS = 1e-14;

const bool debug_flag = true;

void debug(string str)
{
    if (debug_flag)
    {
        cout << str;
    }
}

int H, W;
vector<string> s;
vector<vector<int>> visited;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
queue<pair<int, int>> q;

void bfs(int i, int j){
    q.push(mp(i, j));
    while(!q.empty()){
        pair<int, int> p;
        p = q.front();
        q.pop();
        int x=p.first;
        int y=p.second;
    for(int d=0; d<4; ++d){
        if (0 <= x + dx[d] && x + dx[d] < H && 0 <= y + dy[d] && y + dy[d] < W && visited[x + dx[d]][y + dy[d]] == -1 && s[x + dx[d]][y + dy[d]] == '.'){
            visited[x + dx[d]][y + dy[d]] = visited[x][y] + 1;
            q.push(mp(x + dx[d], y + dy[d]));
        }
    }
    }
}

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(10);

    int dots=0;

    cin>>H>>W;
    s.resize(H);
    for(int i=0; i<H; ++i){
        cin>>s[i];
        for(int j=0; j<W; ++j){
            if(s[i][j]=='.')dots++;
        }
    }

    visited = vector<vector<int>>(H, vector<int>(W, -1));
    visited[0][0] = 1;
    bfs(0, 0);
    if (visited[H - 1][W - 1] == -1){
        cout<<-1<<endl;
    }else{
        cout << dots - visited[H - 1][W - 1] << endl;
    }

    return 0;
}


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

using namespace std;

int d, best = INT_MAX;
long long g, c[15], p[15];
bool u[15];

void go(int a, long long b) {
	for (int i = 1; i <= d; i++)
		if (!u[i]) {
			if (b + i * 100 * p[i] + c[i] < g) {
				u[i] = 1;
				go(a + p[i], b + i * 100 * p[i] + c[i]);
				u[i] = 0;
			} else if (b + i * 100 * p[i] < g)
				best = min((long long)best, a + p[i]);
			else
				best = min((long long)best, a + (g - b + i * 100 - 1) / (i * 100));
		}
}

int main() {
	scanf("%d%lld", &d, &g);
	for (int i = 1; i <= d; i++)
		scanf("%lld%lld", p + i, c + i);
	go(0, 0);
	printf("%d\n", best);
	return 0;
}


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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int n;
    cin >> n;
    int t = n % 10;
    string ans = "";
    if(t == 3){
        ans = "bon";
    }else if(t == 0 || t == 1 || t == 6 || t == 8){
        ans = "pon";
    }else{
        ans = "hon";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
A = list(map(int, input().split()))
S = sum(A)
cnt = 0

for Ai in A:
    if Ai*4*M>=S:
        cnt += 1

if cnt>=M:
    print('Yes')
else:
    print('No')

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

/////////////////////////////////////////////////////////
class UnionFind {
 public:
  static const int MAX_N_LIB = (int)(2e5 + 100);

  int uf_par[MAX_N_LIB];
  int uf_rank[MAX_N_LIB];
  int uf_size[MAX_N_LIB];

  UnionFind(int n) { init(n); }

  void init(int n) {
    for (int i = 0; i < n; ++i) {
      uf_par[i] = i;
      uf_rank[i] = 0;
      uf_size[i] = 1;
    }
  }

  int find(int x) {
    if (uf_par[x] == x)
      return x;
    else {
      return uf_par[x] = find(uf_par[x]);
    }
  }

  void unite(int leaf_x, int leaf_y) {
    int x = find(leaf_x);
    int y = find(leaf_y);

    if (x == y) return;

    if (uf_rank[x] < uf_rank[y]) {
      uf_par[x] = y;
      uf_size[y] += uf_size[x];
    } else if (uf_rank[x] > uf_rank[y]) {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
    } else {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
      uf_rank[x] += 1;
    }
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int x) { return uf_size[find(x)]; }
};
/////////////////////////////////////////////////////////

ll n;
int m;
vector<pair<int, int>> vec;

UnionFind uf(MAX_N);

vector<ll> ans;

int main(void) {
  // Here your code !
  scanf("%lld %d", &n, &m);

  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    vec.push_back(make_pair(a, b));
  }

  reverse(vec.begin(), vec.end());

  ll num = (n - 1 + 1) * (n - 1) / 2;

  ans.push_back(num);

  for (int i = 0; i < m - 1; ++i) {
    auto e = vec[i];

    if (uf.same(e.first, e.second)) {
      ans.push_back(num);
      continue;
    }

    num -= (ll)(uf.size(e.first)) * (ll)(uf.size(e.second));

    uf.unite(e.first, e.second);
    
    ans.push_back(num);
  }
  
  reverse(ans.begin(), ans.end());

  for (auto &e: ans) {
    printf("%lld\n", e);
  }

  return 0;
}


Measured memory_bytes: 4212
#include <iostream>
using namespace std;
int main(void){
string S;
cin>>S;
int answer=0;
for (int i=0;i<S.length();i++){
    if(S[i]=='+'){
        answer+=1;
    }
    else if(S[i]=='-'){
        answer-=1;
    }
}
cout<<answer<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define cin_desync()                      \
	do {                                  \
		ios_base::sync_with_stdio(false); \
		cin.tie(0);                       \
	} while (0)                           \

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int main()
{
	ll X, Y;
	cin >> X >> Y;
	ll a = X;

	int ans = 0;
	while(a <= Y) {
		++ans;
		a *= 2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import sys

# input処理を高速化する
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())

    # 隣接リストを作成
    adjacencyList = [[] for _ in range(N)]

    # 距離の情報
    dp = [0] * N

    # 入次数　（いりじすう）
    deg = [0] * N

    for _ in range(M):
        v, nv = map(int, input().split())
        adjacencyList[v-1].append(nv-1)
        #　入次数に1を足す
        deg[nv-1] += 1

    queue = []

    # BFS探索
    # 入次数がゼロの頂点から探索を始める
    for v in range(N):
        if deg[v] == 0:
            queue.append(v)

    while queue:
        # 現在の頂点をqueueからpop
        v = queue.pop(0)
        for nv in adjacencyList[v]:
            # 探索済みの頂点の入次数を減らす
            deg[nv] -= 1

            # 完全に探索済みの頂点の入次数がゼロの時、経路の距離を出発点から計算
            if deg[nv] == 0:
                # 頂点をqueueに追加する
                queue.append(nv)
                dp[nv] = max(dp[v] + 1, dp[nv])

    print(max(dp))
    
main()

Measured memory_bytes: 54960
S = input()[::-1]

s1 = 'dream'[::-1]
s2 = 'dreamer'[::-1]
s3 = 'erase'[::-1]
s4 = 'eraser'[::-1]

index = 0

while True:
    if S[index:index+len(s2):] == s2:
        index += len(s2)
    elif S[index:index+len(s4):] == s4:
        index += len(s4)
    elif S[index:index+len(s1):] == s1 or S[index:index+len(s3):] == s3:
        index += len(s1)
    else:
        break
    if index == len(S):
        break
if index == len(S):
    print('YES')
else:
    print('NO')
    
        
        


Measured memory_bytes: 3188
N = int(input())
A = [int(x) for x in input().split()]
li = []
ans = 0
for ind,i in enumerate(A):
    li+=[i-(ind+1)]
li.sort()
x = li[(len(li)-1)//2]
for i in li:
    ans+=abs(i-x)
print(ans)


Measured memory_bytes: 26020
// /*
// power code taken from geeks for geeks
// */
// cout << setprecision (2) << fixed << 1.2;

#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 100000000
#define MAX_N 200001
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef long double ld;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}

ll power(ll k, ll p, bool f){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P);
 
    if (p % 2 == 1)
        P = (P * k) ;
 
    return P;
}


struct p_str{
    ll a, b;
};


void solve(){
    ll n, k;
    cin>>n>>k;
    ll a[n];
    for(ll i = 0;i < n; i++) {
        cin >> a[i];
    }

    sort(a, a+n);
    
    ll ans = 0;
    for(ll i = 0; i < k; i++) {
        ans += a[i];
    }
    cout<<ans<<endl;
}



int main(){



    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    



    ll t=1;


    // cin>>t;
    


    while(t--){
        solve();
    }
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    char flag='n';
    for(int i=0;i<3;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<"Bad";
            flag='y';
            break;
        }
    }
    if(flag=='n')
        cout<<"Good";
    






    fflush(stdout);
    return 0;


} 







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

int main()
{
    int n;
    scanf("%d",&n);
    vector<pair<int,int>>ans;
    vector<int>v[n];

    for(int i=0;i<n-1;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        x--,y--;

        v[x].push_back(y);
        v[y].push_back(x);

        ans.push_back({x,y});
    }

    int vis[n]={0},par[n]={0};

    map<pair<int,int>,int>m;

    queue<int>q;

    q.push(0);

    vis[0]=1;

    int re=0;

    while(!q.empty())
    {
        int val=q.front();
        q.pop();
        int mx=v[val].size();
        re=max(re,mx);

        int color=1;

        for(auto it:v[val])
        {
            if(vis[it])continue;

            if(color==par[val])color++;

            vis[it]=1;

            par[it]=color;
            m[{it,val}]=color;
            m[{val,it}]=color;
            color++;
            q.push(it);
        }
    }

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

    for(auto it:ans)
    {
        printf("%d\n",m[it]);
    }


    return 0;

}


Measured memory_bytes: 20084
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int pm, pe, pj;
	
	while (scanf("%d", &n), n != 0){
		for (i = 0; i < n; i++){
			scanf("%d %d %d", &pm, &pe, &pj);
			if (pm == 100 || pe == 100 || pj == 100 || (pm + pe) / 2 >= 90 || (pm + pe + pj) / 3 >= 80){
				puts("A");
			} else if ((pm + pe + pj) / 3 >= 70 || (pm + pe + pj) / 3 >= 50 && pm >= 80 || pe >= 80){
				puts("B");
			} else{
				puts("C");
			}
		}
	}
	
	return (0);
}

Measured memory_bytes: 584
#include<stdio.h>
#include<set>
using namespace std;
int main(){
	
	set<int> s;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(s.count(x)==0)
		s.insert(x);
		else
		s.erase(x);
		}
		printf("%d\n",s.size());
		return 0;
} 

Measured memory_bytes: 4864
# n:文字列の長さ
n = gets.to_i
# s:文字列
s = gets.chomp

if n.odd?
  puts "No"
else
  if s[0, n / 2] == s[n / 2, n / 2]
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 1788