akhauriyash/Code-Regression huggingface dataset:
A = []
B = []
cnt = 0

for i in range(3):
    A.append(list(map(int, input().split())))

N = int(input())

for i in range(N):
    B.append(int(input()))

for i in range(3):
    for j in range(3):
        for k in B:
            if A[i][j] == k:
                A[i][j] = 0
import sys
for i in range(3):            
    if A[i][0]==0 and A[i][0]==A[i][1] and A[i][1]==A[i][2]:
        print('Yes')
        sys.exit()
    elif A[0][i]==0 and A[0][i]==A[1][i] and A[1][i]==A[2][i]:
        print('Yes')
        sys.exit()
    elif A[0][0]==0 and A[0][0]==A[1][1] and A[1][1]==A[2][2]:
        print('Yes')
        sys.exit()
    elif A[0][2]==0 and A[0][2]==A[1][1] and A[1][1]==A[2][0]:
        print('Yes')
        sys.exit()

print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define printmx(matrix) Loop(i, matrix.size()) { Loop(j, matrix[i].size()) { cout << matrix[i][j] << " "; } cout << endl; }
#define rnd(d) (ll)((double)(d) + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)(x) ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define ceildiv(a, b) ((ll)(a) / (ll)(b) + ((ll)(a) % (ll)(b) == 0 ? 0 : 1))
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

/*******************************************************/


int main() {
	int n; cin >> n;
	vll a(n); Loop(i, n) cin >> a[i];
	map<ll, ll> mp;
	ll sum = 0;
	Loop(i, n) {
		sum += a[i];
		mp[sum]++;
	}
	ll ans = 0;
	sum = 0;
	Loop(i, n) {
		ans += mp[sum];
		sum += a[i];
		mp[sum]--;
	}
	cout << ans << endl;
}

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

