akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define ld long double
    #define MOD 998244353
    #define mod9 1000000009
    #define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #define mp make_pair
    #define pb push_back
    #define ct ll t;cin>>t;while(t--)
    #define bi begin()
    #define ei end()
    #define fi first 
    #define se second  
    #define foe(i,a,b) for(ll i=a;i<b;i++)
    #define rfoe(i,a,b) for(ll i=a;i>=0;i--)
    #define sz(s) s.size() 
    #define mem(a,s) memset(a,s,sizeof(a)) 
    #define all(v) v.bi,v.ei
    #define MAX             8000000000000000064LL
    #define MIN            -8000000000000000064LL   

    typedef pair<ll,ll> pii;
    
    ll add(ll a, ll b){return (a%MOD + b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll sub(ll a, ll b){return (a%MOD - b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll mul(ll a, ll b){return ((a%MOD)*(b%MOD) + ((MAX)/MOD)*MOD)%MOD;}
    ll lcm(ll a,ll b){return(a*b)/__gcd(a,b);}
    ll fact[1000007]={0};
    ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
    y=y>>1;x=(1ll*x*x)%MOD;} return res;}
    void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%MOD;}
    ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],MOD-2)))%MOD; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res;}
    ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
    int const N=2e5+9;
    ll const INF = 2e18+5;
    ll dx[8]={0,0,1,-1,1,1,-1,-1};
    ll dy[8]={1,-1,0,0,-1,1,-1,1};
    
    void solve()
    {  
      ll a,b,c,d;
      cin>>a>>b>>c>>d;
      cout<<max(b*d,max(a*c,max(a*d,b*c)))<<"\n";
        // ll x,y;
        // if(b>0&&d>0)
        // {
        //     cout<<b*d<<"\n";
        //     return;
        // }
        // if(b>0&&d<=0)
        // {
        //     cout<<d*a<<"\n";
        //     return;
        // }       
        // if(d>0&&b<=0)
        // {
        //     cout<<b*c<<"\n";
        //     return;
        // }
        // if(b<0&&d<0)
        // {
        //     cout<<b*d<<"\n";
        //     return;
        // }
        // if(b==0&&d==0)
        // {
        //     cout<<a*c<<"\n";
        //     return;
        // }
        // if(b==0||d==0)
        // {
        //     i
        // }
    }
    int main()
    {
        // fast
        // facto();
        // Sieve();
    //    ct    
        { 
            solve();
        }
    }


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
#define fi first
#define INF 1000000000
#define sec second
#define pb push_back
using namespace std;
typedef pair<int,int> P;

int n, k;
int cost[100];
vector<P> e[100];

void dijkstra(int s, int E){
	queue<P> que;
	rep(i,100) cost[i] = INF;
	cost[s] = 0;
	que.push(P(s,0));
	while(true){
		if(que.size() == 0) break;
		P p = que.front(); que.pop();
		if(cost[p.fi] < p.sec) continue;
		rep(i,e[p.fi].size()){
			if(cost[e[p.fi][i].fi] > p.sec+e[p.fi][i].sec){
				cost[e[p.fi][i].fi] = p.sec+e[p.fi][i].sec;
				que.push(P(e[p.fi][i].fi,cost[e[p.fi][i].fi]));
			}
		}
	}
	if(cost[E] == INF) printf("-1\n");
	else printf("%d\n", cost[E]);
}

int main(){
	while(scanf("%d%d", &n, &k),n||k){
		rep(i,100) e[i].clear();
		rep(i,k){
			int a; scanf("%d", &a);
			if(a == 0){
				int b, c; scanf("%d%d", &b, &c);
				b--; c--;
				dijkstra(b,c);
			} else{
				int b, c, d; scanf("%d%d%d", &b, &c, &d);
				b--; c--;
				e[b].pb(P(c,d));
				e[c].pb(P(b,d));
			}
		}
	}
}

Measured memory_bytes: 1248
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	int X[3];
	cin >> N >> X[0] >> X[1] >> X[2];
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int INF = (int)1 << 50;

	int res = INF;

	for (int i = 0; i < (1ll << (2 * N)); i++) {

		int S[4];
		int T[4];
		for (int j = 0; j < 4; j++) {
			S[j] = 0;
			T[j] = 0;
		}
		for (int j = 0; j < N; j++) {
			S[(i >> (j * 2)) & 3] += A[j];
			T[(i >> (j * 2)) & 3]++;
		}
		int c = 0;
		for (int j = 0; j < 3; j++) {
			if (T[j] == 0)c += INF;
			c += (T[j] - 1) * 10;
			c += abs(X[j] - S[j]);
		}
		res = min(res, c);

	}


	cout << res << endl;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
#define TRACE

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

const int N = 100005;
const int M = 200005;

vector<pii> con[N];
ll dist[N];
bool vis[N];
bool ok = 1;
void dfs(int s, ll d){
	if(vis[s] && dist[s] != d){
		ok = 0;
		return;
	}
	if(vis[s]) return;
	dist[s] = d;
	vis[s] = 1;
	for(auto it : con[s]){
		int v = it.F;
		ll D = d + it.S;
		dfs(v, D);
	}
}

