akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m, x, sum=0, sum2=0;
    cin>>n>>m>>x;
    int a[m+1];
    for(int i=0; i<m; ++i) cin>>a[i];
    
    for(int i=x; i<=n; ++i)
        for(int j=0; j<m; ++j)
            if(a[j]==i)
                sum++;
                
    for(int i=0; i<=x; ++i){
        for(int j=0; j<m; ++j)
            if(a[j]==i)
                sum2++;
    }
    
    cout<<min(sum, sum2);
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(N)]
CD = [list(map(int, input().split())) for _ in range(M)]

for i in range(N):
  check = []
  for j in range(M):
    check.append(abs(AB[i][0] - CD[j][0]) + abs(AB[i][1] - CD[j][1]))
  print(check.index(min(check)) + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

int main(){
	fastread;
	vector<int> a(3);
	cin>>a[0]>>a[1]>>a[2];
	sort(a.begin(), a.end());
	if(a[0]==5 && a[1]==5 && a[2]==7){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}


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

using namespace std;

int main() {
    string S;
    cin >> S;
    vector<int> cnt(2,0); //長さ2の配列に答えを入れる 0で初期化
    //cnt(要素数, すべての要素の値)
    //cnt ... count
    for(int i = 0; i < S.size(); i++) //stringのサイズは.size()で取得
    {
        // '1' - '0' == 1
        // '0' - '0' == 0
        cnt[S[i] - '0']++;
        /*
        if (S[i] == '0') {
            cnt[0]++;
        } else {
            cnt[1]++;
        }
        */
    }
    int ans = min(cnt[0], cnt[1])*2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

lint gcd(lint a, lint b) {
	//aとbの最大公約数を返す
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	return a / gcd(a, b) * b;
}

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	string S;
	cin >> S;
	int Z = S.size();
	rep(i, 4) {
		cout << S[i];
	}
	cout << ' ';
	for (int i = 4; i < Z; i++) {
		cout << S[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
#include <boost/math/constants/constants.hpp>
using namespace std;
namespace rng {
    using namespace boost;
    using namespace boost::range;
    using namespace boost::adaptors;
    template<class R, class P> auto partition_point(const R& r, P p) { return ::std::partition_point(begin(r), end(r), p); }
}

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

using boost::irange;
using boost::math::double_constants::pi;
using i64 = int64_t;
constexpr char nl = '\n';
auto yesno(bool b) { return b ? "Yes" : "No"; }

template<class T> istream& operator>>(istream& in, vector<T>& vs) { for (T& v :vs) in >> v; return in; }
template<class T> ostream& operator<<(ostream& out, const vector<T>& vs) { for (size_t i = 0; i < vs.size(); ++i) { if(i) { out << ' '; } out << vs[i]; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const T& v) { cout << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cout << nl; for (const auto& v : m) { trace_(v); cout << nl; } }
template<class T> void trace_(const char* s, const T& v) { cout << s << "="; trace_(v); cout << nl; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cout << *s; } cout << "="; trace_(v); cout << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    string s;
    cin >> s;
    for (char c : s) {
        if (c == '7') {
            cout << "Yes" << nl;
            return 0;
        }
    }
    cout << "No" << nl;
}


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

vector<list<int>>v;


int fun(vector<int> &dp,int src){
       if(v[src].empty())
          {    dp[src] = 0;
               return 0;}

       if(dp[src] != -1)
          return dp[src];

          int bestchild = -1;
        for(int nbr : v[src]){
          
            bestchild =  max(bestchild,fun(dp,nbr));
        }
       return dp[src] = 1+bestchild;
}

void solve(){
  int n,m;
  cin >> n >> m;
  v.resize(n+1);
  for(int i=0; i<m; i++){
      int x , y;
      cin >> x >> y;
      v[x].push_back(y);
  } 
      vector<int>dp(n+1,-1);
     
       int ans = 0;
   for(int i=1; i<=n; i++)
       { ans = max(ans,fun(dp,i));}

  cout << ans;

}
int main(){
//  #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif 

solve();
return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;
int f[100004][4];
int n,a[100004],b[100004],c[100004];
int w33ha(){
    f[0][1]=f[0][2]=f[0][3]=0;
    for(int i=1;i<=n;i++)scanf("%d%d%d",&a[i],&b[i],&c[i]);
    for(int i=1;i<=n;i++){
        f[i][0]=max(f[i-1][1]+a[i],f[i-1][2]+a[i]);
        f[i][1]=max(f[i-1][0]+b[i],f[i-1][2]+b[i]);
        f[i][2]=max(f[i-1][0]+c[i],f[i-1][1]+c[i]);
    }
    printf("%d\n",max(f[n][2],max(f[n][0],f[n][1])));
    return 0;
}
int LiangJiaJun(){
    while(scanf("%d",&n)!=EOF)w33ha();
    return 0;
}


Measured memory_bytes: 2944
N,X=[int(i) for i in input().split()]
m = [int(input()) for _ in range(N)] 

for i in range(N):
    X = X - m[i]

count = N
md = min(m) 

while X > 0:
    X = X - md
    count = count +1

if X < 0:
    print(count-1)
else :
    print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>

using namespace std;

int H,W,T;
string str,u;
bool used[26],flg;

int A[26],B[26],C[26],D[26];

char t[50][50];

char tmp;

void input();
void init();

bool check(char ch){
  int z= ch-'A';
  for(int i=A[z];i<=C[z];i++){
    for(int j=D[z];j<=B[z];j++){
      if(t[i][j]!='.'&&used[t[i][j]-'A']==false)continue;
      if(t[i][j]!=ch)return false;
    }
  }
  return true;
}



int main(){
  cin>>T;
  while(T--){
    init();
    input();

    while(1){
 
      flg=false;

      for(int i=0;i<(int)u.size();i++){
	
	if(used[u[i]-'A']==false)continue;
	if(check(u[i])==true){
	  flg=true;
	  used[u[i]-'A']=false;
	  break;
	}
      }
      if(flg==false)break;
    }

    flg=false;
    for(int i=0;i<26;i++)flg|=used[i];
    cout<<(flg?"SUSPICIOUS":"SAFE")<<endl;
  }
  return 0;
}

void input(){
  int X;
  cin>>H>>W;
  for(int i=0;i<H;i++){
    cin>>str;
    for(int j=0;j<W;j++){
      t[i][j]=str[j];
      if(t[i][j]=='.')continue;
      X=t[i][j]-'A';
      if(used[X]==false)u.push_back(t[i][j]);
      used[X]=true;
      A[X]=min(A[X],i);
      B[X]=max(B[X],j);
      C[X]=max(C[X],i);
      D[X]=min(D[X],j);
    }
  }
}

void init(){
  for(int i=0;i<26;i++){
    A[i]=50;
    B[i]=0;
    C[i]=0;
    D[i]=50;
    used[i]=false;
  }
  u="";
}

Measured memory_bytes: 1200
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import itertools as it

N=one_int()

zahyous = [ two_int() for i in range(N)]

all_sums = 0
t = list(it.permutations(zahyous,N))
for i in t:
    sums=0
    for j in range(len(i)-1):
        sums += ( (i[j][0]-i[j+1][0])**2 +(i[j][1]-i[j+1][1])**2 ) ** (1/2)
    all_sums += sums/len(t)

print(all_sums)

Measured memory_bytes: 47088
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1)a = 14;
	if (b == 1)b = 14;
	if (a > b) {
		cout << "Alice" << endl;
	}
	else if (a < b) {
		cout << "Bob" << endl;
	}
	else {
		cout << "Draw" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

var h, w int
var a []string

func main() {
	fmt.Scan(&h, &w)

	a = make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&a[i])
	}

	m := [8][8]bool{}
	m[0][0] = true
	i, j := 0, 0
	for {
		if i < h-1 && a[i+1][j] == '#' {
			i++
			m[i][j] = true
		} else if j < w-1 && a[i][j+1] == '#' {
			j++
			m[i][j] = true
		} else {
			break
		}
	}

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if a[i][j] == '#' && !m[i][j] {
				fmt.Println("Impossible")
				return
			}
		}
	}

	fmt.Println("Possible")
}


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

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  int minimum = 2000001;
  int p;
  int ans = 0;
  rep(i, n) 
  {
    cin >> p ;
    minimum = min(minimum, p);
    if(minimum == p) ++ans;
    if(p == 1) break;
  }
  cout << ans << endl;

  return 0;
}


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

#define ll long long

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b;
	return 0;
}


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