int main()
{
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    if(s == "Cloudy") cout << "Rainy" << endl;
    if(s == "Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		Pattern pattern=Pattern.compile("@\\d.");
		for(; sc.hasNext();){
			String s=sc.next();
			
			Matcher matcher=pattern.matcher(s);
			while(matcher.find()){
				String match=matcher.group();
				int n=match.charAt(1)-'0';
				char c=match.charAt(2);
				String ss="";
				for(int i=0; i<n; i++)
					ss+=c;
				s=s.replaceFirst(matcher.group(), ss);
			}
				println(s);

			/**
			 * 			String s=sc.next();
			while(true){
			
			Matcher matcher=pattern.matcher(s);
			if(matcher.find()){
				String match=matcher.group();
				int n=match.charAt(1)-'0';
				char c=match.charAt(2);
				String ss="";
				for(int i=0; i<n; i++)
					ss+=c;
				s=s.replaceFirst(matcher.group(), ss);
			}else{
				println(s);
				break;
			}
			}
			 */
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 12000
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "utility"

// typedef std::pair<int,int> pint;

int main(int argc, char const *argv[]) {

  int NN, MM, QQ;
  std::cin >> NN>> MM>> QQ;

  int um[NN][NN];


  for (size_t i = 0; i < NN; i++) {
    for (size_t i2 = 0; i2 < NN; i2++) {
      um[i][i2] =0;
    }
  }

  for (size_t i = 0; i < MM; i++) {
    int L, R;
    scanf("%d", &L);
    scanf("%d", &R);
    um[L-1][R-1] +=1;
  }


  int consum[NN+1][NN+1];

  for (size_t i = 0; i < NN; i++) {
    consum[i][0] = 0;
    for (size_t i2 = 1; i2 < NN+1; i2++) {
      consum[i][i2] = consum[i][i2-1] + um[i][i2-1];
    }
  }

  // std::cout << "consum::::::::::::" << '\n';
  //
  // for (size_t i = 0; i < NN; i++) {
  //   for (size_t i2 = 0; i2 < NN; i2++) {
  //     std::cout << consum[i][i2] << ' ';
  //   }
  //   std::cout  << '\n';
  // }
  //
  // std::cout << "consum::::::::::::" << '\n';



  int ans[QQ];

  for (size_t i = 0; i < QQ; i++) {
    int p, q;
    scanf("%d", &p);
    scanf("%d", &q);

    int sum = 0;
    for (size_t i = p-1; i < q; i++) {
      sum += consum[i][q] - consum[i][p-1];
    }
    ans[i] = sum;
    // std::cout << sum << '\n';
  }

  for (size_t i = 0; i < QQ; i++) {
    std::cout << ans[i] << '\n';
  }

  return 0;
}


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)
int main(){
	int n;
	string s;
	cin >> n >> s;
	int maxi = 0;
	int x = 0;
	//sを0~n-1文字目まで前から見ていく
	for(int i = 0; i < n; i++){
		if(s[i] == 'I')x++; //sのi文字目を参照して指示通りにxを操作
		else x--;

		maxi = max(maxi,x); //毎回最大値を更新
	}
	cout << maxi << endl;
	return 0;
}

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

struct rec{
	int i, pi, ci;
};

int main() {
	int d, g;
	std::cin >> d >> g;

	std::vector<rec> v;
	v.resize(d);
	for (int i{}; i < d; ++i) {
		v[i].i = 1+i;
		std::cin >> v[i].pi >> v[i].ci;
	}

	int ans{1<<30};
//	std::cout << ans << "\n";
	for (int i{ 0 }; i < (1 << d); ++i) {

		int sum{}, count{}, max_rem{};
		for (int j{ 0 }; j < d; ++j) {
			if (1 & (i >> j)) {
//				std::cout << i << " >> " << j << " => " << (i>>j) << "\n";
				sum += v[j].ci + v[j].pi*(v[j].i) * 100;
				count += v[j].pi;
//				std::cout << count << "\n";
			}else {
				max_rem = j;
			}
		}


		if (sum < g) {

			auto x = v[max_rem].i * 100;
			auto additional = (g - sum + x-1) / x;
//			std::cout << g << " " << sum << " " << x << " " << additional << "\n";
			if (additional >= v[max_rem].pi)
				continue;

			count += additional;
			sum += additional * x;
		}

		if (sum >= g) {
//			std::cout << ans << "\n";
			ans = std::min(ans, count);
		}
	}
	
	std::cout << ans << "\n";

	return 0;
}

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

namespace _142_Nature_of_Prime_Numbers
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				int num = int.Parse (inputStr);
				int halfNum = num / 2;

				int[] mod = new int[halfNum];

				for (int lp = 1; lp < halfNum + 1; lp++)
				{
					mod[lp - 1] = (lp * lp) % num;
				}

				HashSet<int> uniqueMod = new HashSet<int> (mod);
				List<int> uniqueList = uniqueMod.ToList ();
				uniqueList.Sort (( item1, item2 ) => item2 - item1);

				int[] counter = new int[halfNum];

				for (int lp = 0; lp < uniqueList.Count; lp++)
				{
					for (int lp2 = lp + 1; lp2 < uniqueList.Count; lp2++)
					{
						int subtract = uniqueList[lp] - uniqueList[lp2];

						if (halfNum < subtract)
						{
							subtract = num - subtract;
						}

						counter[subtract - 1] += 2;
					}
				}

				foreach (var item in counter)
				{
					Console.WriteLine (item);
				}

			}
		}
	}
}



Measured memory_bytes: 10288
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    while (1) {
        int n, m; cin >> n >> m;

        if (n == 0 && m == 0) break;

        vi c(m); REP(i, m) cin >> c[i];
        vi x(n); REP(i, n) cin >> x[i];

        vll cur(256, INF);
        cur[128] = 0;

        auto round = [](int x) -> int {
            if (x < 0) return 0;
            if (x > 255) return 255;
            return x;
        };

        REP(i, n) {
            vll nxt(256, INF);
            REP(j, 256) {
                REP(k, m) {
                    int y = round(j + c[k]);
                    nxt[y] = min(nxt[y], cur[j] + (x[i] - y) * (x[i] - y));
                }
            }

            swap(cur, nxt);
        }

        ll ans = INF;
        for(auto &e: cur) ans = min(ans, e);

        print(ans);
    }
}


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