int main(){
	int n, m;
	sd(n); sd(m);
	for(int i = 1;i <= m; i++){
		int l, r, d;
		sd(l); sd(r); sd(d);
		con[l].pb({r, d});
		con[r].pb({l, -d});
	}
	for(int i = 1; i <= n; i++) if(!vis[i]) dfs(i, 0);
	if(!ok){
		cout << "No" << endl;
	}
	else printf("Yes\n");
}

Measured memory_bytes: 11520
s=input()
l=s[0]+s[1]
m=s[2]+s[3]
month=['01','02','03','04','05','06','07','08','09','10','11','12']
if month.count(l)==1 and month.count(m)==1:
    print('AMBIGUOUS')
elif month.count(l)==1 and month.count(m)==0:
    print('MMYY')
elif month.count(m)==1 and month.count(l)==0:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];

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

    cout << a[N-1] - a[0] << endl;    
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890l
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define space " "
#define cbr cout << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, m; ll ans = 0;
ll f(ll x, ll i)
{
	++x;
	ll ans = x/(1ll<<(i+1)) * (1ll<<i);
	ans += max(0ll, ( (x%(1ll<<(i+1))) - (1ll<<i)));
	return ans;
}
int main()
{
	cin>>n>>m;
	for(ll i = 0; i <= 40; i++)
	{
		ll amt = f(m,i) - f(n-1,i);
		// if(i<3)cout << amt << '\n';
		if(amt%2) ans ^= (1ll<<i);
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,c,max;
  c=1;
  cin >> n;
  vector <int>a(n);
  for (int i=0;i<n;i++)
  cin >> a.at(i);
  max=a.at(0);
for(int i=1;i<n;i++){
    if(a.at(i)>=max){
        c++;
        max=a.at(i);
    }
}
  cout << c << endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h,w;
  while(1){
    cin>>h>>w;
  if(h==0&&w==0)break;
  for(int i=0; i<w; i++){
    cout<<"#";
}
  cout<<"\n";
    for(int i=0; i<h-2; i++){
      cout<<"#";
    for(int i=0; i<w-2; i++){
      cout<<".";
    }
    cout<<"#\n";
    }
for(int i=0; i<w; i++){
    cout<<"#";
 }
    cout<<"\n\n";
  }
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N+2),B(N+1);
    for(int i=1;i<=N+1;i++) cin >> A[i];
    for(int i=1;i<=N;i++) cin >> B[i];
    long long killed = 0;
    for(int i=1;i<=N;i++){

        if(A[i] <= B[i]){
            killed += A[i];
            B[i] -= A[i];
            A[i] = 0;
        } else {
            killed += B[i];
            A[i] -= B[i];
            B[i] = 0;
        }

        if(A[i+1] <= B[i]){
            killed += A[i+1];
            B[i] -= A[i+1];
            A[i+1] = 0;
        } else {
            killed += B[i];
            A[i+1] -= B[i];
            B[i] = 0;
        }
    }
    
    cout << killed << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <random>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

int D;
vi C, S[370], T, V, cost;

int calc_minus(int day){
    int res = 0;
    rep(i, 26){
        res += C[i] * (day - cost[i]); 
    }
    return res;
}

int calc_S(vi t){
    ll ans = 0;
    cost.resize(26, 0);

    rep(i, D){
        ans += S[i][t[i]-1];
        cost[t[i]-1] = i+1;
        ans -= calc_minus(i+1);
    }

    return ans;
}

int get_max_c(int day){
    int res = -1, tmp = 0;

    rep(i, 26){
        if(tmp < S[day][i] + C[i]){
            res = i;
            tmp = S[day][i] + C[i];
        }
    }

    return res;
}

void solve(){
    int Score = calc_S(T);

    rep(k, 2000){
        int tmpd = rand() % D;
        int tmpc = rand() % 26 + 1;
        int tmpScr;

        swap(T[tmpd], tmpc);
        tmpScr = calc_S(T);

        if(Score >= tmpScr){
            swap(T[tmpd], tmpc);
        } else {
            Score = tmpScr;
            // cout << Score << endl;
        }
    }

    rep(i, D) cout << T[i] << endl;
}

int main(){
    cin >> D;
    C.resize(26);
    T.resize(D, 1);
    
    
    rep(i, 26){
        cin >> C[i];
    }   

    rep(i, D){
        S[i].resize(26);
        rep(j, 26) cin >> S[i][j];
    }

    solve();
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int N;
    cin >> N;
    map<ll, ll> mp;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        mp[a]++;
    }

    ll ans=0;
    for (map<ll,ll>::iterator iter=mp.begin(); iter != mp.end(); iter++){
        if (iter->second % 2 == 1) {
            ans++;
        }
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll N, M;
    cin >> N >> M;
    // E[X] = 1 / (1 << M) + (100 * (N - M) + 1900 * M) + ((1 << M) - 1) / (1 << M) * (E[X] + 100 * (N - M) + 1900 * M)
    // 1 / (1 << M) E[X] = (1 / (1 << M) + (((1 << M) - 1) / (1 << M))) * (100 * (N - M) + 1900 * M)
    // E[X] = (1 << M) * (100 * (N - M) + 1900 * M)
    cout << (1LL << M) * (100LL * (N - M) + 1900LL * M) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, x, y, z, s, ans = 0;
  ll a[101], b[101], c[101];
  rep(i, 101) a[i] = b[i] = c[i] = 0;
  cin >> n;
  cin >> x;
  rep(i, x) {
    cin >> s;
    a[s]++;
  }
  cin >> y;
  rep(i, y) {
    cin >> s;
    b[s]++;
  }
  cin >> z;
  rep(i, z) {
    cin >> s;
    c[s]++;
  }
  rep(i, 101) {
    if((!a[i] && c[i]) || (b[i]) && c[i]) ans++;
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif


constexpr int mod = 1'000'000'007;

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);

    int n; std::cin >> n;
    if(n < 3){ std::cout << "0\n"; return 0; }
    std::vector<int> dp(n + 1, 0), sum(n + 1, 0);
    dp[0] = 1;
    sum[1] = 1; sum[2] = 1;
    for(int i = 3; i <= n; ++i){
        dp[i] = dp[i - 3] + sum[i - 3]; if(dp[i] >= mod) dp[i] -= mod;
        sum[i] = dp[i - 1] + sum[i - 1]; if(sum[i] >= mod) sum[i] -= mod;
    }
    std::cout << dp[n] << '\n';
    return 0;
}

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

#define BUF_SIZE 400

int comp(const void* a, const void* b) {
  return *(int*)b - *(int*)a;
}

int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];

  int num;
  int i;
  char *tmpbuf;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  sscanf(line, "%d", &num);

  // line 2
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  tmpbuf = line;
  int* arr = malloc(sizeof(int)*(num+1));
  for(i = 0; i < num; i++) {
    char *buf = strtok(tmpbuf, " ");
    arr[i] = strtol(buf, NULL, 10);
    tmpbuf = NULL;
  }
  arr[num] = 0;
  qsort(arr, num, sizeof(int), comp); // descending

  int diff = 0;
  for(i = 0; i < num; i += 2) {
    diff += arr[i] -  arr[i+1];
  }

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


  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#define INF 1000000000
