akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nk[0];
        var k = nk[1];
        var seqP = Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray();

        var es = new double[seqP.Length + 1];
        for (int i = 1; i < es.Length; ++i)
        {
            var x = (1 + seqP[i - 1]) * seqP[i - 1] / 2 / seqP[i - 1];
            es[i] = es[i - 1] + x; // x < es[i - 1] ? x + es[i - 1] : es[i - 1] + x;
        }

        var max = new Transitive<double>(0);
        for (int i = k; i < es.Length; ++i)
        {
            max += es[i] - es[i - k];
        }

        Console.WriteLine($"{max}");
    }

    struct Transitive<T>
    where T : IComparable<T>
    {
        public T Value;
        public Transitive(T value)
        {
            Value = value;
        }

        public override string ToString() => Value.ToString();

        public static implicit operator Transitive<T>(T value) => new Transitive<T>(value);
        public static Transitive<T> operator -(Transitive<T> x, Transitive<T> y) => x.Value.CompareTo(y.Value) < 0 ? x : y;
        public static Transitive<T> operator +(Transitive<T> x, Transitive<T> y) => x.Value.CompareTo(y.Value) > 0 ? x : y;
    }
}


Measured memory_bytes: 34140
#include <iostream>

typedef long long ll;

using namespace std;

int main()	{
  ll n;
  cin >> n;
  ll x;
  ll n_2s = 0, n_4s = 0;
  for (int i = 0; i < n; i++)	{
    cin >> x;
    if (x % 2 == 0 && x % 4)	{
      n_2s++;
    }
    else if (x % 4 == 0)	{
      n_4s++;
    }
  }
  if (n_2s / 2 + n_4s >= n / 2)	{
    cout << "Yes" << endl;
  }
  else	{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	vector<int>vec1(n);
	rep(i, n) {
		cin >> vec1[i];
	}
	
	int ans = 0;

	for (int i = 1; i < n - 1; i++) {
		if (vec1[i - 1] > vec1[i] && vec1[i] > vec1[i + 1] || vec1[i - 1] < vec1[i] && vec1[i] < vec1[i + 1]) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
    if(flg) {
        cout << hoge << endl;
        exit(0);
    }
}
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n>>m;
    cout<<(n==m?"Yes":"No")<<endl;
}

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

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

  int m = n-1;

  vector<int> a(m);
  rep(i,m){
    cin >> a[i];
  }

  vector<int> b(n);
  rep(i,m) {
    b[a[i]-1]++ ;
  }

  rep(i,n) {
    cout << b[i] << endl;
  }


}


Measured memory_bytes: 4844
#include<stdio.h>
int main() {
  int data[5], sum = 0, ave, i;
  for(i = 0; i < 5; i++) {
    scanf("%d", &data[i]);
    if(data[i] < 40) {
      data[i] = 40;
    }
    sum += data[i];
  }
  ave = sum / 5;
  printf("%d\n", ave);
  return 0;
}
  

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n;str s; cin >> n >> s;ll ans = 0, flag = 0;
  for(ll i = 0;i < n;i++)
  {
    if(s[i] == 'I') ans++;
    else ans--;
    flag = max(flag, ans);
  }
  fin(flag)
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


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

