akhauriyash/Code-Regression huggingface dataset:
from sys import stdin, setrecursionlimit


class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        p = self.parent
        if x != y:
            x, y = sorted([x, y])
            p[x], p[y] = p[x] + p[y], x

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

    def size(self, x):
        return -self.parent[self.find(x)]


def main():
    n, m, k = map(int, stdin.readline().split())

    f = UnionFindTree(n)

    f_or_b = [0] * n

    for _ in range(m):
        a, b = map(int, stdin.readline().split())
        f.union(a - 1, b - 1)
        f_or_b[a - 1] += 1
        f_or_b[b - 1] += 1

    for _ in range(k):
        c, d = map(int, stdin.readline().split())
        if f.same(c - 1, d - 1):
            f_or_b[c - 1] += 1
            f_or_b[d - 1] += 1

    print(*[f.size(i) - f_or_b[i] - 1 for i in range(n)])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Measured memory_bytes: 59736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

ll x[200005];	
ll x_inv[200005];
ll cmb(ll a,ll b){
	return (x[a]*x_inv[b]%MOD*x_inv[a-b]%MOD)%MOD;
}
ll get_inv(ll x){
	ll m = MOD-2;
	ll s = 1;
	while(m!=0){
		if(m&1)s=(s*x)%MOD;
		x=(x*x)%MOD;
		m>>=1;
	}
	return s;
}


int main(){
	ll h,w,a,b,i;
	cin>>h>>w>>a>>b;
	x[0]=x_inv[0]=1;
	loop(i,0,w+h+3){
		x[i+1]=x[i]*(i+1)%MOD;
		x_inv[i+1]=get_inv(x[i+1]);
	}
	vl p1(h-a,0),p2(h,0);
	p1[0]=1;
	p2[h-1]=1;
	loop(i,1,h-a){
		p1[i]=(p1[i-1]*(i+b-1)/i)%MOD;
	}
	rloop(i,h-2,0){
		p2[i]=(p2[i+1]*(h+w-2-b-i)/(h-1-i))%MOD;
	};
	ll ans=0;
	loop(i,0,h-a){
		ans=ans+(cmb(i+b-1,b-1)*cmb(h-i+w-b-2,w-b-1))%MOD;
		ans%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4864
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := scanInt()
	m := scanInt()

	tsk := 0
	for i := 0; i < m; i++ {
		tsk += scanInt()
	}

	if tsk > n {
		fmt.Println(-1)
	} else {
		fmt.Println(n - tsk)
	}
}

func scanInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	string t, p; cin >> t >> p;

	rep(i, sz(t) - sz(p) + 1) {
		bool flag = true;
		FOR(j, i, i + sz(p)) {
			if (t[j] != p[j - i])flag = false;
		}
		if (flag)Cout(i);
	}
}


Measured memory_bytes: 3240
#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int m;
	while(cin >> m, m)
	{
		vector<int> a(m);
		vector<int> b(m);
		for(int i = 0; i < m; ++i)
		{
			cin >> a[i] >> b[i];
		}
		int dp[8][1001] = {0};
		dp[0][0] = 1;
		for(int i = 0; i < m; ++i)
		{
			for(int j = 0; j < 1001; ++j)
			{
				for(int k = 0; k <= b[i]; ++k)
				{
					if(j + k * a[i] > 1000)
					{
						break;
					}
					dp[i + 1][j + k * a[i]] += dp[i][j];
				}
			}
		}
		int g;
		cin >> g;
		for(int i = 0; i < g; ++i)
		{
			int declare;
			cin >> declare;
			cout << dp[m][declare] << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1228
A, B, K = map(int, input().split())

if A > B:
    A, B = B, A
    
if B % A == 0:
    now = 1
    result = A
else:
    now = 0

num = A // 2
while now < K:
    if A % num == 0 and B % num == 0:
        now += 1
        result = num

    num -= 1

print(result)


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

#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define X first
#define Y second
#define mp make_pair
#define eb emplace_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
    char c = getchar();
    bool f = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            f = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (f) {
        x = -x;
    }
}

const int MAX_N = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int n, a[MAX_N];


int main()
{
    int n,m,x,y;
    int a[101],b[101];
    scanf("%d%d%d%d\n",&n,&m,&x,&y );
    for (int i = 0; i < n; i++) {
        scanf("%d\n",&a[i] );
    }
    for (int i = 0; i < m; i++) {
        scanf("%d\n",&b[i] );
    }
    sort(a,a+n);
    sort(b,b+m);
    bool f=false;
    if ( x < y ) {
            for (int i = x+1; i < y+1; i++) {
                if ( a[n-1]<i and i<=b[0]) {f=true ;break;}
    //            printf("%d\n",i);
            }
    }

    f ? printf("No War") : printf("War");
    //printf("%d %d %d %d\n",x,y,a[n-1],b[0]);

}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
    long N, Q;
    char S[100001];
    long l, r;
    scanf("%ld %ld", &N, &Q);
    scanf("%s", S);

    long how_many_ac[100000];
    long count_ac = 0;
    bool flag_a = false;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'A') {
            flag_a = true;
        } else if (S[i] == 'C' && flag_a) {
            flag_a = false;
            count_ac++;
        } else {
            flag_a = false;
        }
        how_many_ac[i] = count_ac;
    }
    
    while (scanf("%ld %ld", &l, &r) != EOF) {
        printf("%ld\n", how_many_ac[r-1] - how_many_ac[l-1]);
    }


}


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