using namespace std;
typedef pair<int,int> P;
struct edge{
    int to,cost;
};
vector<edge> G[100000];
int d[100000];
int main(){
    int v,e,r;
    scanf("%d %d %d",&v,&e,&r);
    for(int i=0;i<e;i++){
        int s,t,d;
        edge k;
        scanf("%d %d %d",&s,&t,&d);
        k.cost=d;
        k.to=t;
        G[s].push_back(k);
    }
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+v,INF);
    d[r]=0;
    que.push(P(0,r));
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int x=p.second;
        if(p.first>d[x]) continue;
        for(int i=0;i<G[x].size();i++){
            edge e=G[x][i];
            if(e.cost+d[x]<d[e.to]){
                d[e.to]=e.cost+d[x];
                que.push(P(d[e.to],e.to));
            }
        }
    }
    for(int i=0;i<v;i++){
        if(d[i]!=INF)
            printf("%d\n",d[i]);
        else printf("INF\n");
    }
    return 0;
}

Measured memory_bytes: 11184
using System;
using System.Collections.Generic;
using System.Linq;

namespace StringsConcat
{
    class Program
    {
        static void Main(string[] args)
        {
            var st = Console.ReadLine().Split();
            string S = st[0];
            string T = st[1];
            Console.WriteLine(T + S);
        }
    }
}


Measured memory_bytes: 11092
from heapq import heappush, heappop, heapify
N, M = map(int, input().split())
a = [-int(a) for a in input().split()]
heapify(a)
for _ in range(M):
  heappush(a, heappop(a) / 2)
print(sum(int(-x) for x in a))


Measured memory_bytes: 14180
N = int(input())
L = []
S = []
for i in range(N):
    L.append(input())
    C, P = L[i].split()
    S.append('{:s} {:3d}'.format(C, 100-int(P)))
S.sort()

LS = []
for i in range(N):
    C, P = S[i].split()
    LS.append('{:s} {:d}'.format(C, 100-int(P)))
    
for i in range(N):
    for j in range(N):
        if LS[i] == L[j]:
            print(j+1)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String[] input = sc.next().split("");
		boolean[] alpha = new boolean[26];
		int count = 0;
		for (String string : input) {
			int pos = string.toCharArray()[0]-97;
			if (alpha[pos]) {
				continue;
			} else {
				alpha[pos] = true;
				count++;
				if (count == 26) {
					System.out.println("None");
					System.exit(0);
				}
			}
		}
		for (int i = 0; i < alpha.length; i++) {
			if (!alpha[i]) {
				System.out.println((char)(i+97));
				break;
			}

		}
	}
}