int main(){
  string s;
  while(cin >> s, s != "0"){
    vector<long long> dp(11,0);
    long long ans = 0;
    for(auto c : s){
      int d = c-'0';
      vector<long long> dp_(11,0);
      for(int i = 0; i < 11; ++i){
        dp_[(i*10+d)%11] += dp[i];
      }
      if(d)
        dp_[d] += 1;
      dp = dp_;
      ans += dp[0];
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3280
#include <stdio.h>
#define INFNITY 900000
#define N 100
#define W 0
#define G 1
#define B 2


int data[N][N];

int prim(int);

int main(){
  int n,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
        scanf("%d",&data[i][j]);
      if(data[i][j]==-1){
      data[i][j]=INFNITY;
      }
    }
  }

  i=prim(n);
   
   printf("%d\n",i);

  return 0;
}


int prim(int n){//プリム                                                             
  int i,p[N],d[N],color[N],minv,u,sum=0;

  for(i=0;i<n;i++){
    d[i]=INFNITY;
    p[i]=-1;
    color[i]=W;
      }

     d[0]=0;



  while(1){
    minv=INFNITY;
    u=-1;

    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=B){
        u=i;
        minv=d[i];
      }
    }

    if(u==-1) break;

    color[u]=B;
    for(i=0;i<n;i++){
      if(color[i]!=B && data[u][i]!=INFNITY){
        if(d[i]>data[u][i]){
          d[i]=data[u][i];
          p[i]=u;
          color[i]=G;
        }
      }
    }
  }
    for(i=0;i<n;i++){
      if(p[i]!=-1) sum=sum+data[i][p[i]];
    }
  

return sum;
  }






Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W,K,answer=0;
  cin>>H>>W>>K;
  vector<vector<int>> chocolate(H,vector<int>(W));
  for(int i=0;i<H;i++){
    string S;
    cin>>S;
    for(int j=0;j<W;j++){
      chocolate.at(i).at(j)=S.at(j)-'0';
    }
  }
  //分けない場合
  int white=0;
  for(int i=0;i<W;i++){
    int count=0;
    for(int j=0;j<H;j++){
      if(chocolate.at(j).at(i)==1){white++;count++;}
    }
    if(count>K){answer=10000;break;}
    if(white>K){
      i--;
      white=0;
      answer++;
    }
  }
  //分ける場合
  for(int bit=1;bit<(1<<(H-1));bit++){
    queue<int> q;
    for(int i=0;i<H-1;i++){
      if(bit&1<<i){q.push(i);}
    }
    int ans=q.size();
    q.push(H-1);
    queue<int> qcopy=q;
    unordered_map<int,int> mp;
    int check=-1;
    for(int h=0;h<W;h++){
      int a=0,b=q.front(),c=q.size();
      for(int j=0;j<c;j++){
        for(int i=a;i<=b;i++){
          if(chocolate.at(i).at(h)==1){mp[a]++;}
        }
        if(mp[a]>K){
          if(h==check){check=-2;break;}
          check=h;
          h--;
          mp.clear();
          ans++;
          break;
        }
        a=b+1;
        q.pop();
        b=q.front();
      }
      if(check==-2){ans=10000;break;}
      q=qcopy;
    }
    answer=min(answer,ans);
    mp.clear();
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 3668
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(N)]

for i in range(N):
    if i == N-1:
        B[i] = K - A[i] + A[0]
    else:
        B[i] = A[i+1] - A[i]

C = sum(B) - max(B)

print(C)


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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.first << ", " << p.second << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int x;
    cin >> x;
    if (x == 1) {
        cout << 1;
    } else {
        int closest = -1;
        for (int i = 2; i < x; i++) {
            int cur_val = i;
            int cur_pow = 2;
            while (cur_val <= x) {
                cur_val = pow(i, cur_pow);
                cur_pow++;
            }
            int actual_pow = cur_pow - 2;
            int actual_val = pow(i, actual_pow);
            if (closest < actual_val && actual_pow > 1) {
                closest = actual_val;
            }
        }
        cout << closest;
    }
}


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