namespace ConsoleApplication17
{
    class Program
    {
        static void Main()
        {
            double[] a = Console.ReadLine().Split().Select(double.Parse).ToArray();
            double b = (a[2] - a[0]) * (a[2] - a[0]) + (a[3] - a[1]) * (a[3] - a[1]);
            Console.WriteLine(Math.Sqrt(b));
        }
    }
}

Measured memory_bytes: 9664
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int INF = INT_MAX / 4;

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

    map<string, int> index;
    vector<string> to(n);
    for(int i=0; i<n; ++i){
        string s;
        cin >> s;
        if(s == "goto"){
            cin >> s;
            to[i] = s.substr(0, s.size()-1);
        }else{
            index[s.substr(0, s.size()-1)] = i;
        }
    }
    
    multimap<int, int> mm;
    mm.insert(make_pair(0, 0));
    vector<int> dp(n+1, INF);
    dp[0] = true;

    for(;;){
        int cost = mm.begin()->first;
        int curr = mm.begin()->second;
        mm.erase(mm.begin());

        if(curr == n){
            cout << cost << endl;
            return 0;
        }

        if(to[curr] == ""){
            int next = curr + 1;
            if(cost < dp[next]){
                mm.insert(make_pair(cost, next));
                dp[next] = cost;
            }
        }else{
            int next = curr + 1;
            if(cost + 1 < dp[next]){
                mm.insert(make_pair(cost+1, next));
                dp[next] = cost + 1;
            }

            next = index[to[curr]];
            if(cost < dp[next]){
                mm.insert(make_pair(cost, next));
                dp[next] = cost;
            }
        }
    }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM=MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[]={2,2,-2,-2,1,1,-1,-1},ddy[]={1,-1,1,-1,2,-2,2,-2};