Measured memory_bytes: 48088
import bisect


def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    ans = 0
    for b in B:
        ans += bisect.bisect_left(A, b) * (N - bisect.bisect_right(C, b))
    print(ans)


main()


Measured memory_bytes: 23156
n, k, q = map(int, input().split())
score = {i: 0 for i in range(n)}
for i in range(q):
    a = int(input()) - 1
    score[a] += 1

for i in range(n):
    if k - q + score[i] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 15084
#include <stdio.h>
#include <string>
#include <algorithm>
using namespace std;
char in[110];
int main(){
    int a,b;scanf("%d%d",&a,&b);
    for(int i=0;i<b;i++)in[i]='0'+a;
    string L=in;
    for(int i=0;i<a;i++)in[i]='0'+b;
    string R=in;
    printf("%s\n",min(L,R).c_str());
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main() {
    int A,B,K;
    cin >> A >> B >> K; 
    int i = 100;
    int Y = 0;
    while(Y < K){
        if(A % i == 0 && B % i == 0){
            Y++;
             i = i - 1; 
        }
        else{ 
            i = i - 1; 
        }
        }
        i++;
    cout << i << endl;
}

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

int dist[2005][2005];
int cnt[2005];
int main(){
	int n,x,y;
	cin >> n >> x >> y;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			dist[i][j] = j-i;
			int tmp = j-i;
			dist[i][j] = min(dist[i][j],abs(i-x)+abs(j-y)+1);
			cnt[dist[i][j]]++;
		}
	}
	for(int i=1;i<n;i++)
		cout << cnt[i] << endl;
}

Measured memory_bytes: 15360
#include <stdio.h>

long long pow10[16]=
{     1,     10,     100,     1000,     10000,
 100000,1000000,10000000,100000000,1000000000,
 1000000000,10000000000,100000000000,1000000000000,10000000000000,
 100000000000000};
 
int main(void){
    // Your code here!
    long long N;
    scanf("%lld",&N);
    
    long long Sn = 0;
    for(int r = 1; r <= 10; r++){
        Sn += (N/pow10[r-1]) %10; 
        //printf("%lld,",  (N/pow10[r-1]) %10);
    }
    //printf("Sn=%d",Sn);
    if(N % Sn == 0L) puts("Yes");
    else puts("No");
}

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

using namespace std;