int main(){
  int N,K,x,cnt;
  cin >> N >> K;
  vector<int> A(1000,0);
  for(int i=1; i<=K; i++){
    int d;
    cin >> d;
    for(int j=1; j<=d; j++){
      cin >> x;
      A.at(x)++;
    }
  }  
    for(int l=1; l<=N; l++){
      if(A.at(l)==0){
        cnt++;
      }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(){
  int i,j,k;
  int A[5];
  
  for(i=0;i<5;i++){
    scanf("%d",&A[i]);
  }
  int tmp;
  for (i=0; i<5; ++i) {
    for (j=i+1; j<5; ++j) {
      if (A[i]%10 < A[j]%10) {
        tmp =  A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }

  for(i=0;i<5;i++){
    if(A[i]%10 == 0)
      break;
  }
  
  for(j=0;j<i-1;j++){
    k+=(A[j]/10 +1 )*10;
  }
  k+=A[i-1];
  for(j=i;j<5;j++){
    k+=A[j];
  }
  printf("%d\n",k);
  return 0;
}
    

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iostream>
#include <utility>
 
using namespace std;
using ll = long long;
using ld = long double;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;

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

ll n, k;

Vl h(100001);

int main() {
    cin >> n >> k;
    REP(i,n) { cin >> h[i]; }
    Vl dp(n + 1, 1e18);
    dp[0] = 0;
    FOR(i, 1, n-1) {
        int start =  max(0,int(i-k));
        FOR(j, start, i-1) {
            dp[i] = min(dp[i], abs(h[i] - h[j]) + dp[j]);
        }
    }
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		int taro[128], hana[128];
		rep (i, n)
			cin >> taro[i];
		rep (i, m)
			cin >> hana[i];

		int diff = accumulate(taro, taro + n, 0) - accumulate(hana, hana + m, 0);
		int taro_swap = 1919, hana_swap = 810;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				if (2 * (taro[i] - hana[j]) == diff
					&& taro[i] + hana[j] < taro_swap + hana_swap)
					taro_swap = taro[i], hana_swap = hana[j];
		if (taro_swap == 1919)
			puts("-1");
		else
			printf("%d %d\n", taro_swap, hana_swap);
	}
}

Measured memory_bytes: 0
import numpy as np
N = int(input())
Alist = np.array(list(map(int, input().split())), dtype=np.int64)
Blist = np.array(list(map(int, input().split())), dtype=np.int64)
sbn = Alist - Blist
sei = sbn[sbn > 0]
hu = sbn[sbn < 0]

if sum(sei) < abs(sum(hu)):
    print(-1)
elif len(hu) == 0:
    print(0)
else:
    sei = np.sort(sei)[::-1].cumsum()
    print(len(hu) + np.argmax(sei >= abs(sum(hu))) + 1)


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


void solve(long long N, std::vector<long long> A){
  long double acc = 0;
  for(long long i = 0; i < N; i++){
    acc += (1.0l/A[i]);
  }

  cout << (1.0/acc) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
    solve(N, std::move(A));
    return 0;
}


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

using namespace std;

long long root(long long x, vector<long long>& par) {
	if (par[x] < 0) return x;
	return par[x] = root(par[x], par);
}

int main() {
	long long N;
	int M;
	cin >> N >> M;
	vector<pair<long long, long long>> E(M);
	for (long long i = 0; i < M; i++) cin >> E[i].first >> E[i].second;
	vector<long long> Ans(M);
	vector<long long> par(N, -1);
	Ans[M - 1] = N * (N - 1) / 2;
	for (int i = M - 1; i >= 1; i--) {
		long long a = E[i].first, b = E[i].second;
		Ans[i - 1] = Ans[i];
		long long ra = root(a - 1, par);
		long long rb = root(b - 1, par);
		if (ra != rb) {
			Ans[i - 1] -= -par[ra] * (-par[rb]);
			par[rb] += par[ra];
			par[ra] = rb;
		}
	}
	for (long long a : Ans) cout << a << endl;
}


Measured memory_bytes: 6376
import java.util.Scanner;

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

	void solver() {
		Scanner sc = new Scanner(System.in);

		int n = -1;
		while (n != 0) {
			n = sc.nextInt();
			if(n==0)
				break;
			double[] x = new double[n];
			double[] y = new double[n];
			for (int i = 0; i < n; i++) {
				x[i] = sc.nextDouble();
				y[i] = sc.nextDouble();
			}
			long ans = 1;
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					if (dis_sq(x[i], y[i], x[j], y[j]) > 4)
						continue;
					double[][] c = calc_center(x[i], y[i], x[j], y[j]);
					for (int sign = 0; sign < 2; sign++) {
						long sum = 2;
						double cx = c[sign][0];
						double cy = c[sign][1];
						for (int k = 0; k < n; k++) {
							if (k == i || k == j)
								continue;
							if (dis_sq(cx, cy, x[k], y[k]) <= 1) {
								sum++;
							}
						}
						ans= Math.max(ans, sum);
					}
				}
			}
			System.out.println(ans);
		}
	}

	double[][] calc_center(double x1, double y1, double x2, double y2) {
		double[][] c = new double[2][2];
		double t = Math.sqrt(1 / ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) - 1.0 / 4.0);
		c[0][0] = (x1 + x2) / 2 + (y1 - y2) * t;
		c[0][1] = (y1 + y2) / 2 + (x2 - x1) * t;
		c[1][0] = (x1 + x2) / 2 - (y1 - y2) * t;
		c[1][1] = (y1 + y2) / 2 - (x2 - x1) * t;
		return c;
	}

	double dis_sq(double x1, double y1, double x2, double y2) {
		return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	}
}