int cells[2000][2000];

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; ++i) {
    cin >> grid[i];
  }
  for (int i = 0; i < h; ++i) {
    int l = 0;
    for (int j = 0; j < w; ++j) { 
      if (grid[i][j] == '#') { 
        for (int k = l; k < j; ++k) {
          cells[i][k] += j-l;
        }
        l = j+1;
      }
    }
    for (int k = l; k < w; ++k) {
      cells[i][k] += w-l;
    }
  }
  for (int i = 0; i < w; ++i) {
    int l = 0;
    for (int j = 0; j < h; ++j) { 
      if (grid[j][i] == '#') { 
        for (int k = l; k < j; ++k) {
          cells[k][i] += j-l;
        }
        l = j+1;
      }
    }
    for (int k = l; k < h; ++k) {
      cells[k][i] += h-l;
    }
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) { 
      ans = max(ans, cells[i][j]-1);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 19968
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int m=1000000007;



  unordered_map<int,int> fmap;
    unordered_map<int,int> r;
    int find(int a)
    {
        if(fmap.count(a)!=1)
        {fmap[a]=a; }
        
        if(fmap[a]==a)return a;
        else
        {
            int pr=find(fmap[a]);
            fmap[a]=pr;
            return pr;
        }
        
            
    }
    
    void merge(int a,int b)
    {
      
        int pra=find(a);
        // cout<<pra<<endl;
        int prb=find(b);//cout<<prb<<endl;
         
         
        if(pra!=prb)
        {
          //cout<<r[pra]<<" "<<r[prb]<<endl;
           
          
            if(r[pra]>r[prb])
            {
                fmap[prb]=pra;
            }
            else if(r[pra]<r[prb])
            {
                fmap[pra]=prb;
            }
            else
            {
                r[pra]=r[pra]+1;
                fmap[prb]=pra;
                
            }
        }
    }
    
    

int main() {
    ll n,m;
    cin>>n>>m;
    
    for(int i=0;i<m;i++)
    {
        int a,b; cin>>a>>b;
        merge(a,b);
    }
    
    unordered_map<int,int> cal;
    for(int i=1;i<=n;i++)
    {
        if(fmap.count(i)!=1)
        cal[i]++;
        else
        cal[find(i)]++;
        
    }
    
    int ans=1;
    for(auto it=cal.begin();it!=cal.end();it++)
    ans=max(ans,(*it).second);
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 19736
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

struct item{
    ll x, y, d;
    item(ll x, ll y, ll d):x(x), y(y), d(d){}
};
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll h,w; cin >> h >> w;
    ll cx,cy; cin >> cx >> cy;
    ll gx,gy; cin >> gx >> gy;
    cx--;cy--;gx--;gy--;
    vector<string> s(h);
    rep(i,0,h){
        cin >> s[i];
    }
    ll dx[] = {0,0,1,-1};
    ll dy[] = {1,-1,0,0};
    auto is_out = [&](ll x, ll y){
       if(x < 0 || x >= h || y < 0 || y >= w)return true;
       return false;
    };
    vector<vector<ll>> dp(h, vector<ll>(w, INF));

    dp[cx][cy] = 0;
    deque<item> deq;
    deq.emplace_front(cx, cy, 0);
    while(!deq.empty()){
        auto [x, y, d] = deq.front();
        deq.pop_front();
        if(dp[x][y] < d)continue;
        rep(i,0,4){
            ll nx = x + dx[i], ny = y + dy[i];
            if(is_out(nx, ny))continue;
            if(s[nx][ny] == '#')continue;
            if(chmin(dp[nx][ny], d)){
                deq.emplace_front(nx, ny, d);
            }
        }
        rep(i,-2,3)rep(j,-2,3){
            ll nx = x + i, ny = y + j;
            if(is_out(nx, ny))continue;
            if(s[nx][ny] == '#')continue;
            if(chmin(dp[nx][ny], d + 1)){
                deq.emplace_back(nx, ny, d + 1);
            }
        }
    }

    cout << (dp[gx][gy] != INF ? dp[gx][gy] : -1) << "\n";
}

Measured memory_bytes: 12736
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
const int MAXV = 13;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s;
  cin >> s;
  int n = s.size();

  vector<ll> dp(MAXV, 0);
  dp[0] = 1;

  int mul = 1;
  repr(i, 0, n) {
    vector<ll> next(MAXV, 0);
    char c = s[i];

    if (c == '?') {
      rep(k, 0, 10) {
        rep(j, 0, MAXV) {
          next[(k * mul + j) % MAXV] += dp[j];
          next[(k * mul + j) % MAXV] %= MOD;
        }
      }
    } else {
      int k = (int)(s[i] - '0');
      rep(j, 0, MAXV) {
        next[(k * mul + j) % MAXV] += dp[j];
        next[(k * mul + j) % MAXV] %= MOD;
      }
    }
    mul *= 10;
    mul %= MAXV;
    dp = next;
  }

  cout << dp[5] << endl;
}


Measured memory_bytes: 3680
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;