int main(){
    int x;
    cin >> x;
    // if (x < 600) {
    //     cout << 8;
    // }
    // else if (x < 800){
    //     cout << 7;
    // }
    // else if (x < 1000){
    //     cout << 6;
    // }
    // else if (x < 1200){
    //     cout << 5;
    // }
    // else if (x < 1400){
    //     cout << 4;
    // }
    // else if (x < 1600){
    //     cout << 3;
    // }
    // else if (x < 1800){
    //     cout << 2;
    // }
    // else{
    //     cout << 1;
    // }
    cout<<8-((x-400)/200);
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>

typedef unsigned long long ll;

const ll MAX = 1000; 

int main() {
  ll N, M;

  scanf("%lld", &N);
  scanf("%lld", &M);

  ll ans;
  if (N == 1 && M == 1) {
    ans = 1;
  } else if (N == 1) {
    ans = M - 2;
  } else if (M == 1) {
    ans = N - 2;
  } else {
    ans = N * M - (N * 2 + M * 2 - 4);
  }
  printf("%lld\n", ans);

  return 0;
}


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

int main(){
  int p,i,j,k,l,m,n,gx,gy,dp[17][17],map[17][17][17][17];
  int N;
 
  
  cin >> n;
  for( N = 0; N < n; N++){

    for(i = 0; i < 17; i++){
      for(j = 0; j < 17; j++){
	dp[i][j]=0;
	for(k = 0; k < 17; k++){
	  for(l = 0; l < 17; l++){
	    map[i][j][k][l]=0;
	  }
	}
      }
    }
    
    dp[1][1]=1;
    
    cin >> gx >> gy;
    gx++;
    gy++;

    cin >> p;
    for(m  = 0; m < p; m++){
      cin >> i >> j >> k >> l;
      map[i+1][j+1][k+1][l+1]=1;
      map[k+1][l+1][i+1][j+1]=1;
      
    }
    for(i = 1; i < gx+1; i++){
      for(j = 1; j < gy+1; j++){
	if(map[i][j][i-1][j]!=1){
	  dp[i][j]+=dp[i-1][j];
	  
	}
	if(map[i][j][i][j-1]!=1){
	  dp[i][j]+=dp[i][j-1];
	}
      }
    }
    if( dp[gx][gy]==0){
      cout<<"Miserable Hokusai!"<<endl;
    }else{
      cout << dp[gx][gy] << endl;
    }
  }

  
  return 0;
}

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

const ll INF = 100100100100;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (auto &h : H) cin >> h;
  vector<ll> C(N, INF);
  C[0] = 0;
  rep(i, N - 1) {
    for (int k = i + 1; k <= min(i + K, N - 1); k++) {
      int cost = abs(H[i] - H[k]);
      C[k] = min(C[k], C[i] + cost);
    }
  }
  std::cout << C.back() << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>

void kaijo(int);
void kaijo2(int);
void kaijo5(int);

int count2,count5;

int main(void)
{
  int n,i;

  while(1)
    {
      scanf("%d",&n);
      if(n==0)break;
      count2=0;
      count5=0;

      kaijo(n);

      if(count2>count5)printf("%d\n",count5);
      else printf("%d\n",count2);
    }
  return 0;
}

void kaijo(int n)
{
  int i;

  for(i=n;i>0;i--)
    {
      kaijo2(i);
      kaijo5(i);
}
}

void kaijo2(int n)
{
  while(1)
    {
      if(n%2!=0)break;
      n=n/2;
      count2++;
    }
}

void kaijo5(int n)
{
  while(1)
    {
      if(n%5!=0)break;
      n=n/5;
      count5++;
    }
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int R;
  std::cin >> R;
  std::cout << 2 * 3.141592 * R << '\n';
}

Measured memory_bytes: 3764
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 100000;
int n;
ll a[MAX_N + 1];
ll mx[MAX_N + 1];
ll mn[MAX_N + 1];

int main() {
    fastio();

    cin >> n;
    forn(i, n + 1) cin >> a[i];

    mx[n] = a[n];
    for (int i = n - 1; i >= 0; i--) {
        mx[i] = a[i] + mx[i + 1];
    }

    bool ok = true;

    ll ans = mn[0] = 1;
    ok &= mn[0] >= a[0];
    for (int i = 1; i <= n; i++) {
        mn[i] = min(2LL * (mn[i - 1] - a[i - 1]), mx[i]);
        ok &= mn[i] >= a[i];
        ans += mn[i];
    }

    ok &= mn[n] == a[n];

    if (ok) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5956
//ドワンゴプログラミングコンテストソース
#include <bits/stdc++.h>

using namespace std;
int main(){

	int n;
	int a[110]={};
	double num=0.0;
	double hoge=0.0;
	double count=100000;
	int number=0;
	cin>>n;
	
	for(int i=0;i<n;i++){
	cin>>a[i];
	num+=a[i];
	}
	//cout<<num;
	num=num/n;
	//cout<<num;
	
	for(int i=0;i<n;i++){
		hoge = abs(num-a[i]);
		if(hoge<count){
		count=hoge;
			
			number=i;
		}
		//cout<<number<<" ";
	}
	
	cout<<number<<endl;
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static long solve(long K , long A[]){
		long low = 0;
		long high = 0;
		for(long a : A){
			high = Math.max(a, high);
		}
		while(high - low > 1){
			long mid = (high + low) / 2;
			long X = 0;
			for(long a : A){
				long n = ((a + mid - 1) / mid);
				X += n - 1;
			}
			if(X > K){
				low = mid;
			}else{
				high = mid;
			}
		}
		return high;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long A[] = new long[N];
		for(int i = 0 ; i < N ; ++i){
			A[i] = sc.nextLong();		
		}
		System.out.println(solve(K , A));
	}
}


Measured memory_bytes: 62876
N,M=map(int,input().split())
G=[[] for _ in range(M)]
for i in range (M):
  L,R=map(int,input().split())
  G[i].append([L,R])
small=[]
for i in range(M):
  small.append(G[i][0][0])
s=max(small)
large=[]
for i in range(M):
  large.append(G[i][0][1])
l=min(large)
if s<=l:
  ans=l-s+1
else:
    ans=0
print(ans)

Measured memory_bytes: 32332
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader br=  new BufferedReader(new InputStreamReader(System.in));
		
		String[] in = br.readLine().split(" ");
		int n = Integer.parseInt(in[0]);
// 		int k = Integer.parseInt(in[1]);
		
// 		StringBuilder str = new StringBuilder();
		int[][] arr=  new int[n][3];
		for(int i=0;i<n;i++){
		    in = br.readLine().split(" ");
		    arr[i][0] = Integer.parseInt(in[0]);
		    arr[i][1] = Integer.parseInt(in[1]);
		    arr[i][2] = Integer.parseInt(in[2]);
		}
		int ans = Math.max(arr[0][0],Math.max(arr[0][1],arr[0][2]));
		for(int i=1;i<n;i++){
		    arr[i][0] += Math.max(arr[i-1][1],arr[i-1][2]);
		    arr[i][1] += Math.max(arr[i-1][0],arr[i-1][2]);
		    arr[i][2] += Math.max(arr[i-1][0],arr[i-1][1]); 
		    if(i==n-1){
		        ans = Math.max(arr[i][0],Math.max(arr[i][1],arr[i][2]));
		    }
		}
        System.out.println(ans);
	}
}


