akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod.m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while(b){
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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


int main(){
    int h,w;
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    vector<vector<char>> s(h, vector<char>(w));
    rep(i,h) rep(j,w) cin >> s[i][j];
    vector<vint> visit(h, vint(w, -1));

    queue<pii> q;
    queue<pii> edge_q;
    q.push(mp(ch,cw));
    int warp = 0;
    visit[ch][cw] = warp;
    while(!q.empty() || !edge_q.empty()){
        while(!q.empty()){
            pii pos = q.front(); q.pop();
            rep(i,4){
                int ny = pos.F + dy[i];
                int nx = pos.S + dx[i];
                if( 0<=nx && nx<w && 0<=ny && ny<h && s[ny][nx] == '.'){
                    if(visit[ny][nx] == -1){
                        visit[ny][nx] = warp;
                        q.push(mp(ny, nx));
                    }
                }
                if( 0<=nx && nx<w && 0<=ny && ny<h && s[ny][nx] == '#'){
                    edge_q.push(pos);
                }
            }
        }
        warp++;
        while(!edge_q.empty()){
            pii pos = edge_q.front(); edge_q.pop();
            rep(i, 5){
                rep(j,5){
                    int ny = pos.F + i -2;
                    int nx = pos.S + j -2;
                    if( 0<=nx && nx<w && 0<=ny && ny<h && s[ny][nx] == '.'){
                        if(visit[ny][nx] == -1){
                            visit[ny][nx] = warp;
                            q.push(mp(ny, nx));
                        }
                    }
                }
            }
        }
    }
    cout << visit[dh][dw] << endl;
}



Measured memory_bytes: 8724
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

#define HONEST 'H'
#define LIAR 'D'

int main(void)
{
	char a, b;
	cin >> a >> b;

	char ret = b;
	if(a == LIAR)
		if(b == HONEST)
			ret = LIAR;
		else
			ret = HONEST;

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    class Program
    {
        static void Main()
        {
            var l = int.Parse(Console.ReadLine());

            decimal l3 = l / 3m;
            decimal ans = l3 * l3 * l3;
            Console.WriteLine(ans.ToString());
            Console.ReadLine();
        }
    }

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

string solve(string s) {
	string ret = "";

	int indx = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == '-')
			continue;
		else if(s[i] == '>') {
			indx++;
		}
		else if(s[i] == '<') {
			indx--;
		}
		else {
			if(indx < 0) {
				ret.insert(ret.begin(), s[i]);
				indx = 0;
			}

			else if(indx == ret.size()) {
				ret.push_back(s[i]);
			}
		}
	}

	return ret;
}

int main() {
	int n;

	cin >> n;
	for(int i = 0; i < n; i++) {
		string s;
		cin >> s;
		cout << solve(s) << endl;
	}

	return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}



  








      

 