struct node {
	int child[26],cnt[26];
	int sub;
	node()
	{
		sub=0;
		MEM0(cnt);
		MEM_1(child);
	}
};
vector<node> trie;
int init()
{
	node x;
	trie.push_back(x);
	return (int)trie.size() - 1;
}
int tt[1000005];
void add(int n, string &s, int i)
{
	fup(k,0,25,1)if(tt[i] & (1<<k))trie[n].cnt[k]++;
	if (i == s.length())
	{
		return;
	}
	int c = s[i] - 'a';
	if (trie[n].child[c] == -1)
	{
		int next = init();
		trie[n].child[c] = next;
	}
	add(trie[n].child[c], s, i + 1);
}
int go(int n,string &s,int i){
	if(i==s.length()-1){
		return trie[n].cnt[s[i]-'a'];
	}
	int c = s[i] - 'a';
	if (trie[n].child[c] != -1)return go(trie[n].child[c],s,i+1);
	else return 0;
}
string s[200000];
int t[200000];
int main(){
	SYNC;
	int n;
	cin>>n;
	init();
	fup(i, 0, n - 1, 1){
		t[i]=i;
		cin>>s[i];
		reverse(ALL(s[i]));
	}
	sort(t,t+n,[&](int a,int b){
		return s[a].length()>s[b].length();
	});
	Vi tmp;
	ll ans=0;
	fup(j,0,n-1,1){
		if(j>0 && s[t[j-1]].length() != s[t[j]].length()){
			while(!tmp.empty()){
				int i=tmp.back();
				tmp.pop_back();
				int N=s[i].length();
				tt[N]=0;
				fdn(k,N-1,0,1){
					tt[k]=tt[k+1]|(1<<(s[i][k]-'a'));
				}
				add(0,s[i],0);
			}
		}
		int i=t[j];
		ans+=go(0,s[i],0);
		tmp.pb(i);
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 232028
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int a[110];

int main(void){
	          int i,j;

	          int N,M;
	          cin >> N >> M;
	          for(i=1;i<=N;i++) cin >> a[i];

	          for(i=1;i<=M;i++){
	        	  for(j=1;j<N;j++){
	        		  if(a[j]%i>a[j+1]%i) swap(a[j],a[j+1]);
	        	  }
	          }

	          for(i=1;i<=N;i++) cout << a[i] << endl;

	          return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
 
//#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int a, b;
	cin >> a >> b;

	for (int i = 1; i < 100000; i++) {
		if (i * 8 / 100 == a && i * 10 / 100 == b) {
			cout << i << endl;
			return 0;
		}
	}

	cout << - 1 << endl; 

	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main(void){
    int n,c;
    int ans = 1000000000;
    cin >> n >> c;
    int d[c][c];
    rep(i,c) rep(j,c)cin >>d[i][j];
    int c2[n][n];
    rep(i,n) rep(j,n)cin >>c2[i][j];
    int iwakan[c][3];
    rep(i,c)rep(j,3)iwakan[i][j] = 0;
    rep(i,c)rep(j,n)rep(k,n){
        iwakan[i][(j+k)%3] += d[c2[j][k]-1][i];
    }
    rep(i,c) rep(j,c) rep(k,c){
        if(i == j || j == k ||k == i)continue;
        int ans2 = iwakan[i][0]+iwakan[j][1]+iwakan[k][2];
        if(ans2 < ans)ans = ans2;
    }
    cout << ans << endl;
    return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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



void func(long long N, std::vector<long long> L){

    SORT(L);

    lli ans = 0;
    REP(i,0,N){
        REP(j,i+1,N){
            if(L[i]==L[j])continue;
            REP(k,j+1,N){
                if(L[i]==L[k] || L[k]==L[j])continue;
                if(L[i]+L[j] <= L[k])continue;
                ans++;
            }
        }
    }
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

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


Measured memory_bytes: 3692
#include<iostream>
using namespace std;
int main()
{
  string t,s;
  cin>>s>>t;
  int min_change=t.size();
  for(int i=0;i<s.size()-t.size()+1;i++)
  {
   int j=i;
   int change=t.size();
   while(j<i+t.size())
   {
     if(s[j]==t[j-i])
        change--;
        j++;
   }
   if(change<min_change)
    min_change=change;
  }
  cout<<min_change<<endl;
return 0;}


Measured memory_bytes: 3628
/*********************
*  Author: xuziyuan  * 
*********************/
 
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

LL h,num=1,ans=0;

int main()
{
	cin>>h;
	while(h>0)
	{
		h/=2;
		ans+=num;
		num*=2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 200000;
int N;
int X[MAX_N];

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

  cin >> N;
  rep(i, N) cin >> X[i];

  vector<int> v;
  rep(i, N) v.push_back(X[i]);
  sort(all(v));
  
  int mid1 = v[N/2-1];
  int mid2 = v[N/2];

  for (int i = 0; i < N; ++i) {
      if (X[i] <= mid1) {
          cout << mid2 << endl;
      } else {
          cout << mid1 << endl;
      }
  }

  return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define pb push_back
#define inf 1e16
#define mod 1000000007
#define en '\n'
#define ld long double
ll pw(ll b, ll r){
	ll ans = 1;
	while(r){
		if(r&1)ans = (ans*b)%mod;
		b = (b*b)%mod;
		r>>=1;
	}
	return ans;
}
ll par[100010];
ll size[100010];
ll fndpar(ll a){
	if(a==par[a])return a;
	return par[a]=fndpar(par[a]); 
}
bool uni(ll a, ll b){
	ll pa=fndpar(a),pb=fndpar(b);
	if(pa==pb)return false;
	par[pa]=pb;
	size[pb]+=size[pa];
	return true;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,m;cin>>n>>m;
	for(int i = 1 ; i <= n ; i ++ )par[i]=i,size[i]=1;
	stack<pi>stk;
	for(int i = 0 ; i < m ; i ++ ){
		ll a,b;cin>>a>>b;
		stk.push({a,b});
	}
	stack<ll>ans;
	ans.push({(n*(n-1))/2});
	while(!stk.empty()){
		ll a=stk.top().first, b= stk.top().second;
		stk.pop();
		ll pa = fndpar(a), pb = fndpar(b);
		if(pa!=pb){
			ans.push(ans.top()-size[pa]*size[pb]);
			uni(a,b);
		} else ans.push(ans.top());
	}
	ans.pop();
	while(!ans.empty()){
		cout<<ans.top()<<en;
		ans.pop();
	}
	return 0 ; 
}



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

int main(){
  int n,m;
  cin >> n >> m;
  if(m>n){
    cout << -1 << endl;
    return 0;
  }
  int t = 0;
  rep(i,m){
    int a;
    cin >> a;
    t +=a;
    if(t>n){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << n-t << endl;
  return 0;
}


Measured memory_bytes: 3624
#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()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n,m,x;
    cin >> n >> m >> x;
    set<int> a;
    rep(i,m) {
        int k;
        cin >> k;
        a.insert(k);
    }
    int l = 0,r = 0;
    for(int i = x-1; i > 0; i--) {
        if(a.count(i)) l++;
    }
    rep2(i,x+1,n){
        if(a.count(i)) r++;
    }
    cout << min(l,r) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;
int main(){
  int h,w;
  int count=0;
  cin>>h>>w;
  char n[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>n[i][j];
      if(n[i][j]=='#')
        count++;
    }
  }
  if(count==(h+w-1))
    cout<<"Possible"<<endl;
  else
    cout<<"Impossible"<<endl;
}

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


def main():
    N, A, B = [int(x) for x in input().split()]
    ans = (B - A) // 2
    if (B - A) % 2 == 1:
        ans1 = A - 1
        B1 = (B - ans1)
        ans1 = ans1 - (-(B1 - 1) // 2)
        ans2 = N - B
        A1 = (A + ans2)
        ans2 = ans2 - (-(N - A1) // 2)
        print(min(ans1, ans2))
    else:
        print(ans)





if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[100000];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	
	rep(i, n) if (a[i] > 0) break;
	if (i == n) { cout << "Yes" << endl; return 0; }
	if (n % 3 != 0) { cout << "No" << endl; return 0; }
	
	rep(i, n) if (a[i] == 0) break;
	if (i < n) {
		int cnt = 0, t = -1;
		rep(i, n) if (a[i] != 0) { t = a[i]; cnt++; }
		if (cnt != n / 3 * 2) { cout << "No" << endl; return 0; }
		rep(i, n) if (a[i] != 0 && a[i] != t) break;
		if (i < n) { cout << "No" << endl; return 0; }
		cout << "Yes" << endl; return 0;
	}
	
	map<int, int> mp;
	rep(i, n) {
		mp[a[i]]++;
	}
	if (mp.size() != 3) { cout << "No" << endl; return 0; }
	
	vector<int> vec;
	for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {
		if (it->second != n / 3) { cout << "No" << endl; return 0; }
		vec.push_back(it->first);
	}
	if ((vec[0] ^ vec[1]) != vec[2]) { cout << "No" << endl; return 0; }
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 4224
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

bool check(const vector<int>& v)
{
    for(int i=1; i<30; ++i){
        if(i == 9 || i == 12 || i == 15 || i == 18 || i == 21)
            continue;
        if(v[i] != v[i-1])
            return false;
    }
    return true;
}

int solve(const vector<int> init)
{
    vector<vector<int> > a =
    {
        {1, 4, 7, 10, 24, 27, 30, 21},
        {3, 6, 9, 12, 22, 25, 28, 19},
        {1, 2, 3, 15, 28, 29, 30, 16},
        {7, 8, 9, 13, 22, 23, 24, 18}
    };
    vector<vector<int> > b =
    {
        {16, 17, 18},
        {15, 14, 13},
        {21, 20, 19},
        {10, 11, 12}
    };

    queue<vector<int> > q;
    set<vector<int> > s;
    q.push(init);
    s.insert(init);

    int ans = -1;
    for(;;){
        ++ ans;
        int n = q.size();
        while(--n >= 0){
            vector<int> v = q.front();
            q.pop();
            if(check(v))
                return ans;

            for(int i=0; i<4; ++i){
                vector<int> v2 = v;
                for(int j=0; j<8; ++j)
                    v2[a[i][j]-1] = v[a[i][(j+4)%8]-1];
                for(int j=0; j<3; ++j)
                    v2[b[i][j]-1] = v[b[i][2-j]-1];

                if(s.find(v2) == s.end()){
                    q.push(v2);
                    s.insert(v2);
                }
            }
        }
    }
}

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

    while(--n >= 0){
        vector<int> v(30);
        for(int i=0; i<30; ++i)
            cin >> v[i];

        cout << solve(v) << endl;
    }
}

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

using namespace std;

int n, ans;

string s, t;

int main() {
    cin >> n;

    cin >> s;
    cin >> t;

    for (int i = 0; i <= n; i++) {
        bool isGood = true;
        for (int j = i; j < n; j++) {
            if (s[j] != t[j - i]) {
                isGood = false;
            }
        }

        if (isGood) {
            ans = i + n;

            break;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N, M, X; cin >> N >> M >> X;
	ll a = 0, b = 0;
	rep(i, 0, M) {
		ll m; cin >> m;
		if (m < X)a++;
		if (m > X)b++;
	}
	cout << min(a, b) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main ()
{
   int N,a=0;
   scanf ("%d",&N);
   if (N<=999)
   {
      a=N%10;
      if (a==2||a==4||a==5||a==7||a==9)
      {
          printf ("hon\n");
      }
      else if (a==0||a==1||a==6||a==8)
      {
          printf ("pon\n");
      }
      else
      {
          printf ("bon\n");
      }
   }
   return 0;
}



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

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            String str = Console.ReadLine();
            int S = int.Parse(str);
            int s = S % 60;
            int m = S / 60;
            int h = m / 60;
            m = m % 60;
            Console.WriteLine(h + ":" + m + ":" + s);
            
            
           
         

        }
    }
}

Measured memory_bytes: 5612
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  bool cond = s[0] == '7' || s[1] == '7' || s[2] == '7';

  cout << (cond? "Yes" : "No") << endl;

  return 0;
}


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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n,k,ans=1;cin>>n>>k;
  rep(i,n) ans*2<ans+k ? ans*=2 : ans+=k;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=(int) n;i--)
#define p(s) cout<<(s)<<endl
#define DEBUG(x,y) cout<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl;
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;

int A[55];
ll dp[55][2];
int main(){
	int N,P;
	cin>>N>>P;
	REP(i,0,N) cin>>A[i];
	dp[0][0]=1;
	dp[0][1]=0;
	REP(i,0,N){
		if(A[i]%2==0) {
			dp[i+1][0]=dp[i][0]*2;
			dp[i+1][1]=dp[i][1]*2;
		}else{
			dp[i+1][0]=dp[i][1]+dp[i][0];
			dp[i+1][1]=dp[i][0]+dp[i][1];
		}
	}
	p(dp[N][P]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
#define NIL -1
using ll = long long;
const ll MOD = 1000000007;
#define REP(i,n) for (ll i=0; i < (n); ++i)
#define FOR(i,a,b) for (ll i=(a); i < (b); ++i)
using namespace std;

int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

  int n;
  cin >> n;
  vector<int> b(n-1);
  REP(i,n-1) cin >> b[i];

  int sum = b[0] + b[n-2];
  FOR(i,1,n-1) {
    sum += min(b[i-1], b[i]);
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
cin>>head;
CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair

int main(){
  CIN(n,a);V x(n);
  VECCIN(x);
  //dp[i][j][k] : i番目までの中からj個選んで総和がk
  vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(n*50+1,0)));
  dp[0][0][0]=1;
  REP(i,n){
    REP(j,n){
      REP(k,n*50+1){
        if(dp[i][j][k]!=0){
          dp[i+1][j][k]+=dp[i][j][k];
          if(k+x[i]<n*50+1)dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
        }
      }
    }
  }
  ll ans=0;
  int i=1;
  while(a*i<n*50+1&&i<n+1){ans+=dp[n][i][i*a];i++;}
  COUT(ans);


  return 0;
}


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

string s;
int numjoi,numioi,i;

int main(){
	while(cin >> s){
		numioi=numjoi=0;
		i=0;
		while(1){
			i=s.find("JOI",i);
			if(i<0)break;
			//cout <<i<<" ";
			numjoi++;
			i++;
		}
		i=0;
		while(1){
			i=s.find("IOI",i);
			if(i<0)break;
			//cout <<i<<" ";
			numioi++;
			i++;
		}
		cout <<numjoi <<endl;
		cout <<numioi <<endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#define rep(i, s, n) for(int i = s; i < n; i++)
using namespace std;
#define N 1000000000
#define ll long long

int main() {
    unsigned int n, k, s;
    cin >> n >> k >> s;
    
    vector<int> ans(n, 1);
    if(s < N) {
        rep(i, 0, k) ans[i] = s;
        rep(i, k, n) ans[i] = s+1;
    }
    else if(s == N) {
        rep(i, 0, k) ans[i] = s;
    }
    rep(i, 0, n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
a, b = map(int, input().split())

def f(x):
    if x % 2 == 1:
        if (x + 1) // 2 % 2 == 1:
            return 1
        else:
            return 0
    else:
        if x // 2 % 2 == 1:
            return 1 ^ x
        else:
            return x

print(f(a - 1) ^ f(b))

Measured memory_bytes: 3316
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			Collections.reverse(list.subList(sc.nextInt(), sc.nextInt()));
		}
		StringBuilder sb = new StringBuilder();
		for (int num : list) {
			sb.append(num + " ");
		}
		String str = sb.toString();
		str = str.substring(0, str.length() - 1);
		System.out.println(str);
		sc.close();
	}
}




Measured memory_bytes: 32892
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 1000000007
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;


int main()
{
	int n, a = 0, w = 0, t = 0, r = 0;
	cin >> n;
	string s;
	rep(i, 0, n) {
		cin >> s;
		if (s == "AC")a++;
		if (s == "WA")w++;
		if (s == "TLE")t++;
		if (s == "RE")r++;
		}
	cout << "AC x " << a << endl;
	cout << "WA x " << w << endl;
	cout << "TLE x " << t << endl;
	cout << "RE x " << r << endl;
}

Measured memory_bytes: 3636
N = int(input())
K = int(input())
from functools import lru_cache

@lru_cache(maxsize=100000000000)
def dp(n, k): #0以上n以下の数で０でない数字がちょうどk個あるもの。
  if k == 0:
    return 1
  elif n == 0:
    return 0
  else:
    n = int(n)
    s = str(n)
    digit = len(s)
    m, fdigit = divmod(n,10)
    if m >= 1:
        return int(dp(m, k-1) * fdigit + dp(m-1, k-1)* (9-fdigit) + dp(m, k))
    elif k == 1:
        return n
    elif k == 2 or k == 3:
        return 0
    else:
        return 1
if K == 0:
    answer = dp(N, K)-1
else:
    answer = dp(N, K)
print(int(answer))

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

struct Dice{
    int f1,f2,f3,f4,f5,f6;

    Dice()=default;

    void rotate(string command){
        REP(i,command.size()){
            int c_f1=f1,c_f2=f2,c_f3=f3,c_f4=f4,c_f5=f5,c_f6=f6;
            if(command[i]=='N'){
                f1=c_f2;
                f2=c_f6;
                f6=c_f5;
                f5=c_f1;
            }else if(command[i]=='S'){
                f1=c_f5;
                f2=c_f1;
                f6=c_f2;
                f5=c_f6;
            }else if(command[i]=='W'){
                f1=c_f3;
                f3=c_f6;
                f6=c_f4;
                f4=c_f1;
            }else if(command[i]=='E'){
                f1=c_f4;
                f3=c_f1;
                f6=c_f3;
                f4=c_f6;
            }           
        }
    }
};

int main(){
    Dice d;
    string com;
    cin>>d.f1>>d.f2>>d.f3>>d.f4>>d.f5>>d.f6;
    cin>>com;

    d.rotate(com);

    cout<<d.f1<<endl;
}


Measured memory_bytes: 3208
N = int(input()) 
s = str(input())
L=list(s)
L = [int(s) for s in L]
x=0
L1=[]
for i in range(N):
  L2=[]
  if not L[i] in L1:
    L1.append(L[i])
    for j in range(i+1,N):
      if not L[j] in L2:
        L2.append(L[j])
        x+=len(set(L[j+1:N]))
print(x)

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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> all_sushi[100010];

    for (int i = 0; i < N; i++) {
        ll t, d;
        cin >> t >> d;
        all_sushi[t - 1].push_back(d);
    }

    vector<ll> y0, y1;
    for (int i = 0; i < N; i++) {//合計N個
        if(all_sushi[i].size()==0)
            continue;
        sort(all(all_sushi[i]));
        y1.push_back(all_sushi[i].back());
        all_sushi[i].pop_back();
        y0.insert(y0.end(), all_sushi[i].begin(), all_sushi[i].end());
    }

    sort(y0.rbegin(), y0.rend());
    sort(y1.rbegin(), y1.rend());

    ll res = 0;
    int Y = max(0, K - int(y0.size()));
    ll X = 0;

    for (int i = 0; i < Y; i++) {
        X += y1[i];
    }
    for (int i = 0; i < K-Y; i++) {
        X += y0[i];
    }

    while(1){
        res = max(res, X + (ll)Y * Y);
        if(Y>=K||Y>=y1.size())break;
        X += y1[Y];
        X -= y0[K - Y - 1];
        Y++;
    }

    cout << res << endl;

    return 0;
}

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

#define endl '\n'

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

    int n,k, r, s, p; cin >> n >> k >> r >> s >> p;
    string t; cin >> t;
    int ans = 0;
    char used[n];
    for (int i=0; i<n; i++){
        if (t[i] == 'r'){
            if (i-k < 0 || used[i-k] != 'p'){
                used[i] = 'p';
                ans += p;
            } else used[i] = '@';
        } else if (t[i] == 's'){
            if (i-k < 0 || used[i-k] != 'r'){
                used[i] = 'r';
                ans += r;
            } else used[i] = '@';
        } else{
            if (i-k < 0 || used[i-k] != 's'){
                used[i] = 's';
                ans += s;
            } else used[i] = '@';
        }
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  long suma=0,sumaa=0;
  long sumb=0,sumbb=0;
  for(int i=0;i<n;i++){
    long a;
    cin >> a;
    suma+=a;
    sumb+=a;
    if(i%2==0){
      if(suma>=0){
        sumaa+=suma+1;
        suma=-1;
      }
      if(sumb<=0){
        sumbb+=-sumb+1;
        sumb=1;
      }
    }
    else{
      if(suma<=0){
        sumaa+=-suma+1;
        suma=1;
      }
      if(sumb>=0){
        sumbb+=sumb+1;
        sumb=-1;
      }
    }
  }
  cout << min(sumaa,sumbb);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    vector<int> c(m);
    vector<int> a(n);
    vector<vector<int>> sum(m,vector<int>(n+1));
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i]--;
        c[a[i]]++;
        for(int j=0;j<m;j++){
            if(j==a[i]){
                sum[j][i+1]=sum[j][i]+1;
            }
            else{
                sum[j][i+1]=sum[j][i];
            }
        }
    }
    vector<int> dp(1<<m,n);
    dp[0]=0;
    for(int i=0;i<(1<<m);i++){
        int t=0;
        for(int j=0;j<m;j++){
            if(i&(1<<j)){
                t+=c[j];
            }
        }
        for(int j=0;j<m;j++){
            if(i&(1<<j)){
                continue;
            }
            chmin(dp[i|(1<<j)],dp[i]+c[j]-(sum[j][t+c[j]]-sum[j][t]));
        }
    }
    cout << dp[(1<<m)-1] << endl;
}


Measured memory_bytes: 15044
#include <stdio.h>
#define MAX 251
 
int parent(int i){
  return i/2;
}
 
int left(int i){
  return 2*i;
}
 
int right(int i){
  return 2*i+1;
}
 
int main(void){

  int i,n,heap[MAX];

  scanf("%d",&n);

  for(i = 1; i <= n; i++){
    scanf("%d",&heap[i]);
  }
 
  for(i = 1; i <= n; i++){
    printf("node %d: key = %d, ",i,heap[i]);

    if(i > 1){
    printf("parent key = %d, ",heap[parent(i)]);
    }

    int l=left(i);
    int r=right(i);

    if(l <= n){
    printf("left key = %d, ",heap[l]);
    }
    if(r <= n){
    printf("right key = %d, ",heap[r]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
vector<ll>d[4];
int main()
{
	int num;
	ll gen;
	scanf("%d%lld", &num, &gen);
	ll base;
	for (int i = 0; i < num; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		if (i == 0)base = za;
		d[za - base].push_back(zb);
	}
	for (int i = 0; i < 4; i++)
	{
		sort(d[i].begin(), d[i].end());
		d[i].push_back(0);
		reverse(d[i].begin(), d[i].end());
		for (int j = 1; j < d[i].size(); j++)d[i][j] += d[i][j - 1];
	}
	ll ans = 0;
	for (int i = 0; i < d[0].size(); i++)
	{
		for (int j = 0; j < d[1].size(); j++)
		{
			for (int k = 0; k < d[2].size(); k++)
			{
				for (int l = 0; l < d[3].size(); l++)
				{
					if (base*i + (base + 1)*j + (base + 2)*k + (base + 3)*l <= gen)
					{
						ans = max(ans, d[0][i] + d[1][j] + d[2][k] + d[3][l]);
					}
				}
			}
		}
	}
	printf("%lld\n", ans);
}

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

int main(){
    int n;
    cin >> n;
    vector<int> L(n);
    for (int i = 0; i < n;i++){
        cin >> L.at(i);
    }
    sort(L.begin(), L.end());
    int sum = 0;
    for (int i = 0; i < n-1;i++){
        sum += L.at(i);
    }
    puts(L.at(n-1) < sum ? "Yes" : "No");
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    Vec a(n);
    Vec f(n);
    rep(i,n){
        ll tmp;
        cin>>tmp;
        a[i]=tmp;
    }
    rep(i,n){
        ll tmp;
        cin>>tmp;
        f[i]=tmp;
    }
    sort(ALL(a));
    sort(ALL(f),greater<>{});

    ll l=-1; ll r=1e13;

    while (l+1<r){
        ll c = (l+r)/2;
        bool ok=[&]{
            ll sum=0;
            rep(i,n){
                sum += max(0LL,a[i]-c/f[i]);
            }
            //dbg(sum);
            return sum <= k;
        }();
        if(ok){
            r = c;
        }else{
            l = c;
        }
       // dbg(c);
    }
    cout<<r<<endl;
    return  0;
}


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

int main() {
  while (true) {
    int N, a, count = 0;
    cin >> N;
    if (N == 0) break;
    // Nを2個以上の連続する正整数の和で表す方法の数はnの3以上の奇数の約数の個数に等しい
    for (int i = 1; i <= sqrt(N); i++) {
      if (N % i == 0) {
        a = N / i;
        if (a > 2 && a % 2 == 1) count++;
        if (i > 2 && a != i && i % 2 == 1) count++;
      }
    }
    cout << count << endl;
  }
}


Measured memory_bytes: 3072