Measured memory_bytes: 47040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char b;
  cin>>b;
  char ans = 'A';
  if(b=='A'){
    ans = 'T';
  }
  else if(b=='C'){
    ans = 'G';
  }
  else if(b=='G'){
    ans = 'C';
  }
  cout<< ans <<endl;
}

Measured memory_bytes: 256
n=int(input())
S=input()

maxx=0
for i in range(1,n):
    l={}
    r={}
    for j in range(i):
        if S[j] in l:
            l[S[j]]+=1
        else:
            l[S[j]]=1
    for j in range(i,n):
        if S[j] in r:
            r[S[j]]+=1
        else:
            r[S[j]]=1
    count=0
    for c in l:
        if c in r:
            count+=1
    maxx=max(maxx,count)

print(maxx)

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

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define int ll
#define endl "\n"
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define all( x ) x.begin(), x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);

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

const int inf = 1e9 + 5;
const long double PI = 3.141592653589793;

vector<int> dp(1e6 + 5, 0);
void solve(){
  int n;
  cin>>n;
  int x = n, y;
  while(x--){
    cin>>y;
    dp[y]++;
  }
  y = 0;
  for(int i=1;i<=1e6;i++){
    if(!dp[i]){
      continue;
    }
    int j = 2 * i;
    while(j<=1e6){
      dp[j] = false;
      j+=i;
    }
    if(dp[i] == 1){
      y++;
    }
  }
  cout<<y<<endl;
}  
signed main(){
  fast;
  int t;
  t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}


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

for cnt in range(K):
  B = [0] * (N+1)
  for i in range(N):
    bright = A[i]
    l = max(i-bright,0)
    r = min(i+bright+1, N)
    B[l] += 1
    B[r] -= 1
  for i in range(N):
    B[i+1] += B[i]
  
  A = B[:-1]
  #print(A)
  if min(A) == N:
    #print(cnt)
    break
    
print(" ".join(map(str,A)))



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

int main() {
    string S, C, bS, eS;
    ll Q;
    int T, F;
    cin >> S >> Q;
    int revf = false;
    rep(i, Q) {
        cin >> T;
        if (T == 1) {
            revf ^= true;
        } else {
            cin >> F >> C;
            if (revf) {
                if (F == 1) {
                    eS = eS + C;
                } else {
                    bS = C + bS;
                }
            } else {
                if (F == 1) {
                    bS = C + bS;
                } else {
                    eS = eS + C;
                }
            }
        }
    }

    S = bS + S + eS;
    if (revf) {
        for (ll i = S.size() - 1; i >= 0; i--) {
            cout << S[i];
        }
    } else {
        cout << S;
    }
    cout << endl;
}

Measured memory_bytes: 1464
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int l;
    int length = 2;
    int input[length];
    for(int i = 0;i < length && cin>>l;i++){
        input[i] = l;
    }
    long out[length];
    out[0] = input[0] * input[1];
    out[1] = (input[0] + input[1]) * 2;
    cout << out[0] << " " << out[1] << endl;
    return 0;
}



Measured memory_bytes: 3084
// One-stroke Path
#include <iostream>
using namespace std;

int n,m;
int a,b,d[100][100];
bool visited[100];

int dfs(int v){
    bool all_visited=true;
    for(int i=0;i<n;i++)if(visited[i]==false) all_visited=false;
    if(all_visited) return 1;
    int r=0;
    for(int i=0;i<n;i++){
        if(d[v][i]&&!visited[i]){
            visited[i]=true;
            r+=dfs(i);
            visited[i]=false;
        }
    }
    return r;
}