int main(){
    int n,m,c;
    cin >> n >> m >> c;
    int b[m+1],a[n+1][m+1];
    rep (i,m){
      cin >> b[i];
    }
    rep (i,n){
      rep (j,m){
        cin >> a[i][j];
      }
    }
    int cnt=0,s;
    rep (i,n){
      s=0;
      rep(j,m){
        s += a[i][j]*b[j];
      }
      s += c;
      if (s>0) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,S,W,Q;
ll A[100005];

int main(){
  while( cin >> N >> S >> W >> Q && (N|S|W|Q) ) {
    ll G = S;
    for(int i=0;i<N;i++){
      A[i] = (G/7) % 10;
      if( G % 2 == 0 ) G = ( G/2 );
      else G = ( G/2 ) ^ W;
    }

    vector<ll> S(N+1,0);
    ll k = 1;
    for(int i=N-1;i>=0;i--){
      S[i] = (A[i]*k + S[i+1]) % Q;
      k = (k*10LL) % Q;
    }
    
    ll res = 0;    

    if( Q != 2 && Q != 5 ){
      map<ll,ll> mp;
      for(int i=0;i<N;i++){
        if( A[i] ) mp[S[i]]++;
        res += mp[ S[i+1] ];
      }
    } else {
      ll pr = 0;
      for(int i=0;i<N;i++){
        if( A[i] ) pr++;
        if( A[i]%Q == 0 )res += pr;
      }
    }
    cout << res << endl;
  }
}

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

int main() {
  int N, r = 0;
  int i, j;
  int *m, *n;

  scanf("%d", &N);
  m = (int*)malloc(sizeof(int) * N);
  n = (int*)malloc(sizeof(int) * N);
  for (i = 0; i < N; i++) {
    scanf("%d", (m + i));
  }

  for (i = 0; i < N - 1; i++) {
    if ((i + 1) == *(m + i)) {
      j = *(m + i);
      *(m + i) = *(m + i + 1);
      *(m + i + 1) = j;
      r++;
    }
  }

  for (i = N - 1; i > 0; i--) {
    if ((i + 1) == *(m + i)) {
      j = *(m + i);
      *(m + i) = *(m + i -1);
      *(m + i - 1) = j;
      r++;
    }
  }
  printf("%d\n", r);
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>

using namespace std;


int main(){

        int a,b,c,d=0;

        scanf("%d %d %d\n",&a,&b,&c);

        for(int i=a;i<=b;i++){
                if(c%i==0)
                        d++;
        }
        printf("%d\n",d);

}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1e2 + 7;

int n, m, k;

int arr[maxn][maxn];
char ch[maxn][maxn];

int main()
{
    scanf("%d%d", &n, &m);
    for(int i=0;i<n;i++){
        scanf("%s", ch[i]);
        for(int j=0;j<m;j++)arr[i][j] = 200;
    }
    arr[0][0] = ch[0][0] == '#';
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(i + 1 < n)arr[i + 1][j] = min(arr[i + 1][j], arr[i][j] + (ch[i + 1][j] != ch[i][j] && 
                        ch[i + 1][j] == '#'));
            if(j + 1 < m)arr[i][j + 1] = min(arr[i][j + 1], arr[i][j] + (ch[i][j + 1] != ch[i][j] &&
                        ch[i][j + 1] == '#'));
        }
    }
    printf("%d\n", arr[n - 1][m - 1]);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<int>a(3);
    int five=0,seven=0;
    cin >> a.at(0) >> a.at(1) >> a.at(2);
    for(int i=0;i<3;i++){
        if(a.at(i)==5){
            five++;
        }else if(a.at(i)==7){
            seven++;
        }
    }
    if(five==2 && seven==1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	int n, t, a; cin >> n >> t >> a;

	vector<double>h(n);
	rep(i, n)cin >> h[i];

	vector<int>hl(n);
	rep(i, n) {
		hl[i] = t * 1000.0 - (h[i] * 6.0);
	}
	vector<double>ab(n);
	rep(i, n) {
		ab[i] =	hl[i] - a * 1000.0;
	}

	rep(i, n) {
		if (ab[i] < 0) {
			ab[i] = abs(ab[i]);
		}
	}
	int ans = INF;
	int now = 0;
	rep(i, n) {
		if (ab[i] < ans) {
			now = i;
			ans = ab[i];
		}
	}
	cout << now + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0){
		cout<<"Possible";
	}
	else cout<<"Impossible";
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range (n-1):
  if a[i]+1 == a[i+1]:
    ans += c[a[i]-1]
print(ans+sum(b))

Measured memory_bytes: 9196
import std;

void main()
{
  const K = readln().chomp().to!ulong();
  
  ulong sum = 0;
  foreach (i; 1 .. K + 1)
  foreach (j; 1 .. K + 1)
  foreach (k; 1 .. K + 1)
  {
    sum += gcd(gcd(i, j), k);
  }
  
  writeln(sum);
}


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

char c[80][80];
struct str {
	string s;
	str(string s = "") :s(s) {}
}d[80][80];
bool operator<(str a, str b) {
	if (a.s.size() == b.s.size())return a.s < b.s;
	return a.s.size() < b.s.size();
}
int main() {
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		rep(i, h)scanf("%s", c[i]);
		str Max = (string)"0";
		rep(i, h)rep(j, w) {
			if ('0' <= c[i][j] && c[i][j] <= '9') {
				d[i][j] = to_string(c[i][j] - '0');
				if (i)d[i][j] = max(d[i][j], str(d[i - 1][j].s + c[i][j]));
				if (j)d[i][j] = max(d[i][j], str(d[i][j - 1].s + c[i][j]));
				str s = d[i][j];
				while (!s.s.empty() && s.s.front() == '0')s = s.s.substr(1);
				Max = max(Max, s);
			}
			else d[i][j] = (string)"";
		}
		cout << Max.s << endl;
	}
}

Measured memory_bytes: 3400
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int com(const char *x,const char *y){
  return strcmp(x,y);
}
int main(){
 int n,l;
  char string[100][101];
  scanf("%d%d",&n,&l);
  for(int c=0;c<n;c++){
    scanf("%s",string[c]);
  }
  qsort(string,n,sizeof(string[0]),com);
  for(int i=0;i<n;i++){
    printf("%s",string[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 252
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    
    for k in range(K):
        B = [0 for i in range(N)]
        for i in range(N):
            low = max(0,i-A[i])
            high = min(N-1,i+A[i])
            B[low] += 1
            if high+1 < N:
                B[high+1] -= 1
        for i in range(1,N):
            B[i] += B[i-1]
        if A == B:
            break
        A = B
    
    print(*A)
    
if __name__ == '__main__':
    main()

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n, l;
    cin >> n >> l;

    vector<pair<int, vector<int>>> st;

    st.push_back({2000000000, {}});

    long res = 0;

    for (int ii = 0; ii < n; ii++) {
        int x;
        cin >> x;
        while (st.back().first < x) {
            auto r = st.back().first;
            auto p = st.back().second;
            st.pop_back();
            int c = p.size();
            if (c < l) {
                while (st.size() > 1) {
                    st.pop_back();
                }
                break;
            }
            vector<int> cc;
            for (int q = c / l; q > 0; q--) {
                cc.push_back(p[p.size() - q * l]);
            }
            if (st.back().first == r + 1) {
                int xx = st.back().second.back();
                for (int t : cc) {
                    st.back().second.push_back(
                            xx + t
                    );
                }
            } else {
//                for (int i = 1; i < cc.size(); i++) {
//                    cc[i] += cc[i - 1];
//                }
                st.push_back({r + 1, cc});
            }
        }
        if (st.back().first == x) {
            st.back().second.push_back(
                    st.back().second.back() + 1
            );
        } else {
            st.push_back({x, {1}});
        }
        res += 1;
        if (st.back().second.size() >= l) {
            res += st.back().second[st.back().second.size() - l];
        }
        int r = st.back().first;
        int c = st.back().second.size();
//        for (auto p: st) {
//            cout << p.first << ": ";
//            for (auto x : p.second) {
//                cout << x << " ";
//            }
//            cout << "\n";
//        }
        for (int i = (int)st.size() - 2; i >= 0; i--) {
            while (st[i].first != r) {
                r++;
                c /= l;
                if (c == 0) break;
            }
            if (c == 0 || st[i].first != r) break;
            if (c >= l) {
                res += st[i].second[st[i].second.size() - 1];
            } else {
                if (c + st[i].second.size() < l) {
                    break;
                } else {
                    res += st[i].second[st[i].second.size() - (l - c)];
                }
            }
            c += st[i].second.size();
        }
//        cout << "!!! " << res << endl;
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    while(n--) {
        string S;
        cin >> S;
        set<string> st;
        for(int i = 1; i < S.size(); i++) {
            string T = S.substr(0, i);
            string U = S.substr(i, S.size());
            st.insert(T+U);
            st.insert(U+T);
            reverse(T.begin(), T.end());
            st.insert(T+U);
            st.insert(U+T);
            reverse(U.begin(), U.end());
            st.insert(T+U);
            st.insert(U+T);
            reverse(T.begin(), T.end());
            st.insert(T+U);
            st.insert(U+T);
        }
        cout << st.size() << endl;
    }
    return 0;
}


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

int main() {
  int N , K , Q ; 
  cin >> N >> K >> Q ; 
  vector<int> A(Q) ;
  vector<int> T(N) ;
  
  for(int i = 0 ; i < N ; i++){
    T.at(i) = 0 ; 
  }
  
  for(int i = 0 ; i < Q ;i++ ){
    cin >> A.at(i) ; 
    T.at( A.at(i)- 1)++ ; 
  }
  
  for(int i = 0 ; i < N ; i++){
    if(K - Q + T.at(i) > 0 ){
      cout << "Yes" << endl ; 
    }
    else{
      cout << "No" << endl ; 
    }

  }
}

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

public class Main {
    static final int MAX_V = 1000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long w = sc.nextLong();
        long[] W = new long[n + 10];
        int[] V = new int[n + 10];
        for(int i = 0; i < n; i++) {
            W[i] = Integer.parseInt(sc.next());
            V[i] = Integer.parseInt(sc.next());
        }
        long[][] dp = new long[n + 10][n * MAX_V + 10];
        for(long[] r : dp) Arrays.fill(r, Integer.MAX_VALUE);
        dp[0][0] = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j <= n * MAX_V; j++) {
                dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j]);
                if(j - V[i] >= 0) {
                    dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j - V[i]] + W[i]);
                }
            }
        }
        long ans = 0;
        for(int i = 0; i < n * MAX_V + 10; i++) {
            if(dp[n][i] <= w) ans = i;
        }
        System.out.println(ans);
    }
}

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