using namespace std;

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

    int N, M;
    cin >> N >> M;
    vector<int> a(M), bl(N + 1, 0);
    for (int i = 0; i < M; ++i) {
        cin >> a[i];
        bl[a[i]] = 1;
    }
    constexpr int MOD = 1'000'000'007;
    vector<int> dp(N + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < N; ++i) {
        if (i + 1 <= N && !bl[i + 1]) {
            dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
        }
        if (i + 2 <= N && !bl[i + 2]) {
            dp[i + 2] = (dp[i + 2] + dp[i]) % MOD;
        }
    }
    cout << dp[N] << "\n";

    return 0;
}

Measured memory_bytes: 1408
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
ll n, a;
ll pw(ll x, int y) {
    ll c = 1;
    for (int i = 0; i < y; i++) c *= x;
    return c;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> a;
    ll best = n;
    for (ll p = 1; p * p <= 3 * n; p++) {
        best = min(best, p + (n + p - 1) / p + a);
    }
    for (int i = 2; i <= 40; i++) {
        for (int cnt = 1; cnt <= i; cnt++) {
            for (ll x = 1; ; x++) {
                ll t1 = pw(x, cnt) * pw(x + 1, i - cnt);
                ll t2 = cnt * x + (i - cnt) * (x + 1);
                ll tot_val = t2 + (n + t1 - 1) / t1 + i * a;
                best = min(best, tot_val);
                if (t1 > n) break;
            }
        }
    }
    cout << best;
   /* map < ll, ll > mp;
    mp[1] = 0;
    while (true) {
        int lst = mp.size();
        map < ll, ll > nmp;
        for (auto& it : mp) {
            if (it.first > 8e12) continue;
            nmp[it.first] = it.second;
            nmp[it.first * 2] = it.second + 2 + a;
            nmp[it.first * 3] = it.second + 3 + a;
        }
        mp = nmp;
        if (mp.size() == lst) break;
    }
    for (auto& it : mp) {
        cout << it.first << " " << it.second << endl;
    }
    ll best = 1e18;
    for (auto& it : mp) {
        best = min(best, it.second + (n + it.first - 1) / it.first);
    }
    cout << best;*/
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>

#define num 100000

int main(void)
{
  long int n;
  scanf("%ld", &n);

  long int a[n];
  for(int i=0;i<n;i++){
    scanf("%ld", &a[i]);
  }

  long int q;
  scanf("%ld", &q);

  long int b[q], c[q];
  for(int i=0;i<q;i++){
    scanf("%ld %ld", &b[i], &c[i]);
  }

  long int sum=0;
  for(int i=0;i<n;i++){
    sum += a[i];
  }
  
  long int d[num+1];
  for(int i=0;i<=num;i++){
    d[i] = 0;
  }
  
  long int tmp;
  for(int i=0;i<n;i++){
    tmp = a[i];
    d[tmp]++;
  }
  
  long int before, after;
  long int s[q];
  for(int i=0;i<q;i++){
    before = b[i];
    after = c[i];
    if(i==0){
      s[0] = sum + (after-before)*d[before];
    }
    else{
      s[i] = s[i-1] +(after-before)*d[before];
    }
    d[after] += d[before];
    d[before] = 0;
  }

  for(int i=0;i<q;i++){
    printf("%ld\n", s[i]);
  }

  return 0;
}


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll N, K;
    cin >> N >> K;
    VL A(N), F(N);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> F[i];

    sort(ALL(A));
    sort(ALL(F), greater<ll>());

    ll L = -1, R = 1e18;
    while(R - L > 1){
        ll M = L + (R - L)/2;
        ll tk = K;
        rep(i, 0, N){
            if(A[i] * F[i] > M){
                tk -= (A[i] * F[i] - M + F[i] - 1) / F[i];
            }
        }
        if(tk < 0) L = M;
        else R = M;
    }
    cout << R << endl;
    return 0;
}