int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        d[a-1][b-1]=1;
        d[b-1][a-1]=1;
    }
    visited[0]=true;
    cout<<dfs(0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vvi s = vvi(m);
  rep(i, m) {
    int k;
    cin >> k;
    s[i] = vector<int>(k);
    rep(j, k) {
      int now;
      cin >> now;
      s[i][j] = now - 1;
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];

  int ans = 0;
  rep(i, pow(2, n)) {
    int now = 0;
    rep(j, m) {
      int count = 0;
      rep(k, s[j].size()) {
        if((i >> s[j][k]) & 1) {
          count++;
        }
      }
      if(count % 2 == p[j]) {
        now++;
      }
    }
    if(now == m) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n, a, b = map(int,input().split())
s = list(str(input()))
a_Yes = 0
b_Yes = 0

for i in range(n):
    if s[i] == "a":
        if  a_Yes + b_Yes <a+b:
            print("Yes")
            a_Yes += 1
        else:
            print("No")

    elif s[i] == "b" :
        if b_Yes < b and  a_Yes + b_Yes <a+b:
            print("Yes")
            b_Yes += 1
        else:
            print("No")

    else:
        print("No")


Measured memory_bytes: 4708
import itertools

h, w, k = map(int, input().split())
s = [0] * h
countH = [0] * h
countW = [0] * w
ans = []
ans_sub = [[0 for j in range(2)] for i in range(h * w)]
num = 0
ans_count = 0

for i in range(h):
    s[i] = list(input())
    for j in range(w):
        if s[i][j] == '#':
            ans_sub[num][0] = i
            ans_sub[num][1] = j + h
            ans.append(ans_sub[num])
            num += 1

lis = list(range(h + w))
#print(ans)

for n in range(h + w):
    for pair in itertools.combinations(lis, n + 1):
        count = 0
        for i in range(len(ans)):  # blacklist
            if (ans[i][0] not in pair) and (ans[i][1] not in pair):
                count += 1  # その黒がけずられないか
            
        if count == k:
            #print(len(ans), count)
            ans_count += 1
            #print(ans_count)
if k == len(ans):
    ans_count += 1

print(ans_count)


            

Measured memory_bytes: 9164
#include<iostream>
#include<vector>
#define INF 10000000
using namespace std;
vector<vector<int> > cost;
vector<int> mincost;
int s,d;
int prim(){
	vector<bool> used(d+1,false);
	mincost[0]=0;
	int res=0;
	while(1){
		int v=-1;
		for(int u=0;u<d+1;u++){
			if(!used[u]&&(v==-1||mincost[u]<mincost[v])){
				v=u;
			}
		}
		if(v==-1)
			break;
		used[v]=true;
		res+=mincost[v];
		for(int u=0;u<d+1;u++){
			mincost[u]=min(mincost[u],cost[v][u]);
		}
	}
	return res;
}
int main(){
	while(cin>>s>>d,s||d){
		cost=vector<vector<int> >(d+1,vector<int>(d+1,INF));
		mincost=vector<int>(d+1,INF);
		for(int i=0;i<s;i++){
			for(int j=0;j<d;j++){
				int x;
				cin>>x;
				if(!x)
				continue;
				cost[d][j]=min(cost[d][j],x);
				cost[j][d]=min(cost[d][j],x);
			}
		}
		for(int i=0;i<d-1;i++){
			for(int j=1;j<d-i;j++){
				int x;
				cin>>x;
								if(!x)
				continue;

				cost[i][i+j]=x;
				cost[i+j][i]=x;
			}
		}
		cout<<prim()<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
typedef long long ll;
int dp[maxn];
int main()
{
    for(int i=0;i<maxn;i++){
        dp[i]=1e9;
    }
    dp[0]=0;
    for(ll i=0;i<=maxn;i++){
        dp[i+1]=min(dp[i+1],dp[i]+1);
        for(ll j=6;i+j<=maxn;j*=6){
            dp[i+j]=min(dp[i+j],dp[i]+1);
        }
        for(ll j=9;i+j<=maxn;j*=9){
            dp[i+j]=min(dp[i+j],dp[i]+1);
        }
    }
    int n;
    cin>>n;
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 7544
#include <iostream>
#include <deque>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#define llint long long
#define mod 998244353
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

llint n;
llint a[200005];
llint dp[200005][5];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 5; j++){
			dp[i][j] = inf;
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 5; j++){
			if(j == 0 || j == 4) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + a[i+1]);
			if(j == 1 || j == 3){
				if(a[i+1] > 0) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + a[i+1]%2);
				else dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 2);
			}
			if(j == 2) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1-a[i+1]%2);
		}
		for(int j = 1; j < 5; j++) dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-1]);
	}
	cout << dp[n][4] << endl;
	
	return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  UnionFind uf(n);
  rep(i, m){
    cin >> a[i] >> b[i];
    a[i]--;b[i]--;
  }
  vector<ll> ans(m);
  ans[m-1]=(ll)n*(n-1)/2;
  for(int i=m-2; i>=0; i--){
    ll tmp=uf.size(a[i+1])*uf.size(b[i+1]);
    if(uf.same(a[i+1], b[i+1]))tmp=0;
    ans[i]=ans[i+1]-tmp;
    uf.unite(a[i+1], b[i+1]);
  }
  rep(i, m){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 5116
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forin(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define dbg(x) cerr<<#x<<" "<<x<<"\n";
#define yn {puts("YES");}else{puts("NO");}
#define maxs(x,y) (x = max(x,y))
#define sz(x) (int)(x).size()
#define mins(x,y) (x = min(x,y))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const int MAX = 100001;

int dp[MAX] = {};

int main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr); 
	int n, k ; 
	cin >> n>> k;
	vi h(n);
	forn(i,n) {
		cin >> h[i];
		dp[i] = 1000000007;
	}
	dp[0] = 0;
	forn(i,n){
		for1(j,k){
			if(i-j >= 0) mins(dp[i], abs(h[i]-h[i-j]) + dp[i-j]);
		}
	}
	cout << dp[n-1];
	return 0;
}





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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    cin >> N;
    vector<ll> A(N, 0);

    unordered_map<ll,ll> nums;
    ll sum = 0;
    REP(i, N){ cin >> A[i]; 
       nums[A[i]]++;
       sum += A[i];
    }

    ll Q;
    cin >> Q;

    REP(i, Q){
        ll B, C;
        cin >> B >> C;

        if( nums.find(B) == nums.end() ){
        }else{
            sum -= B * nums[B];
            sum += C * nums[B];
            nums[C] += nums[B];
            nums[B] = 0;
        }
        cout << sum << endl;
    }


}


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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
    int x;
    cin>>x;
    cout<<1-x<<endl;
}