int aray[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; gi(n);
	print(aray[n]);
}


Measured memory_bytes: 2304
#include <vector>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#define pb push_back
#define mp make_pair
#define y1 y1asd
#define f first
#define s second
#define sz(s) ((int)s.size())
#define all(s) (s).begin(), (s).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
const int inf = (1 << 30) - 1;
const int N = (int)1e5 + 5;

int n, a[N];
char s[N];

int main() {

	scanf("%s", s);
	n = strlen(s);
	a[n] = 1;
	int ans = n - 1;
	for (char ch = 'a'; ch <= 'z'; ch++) {

		int res = 0;
		for (int i = n-1; i >= 0; i--) {
			a[i] = min(s[i] == ch ? 0 : a[i+1] + 1, n - i);
			res = max(res, a[i]);
			// if (ch == 'v')
			// printf("%c %d %d\n", s[i], a[i], res);
		}
		ans = min(ans, res);
	}
	printf("%d\n", ans);

	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s;cin>>s;
  bool ans=false;
  if((s[2]==s[3])&&(s[4]==s[5])){
    ans=true;
  }
  cout<<yesno(ans)<<endl;
  return 0;
}


Measured memory_bytes: 764
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  long long L, R;
  std::cin >> L >> R;

  int mod = 2019;

  // Main
  long long l, r;
  l = L % mod;
  r = R % mod;

  // std::cout << "l, r = " << l << ", " << r << std::endl;

  int min = IINF;
  if (R - L < mod) {
    if (l < r) {
      for (int i = l; i <= r; ++i)
        for (int j = i + 1; j <= r; ++j) {
          // std::cout << (i * j) % mod << std::endl;
          chmin(min, (i * j) % mod);
        }
    } else {
      for (int i = 0; i <= r; ++i)
        for (int j = i + 1; j <= r; ++j)
          chmin(min, (i * j) % mod);
      for (int i = l; i < mod; ++i)
        for (int j = i + 1; j < mod; ++j)
          chmin(min, (i * j) % mod);
    }
  } else {
    for (int i = 0; i < mod; ++i)
      for (int j = 0; j < mod; ++j)
        chmin(min, (i * j) % mod);
  }

  // Output
  std::cout << min << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    int n;
    cin >> n;
    int sum = 0;
    map <int, int> check;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        check[x]++;
        sum += x;
    }
    int q;
    cin >> q;
    for (int v = 0; v < q; ++v)
    {
        int a, b;
        cin >> a >> b;
        sum = sum - a * check[a] + b * check[a];
        check[b] += check[a];
        check[a] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 9452
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
  double d;
  vector<double> v;

  while(cin >> d){
    v.push_back(d);
  }

  sort(v.begin(), v.end());

  cout << v.at(v.size() - 1) - v.at(0) << endl;
  

  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
    
    vector<int> arr(n);
    double mx = 0;
    for(auto &x: arr) {
        cin >> x;
        mx += x;
    }
  
    int count = 0;
    for(auto x: arr) {
        if(x*4*m >= mx)
            ++count;
    }
    
    if(count >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>

long factorial( long x, int n ) {
    long ret = 1;
    for ( int i=0; i<n; i++ ) {
        ret *= x;
    }
    return ret;
}

int main()
{
    // input
    int X;
    scanf( "%d", &X );

    // process
    long min_int = -2147483648;
    long max_long = 9223372036854775807;
    double near_max_long = 9223300000000000000;
    std::vector<long> list_5fact, list_base;
    list_5fact.push_back(0);
    list_base.push_back(0);
    long max_index = std::pow(near_max_long, 0.2);
    for ( long i=1; i <= max_index; i++ ) {
        long num = factorial( i, 5 );
        list_5fact.push_back(num);
        list_base.push_back(i);
        list_5fact.push_back(-num);
        list_base.push_back(-i);
    }
    int length = list_5fact.size();
    for ( int i=0; i<length; i++ ) {
        for ( int j=0; j<length; j++ ) {
            if ( list_5fact[i] - list_5fact[j] == X ) {
                printf("%ld %ld\n", list_base[i], list_base[j]  );
                return 0;
            }
        }
    }
    while ( true ) {
    }

    // output

    return 0;
}


Measured memory_bytes: 3496
#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>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
template <typename T, class Operator>
struct SegTree
{
	vector<T> tree;
	Operator op;
	T def;
	int s;
	SegTree(int size, T val, Operator opr)
	{
		s=size;
		op=opr;
		tree.resize(4*size,val);
		def=val;
	}

	void add(int pos, T value)
	{
		add(pos,value,0,s,0);
	}

	// [low, hi) は全体の範囲
	void add(int pos, T value, int low, int hi, int i)
	{
		while(1)
		{
			tree[i]=op(tree[i],value);
			if(low+1<hi){
				int mid=(low+hi)/2;
				if(pos<mid){
					i=2*i+1;
					hi=mid;
				}
				else
				{
					i=2*i+2;
					low=mid;
				}
			}
			else
			{
				break;
			}
		}
	}

	// [a,b) を取得
	T get(int a, int b)
	{
		return get(a,b,0,s,0);
	}

	T get(int a, int b, int low, int hi, int i)
	{
		if(hi<=a||b<=low||hi<=low){
			return def;
		}
		if(a<=low&&hi<=b){
			return tree[i];
		}
		int mid=(low+hi)/2;
		return op(get(a,b,low,mid,2*i+1),get(a,b,mid,hi,2*i+2));
	}
};
template<typename T>
struct Min
{
	T operator()(T a, T b){
		return min(a,b);
	}
};

const int L=200*1000+10;
LL x[L];
LL sum[L];
const LL inf=1LL<<60;
int main() {
	int N,Q,A,B;
	cin >> N >> Q >> A >> B;
	for(int i=0;i<Q;i++){
		cin >> x[i];
	}
	for(int i=Q-2;i>=0;i--)
	{
		sum[i]=sum[i+1]+abs(x[i]-x[i+1]);
	}
	SegTree<LL,Min<LL> > ltree(N+2,inf,Min<LL>()),rtree(N+2,inf,Min<LL>());
	LL ret=min(abs(B-x[0]),abs(A-x[0]))+sum[0];
	ltree.add(A,abs(B-x[0])+sum[0]-A);
	ltree.add(B,abs(A-x[0])+sum[0]-B);
	rtree.add(A,abs(B-x[0])+sum[0]+A);
	rtree.add(B,abs(A-x[0])+sum[0]+B);
	for(int i=1;i<Q;i++)
	{
		LL v=ltree.get(0,x[i])-sum[i-1]+x[i]+sum[i];
		LL w=rtree.get(x[i],N+1)-sum[i-1]-x[i]+sum[i];
		v=min(v,w);
		ret=min(ret,v);
		ltree.add(x[i-1],v-x[i-1]);
		rtree.add(x[i-1],v+x[i-1]);
	}
	cout << ret << endl;


	return 0;
}



Measured memory_bytes: 15872
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,K = MI()
D = LI()

A = []  # 使ってよい数字
for i in range(10):
    if not i in D:
        A.append(i)

def f(x):
    if x <= max(A):
        for i in range(10-K):
            if A[i] >= x:
                return A[i]
    else:
        if x % 10 > max(A):
            return 10*f(x//10+1)+min(A)
        else:
            for i in range(10-K):
                if A[i] >= x % 10:
                    a = A[i]
                    break
            return min(10*f(x//10)+a,10*f(x//10+1)+min(A))

print(f(N))

Measured memory_bytes: 62072
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    b = [0]*(n+1)
    for i in range(1,n+1)[::-1]:
        x = i
        s = 0
        while x <= n:
            s ^= b[x]
            x += i
        b[i] = s^a[i-1]
    ans = [i for i in range(1,n+1) if b[i]]
    print(len(ans))
    print(*ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	bool ok = false;

	rep(i, b-a+1) {
		if ((i+a)%k == 0) {
			ok = true;
		}
	}

	if(ok) cout << "OK" << endl;
	else cout << "NG" << endl;

	return 0;
}

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

int main()
{
  vector<int> nums {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (auto&& e : a) cin >> e;
  vector<string> dp(n + 7, "0");
  dp[0].clear();

  for (int i = 0; i < n; i++) {
    if (dp[i] == "0") continue;
    for (auto&& e : a) {
      string s = dp[i + nums[e]];
      string t = dp[i] + to_string(e);
      if (s.length() > t.length()) continue;
      if (s.length() < t.length() || s < t) {
        dp[i + nums[e]] = dp[i] + to_string(e);
      }
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 33536
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<sstream>
#include<cctype>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<stack>
#include<functional>
#include<utility>
#include<numeric>
#include<bitset>
#include<iterator>
#define INF (int)1e9
#define MOD 1000000007
#define tr(c, it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define debug(x) cout<<#x" = "<<(x)<<endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz size
#define ll long long
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MEM(a, b) memset(a, (b), sizeof(a))
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?"\n":" ")
#define printv(a) printa(a,0,a.size())
#define print2d(a,r,c) for(int i=0;i<r;i++) for(int j=0;j<c;j++) cout<<a[i][j]<<(j==c-1?"\n":" ")
#define PRE(i, m, n, in) for(int (i)=(m);(i)<(n);i+=in)
#define RFOR(i, n) for(int i=n ; i>=0 ; i--)
#define RPRE(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define ERS(A, P) A.erase(A.begin() + P)
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define mnv(v) *min_element(v.begin(),v.end())
#define mxv(v) *max_element(v.begin(),v.end())
#define countv(v,a) count(v.begin(),v.end(),a)
#define toint(a) atoi(a.c_str())
using namespace std;
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
typedef vector <int> VI;
typedef vector <ll> VL;
typedef vector<string> VS;
typedef vector <VS> VSS;
typedef vector <II> VII;
typedef vector <LL> VLL;
typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VII> VVII;
typedef vector <VLL> VVLL;
typedef map<int,int> MPII;
typedef map<ll,ll> MPLL;
typedef map<string, int>MPSI;
typedef map<string, ll>MPSL;
typedef map<int, string>MPIS;
typedef map<ll, string> MPLS;
typedef map<string, string> MPSS;
typedef set<int> SETI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //freopen("input.txt", "r", stdin);
  /* code */
  int n; cin >> n; VI h(n); FOR(i, n) {
    cin >> h[i];
  }
  VI dis(n);
  dis[1] = dis[0] + abs(h[1] - h[0]);
  PRE(i, 2, n, 1) {
    dis[i] = min(dis[i - 1] + abs(h[i - 1] - h[i]), dis[i - 2] + abs(h[i - 2] - h[i]));
  }
  cout << dis[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}


signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  map<lol, lol> yaku;
  reps(i, n){
    int memo = i;
    while(memo % 2 == 0){
      yaku[2] ++;
      memo /= 2;
    }
    for(int j = 3;j * j <= i;j += 2){
      while(memo % j == 0){
	yaku[j] ++;
	memo /= j;
      }
    }
    if(memo != 1){
      yaku[memo] ++;
    }
  }
  lol ans = 1;
  for(auto x:yaku){
    ans *= (x.se + 1);
    ans %= MOD;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int main(){
    int num = 0; 
    int N;
    size_t X;

    std::cin >> N >> X;
    
    std::vector<int> M(N);
    for(auto& it : M){
        int mi;
        std::cin >> mi;
        it = mi;

        X -= mi;
        ++num;
    }

    std::sort(M.begin(),M.end());

    while(X >= M.at(0)){
        X -= M.at(0);
        ++num;
    }

    std::cout << num;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


def main():
    N = int(input())
    S = [input() for _ in range(N)]
    S = Counter(S)

    SM = S.most_common()[0][1]
    S = sorted(S.items(), key=lambda x: [-x[1], x[0]])
    for key, value in S:
        if value == SM:
            print(key)
        else:
            break


if __name__ == "__main__":
    main()


Measured memory_bytes: 63956
import collections, itertools
N = int(input())
mod = 10**9 + 7
dp = collections.defaultdict(int)
dp['TTTA'] = dp['TTTG'] = dp['TTTC'] = dp['TTTT'] = 1
for _ in range(N - 1):
    dp2 = collections.defaultdict(int)
    for p, q, r, s, t in itertools.product('AGCT', repeat=5):
        if 'AGC' in [q + s + t, s + r + t, r + s + t, q + r + t, r + t + s]:
            continue
        else:
            dp2[q + r + s + t] += dp[p + q + r + s]
    dp = dp2
print(sum(dp.values()) % mod)


Measured memory_bytes: 9476
object Main extends App {

  def swap(a: Array[Int], i: Int, j: Int) = {
    val tmp = a(i)
    a(i) = a(j)
    a(j) = tmp
  }

  def partition(a: Array[Int]): Int = {
    val r = a.size - 1
    val p = 0
    val x = a(r)

    var i = p - 1

    for (j <- p until r) {
      if (a(j) <= x) {
        i = i + 1
        swap(a, i, j)
      }
    }
    swap(a, i + 1, r)
    i + 1
  }

  val sc = new java.util.Scanner(Console.in)

  def readInt() = sc.next().toInt

  val a = Array.fill(readInt())(readInt())
  val i = partition(a)
  for (j <- 0 until a.size) {
    if (j > 0) print(' ')
    print(if (j == i) s"[${a(j)}]" else a(j))
  }
  println()
}



Measured memory_bytes: 111708
N = input()
n = map(int,raw_input().split(' '))
c = 0
for i in range(N-1):
	mini = i
	for j in range(i+1,N):
		if n[mini] > n[j]:
			mini = j
	if mini != i:
		temp = n[i]
		n[i] = n[mini]
		n[mini] = temp
		c+=1
print " ".join(str(i) for i in n)
print c

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

int N, Y;

int main() {
  cin >> N >> Y;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N - i; ++j) {
      int k = N - i - j;
      bool sol = (10 * i + 5 * j + k) * 1000 == Y;
      if (sol) {
        cout << i << ' ' << j << ' ' << k << '\n';
        return 0;
      }
    }
  }
  cout << -1 << ' ' << -1 << ' ' << -1 << '\n';
}

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

const int N = 2e5 + 5;

int A[N], B[N], n, m;

bool pd(int x) {
	int now = x * 2;
	for(int i = x * 2 + 1; i <= n * 2; i += 2) {
		if(A[i] + A[n * 2 + x * 2 + 1 - i] < m) return 0;
	}
	return 1;
}

int calc(int now) {
	int ans = 0;
	for(int i = now + 1; i <= n * 2; i += 2){
		ans = max(ans, A[i] + A[n * 2 + now + 1 - i] - m);
	}
	for(int i = 1; i <= now; ++ i) {
		ans = max(ans, A[i] + A[now + 1 - i]);
	}
	return ans;
}

int main() {
	cin >> n >> m;
	for(int i = 1; i <= (n << 1); ++ i) scanf("%d", &A[i]);
	sort(A + 1, A + (n * 2) + 1);
	int l = 0, r = n, res = -1;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(pd(mid)) {
			r = mid - 1;
			res = mid;
		}
		else l = mid + 1;
	}
	cout << calc(res * 2) << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){

    int h,w,i,j;

    while(1){

      scanf("%d %d",&h,&w);

      if(h==0 && w==0) break;

        for(i=0;i<h;i++){
          for(j=0;j<w;j++){
            printf("#");
          }
          printf("\n");
        }
        printf("\n");

    }

    return 0;

}


Measured memory_bytes: 2108
#include <stdio.h>

int main(void){
    int a, b;
    scanf("%d %d", &a, &b);

    int digit_b = 0, copy_b = b;
    while(copy_b > 0){
        copy_b /= 10;
        digit_b++;
    }

    for(int i = 0; i < digit_b; i++){
        a *= 10;
    }
    a += b;

    int is_sq = 0;
    for(int i = 1; i * i <= a; i++){
        if(i * i == a){
            is_sq = 1;
            break;
        }
    }

    if(is_sq) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
using System;

namespace D___Decayed_Bridges
{
    class Program
    {
        static void Main(string[] args)
        {
            var temp1 = Console.ReadLine().Split(' ');
            int N = int.Parse(temp1[0]);
            int M = int.Parse(temp1[1]);

            var decayed = new int[M,2];
            for(int i=0;i<M;i++)
            {
                var temp2 = Console.ReadLine().Split(' ');
                decayed[i,0] = int.Parse(temp2[0]);
                decayed[i,1] = int.Parse(temp2[1]);
            }

            var inconvenience = new long[M];
            inconvenience[M-1] = (long)N*(long)(N-1)/2;

            var islandGroup = new UnionFind(N);

            for(int i = M-1;i>0;i--)
            {
                int X = decayed[i,0];
                int Y = decayed[i,1];

                if(islandGroup.sameRoot(X,Y))
                {
                    inconvenience[i-1] = inconvenience[i];
                }else{
                    inconvenience[i-1] = inconvenience[i] - islandGroup.RootCount(X)*islandGroup.RootCount(Y);
                    islandGroup.unite(X,Y);
                }
            }

            foreach(long i in inconvenience)
            {
                Console.WriteLine(i);
            }
        }
    }
    
    public class UnionFind
    {
        private int[] parents;
        // 同じ根に属する枝の数を格納する
        private int[] rootCount;

        public int RootCount(int branch)
        {
            return rootCount[root(branch)];
        }
        
        public UnionFind(int count)
        {
            parents = new int[count+1];
            rootCount = new int[count+1];
            for(int i = 0 ;i<count+1;i++)
            {
                parents[i] = i;
                rootCount[i] = 1;
            }
        }

        private int root(int N)
        {
            if(parents[N] == N) return N;
            return parents[N] = root(parents[N]);
        }

        //木を併合する際に、枝の数も合算する
        public void unite(int X,int Y)
        {
            int rootX = root(X);
            int rootY = root(Y);
            if(rootX==rootY) return;
            rootCount[rootX] += rootCount[rootY];
            parents[rootY] = rootX;
        }

        public bool sameRoot(int X,int Y)
        {
            return root(X)==root(Y);
        }

    }
}


Measured memory_bytes: 18888
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n,k;
    cin >> n >> k;
    int ans = k;
    rep(i,n-1) ans *= k-1;
    cout << ans << endl;
}

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

using namespace std;

int MAX = 1e6;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    vector<bool> dp(MAX, false);    
    vector<bool> pr(MAX, true);
    vector<int> D(MAX);
    D[1] = 1;
    for (int i=2; i<MAX; i++) {
        if (pr[i]) {
            D[i] = i;
            for (int j=i; j<MAX/i; j++) {
                D[i*j] = i;
                pr[i*j] = false;
            }
        }
    }
    vector<int> prime;
    int gcd;
    bool ok = false;
    for (int i=0; i<n; i++){
        cin>>a[i];

        if (i == 0) gcd = a[0];
        else gcd = __gcd(gcd, a[i]);

        if (!ok && a[i] > 1) {
            int p = D[a[i]];
            while (p > 1) {
                
                auto it = find(prime.begin(), prime.end(), p);
                if (it == prime.end()) prime.push_back(p);
                else {
                    ok = true;
                    break;
                }
                while (a[i] % p == 0) a[i] /= p;
                p = D[a[i]];
            }
        }
        
    }
    //for (int a : prime) cout << a << " ";
    //cout << '\n';
    if (gcd > 1) cout << "not coprime" << '\n';
    else if (ok) cout << "setwise coprime" << '\n';
    else cout << "pairwise coprime" << '\n';
    return 0;
}

Measured memory_bytes: 11260
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << ((a + b > c + d) ? "Left" : ((a + b < c + d) ? "Right" : "Balanced")) << endl;
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]
        self.stable = [1 for _  in range(size)]

    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            f = ff.stable[s1] * ff.stable[s2]
            if self.table[s1] != self.table[s2]:
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                    self.stable[s1] = self.stable[s1] + self.stable[s2]
                else:
                    self.table[s1] = s2
                    self.stable[s2] = self.stable[s1] + self.stable[s2]
            else:
                self.table[s1] += -1
                self.stable[s1] = self.stable[s1] + self.stable[s2]
                self.table[s2] = s1
            return f
        return 0

n, m = [int(x) for x in input().strip().split(" ")]
ff = UnionFind(n)
import sys
ab = []
for line in sys.stdin:
    ab.append([int(x)-1 for x in line.strip().split(" ")])
g = int((n * (n-1))/2)
rs = [str(g)]
for x,y in ab[::-1]:
    g -= ff.union(x, y)
    rs.append(str(g))
print("\n".join(rs[::-1][1:]))


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

int main() {
  int N; cin >> N;
  string s = "";
  while(N != 0) {
    if(N % -2 != 0){
      --N;
      s = "1"+s;
    } 
    else s = "0"+s;
    N /= -2;
  }
  if(s == "")	s = "0";
  cout << s << endl;
}

Measured memory_bytes: 256