Measured memory_bytes: 69408
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
	return ans;
}
int yakusuunowa(int n) {
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0)ans += i;
	}
	return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int ketanowa(int n) {
	int cnt = 0, sum = 0;
	for (int i = 10; i <= n * 10; i *= 10) {
		if (i == 10)cnt += n % i;
		else sum += (n%i - n % (i / 10)) / (i / 10);
	}
	return cnt + sum;
}
signed main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
	ll
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define FAMILY -1
#define MAX 100000
int par[MAX];
int deg[MAX];
int *chil[MAX];
int dep(int);
void input(void);
void output(void);
int i,j,n, id, k;
int main(void){
    // node number
    scanf("%d", &n);
    // initialize
    for(i=0; i<n; i++)  par[i] = FAMILY;
    input();
    output();
    
}
void input(void){
    for(j=0; j<n; j++){
        scanf("%d%d", &id, &k);
        deg[id] = k;
        chil[id] = (int*)malloc(sizeof(int)*k);
        i=0;
        while(i<k){
            scanf("%d", &chil[id][i]);
            par[chil[id][i]] = id;
            i++;
        }
    }
}

void output(void){
    for(i=0; i<n; i++){
        printf("node %d: parent = %d, depth = %d, ", i, par[i], dep(i));
        if(par[i] == FAMILY) printf("root, [");
        else if(deg[i] == 0) printf("leaf, [");
        else    printf("internal node, [");
        j=0;
        while(j<deg[i]){
            printf("%d", chil[i][j]);
            if(j < deg[i] - 1)   printf(", ");
            j++;
        }
        printf("]\n");
    }
}
int dep(int num){
    if(par[num] == FAMILY)  return 0;
    else    return dep(par[num]) + 1;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define UB upper_bound
#define LB lower_bound
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define be(a) (a).begin(),(a).end()
#define deb(x) cout<< #x <<" "<<endl;
#define deb2(x, y) cout<< #x <<" "<< x <<endl<< #y <<" "<<y<<endl
#define fo(i, n) for(long long i=0; i<n; i++)
#define Fo(i, n, k) for(long long i=k; i<n; i++)
#define mod 1000000007
#define int long long

typedef long long ll;

void fileIO()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
typedef vector<pair<int, int>> vll;
typedef unordered_map<int, int> ump;



bool sortbysecdesc(const pair<int, int> &a, 
                    const pair<int, int> &b) 
{ 
    return a.second>b.second;
}



int32_t main()
{
    IOS;
    int T;
    T = 1;
    //cin>>T;

    while(T--)
    {
        int n;
        cin>>n;
        int *a = new int[n];
        int *b = new int[n];
        int *c = new int[n];

        for(int i = 0; i<n; i++)cin>>a[i]>>b[i]>>c[i];

        int ans = 0;
        int dp[n][3];

        dp[0][0] = a[0]; dp[0][1] = b[0]; dp[0][2] = c[0];

        for(int i = 1; i<n; i++)
        {
            dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
            dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
            dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
        }

        cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));


        delete [] a;
        delete [] b;
        delete [] c;
        
    }
    
    return 0;
}



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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

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

    int ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N;i++){
        cin >> h[i];
    }
    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < N;i++){
        dp[i] = min(dp[i - 1] + abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
p = list(map(int, input().split()))

check = []

for x in range(N):
    check.append(x + 1)

count = 0
for y in range(N):
    if check[y] != p[y]:
        count += 1

if count <= 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
# include <bits/stdc++.h>
# define maxn 200005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define pb push_back
# define mp make_pair
# define int ll
using namespace std;

int32_t main(){_
	//freopen("input","r",stdin);
	int x;
	cin >> x;
	int a = 0;
	x--;
    while(x % 11 != 0) x--,a++;
    if(a == 0) a = 0;
    if(a > 5) a = 2;
    else a = 1;
    rc((x / 11) * 2 + a);
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<int>ans(N);
	for (int i = 0; i < N*(N - 1) / 2; i++) {
		cin >> L >> R >> H >> W;
		L--;
		R--;
		if (H > W)ans[L] += 3;
		else if (H < W)ans[R] += 3;
		else {
			ans[L]++;
			ans[R]++;
		}
	}
	for (auto i : ans) {
		//cout << i << " ";
		int ret = 1;
		for (auto j : ans)ret += i < j;
		cout << ret << endl;
	}
	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n,d;
  cin >> n >> d;
  d = d * 2 + 1;
  int ans = (n + d - 1) / d;
  cout << ans << endl;
  return 0;
}

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

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

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

vll pl;

bool is_prime(const unsigned n) {
  if (n % 2 == 0 || n % 3 == 0) {
    if (n == 2 || n == 3) {
      return true;
    }
    return false;
  }
  if (n == 1) {
    return false;
  }

  for (unsigned i = 5; i * i <= n; i += 6) {
    if (n % i == 0 || n % (i + 2) == 0) {
      return false;
    }
  }

  return true;
}

// prime factorization (素因数分解)
// key: value of prime factor
// value: number of prime factor
std::map<ll, ll> prime_factorization(ll n) {
  std::map<ll, ll> prime_factors;
  for (ll i : pl) {
    if (i * i > n)
      break;

    while (n % i == 0) {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];

  set<ll> primes;

  REP(i, 1e6 + 10) {
    if (is_prime(i)) {
      pl.push_back(i);
    }
  }

  bool is_pairwise = true;

  rep(i, n) {
    auto pf = prime_factorization(a[i]);
    for (auto& p : pf) {
      auto it = primes.lower_bound(p.first);
      if (it != primes.end() && *it == p.first) {
        is_pairwise = false;
      } else {
        primes.insert(p.first);
      }
    }
  }

  ll all_gcd = a[0];
  rep(i, n) {
    all_gcd = gcd(all_gcd, a[i]);
  }

  if (is_pairwise) {
    cout << "pairwise coprime" << endl;
  } else if (all_gcd == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  return 0;
}


Measured memory_bytes: 15256
def d_no_need(N, K, A):
    from bisect import bisect_left
    # 値がK以上の要素は単体で不必要でない要素になれる
    A.sort()
    a_sorted = A[:bisect_left(A, K)]
    ans = len(a_sorted)  # a_sortedの要素は不必要となりうる

    dp = [False] * K  # dp[k]:a_sortedの一部の和を取った値をKにできるか？
    dp[0] = True
    current_max = 0
    for idx, a in reversed(list(enumerate(a_sorted))):
        if current_max + a >= K:
            ans = idx  # これを満たさないaは不必要

        # current_maxはループの中で1回だけ更新する。
        # jを変化させるたびに代入すると時間がかかるため
        updated = True
        for j in range(min(current_max, K - a - 1), -1, -1):
            if dp[j]:
                dp[j + a] = True  # 和をjにできているなら、j+aにもできる
                if updated:
                    current_max = max(current_max, j + a)
                    updated = False
    return ans

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(d_no_need(N, K, A))
# https://beta.atcoder.jp/contests/arc070/submissions/2980516 参考
# https://medaka.5ch.net/test/read.cgi/prog/1534548265/ の>>75によると
# 8 100
# 1 1 8 8 8 25 26 50
# に対して2や5を返すsubmissionが見られるとのこと(実際は0)

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

template<typename T>
vector<T> smallest_prime_factors(T n) {

    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;


    for (T i = 2; i * i <= n; i++) {

        // 素数だったら
        if (spf[i] == i) {

            for (T j = i * i; j <= n; j += i) {

                // iを持つ整数かつまだ素数が決まっていないなら
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }

    return spf;
}

template<typename T>
map<int32,int32> factolization(T x, vector<T> &spf) {
    map<int32,int32> ret;
    while (x != 1) {
        ret[spf[x]]++;
        x /= spf[x];
    }
    return ret;
}


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

  auto spf = smallest_prime_factors((int32)(1e6+10));

  int32 n;
  cin >> n;
  vector<int32> a(n);
  REP(i,n)cin >> a[i];

  set<int32> pf;
  bool pairwiseCoprime = true;
  REP(i,n){
    auto facts  = factolization(a[i],spf);
    for(auto x : facts){
      if(pf.count(x.fi)){
        pairwiseCoprime = false;
        break;
      }
      pf.insert(x.fi);
    }
    if(!pairwiseCoprime)break;
  }
  if(pairwiseCoprime){
    ANS("pairwise coprime");
    return 0;
  }

  int32 g = a[0];
  FOR(i,1,n)g = gcd(g,a[i]);
  if(g == 1){
    ANS("setwise coprime");
  }else{
    ANS("not coprime");
  }
  return 0;
}

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

int main() {
  string s;
  cin >> s;
  stack<char> t;
  for (auto e : s) {
    if (!t.empty() && e != t.top()) {
      t.pop();
    } else {
      t.push(e);
    }
  }
  cout << s.size() - t.size() << endl;
}


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

int main () {
  int x, y = 0;
  bool c = false;
  cin >> x >> y;
  for (int i = 0; i < 51; i++){
  if (2 * x + 2 * i == y && 2 * x <= y && y <= 4 * x ){
   c = true;
  }
  }
  if (c) {
  	cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3624
from itertools import permutations as perm
S = raw_input()
n = len(S)
dp = [[] for i in xrange(n)]
dp[0].append(int(S[0]))
for i in xrange(1,n):
	dp[i].append(int(S[:i+1]))
	for j in xrange(i):
		for k in dp[j]:
			dp[i].append(k+int(S[j+1:i+1]))
print sum(dp[n-1])

Measured memory_bytes: 2692
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll =          long long;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define repp(i,a,n)   for(int i=a;i<n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define w(t)          int t;cin>>t;while(t--)
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = 2e5+5;
const int MOD =(int)1e9+7;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    int t=5,ans=0,cnt=0;
    while(t--)
    {
        int a;
        cin>>a;
        cnt++;
        if(a==0)
        {
            ans=cnt;
            break;
        }
    }cout<<ans<<nl;
    return 0;
}


Measured memory_bytes: 3636
//  すぬけ君の塗り絵 2 イージー  WA
#include <bits/stdc++.h>
using namespace std;

int main(){
    int W, H, N;
    cin >> W >> H >> N;
    int x[N], y[N], a[N];
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i] >> a[i];
    }
    int xl=0, yd=0;
    int xr=W, yu=H;
    for(int i=0; i<N; i++){
        if(a[i]==1){
            xl=max(xl, x[i]);
        }
        if(a[i]==2){
            xr=min(xr, x[i]);
        }
        if(a[i]==3){
            yd=max(yd, y[i]);
        }
        if(a[i]==4){
            yu=min(yu, y[i]);
        }
    }
    
    int s=max(0, xr-xl)*max(0, yu-yd);
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>

#define X first
#define Y second
#define int long long

using namespace std;

void pudge(){
    int n, cur = 1, ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        if (x != cur)
            ans++;
        else
            cur++;
    }
    if (ans == n)
        cout << -1;
    else
        cout << ans;
}

signed main(){
#ifdef LOCAL
    freopen("pudge.in", "r", stdin);
    freopen("pudge.out", "w", stdout);
#endif
    ios_base::sync_with_stdio;
    cin.tie(0);
    cout.tie(0);

    pudge();

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222




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

  vll a;
  MAP mp;
  cin >> n;
  rep(i, n) {
    cin >> tmp;
    a.pb(tmp);
    mp[tmp]++;
  }
  sort(rall(a));
  rep(i,n){
    rrep(bit, 40) {
      if (a[i] >= (1LL << bit)) break;
      if (mp[a[i]] && mp[(1LL << bit) - a[i]]) {
        if (a[i] == (1LL << bit) - a[i] && mp[a[i]] < 2) continue;
        mp[a[i]]--;
        mp[(1LL << bit) - a[i]]--;
        ans++;
      }
    }
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 152688
from scipy.sparse import*
n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
f=c[:]
for i in csgraph.depth_first_order(csr_matrix((f[1:],(t[:-n:2],t[1:-n:2])),[n+1]*2),1,0,0):n-=1;f[i-1]=c[n]
print(sum(c[:-1]),*f)

Measured memory_bytes: 19344
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
        template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
    };

    inp inp1; // input one
}

int main() {

    ll n, k;
    cin >> n >> k;

    vector<ll> sum(n + 2, 0LL);
    rep(i, n + 1) {
        sum[i + 1] = sum[i] + i;
    }

    ll ans = 0LL;
    Rep(i, k, n + 2) { // i個選ぶ
        ll ma = sum[n + 1] - sum[n + 1 - i];
        ll mi = sum[i] - sum[0];
        ans += ma - mi + 1;
        ans %= mod;
    }

    Cout(ans);

    return 0;
}


Measured memory_bytes: 4792
# B - YYMM or MMYY

month = [str(i).zfill(2) for i in range(1, 13)]
year = [str(i).zfill(2) for i in range(0, 100)]

S = str(input())
left = S[0] + S[1]
right = S[2] + S[3]

if left not in month and right not in month:
    print('NA')
else:
    if (left in month and left in year) and (right in month and right in year):
        print('AMBIGUOUS')
    else:
        if left in year and right in month:
            print('YYMM')
        else:
            print('MMYY')


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;
bool CMP(const pair<int,string> &x , const pair<int,string> &y){
	return x.first>y.first;
}

int main(void){
	int n ;
	bool o = false;
	while(cin>>n,n){
		vector<pair<int,string> > v;
		while(n--){
			string s; int a,b,c;
			cin>>s>>a>>b>>c;
			v.push_back(make_pair(a*3+c,s));
		}
		
		sort(v.begin(),v.end(),CMP);
		if(o)cout<<endl;
		o = true;
		for(int i = 0 ; i < v.size() ; i ++){
			cout<<v[i].second<<","<<v[i].first<<endl;
		}
	}
}

Measured memory_bytes: 1216
n,k = map(int,input().split())
d = tuple(map(int, input().split()))
flug = 1
while flug:
    flug = 0
    n2 = list(map(int,str(n)))
    for i in n2:
        if i in d:
            n += 1
            flug = 1
            break
print(n)

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

int main() {
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  string S;
  cin>>S;

  int W;
  cin>>W;

  for(int i=0;i<S.size();i++){
    if(i%W==0) cout<<S.at(i);
  }
  cout<<endl;
}


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

int main() {
	int a;
	std::cin >> a;

	std::string s;
	std::cin >> s;

	if(a >= 3200) {
		std::cout << s << std::endl;
	} else {
		std::cout << "red" << std::endl;
	}

	return 0;
}


Measured memory_bytes: 256
cards = []
patterns = ['S', 'H', 'C', 'D']

n = int(input())

for p in patterns:
	for i in range(1, 13+1):
		cards.append(p + ' ' + str(i))

for i in range(n):
	cards.remove(input())

for i in range(len(cards)):
	print(cards[i])

Measured memory_bytes: 7680
import sys
sys.setrecursionlimit(10000000)
MOD = 998244353
INF = 10 ** 15

def main():
    N,S = map(int,input().split())
    A = list(map(int,input().split()))

    before = [0] * (1 + S)
    before[0] = 1
    ans = 0
    for a in A:
        now = [0] * (1 + S)
        for i in range(S + 1):
            now[i] += before[i]
            if i + a <= S:
                now[i + a] += before[i]
                now[i + a] %= MOD
        now[0] += 1
        ans += now[S]
        ans %= MOD
        before = now
    print(ans)
if __name__ == '__main__':
    main()

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

int main(){
    string w;
    cin >> w;
    vector<char> alpha;
    for (char ch = 'a'; ch<='z'; ch++){
        alpha.push_back(ch);
    }
    vector<int> counter(26, 0);
    rep(i, w.size()){
        rep(j, 26){
            if(alpha[j] == w[i]){
                counter[j]++;
            }
        }
    }
    bool flag = true;
    rep(i, 26){
        if (counter[i] % 2 == 1){
            flag = false;
        }
    }

    if (flag == true){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool is_palindrome(int x){
	string s = to_string(x);
  	for(size_t i = 0; i < s.length(); ++i){
		if(s[i] != s[s.length()-1-i])
          return false;
    }
	return true;
}

int main(){
	int A, B;
  	cin >> A >> B;
  	int ans = 0;
  	for(; A <= B; ++A){
		ans += is_palindrome(A);
    }
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vi a;

int main(){
	cin>>n>>m;
	a=vi(n);
	for(auto &i:a) cin>>i;
	int res=0;
	for(int i=0;i<=n;i++) for(int j=0;j<=min(n,m)-i;j++){
		vi b;
		int tmp=0;
		for(int k=0;k<i;k++){
			tmp+=a[k];
			if(a[k]<0) b.push_back(a[k]);
		}
		for(int k=0;k<j;k++){
			tmp+=a[n-k-1];
			if(a[n-k-1]<0) b.push_back(a[n-k-1]);
		}
		sort(b.begin(),b.end());
		int S=b.size();
		for(int k=0;k<min(S,m-i-j);k++) tmp-=b[k];
		res=max(res,tmp);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256