Measured memory_bytes: 3632
import math
import itertools

def read():
    X, Y = list(map(int, input().strip().split()))
    return X, Y

def init_mod_combinations(MAX=500000, MOD=1000000007):
    fac = [0 for _ in range(MAX)]
    finv = [0 for _ in range(MAX)]
    inv = [0 for _ in range(MAX)]
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD
    return fac, finv, inv

def mod_combinations(n, k, MOD=1000000007):
    fac, finv, inv = init_mod_combinations(MAX=n+1, MOD=MOD)
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD


def solve(X, Y):
    # X = 2p + q, Y = p + 2q
    p = (2 * X - Y) // 3
    q = (2 * Y - X) // 3
    if 2*p+q!=X or p+2*q!=Y:
        # 到達不可能
        return 0
    # p+q 回の移動で到達可能
    # 移動パターンの総数は(p+q)Cp
    return mod_combinations(p+q, p)

if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)


Measured memory_bytes: 96272
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		int dx = tx-sx;
		int dy = ty-sy;

		System.out.print(String.join("", Collections.nCopies(dy, "U")));
		System.out.print(String.join("", Collections.nCopies(dx, "R")));

		System.out.print(String.join("", Collections.nCopies(dy, "D")));
		System.out.print(String.join("", Collections.nCopies(dx, "L")));

		System.out.print("L"+String.join("", Collections.nCopies(dy+1, "U")));
		System.out.print(String.join("", Collections.nCopies(dx+1, "R"))+"D");

		System.out.print("R"+String.join("", Collections.nCopies(dy+1, "D")));
		System.out.print(String.join("", Collections.nCopies(dx+1, "L"))+"U");

		sc.close();
	}
}

Measured memory_bytes: 23764
import java.util.*;
public class Main {
    public static void main(String args[]) {
      Scanner in = new Scanner(System.in);
      int n = in.nextInt();
      String k = in.next();
      int ans = 0;
      char[] arr = k.toCharArray(); int countW = 0; int countR = 0;
    //   for(int i = 0 ; i < n ; i++) if(arr[i] == 'W') countW++; else countR++;
      int left = 0 ; int right = n - 1;
      while(left < right){
          while(left < right && arr[left] != 'W') left++;
          while(left < right && arr[right] != 'R') right--;
          if(arr[left] == 'W' && arr[right] == 'R'){
          char temp = arr[left];
          arr[left] = arr[right];
          arr[right] = temp;
          ans++;}
          left++; right--;
      }
    //   if(countW == 0 || countR == 0) System.out.println(0);
      System.out.println(ans);
      
    }
}

Measured memory_bytes: 40672
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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




int main(){
    int N, M, A; std::cin >> N >> M;
    for(int i(0); i < M; ++i){
        std::cin >> A; N -= A;
    }
    std::cout << std::max(N, -1) << std::endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
using namespace std;

const double pi = acos(-1);

#define nyan cout<<"(=^•ω•^=)"<<endl;
#define int long long

int a,b,k;
int t;

signed main(){
    cin>>a>>b>>k;
    while(true){
        if(a%2==1)a--;
        b+=a/2;
        a/=2;
        t++;
        if(t==k)break;
        if(b%2==1)b--;
        a+=b/2;
        b/=2;
        t++;
        if(t==k)break;
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

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

int main(){
    int N, M, Q;
    std::cin >> N >> M >> Q;
    std::vector< int > A(Q);
    std::vector< int > B(Q);
    std::vector< int > C(Q);
    std::vector< int > D(Q);
    std::deque< std::vector< int > > pat;
    std::deque< std::vector< int > > pat_pre;
    for(int i=0; i<M; i++){
        std::vector< int > tmp(1, i);
        pat.push_back(tmp);
    }
    
    int cnt = 1;
    while(cnt < N){
        pat_pre = pat;
        pat.clear();
        while(!pat_pre.empty()){
            for(int i=pat_pre[0][pat_pre[0].size()-1]; i<M; i++){
                std::vector< int > tmp = pat_pre[0];
                tmp.push_back(i);
                pat.push_back(tmp);
            }
            pat_pre.pop_front();
        }
        cnt++;
    }
    
    for(int i=0; i<Q; i++){
        std::cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--;
        B[i]--;
    }
    
    int max = 0;
    while(!pat.empty()){
        int score = 0;
        for(int i=0; i<Q; i++){
            if(pat[0][B[i]] - pat[0][A[i]] == C[i]){
                score += D[i];
            }
        }
        if(max < score){
            max = score;
        }
        pat.pop_front();
    }
    
    
    std::cout << max << std::endl;
    return 0;
}



Measured memory_bytes: 10536