long int com(long int a){
	return (a==0) ?  0:(a*(a-1))/2;
}



int main (){
	long int NNN;
	cin >> NNN;
	long int temp;
	long int a[NNN+1];
	a[0]=0;
	vector <long int> sum;
	rep(i,NNN){
		cin >>a[i+1];
		a[i+1] += a[i];
		sum.push_back(a[i+1]);
	}

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

	temp=INF;
	long int count=1;
	long int anscount=0;

	rep(i,NNN){
		if(i==0){
			temp = sum[0];
			continue;
		}

		else if(temp==sum[i]){
			count ++;
		}

		else if(temp!=sum[i]){
			anscount += com(count);
			if(temp==0){
				anscount += count;
			}
			temp = sum[i];
			count =1;
		}

	}
	anscount += com(count);
	if(temp==0) anscount += count;


	cout << anscount << endl;

	return 0;
}


Measured memory_bytes: 3568
lst = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(lst[K-1])


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n==0) {
				break;
			}
			int[] x = new int[n];
			int[] y = new int[n];
			boolean[][] p = new boolean[5001][5001];
			for(int i=0;i<n;i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				x[i] = a;
				y[i] = b;
				p[a][b] = true;
			}
			int ans = 0;
			for(int i=0;i<n-1;i++) {
				for(int j=i+1;j<n;j++) {
					int vx = x[j]-x[i];
					int vy = y[j]-y[i];
					int dist = vx*vx+vy*vy;
					if(dist<ans) {
						continue;
					}
					if((check(p,x[i]+vy,y[i]-vx) && check(p,x[j]+vy,y[j]-vx)) ||
							(check(p,x[i]-vy,y[i]+vx) && check(p,x[j]-vy,y[j]+vx))) {
						ans = dist;
					}
				}
			}
			System.out.println(ans);
		}
	}
	private static boolean check(boolean[][] p,int x,int y) {
		if (x>=0 && x<=5000 && y>=0 && y<=5000) {
			return p[x][y];
		}else{
			return false;
		}
	}
}

Measured memory_bytes: 127936
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n<=999)
  {
    int dig=n%10;
    if(dig==2 || dig==4 || dig==5 || dig==7 )
    {
      cout<<"hon"<<endl;

    }

    else if(dig==0 || dig==1|| dig==6 || dig==8)
    {
      cout<<"pon"<<endl;
    }
    else if(dig==3)
    {
      cout<<"bon"<<endl;
    }
    else
    {
      cout<<"hon"<<endl;
}
  }
}


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

#define MX 105

