akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

string S;
long long N;

vector<long long> A;
vector<long long> B;
vector<long long> C;
long long Bmemo[100005];
long long Bsum[100005];

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		long long tmp;
		cin >> tmp;
		A.push_back(tmp);
	}
	for(long long i = 0; i < N; i++){
		long long tmp;
		cin >> tmp;
		B.push_back(tmp);
	}
	for(long long i = 0; i < N; i++){
		long long tmp;
		cin >> tmp;
		C.push_back(tmp);
	}

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	long long ans = 0;
	for(long long bidx = 0; bidx < B.size(); bidx++){
		long long bsize = B[bidx];
		long long cnum = C.size() - (upper_bound(C.begin(), C.end(), bsize) - C.begin());
		Bmemo[bidx] = cnum;
	}

	for(int i = N-1; i >= 0; i--){
		Bsum[i] = Bmemo[i] + Bsum[i+1];
	}

	/*
	for(int i = 0; i < N; i++){
		cout << "Bmemo[" << i << "]=" << Bmemo[i] << endl;
	}

	for(int i = 0; i < N; i++){
		cout << "Bsum[" << i << "]=" << Bsum[i] << endl;
	}
	*/

	for(long long aidx = 0; aidx < A.size(); aidx++){
		long long asize = A[aidx];
		//このidx以上のやつには乗れる
		long long bidx = (upper_bound(B.begin(), B.end(), asize) - B.begin());
		//cout << "asize = " << asize << "bidx = " << bidx << endl;
		ans += Bsum[bidx];
	}
	cout << ans << endl;
}


Measured memory_bytes: 4340
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

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 = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s, t;
    cin >> n >> s >> t;
    LL dp[26] = {};
    
    dp[s[0] - 'a'] = 1;
    for( int i = 1; i < s.size() - 1; ++i ) {
        dp[s[i] - 'a'] = ( dp[s[i] - 'a'] + dp[t[i] - 'a'] ) % MOD;

    }
    cout << dp[t[n - 1] - 'a'] << endl;

    return 0;
}



Measured memory_bytes: 3312
import sys
i_f = {}
for line in sys.stdin:
  v = int(line)
  if i_f.get(v) is None:
    i_f[v] = 0
  i_f[v] += 1

ans = {}
for i, f in i_f.items():
  if ans.get(f) is None:
    ans[f] = []
  ans[f].append(i)
ans = [ (a,vs) for a, vs in ans.items() ]
ans = max(ans, key=lambda x:x[0])
#print(ans)

for i in sorted(ans[1]):
  print(i)