Measured memory_bytes: 3328
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

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

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

ll maxbeki(ll n) {
    ll ret = mypow(2LL, 32);
    while (ret > 0) {
        if (ret <= n) return ret;
        ret /= 2;
    }
    return ret;
}

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

    map<ll, int> dic;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        if (dic.find(a) == dic.end()) dic[a] = 0;
        ++dic[a];
    }

    int ans = 0;
    for (auto itr = dic.rbegin(); itr != dic.rend(); ++itr) {
        ll a;
        int cnt;
        tie(a, cnt) = *itr;
        if (cnt == 0) continue;

        ll to = maxbeki(a * 2) - a;
        if (to == a) {
            ans += cnt / 2;
        } else {
            if (dic.find(to) == dic.end()) continue;

            ans += min(cnt, dic[to]);
            dic[to] -= min(cnt, dic[to]);
        }
    }

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


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100002

int main () {
    int A, B, M; cin >> A >> B >> M;
    int minm = 2e9, mina = 2e9, minb = 2e9;
    int a[MAXN], b[MAXN];
    for (int i = 1; i <= A; i ++) {
        cin >> a[i];
        mina = min (mina, a[i]);
    } 
    
    for (int i = 1; i <= B; i ++) {
        cin >> b[i];
        minb = min (minb, b[i]);
    }
    
    minm = mina + minb;
    
    for (int i = 1; i <= M; i ++) {
        int x, y, m; cin >> x >> y >> m;
        minm = min (minm, max (a[x] + b[y] - m, 0));
    }
    cout << minm;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 1000001;
const int MOD =1000000007;
const int INV2 = (MOD+1)/2;



     signed main(){
   int x;
   cin>>x;
   for(int i=1;i<=1000;i++){
    for(int j=0;j<1000;j++){
      if(i*i*i*i*i-j*j*j*j*j==x){
        cout<<i<<' '<<j<<endl;
        return 0;
      }
      if(i*i*i*i*i+j*j*j*j*j==x){
        cout<<i<<' '<<-j<<endl;
        return 0;
      }
      if(-i*i*i*i*i+j*j*j*j*j==x){
        cout<<-i<<' '<<-j<<endl;
        return 0;
      }
    }
   }

        





}


        


Measured memory_bytes: 3592
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        # 親の番号 根なら要素数(負の数)

    def find(self, x):
        """木の根を求める"""
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        """xとyの属する集合を併合"""
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        """xとyが同じ集合に属するか否か"""
        return self.find(x) == self.find(y)

    def size(self, x):
        """グループのサイズを返す"""
        return -self.parents[self.find(x)]

N, M, K = map(int, input().split())

uf = UnionFind(N)
ans = [0] * N
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    uf.unite(A, B)
    ans[A] -= 1
    ans[B] -= 1

for i in range(N):
    ans[i] += uf.size(i) - 1

for _ in range(K):
    C, D = map(int, input().split())
    C -= 1
    D -= 1
    if uf.same(C, D):
        ans[C] -= 1
        ans[D] -= 1

print(*ans)


Measured memory_bytes: 13380
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  vector<ll> p(A);
  vector<ll> q(B);
  vector<ll> r(C);
  for(ll i=0;i<A;++i){
    cin>>p.at(i);
  }
  for(ll i=0;i<B;++i){
    cin>>q.at(i);
  }
  for(ll i=0;i<C;++i){
    cin>>r.at(i);
  }
  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  sort(r.begin(),r.end());
  vector<ll> ans(0);
  ll answer=0;
  for(ll i=0;i<X;++i){
    ans.push_back(p.at(A-i-1));
    answer+=p.at(A-i-1);
  }
  for(ll i=0;i<Y;++i){
    ans.push_back(q.at(B-i-1));
    answer+=q.at(B-i-1);
  }
  sort(ans.begin(),ans.end());
  for(ll i=0;i<C;++i){
    if(i<X+Y){
      if(ans.at(i)<r.at(C-i-1)){
        answer+=r.at(C-i-1);
        answer-=ans.at(i);
      }
    }
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 4724
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;

int main(){
	int calc[3],counter=0;
	for(int i=0;i<3;i++)
		cin >> calc[i];
	for(int i=0;i<3;i++){
		for(int j=i;j<3;j++){
			if(calc[i]>calc[j])
				swap(calc[i],calc[j]);
		}
	}
	if(calc[0]%2==calc[1]%2&&calc[1]%2==calc[2]%2){
		counter+=(calc[1]-calc[0])/2 + (calc[2]-calc[1]);
	}
	else{
		if(calc[0]%2==calc[1]%2){
			counter+=(calc[1]-calc[0])/2 + (calc[2]-calc[1]);
		}
		if(calc[1]%2==calc[2]%2)
			counter+=(calc[2]+1-calc[0])/2 + (calc[2]-calc[1])/2 + 1;
		if(calc[2]%2==calc[0]%2)
			counter+=(calc[2]+1-calc[1])/2 + (calc[2]-calc[0])/2 + 1;
	}
	cout << counter << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
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(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;cin>>n>>m;
	int d[n+1];
	int a[n+1];
	rep(i, n+1){
		d[i] = 0;
		a[i] = 0;
	}
	rep(i, m){
		int p;
		string s;
		cin>>p>>s;
		if(s=="AC"){
			a[p-1] = 1;
		}else{
			if(a[p-1] == 0){
				d[p-1]++;
			}
		}
		//cout << "test" << d[i] << a[i] << endl;
	}
	int ans= 0 ;
	int miss = 0;
	rep(i, n){
		if(a[i] == 1){
			ans ++;
			miss += d[i];
		}
	}
	//cout << d[0] << d[1] << endl;
	cout << ans << " " << miss << endl;
	return 0;
}


Measured memory_bytes: 1024
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
 
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
 
//ここまで毎回include
//以下プログラム
 
using namespace std;
 
int main() {
	int n;
	cin >> n;
	vector<vector<int>> data(2, vector<int>(n));
	for (int i = 0; i < n; i++) {
		cin >> data.at(0).at(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> data.at(1).at(i);
	}
	int result = 0;
	for (int i = 0; i < n; i++) {
		int check = 0;
		for (int j = 0; j <= i; j++) {
			check += data.at(0).at(j);
		}
		for (int j = i; j < n; j++) {
			check += data.at(1).at(j);
		}
		result = max(result, check);
	}
	cout << result << endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL a, b, c, d;
    cin >> a >> b >> c >> d;

        cout << max({a * c, b * d, b * c, a * d}) << endl;
        return 0;
    if(b <= 0) {

    } else if(d <= 0) {
        cout << max({a * c, b * d, b * c}) << endl;
    } else if(a > 0) {
        cout << max({b * d, a * d});
    }
    return 0;
}



Measured memory_bytes: 3652
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ml m
#define mr m + 1
#define lson id << 1
#define rson id << 1 | 1
#define Error(x) cout << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf  = 0x3f3f3f3f;
const int maxn = 1e5 + 15;
const int maxm = 1e6 + 15;


int main() {
#ifdef NEKO
	freopen("C:\\Nya.txt", "r", stdin);
#endif
	string s; cin >> s;
	ll k; cin >> k;
	for(int i = 0; i < s.size(); i++) {
		int t = 'z' - s[i] + 1;
		if(s[i] == 'a') t = 0;
		if(t <= k) {
			k -= t;
			s[i] = 'a';
		}
	}
	int tail = s.size() - 1;
	if(k) s[tail] = (s[tail] - 'a' + k) % 26 + 'a';
	cout << s << endl;
	return 0;
}

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


int main() {
    int n;
    cin >> n;
    vl a(n);
    rep(i, n) cin >> a[i];

    ll ma = 0;
    ll ans = 0;
    rep(i, n) {
        if (a[i] >= ma) {
            ma = a[i];
        } else {
            ans += ma - a[i];
        }
    }

    prt(ans);

    return 0;
}


Measured memory_bytes: 4748
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

bool func(pair<ll,ll> A, pair<ll,ll> B){
    return A.first < B.first;
}

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

    ll N , M ;
    cin >> N >> M ;

    ll ans = 0;
    vector<pair<ll,ll> > AB;
    rep(i, N){
        ll A, B ;
        cin >> A >> B ;
        AB.pb(mp(A, B));
    }

    sort(all(AB), func);

    rep(i, N){
        ll A = AB[i].first;
        ll B = AB[i].second;

        if(B >= M){
            ans += A * M ;
            M = 0;
        }else{
            ans += A * B ;
            M -= B ;
        }
        if(M == 0) break;
    }

    cout << ans << endl;

	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ll long long
#define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 10 + 5;
const ll inf = LLONG_MAX;
using namespace std;
template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T> void print_container(T &container) { for (auto &t : container) { cout << t << " ";} cout << endl;}
template<class T> void printArr(T &a , int n) { for (int i = 0; i < n; i++) {cout << a[i] << " ";} cout << endl;}

//Template Ends
int n;
int r, c, k;
int a[N][N];

void solve() {
	cin >> r >> c >> k;
	for (int i = 0; i < r; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < c; j++) {
			a[i][j] = s[j];
		}
	}


	int ans = 0;
	for (int maskr = 0 ; maskr < (1 << r); maskr++) {
		for (int maskc = 0 ; maskc < (1 << c); maskc++) {
			int cnt = 0;
			for (int i = 0; i < r; ++i)
			{
				for (int j = 0; j < c; ++j)
				{
					if ( (maskr >> i & 1) || (maskc >> j & 1) ) {
						continue;
					} else {
						if (a[i][j] == '#') {
							cnt++;
						}
					}
				}
			}
			if (cnt == k)ans++;
		}
	}

	cout << ans << endl;
}

int32_t main() {
	IOS;

	solve();

	return 0;
}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

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

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int h,w;
  cin>>h>>w;
  char mp[h][w];
  rep(i,h){
    rep(j,w){
      cin>>mp[i][j];
    }
  }
  queue<PII> bfs;
  int ans[h][w];
  rep(i,h){
    rep(j,w){
      ans[i][j]=INF;
    }
  }
  ans[0][0]=0;
  if(mp[0][0]=='#') ans[0][0]=1;
  bfs.push(make_pair(0,0));
  while(!bfs.empty() ){
    PII p;
    p=bfs.front();
    bfs.pop();
    rep(i,2){
      int X=p.F+dx[i],Y=p.S+dy[i];
      if(X>=0 && X<h && Y>=0 && Y<w){
	int num=ans[p.F][p.S];
	if(mp[X][Y]=='#' && mp[p.F][p.S]=='.') num++;
	if(num<ans[X][Y]){
	  ans[X][Y]=num;
	  bfs.push(make_pair(X,Y));
	}
      }
    }
  }
  cout<<ans[h-1][w-1]<<endl;
  // cout<<endl;
  /* rep(i,h){
    rep(j,w){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
    }*/
	 
	    
	

  return 0;
}


Measured memory_bytes: 384
/*
 * (c) fushar (Ashar Fuadi)
*/

#include <bits/stdc++.h>

#define REP(i,n) for (int i = 0, _n = n; i < _n; i++)
#define FOR(i,a,b) for (int i = a, _b = b; i <= _b; i++)
#define FORD(i,b,a) for (int i = b, _a = a; i >= _a; i--)
#define RESET(c,v) memset(c, v, sizeof c)
#define ALL(c) c.begin(), c.end()
#define TT template<typename T>

using namespace std;
using ll = long long;

TT bool in_range(int x, int a, int b) { return a <= x && x < b; }

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

const int MAXN = 100005;

int N;
vector<int> G[MAXN];

int dfs(int u, int p) {
    if (p != -1 && G[u].size() == 1) {
        return 0;
    }

    int res = 0;
    for (int v : G[u]) if (v != p) {
        res ^= 1 + dfs(v, u);
    }

    return res;
}

int main() {
    scanf("%d", &N);
    REP(i, N-1) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    puts(dfs(0, -1) == 0 ? "Bob" : "Alice");
}


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

int main()
{
	int p1x = 0, p1y = 0, p2x = 0, p2y = 0, q = 0, px = 0, py = 0;
	int a = 0, b = 0;
	long c = 0, s = 0;
	double x = 0, y = 0;

	cin >> p1x >> p1y >> p2x >> p2y;
	cin >> q;

	a = p2y - p1y;
	b = p1x - p2x;
	c = - p1x * p2y + p1y * p2x;

	for (int i = 0; i < q; i++) {
		cin >> px >> py;

		s = a * px + b * py + c;
		x = px - (double)(s * a) / (double)(a * a + b * b);
		y = py - (double)(s * b) / (double)(a * a + b * b);

		cout << setprecision(10) << setiosflags(ios::fixed | ios::showpoint) 
			 << x << " " << y << endl;
	}
		
	return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int s;
	cin >> s;
	bool YYMM = true, MMYY = true;
	if (s / 100 == 0 || s / 100 > 12) {
		MMYY = false;
	}
	if (s % 100 == 0 || s % 100 > 12) {
		YYMM = false;
	}
	if (MMYY == true && YYMM == true) {
		cout << "AMBIGUOUS" << endl;
		return 0;
	}
	if (MMYY == false && YYMM == false) {
		cout << "NA" << endl;
		return 0;
	}
	if (MMYY == true && YYMM == false) {
		cout << "MMYY" << endl;
		return 0;
	}
	if (MMYY == false && YYMM == true) {
		cout << "YYMM" << endl;
		return 0;
	}
	return 0;
}

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

string ans(int x) { return x % 2 ? "First" : "Second"; }

int main() {
    string s; cin >> s;
    const int n = s.size();
    if (s[0] == s[n-1]) cout << ans((n - 1) % 2) << endl;
    else cout << ans(n % 2) << endl;
}


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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

//配列の添え字が最大10^18になる（種類はそんなない）のでmapを使う
map<ll, ll> dp;

// v=0,1,...,Mにおける解の合計
ll rec(ll M) {
    if (M == 0) return 1;
    if (dp.count(M)) return dp[M];

    dp[M] = rec((M - 1) / 2);            // 奇数
    dp[M] += rec(M / 2);                 // 偶数 繰り上がり無
    if (M > 1) dp[M] += rec(M / 2 - 1);  // 偶数 繰り上がり有
    return dp[M] %= MOD;
}

int main() {
    ll N;
    cin >> N;
    cout << rec(N) << endl;
    return 0;
}

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

using namespace std;

const int MOD = 1e9 + 7;
long long fact[101010];

long long factorial(int N){
    if(N==0 || N==1) return fact[N] = 1;
    if(fact[N] != 0) return fact[N]%MOD;
    return fact[N] = (factorial(N-1)*N)%MOD;
}

int main(){
    int N,M;
    cin >> N >> M;
    if(abs(N-M) > 1){
        cout << 0 << endl;
        return 0;
    }

    long long fn = factorial(N);
    long long fm = factorial(M);

    if(N!=M){
        cout << (fn*fm)%MOD << endl;
    }else{
        cout << (2*fn*fm)%MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <set>

using namespace std;

int main()
{
  // intをキーとして扱う集合
  set<int> s;
  int N;
  cin >> N;
  for (int i=0;i<N;i++){
    int a;
    cin >> a;
    s.insert(a);
  }
  int c=0;;
  for (int i=1;i<101;i++){
  size_t n = s.count(i);
  c += n;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
s=list(input())

hugou=[]
for i in range(8):
  z=[]
  k=0
  ans=0
  for j in range(3):
    if k==0:
      z.append(s[k])
      ans+=int(s[k])
    if ((i>>j)&1):
      z.append("+")
      k+=1
      ans+=int(s[k])
      z.append(s[k])
    else:
      z.append("-")
      k+=1
      ans-=int(s[k])
      z.append(s[k])
  if ans==7:
    print("".join(z)+"=7")
    break

Measured memory_bytes: 38512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    if (S.equals("AAA") || S.equals("BBB")) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;




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

Measured memory_bytes: 3596
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
struct edge{int nx,t;}e[MN*2+5];
int h[MN+5],en,f[MN+5];
inline void ins(int x,int y)
{
	e[++en]=(edge){h[x],y};h[x]=en;
	e[++en]=(edge){h[y],x};h[y]=en;
}
int cal(int x){for(int i=17;i;--i)if(x&(1<<i))return i;return -1;}
void dfs(int x,int fa)
{
	int mx=0;
	for(int i=h[x];i;i=e[i].nx)if(e[i].t!=fa)
	{
		dfs(e[i].t,x);
		mx=max(mx,cal(f[x]&f[e[i].t])+1);
		f[x]|=f[e[i].t];
	}
	for(int i=0;;++i)if(i>=mx&&!(f[x]&(1<<i)))
		{f[x]=(f[x]|(1<<i))&((-1)<<i);return;}
}
int main()
{
	int n=read(),i;
	for(i=1;i<n;++i)ins(read(),read());
	dfs(1,0);
	printf("%d",cal(f[1]));
}

Measured memory_bytes: 5888
# -*- coding: utf-8 -*-

import sys
from operator import add

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 2 ** 31 - 1
MOD = 10 ** 9 + 7

class SegTreeLazy:
    """ 遅延評価セグメント木(区間更新、区間合計取得) """

    def __init__(self, N, func, intv):
        self.intv = intv
        self.func = func
        self.LV = (N-1).bit_length()
        self.N0 = 2**self.LV
        self.data = [intv]*(2*self.N0)
        self.lazy = [None]*(2*self.N0)

    # 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
    def gindex(self, l, r):
        L = (l + self.N0) >> 1; R = (r + self.N0) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()
        v = 2
        for i in range(self.LV):
            if rc <= i:
                yield R
            if L < R and lc <= i:
                yield L
            L >>= 1; R >>= 1; v <<= 1

    # 遅延評価の伝搬処理
    def propagates(self, *ids):
        # 1-indexedで単調増加のインデックスリスト
        for i in reversed(ids):
            v = self.lazy[i-1]
            if v is None:
                continue
            self.lazy[2*i-1] = self.data[2*i-1] = self.lazy[2*i] = self.data[2*i] = v >> 1
            self.lazy[i-1] = None

    def update(self, l, r, x):
        """ 区間[l,r)の値をxに更新 """

        *ids, = self.gindex(l, r)
        # 1. トップダウンにlazyの値を伝搬
        self.propagates(*ids)
        # 2. 区間[l,r)のdata, lazyの値を更新
        L = self.N0 + l; R = self.N0 + r
        v = x
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R-1] = self.data[R-1] = v
            if L & 1:
                self.lazy[L-1] = self.data[L-1] = v
                L += 1
            L >>= 1; R >>= 1; v <<= 1
        # 3. 伝搬させた区間について、ボトムアップにdataの値を伝搬する
        for i in ids:
            self.data[i-1] = self.func(self.data[2*i-1], self.data[2*i])

    def query(self, l, r):
        """ 区間[l,r)の和を取得 """

        # 1. トップダウンにlazyの値を伝搬
        self.propagates(*self.gindex(l, r))
        L = self.N0 + l; R = self.N0 + r

        # 2. 区間[l, r)の和を求める
        s = self.intv
        while L < R:
            if R & 1:
                R -= 1
                s = self.func(s, self.data[R-1])
            if L & 1:
                s = self.func(s, self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

N, Q = MAP()
stl = SegTreeLazy(N+1, add, 0)

ans = []
for i in range(Q):
    cmd, *arg = MAP()
    if cmd == 0:
        s, t, x = arg
        stl.update(s, t+1, x)
    else:
        s, t = arg
        ans.append(str(stl.query(s, t+1)))
print('\n'.join(ans))



Measured memory_bytes: 18988
//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 5e5 + 50, oo = 3e18 + 500;
const int mod = 998244353;
//const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-12, PI = 2 * acos(0.0);
int n, m, k;
long long cnt = 0;
int lg = 18;
vi g[N];
vi rg[N];
vi visit(N, 0);



signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("abbreviation.in", "r", stdin);
	freopen("abbreviation.out", "w", stdout);*/
	//ПРОВЕРЯЙ ДЕФАЙНЫ ТУПОЙ!!!

	cin >> n;

	vi a(n+1);

	int sum = 0;
	for (int i = 0; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}

	int cur = 1;
	for (int i = 0; i <= n; i++)
	{
		if (cur < a[i])
		{
			cnt = -1;
			break;
		}

		cnt += cur;
		cur -= a[i];
		sum -= a[i];

		int nxt = min(2 * cur, sum);
		cur = nxt;
	}

	cout << cnt;
}




Measured memory_bytes: 31136