int main()
{
    int n,k;
    string s;
    cin>>n>>k>>s;
    int cnt, dnt;
    cnt = dnt = 0;
    for(int i = 1; i < n; i++)
    {
        if(s[i] == s[i-1])cnt++;
        else dnt++;
    }
    if( dnt < (k<<1) )cout<<cnt+dnt<<endl;
    else cout<<cnt+(k<<1)<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
int main() {
    Int N, X, M; cin >> N >> X >> M;
    vector<vector<Int>> A(M + 1, vector<Int>(40)), S(M + 1, vector<Int>(40));
    for (int i = 0; i < M; i++) {
        A[i][0] = (Int)i * i % M;
        S[i][0] = i;
    }
    for (int t = 1; t < 40; t++) {
        for (int i = 0; i < M; i++) {
            A[i][t] = A[A[i][t-1]][t-1];
            S[i][t] = S[i][t-1] + S[A[i][t-1]][t-1];
        }
    }
    Int ans = 0;
    Int val = X;
    for (int t = 39; t >= 0; t--) {
        if (N >= (1LL << t)) {
            ans += S[val][t];
            val = A[val][t];
            N -= (1LL << t);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 73404
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;
int dp[41][401][401];

int main() {
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  int a[N], b[N], c[N];
  REP(i, N) cin >> a[i] >> b[i] >> c[i];

  REP(i, N + 1) {
    REP(j, 401) {
      REP(k, 401) { dp[i][j][k] = INF; }
    }
  }
  dp[0][0][0] = 0;

  REP(i, N) {
    REP(j, 401) {
      REP(k, 401) {
        if(dp[i][j][k] == INF) continue;
        dp[i + 1][j][k] = min(dp[i][j][k], dp[i + 1][j][k]);
        dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
      }
    }
  }

  int ans = INF;
  REPS(j, 401) {
    REPS(k, 401) {
      if(k * Ma == j * Mb) {
        ans = min(ans, dp[N][j][k]);
      }
    }
  }
  if(ans == INF) ans = -1;

  cout << ans << endl;
}

Measured memory_bytes: 25984
import Debug.Trace

main = do
  n <- readLn :: IO Int
  ts <- getLine >>= return . (map read) . words :: IO [Double]
  vs <- getLine >>= return . (map read) . words :: IO [Double]

  print $ sum $ solve ts vs

  where
    solve :: [Double] -> [Double] -> [Double]
    solve ts vs = solve' 0 ts vs (tail $ maxVelo ts vs)

    solve' :: Double -> [Double] -> [Double] -> [Double] -> [Double]
    solve' _ [] _ _ = []
    solve' s (t:ts) (v:vs) (m:ms) =
      if v <= m then
        if v-s <= t then
          (t*v - (v-s)^2/2) : (solve' v ts vs ms)
        else
          (t*s + t*t/2) : (solve' (s+t) ts vs ms)
      else
        if s+t <= m then
          (t*s + t*t/2) : (solve' (s+t) ts vs ms)
        else
          let
            x1 = v - s;
            x2 = t + m - v;
          in
            if x1 <= x2 then
              (x1*(s+v)/2 + (x2-x1)*v + (t-x2)*(m+v)/2) : (solve' m ts vs ms)
            else
              let x' = t-s+m
              in
                ((x'/2)*(2*s+(x'/2))/2 + (t-(x'/2))*(m+s+(x'/2))/2) : (solve' m ts vs ms)
              
        
    maxVelo :: [Double] -> [Double] -> [Double]
    maxVelo [] _ = [0]
    maxVelo (t:ts) (v:vs) = (min v (next+t)) : r
      where
        r = maxVelo ts vs
        next = head r

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

using namespace std;

int main(void){
    string s;
    int k;
    cin >> s >> k;
    char x;
    char filter='a';
    vector<int> lst;
    set<string> st;
    while(true){
        x='z';
        for(int i=0;i<s.size();i++){
            if(s.at(i)<x&&filter<=s.at(i)){x=s.at(i);}
            // cout << s.at(i) << endl;
        }
        // cout << "x: " << x << endl;
        // cout << x << endl;
        for(int i=0;i<s.size();i++){
            if(s.at(i)==x){lst.push_back(i);}
        }
        // for(int i=0;i<lst.size();i++){
        //     cout << lst.at(i) << endl;
        // }
        for(int j=0;j<lst.size();j++){
            for(int i=1;i<=s.size()&&lst.at(j)+i-1<s.size()&&i<=k;i++){
                // cout << j << endl;
                string sbstr = s.substr(lst.at(j),i);
                if(st.find(sbstr)==st.end()){
                    // cout << sbstr << endl;
                    st.insert(sbstr);
                }
            }
        }
        // cout << st.size() << endl;
        if(st.size()>=k){break;}
        // cout << filter << endl;
        filter=char(max(int(filter),int(x))+1);
        lst.clear();
        if(filter>'z'){break;}
    }
    vector<string> vs(st.begin(), st.end());
    sort(vs.begin(),vs.end());
    // for(int i=0;i<vs.size();i++){
    cout << vs.at(k-1) << endl;
    // }
}


Measured memory_bytes: 256
N, T = list(map(int,input().split()))
c = [0 for i in range(N)]
t = [0 for i in range(N)]
for i in range(N):
  c[i], t[i] = input().split()
  c[i] = int(c[i])
  t[i] = int(t[i])

ans = float('inf')
for i in range(N):
  if t[i] <= T and c[i] < ans:
    ans = c[i]
if ans == float('inf'):
  print('TLE')
else:
  print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
ll bigp = 1000000007;

int main()
{
    ll n;
    cin >> n;
    vector<ll> d(n);
    rep(i,n){
        cin >> d[i];
    }
    ll ans = 0;
    rep(i,n){
        reps(j,i+1,n){
            ans += d[i]*d[j];
        }
    }
    cout << ans;
}

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

int main(){
	int n; cin >> n;
	string s; cin >> s;
	vector<int> sum(n+1);
	sum[0]=0;
	for(int i=0;i<n;i++) {
		if(s[i]=='E') sum[i+1]=sum[i]+1;
		else sum[i+1]=sum[i];
	}
	int ans=n+1;
	for(int i=0;i<n;i++){
		int temp=0;
		temp+=i-sum[i];
		temp+=sum[n]-sum[i+1];
		ans=min(ans,temp);
	}
	cout << ans << endl;
}


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

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v){
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}


const int N = 4e2+1;
int dp[N][N];
int n, a[N];

int fun(int i, int j) {
    if(j-i == 0)return 0;
    if(dp[i][j] != -1)return dp[i][j];
    dp[i][j] = inf;
    int cur = 0;
    for(int k = i; k <= j; k++)cur += a[k];
    for(int k = i; k < j; k++) {
        dp[i][j] = min(dp[i][j], fun(i, k)+fun(k+1, j) + cur);
    }
    return dp[i][j];
}

void solve(int &test) {
    int n;
    cin >> n;
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i < n; i++)
        cin >> a[i];
    cout << fun(0, n-1) << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   
    start = clock(); 

   
    int t = 1;
    // cin >> t;

    cout << fixed << setprecision(2);
     
    for(int i = 1; i <= t; ++i){
        solve(i); 
    }

    cerr << time(start);
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	ll h1,h2;
	int cnt(0),ans(0);
	cin >> h1;
	rep(i,n-1){
		cin >> h2;
		if(h1>=h2){cnt++;}
		else{cnt = 0;}
		h1 = h2;
		ans = max(ans,cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<tuple>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<tuple<string,int,int>> p(n);
    string s;
    int a;
    for(int i=0;i<n;i++){
        cin >> s >> a;
        p[i]=make_tuple(s,100-a,i+1);
    }
    sort(p.begin(),p.end());
    for(int i=0;i<n;i++){
         int&j=get<2>(p[i]);
        cout << j << endl;
    }
    return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	vi s(n); rep(i, n) cin >> s[i];
	int q; cin >> q;
	vi t(q); rep(i, q) cin >> t[i];

	int cnt = 0;
	rep(i, q) {
		if (upper_bound(ASC(s), t[i]) - lower_bound(ASC(s), t[i])) cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3356
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#define mod 1000000007
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define srep(i,s,t) for (ll i = s; i < t; i++)
#define drep(i,n) for(ll i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef vector<vector<char>> field_t;
typedef unsigned long long ull;
typedef pair<ll, ll> point_t;
using Graph = vector<vector<ll>>; // グラフ型 // グラフ


int main()
{
    ll k,d;
    cin >> k>>d;
    vector<ll> x(k),y(k);
    ll ans=0;
    rep(i,k){
        cin>>x[i]>>y[i];
        ll p=x[i]*x[i]+y[i]*y[i];
        ll q=d*d;
        if(q>=p){
            ans++;
        }
    }
    
    cout<<ans<<endl;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  string a, b;
  cin >> a >> b;
  sort(all(a));
  sort(rall(b));

  if (a < b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N;
vector<int> A;
vector<bool> used;

pair<int, int> dfs(int i) {
    used[i] = true;

    int c = 0;
    int j = i + 1;
    for (; j < N && A[j] == A[i]; ++j);
    c = j - i;

    int p = 0;
    rep(b, 1, 31) {
        int target = (1 << b) - A[i];
        if (target <= A[i]) continue;

        int k = lower_bound(all(A), target) - A.begin();
        if (k == N || used[k] || A[k] != target) continue;

        auto r = dfs(k);
        p += r.first;
        p += min(c, r.second);
        c -= min(c, r.second);
    }

    return { p, c };
}

int main() {
    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];
    sort(all(A));

    used.resize(N);

    int ans = 0;
    for (int i = 0, j; i < N; i = j) {
        for (j = i + 1; j < N && A[j] == A[i]; ++j);

        if (!used[i]) {
            if ((A[i] & A[i] - 1) == 0) {
                auto r = dfs(i);
                ans += r.first;
                ans += r.second / 2;
            }
            else {
                auto r = dfs(i);
                ans += r.first;
            }
        }
    }

    write(ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    long long int N;
    cin >> N;
	cout << 50 << "\n";
    long long int ans[50];
    int index = 0;
    for(int i = 49; i >= 0; i--){
        ans[index] = i;
        index++;
    }
    for(int i = 0; i < 50; i++){
       ans[i]+=((N + 49 -i)/50);
    }
    for(int i = 0; i < 50; i++){
        cout << ans[i] << " ";
    }
	cout << "\n";
    return 0;
}

Measured memory_bytes: 256
s = list(map(int, input()))
l = int(str(s[0]) + str(s[1]))
u = int(str(s[2]) + str(s[3]))

if l == 0:
    if u > 12:
        print("NA")
    elif u == 0:
        print("NA")
    else:
        print("YYMM")
elif l <= 12:
    if u > 12:
        print("MMYY")
    elif u == 0:
        print("MMYY")
    else:
        print("AMBIGUOUS")
else:
    if u > 12:
        print("NA")
    elif u == 0:
        print("NA")
    else:
        print("YYMM")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
int32_t main()
{           
    IOS;   
    ll r,g,b,n;
    cin>>r>>g>>b>>n;
    ll ans=0;
    for(ll i=0;i<=6000;i++)
    {
        for(ll j=0;j<=6000;j++)
        {
            if(i*r+j*g>n)
                continue;
            ll left=n-i*r-j*g;
            if(left%b==0)
                ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
    int n;
  cin >>n;
    vector<int> a(n);
    REP(i,n)a[i]=0;
    REP(i,n){
        cin >> a[i];
    if(a[i]%2==0){
        if(a[i]%3==0||a[i]%5==0){
    }else{
        cout << "DENIED";
        return 0;
    }
    }
    }
cout << "APPROVED";
return 0;
}

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

int main() {
  long long money;
  int fo = 0;
  int f = 0;
  cin >> money;
  
  fo = money / 500;
  
  int tmp = money % 500;
  f = tmp / 5;
  
  cout << (fo * 1000) + (f * 5);      
}


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

int main(void)
{
    int n, a[100010], b[3];
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    if(n % 3)
    {
        if(a[n - 1] == 0)
        {
            puts("Yes");
        }
        else
        {
            puts("No");
        }
        return 0;
    }
    for(int i = 0; i < 3; ++i)
    {
        b[i] = a[i * n / 3];
        for(int j = 1; j < n / 3; ++j)
        {
            if(b[i] != a[i * n / 3 + j])
            {
                puts("No");
                return 0;
            }
        }
    }
    if((b[0] ^ b[1]) == b[2] || (b[0] ^ b[2]) == b[1] || (b[1] ^ b[2]) == b[0])
    {
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 640
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    AIN(ll, x, 5);
    REP(i, 5)
    {
        if (x[i] == 0)
        {
            OUT(i + 1);
            break;
        }
    }
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 110;
int a[MAX];
int sum;
void SelectionSort(int a[], int n)
{
	int mini;
	for(int i = 0; i < n; ++ i)
	{
		mini = i;
		for(int j = i; j < n; ++ j)
		{
			if(a[j] < a[mini])
			{
				mini = j;
			}
		}
		swap(a[i], a[mini]);
		if(i != mini)
		{
			sum ++;
		}
	}
}
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; ++ i)
	{
		cin >> a[i];
	}
	
	SelectionSort(a, n);
	
	for(int i = 0; i < n; ++ i)
	{
		if(i == n - 1)
			cout << a[i];
		else
			cout << a[i] << " ";
	}
	cout << endl;
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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

    if(n>=10){
        cout << r << endl;
    }
    else{
        cout << 100 * (10-n) + r << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
  int n,k,s;
  // nは整数，kは集合の数，sは合計
  while(cin>>n>>k>>s,n&&k&&s) {
    int ans=0;
    for (int bits = 0; bits < (1<<n); bits++) {
      if (__builtin_popcount(bits)!=k) continue;
      int res=0;
      for (int i=1; i<n+1; i++) {
        if (bits & 1<<(i-1)) { res += i; }
      }
      if (res == s) ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
    string s,t;
    cin>>s>>t;
    bool ans=false;
    int x =stoi(s+t);
    for(int i=1; i<=1000; i++){
        if(i*i==x) ans=true;
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
def gr_si(i):
    if i==oy_si[i]:
        return i
    else:
        oy_si[i]=gr_si(oy_si[i])
        return gr_si(oy_si[i])

sn,bn=map(int,input().split(" "))
fu=[int(sn*(sn-1)/2)]
siL_br=[]
for _ in range(bn):
    siL_br.append(list(map(int, input().split(" "))))
siL_br=siL_br[::-1]
oy_si=[n for n in range(sn+1)]
ra_gr=[0 for n in range(sn+1)]
yn_gr=[1 for n in range(sn+1)]

for bri in range(bn-1):
    si1,si2=siL_br[bri]
    if gr_si(si1)==gr_si(si2):
        fu.append(fu[bri])
    else:
        gr1, gr2 = gr_si(si1), gr_si(si2)
        if ra_gr[gr1] < ra_gr[gr2]:
            gr1, gr2 = gr2, gr1
        elif ra_gr[gr1] == ra_gr[gr2]:
            ra_gr[gr1] += 1
        fu.append(fu[bri] - yn_gr[gr1] * yn_gr[gr2])
        yn_gr[gr1] += yn_gr[gr2]
        oy_si[gr2] = gr1
print(*fu[::-1],sep="\n")

Measured memory_bytes: 37740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    ll x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int x,int y){
    if(y==0)return x;

    return gcd(y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){

    int A=-1,Z;
    string S;
    cin>>S;

    for(int i=0;i<S.length();i++){
        if(S[i]=='A'&&A==-1)A=i;
        if(S[i]=='Z')Z=i;
    }

    cout<<Z-(A-1)<<endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; ++i)
#define per(i, a, n)  for(int i=n-1; i>=a; --i)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 1000000007
using namespace std;
typedef long long ll;

int main(){
  int N;  cin >> N;
  string S; cin >> S;
  int K;  cin >> K;
  char c = S[K-1];
  for(char& sc:S){
    if(sc != c){
      sc = '*';
    }
  }
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func()
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx++
		return cur
	}
	this.initWordIdx = func() {
		idx = 0
	}
	return &this
}

func (me *ReaderEx) ScanAndSplit() (isScanned bool) {
	isScanned = me.baseScanner.Scan()

	me.words = strings.Fields(me.baseScanner.Text())
	me.initWordIdx()
	return
}

func (me *ReaderEx) Scan() (ok bool) {
	ok = me.baseScanner.Scan()
	return
}
func (me *ReaderEx) getString() string {
	return me.baseScanner.Text()
}

func (me *ReaderEx) getInt() int {
	n, err := strconv.Atoi(me.baseScanner.Text())
	defer func() {
		if err != nil {
			panic(err)
		}
	}()

	return n
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, fa)
		}
	}
	if n > 1 {
		facts = append(facts, factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func solve(stdin io.Reader, stdout io.Writer) {
	r := NewScannerEx(stdin)
	r.ScanAndSplit()
	n := r.getInt()
	min := func(a int, vs ...int) int {
		for _, v := range vs {
			if a > v {
				a = v
			}
		}
		return a
	}
	ans := n
	for i := 0; i <= n; i += 6 {
		cntN := 0
		_cnt := i
		for _cnt > 0 {
			_cnt /= 6
			cntN += _cnt % 6
		}

		_cnt = n - i
		for _cnt > 0 {
			_cnt /= 9
			cntN += _cnt % 9
		}

		cntN += (n - i) % 9

		ans = min(ans, cntN)
	}
	fmt.Fprintln(stdout, ans)

}



Measured memory_bytes: 768