Measured memory_bytes: 5604
#include<iostream>
using namespace std;
int main()
{
    int n,i,r,c=0;
    cin>>n;
    for(i=n;i>0;i=i/10)
    {
        r=i%10;
        if(r==7)
            c++;
    }
    if(c==0)
        cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;


        return 0;


}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N, K;
vector<int> h;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> K;
  h.resize(N);
  for(int i=0; i<N; ++i) cin >> h[i];
  int res = INT_MAX;
  sort(all(h));
  for(int i=0; i+K-1<N; ++i){
    res = min(res, (h[i+K-1] - h[i]));
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<string>
#include<climits>
#include<vector>
#include<iomanip>
#include<deque>
#include<stack>
#define Rep(i,n)        for(int i = 0; i < (n); ++i)
#define Repd(i,n)       for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b)      for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b)     for(int i = (a); i >= (b); --i)
#define ALL(a)          (a).begin(), (a).end()
#define taomap          map<ll,int> mmap
#define Upper(k)        upper_bound(a,a+n,(k))
#define Lower(k)        lower_bound(a,a+n,(k))
#define pb(i)		 push_back((i))
#define NAME            "TEST"
#define FAST            ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define READ            freopen(NAME".INP","r",stdin);
#define WRITE           freopen(NAME".OUT","w",stdout);

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef float fl;
typedef double db;
const int inf = 1e6;
const int Linf = 1e9;
const ll LLinf = (ll)1e18;
const int maxn = 3e3 + 5;
/*
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                              		Be amazed
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
int a[maxn][maxn] , i , n , j , m;
string x , y;
stack <char> dapso;
int commonlength(){
    for(int i = 0 ; i <= x.size() ; ++i){
        for(int j = 0 ; j <= y.size() ; ++j){
            if(i == 0 || j == 0)a[i][j] = 0;
            else a[i][j] = (x[i - 1] == y[j - 1]) ? a[i - 1][j - 1] + 1 : max(a[i][j - 1] , a[i - 1][j]);
        }
    }
    //cout << a[x.size()][y.size()] << endl;
    return a[x.size()][y.size()];
}

int main()
{
    FAST;//READ;WRITE;
    int k;
    int n , m;
    //cin >> n >> m >> k;
    cin >> x >> y;
    n = commonlength();
    //return cout << n , 0;
    i = x.size();
    j = y.size();
    //cout << n << endl;
    //return 0;
    while(i > 0 && j > 0){
        if(x[i - 1] == y[j - 1]){
            dapso.push(x[i - 1]);
            i--;j--;
        }
        else{
            if(a[i - 1][j] > a[i][j - 1])i--;
            else j--;
        }
    }
    while(!dapso.empty())cout << dapso.top() , dapso.pop();
}


Measured memory_bytes: 35456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var F = ReadInt();
            WriteLine((F - 30) / 2);
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 15984
s = input()

mid = int(len(s) / 2)
flg = True

for i in range(mid):
    if s[i] is not s[-i-1]:
        flg = False

for i in range(int((len(s) - 1) / 2)):
    if s[i] is not s[int((len(s) - 1) / 2)-i-1]:
        flg = False

for i in range(int((len(s) + 3) / 2), len(s)):
    if s[i] is not s[-i-1]:
        flg = False

if flg:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int A, B, C;

  std::cin >> A >> B >> C;

  std::cout << (A == B && B == C ? "Yes" : "No") << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  R s;
  int x=0,y=0;
  rep(i,s.size()) {
    if(s[i]=='S') x++;
    else {
      if(!x) continue;
      y+=2;
      x--;
    }
  }
  pr(s.size()-y);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


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

string s[3];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i < 3; i++)
		cin >> s[i];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[0][i] != s[1][i] && s[1][i] != s[2][i] && s[0][i] != s[2][i]) ans += 2;
		else if (s[0][i] != s[1][i] || s[1][i] != s[2][i]) ans++;
	}
	cout << ans << '\n';
	return 0;
}

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

int main() {
    ll ans=0, N;
    cin >> N;

    for(int i=0; i<=N; i++){
	if(i%3!=0 && i%5!=0)
	    ans += i;
    }
    cout << ans << endl;
} 




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

signed main(){
  int A[3];
  rep(i,3)cin>>A[i];
  int P[101];
  rep(i,101)P[i]=0;
  rep(i,3)P[A[i]]+=1;
  int ans=0;
  rep(i,101){
    if(P[i]>0){
      ans+=1;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100000
#define INF 0x3f3f3f3f

int main() {
	static int xx[N];
	int n, k, i, min;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &xx[i]);
	min = INF;
	for (i = 0; i <= n - k; i++) {
		int l, r, time;

		time = 0;
		l = xx[i];
		r = xx[i + k - 1];
		time = r - l;
		if (l >= 0)
			time += l;
		else if (r <= 0)
			time -= r;
		else
			time += (-l < r ? -l : r);
		if (min > time)
			min = time;
	}
	printf("%d\n", min);
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define MAX_LEN 300000

int data[MAX_LEN];
int ndata;

long long solve()
{
  long long result = 0;
  int last = 0;
  int sum = 0;
  for(int first = 0; first < ndata; first++) {
    for(; last < ndata; last++) {
      if((sum ^ data[last]) != sum + data[last]) {
        break;
      }
      sum += data[last];
      result += last-first+1;
    }
    sum -= data[first];
  }
  return result;
}

int main()
{
  scanf("%d", &ndata);
  for(int i = 0; i < ndata; i++) {
    scanf("%d", &data[i]);
  }
  printf("%lld\n", solve());
  return 0;
}


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

int main(void)
{
    int N;
    cin >> N;
    int count;
    count = 0;

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }


    if (N < 3){
        cout << 0 << endl;
        exit(0);
    }

    for(int i = 0; i < N ; i++){
        int& val_i = vec.at(i);
        
        for(int j = i + 1; j < N ; j++){
            int& val_j = vec.at(j);
            
            if( val_i  == val_j ){
                continue;
            }

            for(int k = j + 1; k < N ; k++){
                int& val_k = vec.at(k);
                if( val_j == val_k ){
                    continue;
                }
                if( val_i == val_k ){
                    continue;
                }

                

                //cout << i << j << k << endl;
                //cout << val_i << val_j << val_k << endl;
                
                if( 
                    val_i < val_j + val_k &&
                val_j < val_i + val_k &&
                val_k < val_j + val_i 
                )  {
                    count++;
                }

              
            

            }
        }
        
    }

    cout << count << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
 
using namespace std;
 
typedef long long ll;
 
const ll INF = 1e9;
 
int n, k;
string s;
 
int main ()
{
	cin >> n >> k;

	deque <int> a (n);
	cin >> s;
	int rev = 0, ptr = 0, last = 0;

	for (int i = 0; i < n; i++)
		a[i] = (s[i] == 'B');

	for (int i = 0; i < k && ptr <= n; i++)
	{

		if (!(a[0] ^ rev)) 
		{
			a[0] = !rev;
			continue;
		}

		a.pop_front ();
		ptr++;
		rev ^= 1;
		a.push_back (rev);
		last = i;
	}
	last++;

	if ((n & 1) && ((k - last) & 1)) 
		a[0] = !rev;

	for (int j = 0; j < n; j++)
		if (rev ^ a[j]) putchar ('B');
		else putchar ('A');
}

Measured memory_bytes: 1540
#include<bits/stdc++.h>
using namespace std;
pair<int,int> pii;
vector<int> vec;
int main()
{
  priority_queue<int> que;
  int n,m,a;
  long long sum=0;

  cin>>n>>m;

  for(int i=0; i<n; i++){
    cin>>a;
    que.push(a);
  }

  for(int i=0; i<m; i++){
    que.push(que.top()/2);
    que.pop();
  }

  while(!que.empty()){
    sum+=que.top();
    que.pop();
  }

  cout<<sum<<'\n';

  return 0;
}


Measured memory_bytes: 892
import math
lim = int(math.pow(10, 5))
is_prime = [True for _ in range(lim+1)]
is_prime[0], is_prime[1] = False, False
for i in range(2, int(math.sqrt(lim))+1):
    if is_prime[i]:
        for j in range(i*2, lim+1, i):
            is_prime[j] = False


nums = [0 for _ in range(lim+1)]
for i in range(2, lim):
    if is_prime[i] and is_prime[(i+1)//2]:
        nums[i] = nums[i-1] + 1
        # print(i)
    else:
        nums[i] = nums[i-1]

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split(' '))
    print(nums[r] - nums[l-1])


Measured memory_bytes: 51692
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N;
  cin >> N;
  vll A(N);
  rep(i, N) {
    cin >> A[i];
  }

  ll ans = 0;
  rep(i, N) {
    if (i == 0) {
      ans = A[i];
    } else {
      ans = gcd(ans, A[i]);
    }
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

ll gcd(ll a,ll b){if(!b)return abs(a);return (a%b==0)?abs(b):gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  startupcpp();
  int i,N,x;
  cin>>N;
  vec c(2e5+1,-1),ans(N,0);
  rep(i,N){
    cin>>x;
    if(i)ans[i]=ans[i-1];
    else ans[i]=1;
    if(c[x]!=-1&&c[x]!=i-1){
      (ans[i]+=ans[c[x]])%=mod;
    }
    c[x]=i;
  }
  print(ans[N-1]);
}

Measured memory_bytes: 3328
using System;
using System.Linq;

namespace DPL3_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = scan;
            int H = a[0];
            int W = a[1];
            var G = new int[H, W];
            var dp = new int[H, W];
            int max = 0;
            bool flag = true;
            for (int i = 0; i < H; i++)
            {
                var k = scan;
                for (int j = 0; j < W; j++)
                {
                    G[i, j] = k[j];
                    if (flag)
                    {
                        if (k[j] == 0)
                        {
                            max = 1;
                            flag = false;
                        }
                    }
                }
            }
            for (int i = 0; i < H; i++)
            {
                dp[i, 0] = G[i, 0] == 0 ? 1 : 0;

            }
            for (int j = 0; j < W; j++)
            {
                dp[0, j] = G[0, j] == 0 ? 1 : 0;
            }
            for (int i = 1; i < H; i++)
            {
                for (int j = 1; j < W; j++)
                {
                    if (G[i, j] == 1) continue;
                    dp[i, j] = new[] { dp[i - 1, j - 1], dp[i - 1, j], dp[i, j - 1] }.Min() + 1;
                    max = Math.Max(max, dp[i, j]);
                }
            }
            Console.WriteLine(max * max);
        }

        static int[] scan
        {
            get { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
        }
    }
}

Measured memory_bytes: 38344
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

struct union_find{
    union_find(int n){
        for(int i=0; i<=n; i++){
            par.push_back(i);
            rank.push_back(0);
            size.push_back(1);
        }
    }
    int find(int x){
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(rank[x] < rank[y]){
            par[x] = y;
            // x を含むグループの根は y になるので、
            // size[y] に size[x] を加える。
            size[y]+= size[x];
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            // 上と同様
            size[x]+=size[y];
        }
    }
    // 頂点 x を含む連結成分に含まれる頂点数を返す
    int getSize(int x){
        return size[find(x)];
    }

    private:
        vector<int> par, rank, size;
};

int main(){
    ll N, M;
    cin >> N >> M;
    vector<pair<int,int>> bridge(M+1);
    for(int i=1; i<=M; i++){
        int A, B;  cin >> A >> B;
        bridge[i] = make_pair(A, B);
    }

    union_find island(N);
    vector<ll> conv(M+2,0); // 橋 i 建設後の便利さ = conv[i]
    conv[M+1] = 0; // 橋が 1 つも無いとき便利さは 0

    // 橋 M, M-1, ……, 1 の順に橋を建設する
    for(int i=M; i>=0; i--){
        int A = bridge[i].first;
        int B = bridge[i].second;
        // A と B の根を求める
        A = island.find(A);
        B = island.find(B);
        if(A==B){
            // A, B が互いに行き来できるとき、AとBを繋いでも便利さは増えない
            conv[i] = conv[i+1];
        }else{
            // A, B が互いに行き来できないとき、
            // A, B の各グループの連結成分の数の積だけ便利さが増える
            conv[i] = conv[i+1] + island.getSize(A)*island.getSize(B);
        }
        // A と B を併合
        island.unite(A,B);
    }

    // （橋 i 崩落後の不便さ）+（橋 i + 1 建設後の便利さ）= N*(N-1)/2
    for(int i=1; i<=M; i++){
        ll ans = N*(N-1)/2 - conv[i+1];
        cout << ans << endl;
    }
}

Measured memory_bytes: 4332
import sys
n = int(input())
ans = 0
i = 1
if n%2 == 1:
    print(ans)
    sys.exit()

while True:
    d = 5**i
    if d > n//2:
        break
    else:
        ans += ((n//2) - (n//2)%d)//d
        i += 1
print(ans)

Measured memory_bytes: 9108
using System;
using System.Linq;
namespace ProgrammingContest_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var L = Console.ReadLine().Split().Select(x => int.Parse(x)).OrderBy(x=>x).Select((x,i)=>new { X= x,Index = i}).ToArray();
            int sum = 0;
            foreach (var l in L)
            {
                sum += l.Index % 2 == 0 ? l.X : 0;
            }
            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 3032
#include<stdio.h>
  
#define N 100
  
int G[N][N];
  
  
int main(){
  int i,j,n,k,v,e,t;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&e);
    for(j=0;j<e;j++){
      scanf("%d",&t);
      G[i][t-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",G[i][j]);
      if(j<n-1){
        printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    if (n < 26) {
        char c;
        for (c = 'a'; c <= 'z'; c++) {
            if (s.find(c) == string::npos) {
                break;
            }
        }
        s += c;
        cout << s << endl;
        return 0;
    } else {
        if (s == "zyxwvutsrqponmlkjihgfedcba") {
            cout << -1 << endl;
            return 0;
        } else {
            string t = s, ans;
            next_permutation(s.begin(), s.end());
            for (int i = 0; i < n; i++) {
                ans += s[i];
                if (t[i] != s[i]) {
                    break;
                }
            }
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
H, N = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


dp = [[10**9] * (H + 1) for _ in range(N + 1)]
for x in range(N + 1):
    dp[x][0] = 0
    #dp[0][0] = 0

for n in range(1, N + 1):
    for h in range(1, H + 1):
        if h - A[n - 1] >= 0:
            dp[n][h] = min(dp[n - 1][h], dp[n][h - A[n - 1]] + B[n - 1])
        else:
            dp[n][h] = min(dp[n - 1][h], dp[n][0] + B[n - 1])



#print(dp)
print(dp[N][H])
                    
#dp[i+1][j] = dp[i+1][j-1] + dp[i][j] - dp[i][j-1-a[i]]
#w = c(6,4,3,2)		# 重量
#v = c(19,15,12,8)	# 価値
#f = matrix(0, 5, 21)
#for(n in 1:4) {
#  for(T in 0:20) {
#    f[n+1,T+1] = f[n-1+1,T+1]
#    if(T/w[n] < 1) next          ### for 文はCと違い、1回は必ず実行される
#    for (j in 1:(T/w[n])) {
#       f[n+1,T+1] = max(f[n+1,T+1], j*v[n] + f[n-1+1,T-j*w[n]+1])
#    }
#  }
#}


Measured memory_bytes: 120300
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
for i in range(n):
  a[i+1]+=a[i]
d=[]
for i,x in enumerate(a):
  for y in a[:i]:
    d+=[x-y]
ans=0
t=2**40
for _ in range(41):
  cnt=0
  for j in d:
    cnt+=(ans+t)&j==(ans+t)
  if cnt>=k:ans+=t
  t//=2
print(ans)

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <int MOD>
struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+(const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator-(const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator*(const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/(const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator+=(const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator-=(const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator*=(const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator/=(const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp& r) const noexcept { return this->val == r.val; }
    constexpr bool operator!=(const Fp& r) const noexcept { return this->val != r.val; }
    friend constexpr ostream& operator<<(ostream& os, const Fp<MOD>& x) noexcept { return os << x.val; }

    friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<long long> p(A), q(B), r(C);
    REP(i, A) { cin >> p[i]; }
    REP(i, B) { cin >> q[i]; }
    REP(i, C) { cin >> r[i]; }
    sort(ALL(p));
    reverse(ALL(p));
    sort(ALL(q));
    reverse(ALL(q));
    sort(ALL(r));
    reverse(ALL(r));
    vector<long long> tmp;
    REP(i, X) { tmp.push_back(p[i]); }
    REP(i, Y) { tmp.push_back(q[i]); }
    REP(i, C) { tmp.push_back(r[i]); }
    sort(ALL(tmp));
    reverse(ALL(tmp));
    cout << accumulate(tmp.begin(), tmp.begin() + X + Y, 0LL) << endl;
    return 0;
}

Measured memory_bytes: 8816
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <ll> a;

ll calc(int l, int r){
    return a[r] - (l <= 0 ? 0 : a[l - 1]);
}
ll calc(int l, int i, int r){
    return abs(calc(l, i) - calc(i + 1, r));
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    for(int i = 1 ; i < n ; i++){
        a[i] += a[i - 1];
    }
    int l = 0, r = 2;
    ll ans = 1e18;
    for(int i = 1 ; i < n - 2 ; i++){
        r = max(r, i + 1);
        while(l + 1 < i && calc(0, l, i) > calc(0, l + 1, i)) l++;
        while(r + 1 < n && calc(i + 1, r, n - 1) > calc(i + 1, r + 1, n - 1)) r++;
        ll mn = min(min(calc(0, l), calc(l + 1, i)), min(calc(i + 1, r), calc(r + 1, n - 1)));
        ll mx = max(max(calc(0, l), calc(l + 1, i)), max(calc(i + 1, r), calc(r + 1, n - 1)));
        ans = min(ans, mx - mn);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll INF=2e18;
const ll MOD=1e9+7;
ll N,M;


vector<ll> v[500];
ll a[500][500];
bool isActive[500];
ll idx[500];
int main(){
    cin>>N>>M;
    for(ll i=0;i<N;i++){
        idx[i]=0;
        for(ll j=0;j<M;j++){
            cin>>a[i][j];
        }
    }
    for(ll j=1;j<=M;j++){
        isActive[j]=true;
    }
    ll ans=INF;
    while(1){
        ll cnt[500]={};
        ll maxCnt=0,maxNum=0;
        for(ll i=0;i<N;i++){
            cnt[a[i][idx[i]]]++;
        }
        for(ll i=0;i<N;i++){
            ll n=a[i][idx[i]];
            if(maxCnt < cnt[n]){
                maxCnt=cnt[n];
                maxNum=n;
            }
        }
        isActive[maxNum]=false;
        ans=min(ans,maxCnt);
        for(ll i=0;i<N;i++){
            while(idx[i]<M && !isActive[a[i][idx[i]]]){
                idx[i]++;
            }
            if(idx[i]>=M){
                cout<<ans<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 1408
import sys

# 実行環境(0:vscode, 1:atcoder)
MODE = 1

# 入力の次元
DIMENSION = 2

# int型に変換
INT_TYPE = 1

if not (MODE):
    with open("input.txt", "r") as f:
        s = f.read()
else:
    s = sys.stdin.read()

if DIMENSION == 0:
    if INT_TYPE == 1:
        s = int(s)
elif DIMENSION == 1:
    if INT_TYPE == 0:
        s = s.split()
    elif INT_TYPE == 1:
        s = [int(x) for x in s.split()]
elif DIMENSION == 2:
    if INT_TYPE == 0:
        s = [x.split() for x in s.splitlines()]
    elif INT_TYPE == 1:
        s = [[int(y) for y in x.split()] for x in s.splitlines()]

N = s[0][0]

if s[1].count(0) > 0:
    print(0)
else:
    A_sort = sorted(s[1])
    val = 1
    for i in range(N):
        val *= A_sort[N - i - 1]
        if val > 1e18:
            print(-1)
            sys.exit()
    print(val)


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

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int N=sc.nextInt();
				if(N==0) break;
				double[][] dist=new double[N+2][N+2];
				double[] dp=new double[1<<N];
				double inf=1e100;

				for(int i=0; i<N; i++){
					for(int j=0; j<=N; j++){
						dist[i][j]=sc.nextInt();
					}
				}
				Arrays.fill(dp, inf);
				dp[0]=0;

				for(int i=0; i<(1<<N); i++){
					for(int j=0; j<N; j++){
						if((1&i>>j)==1) {
							continue;
						}
						int nexti=i|(1<<j);
						double nextd=dp[i]+dist[j][0];
						dp[nexti]=Math.min(dp[nexti], nextd);
						for(int k=0; k<N; k++) {
							if((1&i>>k)==0) {
								continue;
							}
							dp[nexti]=Math.min(dp[nexti], dp[i]+dist[j][k+1]);
						}
					}
				}
				int all=(1<<N)-1;
				System.out.println((int)dp[all]);
			}


		}
	}
}


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

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

using namespace std;

int main(){
	int n,l[10]; cin>>n;
	rep(i,n) cin>>l[i];

	sort(l,l+n);

	cout<<(accumulate(l,l+n-1,0)>l[n-1]?"Yes":"No")<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    ll n;
    cin>>n;
    vvll v(n,vll(3));
    rep(i,n)cin>>v[i][0]>>v[i][1]>>v[i][2];
    for(ll x=0;x<=100;x++){
        for(ll y=0;y<=100;y++){
            bool ch=true;
            ll height=INF;
            rep(i,n)chmin(height,abs(v[i][0]-x)+abs(v[i][1]-y)+v[i][2]);
            rep(i,n){
                ll h=abs(v[i][0]-x)+abs(v[i][1]-y)+v[i][2];
                if(h==height||!v[i][2])continue;
                if(h!=height){
                    ch=false;
                }
            }
            if(ch){
                cout<<x<<" "<<y<<" "<<height<<endl;
                return 0;
            }
        }
    }

}

Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    s = list(itertools.accumulate(dp[i - 1]))
    for k in range(K+1):
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)



Measured memory_bytes: 219852
N = int(input())
A_list = list(map(int, input().split()))

# x = A1
S = 0
for i in range(N - 1):
    if i % 2 == 0:
        S -= A_list[i]
    else:
        S += A_list[i]

x = (A_list[-1] - S) // 2

R_list = [0] * N
R_list[0] = x

for i in range(1, N):
    R_list[i] = A_list[i - 1] - R_list[i - 1]

print(" ".join([str(2 * r) for r in R_list]))


Measured memory_bytes: 75364
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif
using namespace std;

V<ll> query_v;

bool query() {
    cout << "?";
    for(ll e : query_v) cout << ' '  << e + 1;
    cout << endl << flush;
    string S;
    cin >> S;
    return S == "Red";
}

int main() {
    ll N;
    cin >> N;
    query_v.resize(N);
    iota(ALL(query_v), 0);
    bool left = query();
    ll l = 0, r = N;
    while(r - l > 1) {
        ll mid = (r + l) / 2;
        iota(ALL(query_v), mid);
        (left == query() ? l : r) = mid;
    }

    V<bool> ans(2 * N);
    ans[l] = left;
    ans[l + N] = !left;
    for(ll i = 0; i < N - 1; i++) query_v[i] = l + i + 1;
    for(ll i = 0; i < 2 * N; i++) {
        if(l <= i && i <= l + N) continue;
        query_v.back() = i;
        ans[i] = query();
    }
    ll rcnt = 0, bcnt = 0, qidx = 0;
    for(ll i = 0; i < 2 * N; i++) {
        if(l < i && i < l + N) continue;
        if(rcnt < (N - 1) / 2 && ans[i]) {
            query_v[qidx] = i;
            qidx++;
            rcnt++;
        }
        if(bcnt < (N - 1) / 2 && !ans[i]) {
            query_v[qidx] = i;
            qidx++;
            bcnt++;
        }
    }
    for(ll i = l + 1; i < l + N; i++) {
        query_v.back() = i;
        ans[i] = query();
    }

    cout << "! ";
    for(auto &&ele : ans) cout << (ele ? 'R' : 'B');
    cout << endl << flush;
    return 0;
}


Measured memory_bytes: 724
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
a=[]
for i in range(k):
    a.append([])
for i in range(n):
    a[i%k].append(t[i])
for i in range(k):
    for j in range(len(a[i])):
        if j>=1:
            if a[i][j]==a[i][j-1]:
                a[i][j]=0
ans=0
for i in range(k):
    for j in range(len(a[i])):
        if a[i][j]=="r":
            ans+=p
        elif a[i][j]=="s":
            ans+=r
        elif a[i][j]=="p":
            ans+=s
print(ans)

Measured memory_bytes: 87632
#include <cstdio>
#include <cstring>
#include <set>
#include <string>

using namespace std;

const int mod = 1000000007;

int mul(int a, int b) {
  return (a * 1LL * b) % mod;
}

int add(int a, int b) {
  int res = a + b;
  if (res >= mod) res -= mod;
  return res;
}

int power(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int dp[102][4][4][4];
set<string> S;

// A = 0, G = 1, C = 2, T = 3
int f(int n, int i, int j, int k) {
  if (dp[n][i][j][k] != -1) return dp[n][i][j][k];
  int& res = (dp[n][i][j][k] = 0);
  if (n == 3) {
    string cur;
    cur.push_back(i + '0');
    cur.push_back(j + '0');
    cur.push_back(k + '0');
    return res = (S.find(cur) == S.end());
  }

  // 4th char
  for (int c = 0; c < 4; ++c) {
    string cur; 
    cur.push_back(c + '0');
    cur.push_back(i + '0');
    cur.push_back(j + '0');
    cur.push_back(k + '0');
    if (S.find(cur) == S.end()) {
      res = add(res, f(n - 1, c, i, j));
    }
  }
  return res;
}

int main() {
  S.insert("012");
  S.insert("102");
  S.insert("021");

  S.insert("3012");
  S.insert("0312");
  S.insert("0132");
  S.insert("0123");
  S.insert("3102");
  S.insert("1023");
  S.insert("3021");
  S.insert("0213");

 //
  S.insert("0012");
  S.insert("0012");
  S.insert("0102");
  S.insert("0120");
  S.insert("0102");
  S.insert("1020");
  S.insert("0021");
  S.insert("0210");

  //
  S.insert("1012");
  S.insert("0112");
  S.insert("0112");
  S.insert("0121");
  S.insert("1102");
  S.insert("1021");
  S.insert("1021");
  S.insert("0211");

  //
  S.insert("2012");
  S.insert("0212");
  S.insert("0122");
  S.insert("0122");
  S.insert("2102");
  S.insert("1022");
  S.insert("2021");
  S.insert("0212");
  int n;
  scanf("%d", &n);
  memset(dp, -1, sizeof(dp));

  int res = 0;
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      for (int k = 0; k < 4; ++k) {
        res = add(res, f(n, i, j, k));
      }
    }
  }
  printf("%d\n", res);
  return(0);
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int sum=0;
    bool ok = true;
    rep(i,0,s.size()){
        if(i==0){
            sum += s[i]-'0';
        }
        if(s[i] != '9' && ok && i != 0){
            sum+=8;
            ok = false;
        }else if(i != 0) sum += 9;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define NIL -1

int F[45];

int fibo(int n){
  int v;
  
  if(F[n] != NIL) return F[n];
  v = fibo(n-1)+fibo(n-2);
  F[n] = v;
  return v;
}


int main(){
  int n,i;
  F[0] = 1;
  F[1] = 1;
  
  scanf("%d",&n);
  
  for(i=2; i < 45; i++){
    F[i] = NIL;
  }
  
  printf("%d\n",fibo(n));
   
  return 0;
}

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

long dp[100010][3];
int a[100010][3];
int main()
{
    int n; cin>>n;
    for(int i=0; i<n; ++i)
        for(int j=0; j<3; ++j)
            cin>>a[i][j];
    
    for(int i=0; i<n; ++i)
        for(int j=0; j<3; ++j)
            for(int k=0; k<3; ++k) if (j!=k)
                dp[i+1][j]=max(dp[i+1][j], dp[i][k]+a[i][j]);

    long res=0;
    for(int i=0; i<3; ++i) res=max(res, dp[n][i]);
    cout<<res<<endl;
}


Measured memory_bytes: 3712
#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"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

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



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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	long long int ans = 0;
	for (int i = 0; i <= d; i++) {
		for (int j = 0; j <= d; j++) {
			N = d - a * i - b * j;
			if (N >= 0 && N%c == 0)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    fastIO;
    ll n;
    cin>>n;
    ll val;
    ll a[n],p[n],q[n],i;
    val=1;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>q[i];
    }
    for(i=1;i<=n;i++)
    {
        val*=i;
    }
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    vector<ll>v[val];
    for(i=0;i<n;i++)
    {
        v[0].push_back(a[i]);
    }
    for(i=1;i<val;i++)
    {
        if(next_permutation(a,a+n))
        {
            for(ll j=0;j<n;j++)
            {
                v[i].push_back(a[j]);
            }
        }
    }
    ll pos,pos1,count=0;
    for(i=0;i<val;i++)
    {
        count=0;
        for(ll j=0;j<n;j++)
        {
            if(p[j]==v[i][j])
            {
                count++;
            }
        }
        if(count==n)
        {
            pos=i;
            break;
        }
    }
    for(i=0;i<val;i++)
    {
        count=0;
        for(ll j=0;j<n;j++)
        {
            if(q[j]==v[i][j])
            {
                count++;
            }
        }
        if(count==n)
        {
            pos1=i;
            break;
        }
    }
    cout<<abs(pos1-pos)<<'\n';
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    ll S;
    cin >> S;
    ll x1, y1, x2, y2, x3, y3;
    x1 = y1 = 0;

    ll t = sqrt(S);
    if (t * t == S) {
        x2 = t;
        y2 = 0;
        x3 = 0;
        y3 = t;
    } else {
        x2 = t + 1;
        y2 = x2 * x2 - S;
        x3 = 1;
        y3 = t + 1;
    }
    
    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=205;
const int inf=10000001;

int n,prime[inf+5],match[N],a[N],b[N],a1,b1,tot;
bool s[inf+5],not_prime[inf+5],vis[N],ma[N][N];

void get_prime(int n)
{
	not_prime[1]=1;
	for (int i=2;i<=n;i++)
	{
		if (!not_prime[i]) prime[++tot]=i;
		for (int j=1;j<=tot&&i*prime[j]<=n;j++)
		{
			not_prime[i*prime[j]]=1;
			if (i%prime[j]==0) break;
		}
	}
}

bool find(int x)
{
	for (int i=1;i<=b1;i++)
		if (ma[x][i]&&!vis[i])
		{
			vis[i]=1;
			if (!match[i]||find(match[i]))
			{
				match[i]=x;
				return 1;
			}
		}
	return 0;
}

int main()
{
	get_prime(inf);
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		int x;scanf("%d",&x);
		s[x]=1;
	}
	for (int i=1;i<=inf;i++)
		if (s[i]!=s[i-1])
		{
			if (i&1) a[++a1]=i;
			else b[++b1]=i;
		}
	for (int i=1;i<=a1;i++)
		for (int j=1;j<=b1;j++)
			if (!not_prime[abs(a[i]-b[j])]) ma[i][j]=1;
	int ans=0,tmp=0;
	for (int i=1;i<=a1;i++)
	{
		memset(vis,0,sizeof(vis));
		if (find(i)) tmp++,ans++;
	}
	ans+=(a1-tmp)/2*2+(b1-tmp)/2*2;
	if (a1%2!=tmp%2) ans+=3;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 22784
#include <iostream>

using namespace std;

int main() {
    int length;
    cin >> length;
    string line;
    cin >> line;

    if (length % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }

    string a, b;
    a = line.substr(0, length / 2);
    b = line.substr(length / 2, length / 2);
    if(a == b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

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

int main(){
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;
	if(a1 + a2 + a3 >= 22) cout << "bust" << endl;
	else cout << "win" << endl;
	return 0;
}	

Measured memory_bytes: 256