akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  string S{}; std::cin >> S;

  vector<ui> cnt(2, 0);
  rep(0, S.size())
  {
    ui tmp = S[i] - '0';
    ++cnt[tmp];
  }

  auto ans = *boost::min_element(cnt) * 2;
  cout << ans << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] peopleSpeaks = br.readLine().split(" ");
            String atCoDeerSpeak = peopleSpeaks[0];
            String topCoDeerSpeak = peopleSpeaks[1];

            if (atCoDeerSpeak.equals(topCoDeerSpeak)) {
                System.out.println("H");
            } else {
                System.out.println("D");
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, a, b;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << '\n';
  } else {
    cin >> a >> b;
    cout << a + b << '\n';
  }
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	int a[20], b[20];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];

	}
	for (int i = 0; i < n; i++) {
		int s;
		if (a[i] > b[i]) {
			s= a[i] - b[i];
			ans += s;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    
    int K,N;
    int d = 0, d_tmp = 0;
    
    //入力
    std:cin >> K >> N;
    vector<int> house(N);

    for(int i=0; i < N; i++){
        scanf("%d", &house[i]);
    }

    //次の家までの距離を算出
    for(int i = 0; i < N; i++){
        if(i == N-1){
            d_tmp = house[0] + K - house[i];
        }else{
            d_tmp = house[i+1] - house[i];
        }
//        std::cout << d << "\n";
//        std::cout << d_tmp << "\n";
        if(d < d_tmp){
            d = d_tmp;
        }

    }

    std::cout << (K-d); 

}

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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> ans(n, k);
    vector<int> sum(n + 5, 0);      // いもす用
    for(int i = 0; i < q; ++i){
        int a;
        cin >> a;
        --a;
        
        sum[0] -= 1;
        sum[a] += 1;
        sum[a+1] -= 1;
        sum[n] += 1;
    }
    
    for(int i = 0; i <= n; ++i){
        sum[i + 1] += sum[i]; 
    }
    
    for(int i = 0; i < n; ++i){
        ans[i] += sum[i];
        if(ans[i] > 0){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = (int)1e9;

using ll = long long;

int a[MAXN];

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

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

    sort(a, a + n);
    cout << a[n - 1] - a[0];
    return 0;
}

Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

A = np.array(A, dtype=int)
cs1 = A.cumsum()
cs2 = cs1[-1] - cs1
ans = np.abs(cs1 - cs2).min()
print(ans)


Measured memory_bytes: 31988
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,M,S,T;
  cin>>N>>M;
  vector<int> c[3*N];
  REP(i,M){
    int u,v;
    cin>>u>>v;
    u--;v--;
    c[u].push_back(v+N);
    c[u+N].push_back(v+2*N);
    c[u+2*N].push_back(v);
  }
  cin>>S>>T;
  S--;T--;
  int d[3*N];
  REP(i,3*N)d[i]=-3;
  d[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int p=q.front();
    q.pop();
    for(auto e:c[p]){
      if(d[e]>0)continue;
      q.push(e);
      d[e]=d[p]+1;
    }
  }
  cout<<d[T]/3<<endl;
  return 0;
}


Measured memory_bytes: 17792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,x=0,y=0;
    cin>>a;
    x=a*800;
    for(int i=0;i<a/15;i++)
    {
        y++;
    }
    cout<<x-y*200<<endl;
    return 0;
}


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

using namespace std;

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

int main() {
  int a, l;
  while (true) {
    cin >> a >> l;
    if (a == 0 && l == 0) break;
    map<int, int> s;
    s[a] = 0;
    while (true) {
      vector<int> v;
      rep (i, l) {
	v.push_back(a % 10);
	a /= 10;
      }
      sort(v.begin(), v.end());
      int mx = 0, mn = 0;
      rep (i, l) {
	mx *= 10;
	mn *= 10;
	mx += v[l - i - 1];
	mn += v[i];
      }
      a = mx - mn;
      //cout << a << " " << s.size() << endl;
      int sz = s.size();
      if (s.count(a) > 0) {
	cout << s[a] << " " << a << " " << sz - s[a] << endl;
	break;
      }
      s[a] = sz;
    }
  }
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	ll n;
	cin >> n;
	n--;
	string res = "";
	do {
		res.pb(char('a' + n % 26));
		n /= 26;
		n--;
	}	while (n >= 0);
	reverse(all(res));
	cout << res;
}


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>

using namespace std;
int main(void) {
  long long int a, b, c, x, y;
  cin>>a>>b>>c>>x>>y;
  long long int ans=0;

  if(2*c<a+b) {
    ans+=min(x, y)*2*c;
    if(x>y) {
      ans+=min(2*c, a)*(x-y);
    } else
      {
	ans+=min(2*c, b)*(y-x);
      }
    }
  else {
    ans+=a*x+b*y;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL LINF=1LL<<62;
#define max 302

LL dp[max][max];
LL c[max][max];
LL d[max];

int main(){
    int N,K,mod;
    cin >> N >> K >> mod;
    for(int i=0;i<max;i++) {
        for(int j=0;j<max;j++) {
            if(j==0) c[i][j]=1;
            else if(i==0) c[i][j]=0;
            else c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
        }
    }
    for(int i=0;i<=K;i++){
        dp[1][i]=1;
    }
    for(int n=2;n<=N+1;n++){
        memset(d,0,sizeof(d));
        for(int k=K-1;k>=0;k--){
            for(int j=0;j<n;j++){
                d[j]=(d[j]+dp[j][k+1])%mod;
            }
            for(int t=1;t<n;t++){
                dp[n][k]=(dp[n][k]+dp[n-t][k]*c[n-2][t-1]%mod*d[t]%mod)%mod;
            }
        }
    }
    cout << dp[N+1][0] << endl;
    return 0;
}

Measured memory_bytes: 1664
/*merge(A, left, mid, right)
  n1 = mid - left;
  n2 = right - mid;
  L[0...n1], R[0...n2] を生成
  for i = 0 to n1-1
    L[i] = A[left + i]
  for i = 0 to n2-1
    R[i] = A[mid + i]
  L[n1] = INFTY
  R[n2] = INFTY
  i = 0
  j = 0
  for k = left to right-1
    if L[i] <= R[j]
      A[k] = L[i]
      i = i + 1
    else
      A[k] = R[j]
      j = j + 1

mergeSort(A, left, right)
  if left+1 < right
    mid = (left + right)/2;
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)*/
    
#include<stdio.h>
#include<stdlib.h>
#define MAX 500000
#define INF 1000000000

void k_tmerge(int *,int,int,int);
void tmergesort(int *,int,int);

int count;


void tmergesort(int A[],int left,int right)
{
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    tmergesort(A,left,mid);
    tmergesort(A,mid,right);
    k_tmerge(A,left,mid,right);
  }
}

void k_tmerge(int *A,int left,int mid,int right)
{
  int i,k,j,n1=0,n2=0;
  int *L,*R;

  n1 = mid - left;
  n2 = right - mid;

  L = (int *)malloc(sizeof(int)*(n1+1));
  R = (int *)malloc(sizeof(int)*(n2+1));

  for(i = 0;i <= n1-1;i++){
    L[i] = A[left + i];
  }

  for(j = 0;j <= n2-1;j++){
    R[j] = A[mid + j];
  }

  L[n1] = INF;
  R[n2] = INF;
  i = 0;
  j = 0;

  for(k = left;k <= right-1;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      count++;
    }
    else {
      A[k] = R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}

int main()
{
  int n,i;
  int A[MAX];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  tmergesort(A,0,n);

  for(i = 0;i < n;i++){
    if( i > 0 ) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 5428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _2006
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();

            string[] b0 = new string[] { "" };
            string[] b1 = new string[] { ".", ",", "!", "?", " " };
            string[] b2 = new string[] { "a", "b", "c" };
            string[] b3 = new string[] { "d", "e", "f" };
            string[] b4 = new string[] { "g", "h", "i" };
            string[] b5 = new string[] { "j", "k", "l" };
            string[] b6 = new string[] { "m", "n", "o" };
            string[] b7 = new string[] { "p", "q", "r", "s" };
            string[] b8 = new string[] { "t", "u", "v" };
            string[] b9 = new string[] { "w", "x", "y", "z" };
            string[][] buttons = new string[][] { b0, b1, b2, b3, b4, b5, b6, b7, b8, b9 };

            for (int i = 0 ; i < n ; i++)
            {
                string line = ReadSt();
                char num = 'x';
                int pushCnt = 0;
                string res = "";

                for (int j = 0 ; j < line.Length ; j++)
                {
                    if (line[j] == '0' && pushCnt > 0)
                    {
                        res += buttons[int.Parse(num.ToString())][(pushCnt - 1) % buttons[int.Parse(num.ToString())].Length];
                        pushCnt = 0;
                    }
                    else if (line[j] != '0' && line[j] == num)
                    {
                        pushCnt++;
                    }
                    else if (line[j] != '0' && line[j] != num)
                    {
                        num = line[j];
                        pushCnt = 1;
                    }
                }
                Console.WriteLine(res);
            }

        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 13908
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;
using ll = long long;

int main() {
	string s; cin >> s;
	int length = s.size();
	int K; cin >> K;
	vector<string> master;
	for (int l = 1; l <= s.size(); l++) {
		for (int p = 0; p + l - 1 < s.size(); p++) {
			string sub = s.substr(p, l);
			if (master.size() < K) {
				master.push_back(sub);

				if (master.size() > 0) {
					sort(ALL(master));
					auto res = unique(ALL(master));
					master.erase(res, master.end());
				}	
			}
			else {
				if (sub < master.back()) {
					master.back() = sub;

					sort(ALL(master));
					auto res = unique(ALL(master));
					master.erase(res, master.end());
				}
			}
		}
	}

	sort(ALL(master));
	auto res = unique(ALL(master));
	master.erase(res, master.end());

	if (master.size() > 5) {
		master = { master[0],master[1],master[2],master[3],master[4] };
	}

	cout << master[K - 1] << endl;

    sysp;
}

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

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

    int64_t ans = 0;
    for (auto i = 1; i <= n; i++) {
        if(i % 3 != 0 and i % 5 != 0) ans += i;
    }

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

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

int main() {
  string s;
  cin >> s;
  
  // 最初の'A'と最後の'Z'の番号を求め，引いて1加える
  int a, z;
  for (int i=0; i<s.size(); ++i) {
    if (s.at(i) == 'A') {
      a = i;
      break;
    }
  }
  for (int j=s.size()-1; j>=0; --j) {
    if (s.at(j) == 'Z') {
      z = j;
      break;
    }
  }
  
  cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
short a, b, c, d, x, y;
int main(void){
  scanf("%hd%hd%hd%hd", &a, &b, &c, &d);
  x=c-a;
  y=d-b;
  printf("%d %d %d %d\n", c-y, d+x, a-y, b+x);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int d, e, f;
  d = abs(a-b);
  e = abs(b-c);
  f = abs(c-a);

  int ans = min({d+e, e+f,f+d});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = long.Parse(line[0]);
        var b = long.Parse(line[1]);
        var c =long.Parse(line[2]);
        var ans = getAns(a, b, c);
        Console.WriteLine(ans);
    }
    static long getAns (long a, long b, long c)
    {
        var ans = 0L;
        var t = Min(b, c);
        ans += 2 * t;
        b -= t;
        c -= t;
        if (c == 0) return ans + b;
        else
        {
            var t2 = Min(a, c);
            ans += t2;
            a -= t2;
            c -= t2;
            if (c == 0) return ans + b;
            else return ans + 1 + b;
        }
    }
}

Measured memory_bytes: 11220
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	int lena=a.size(),lenb=b.size();
	for(int i=0;i<lena;i++){
		for(int j=i+1;j<lena;j++){
			if(a[i]>a[j])swap(a[i],a[j]);
		}
	}
	for(int i=0;i<lenb;i++){
		for(int j=i+1;j<lenb;j++){
			if(b[i]<b[j])swap(b[i],b[j]);
		}
	}
	if(a<b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import functools
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))

if k == 0:
    print(sum(a))
    exit()

bits = [0] * 50
for i in range(n):
    for j in range(50):
        if a[i] % 2:
            bits[j] += 1
        a[i] //= 2



@functools.lru_cache(maxsize=None)
def dfs(d, k):
    b = 2**d
    if k < b:
        return b * bits[d] + (dfs(d - 1, k) if d > 0 else 0)
    else:
        if d > 0:
            if b * 2 <= k:
                return dfs(d - 1, k - b) + max(b * bits[d], b * (n - bits[d]))
            else:
                return max(b * bits[d] + dfs(d - 1, k), b * (n - bits[d]) + dfs(d - 1, k - b))
        else:
            return max(b * bits[d], b * (n - bits[d]))


d = math.ceil(math.log2(k))
print(dfs(49, k))


Measured memory_bytes: 14700
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){

	int a,b,h,m;
	double h_angle, m_angle;
	double angle;
	
	double ans;

	cin >> a >> b >> h >> m;

	m_angle = (m * 6 * M_PI)/180 ;
	h_angle = ((h * 30 + m * 0.5) * M_PI)/180;

	if((m_angle - h_angle) <= M_PI/2){
		angle = m_angle - h_angle;
	} else {
		angle = h_angle - m_angle;
	}

	ans = sqrt(a*a + b*b - 2*a*b*cos(angle));

	cout << fixed << setprecision(21) << ans << endl;

	return 0;
}


Measured memory_bytes: 4224
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

bool t[22][22];

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

  ll h, w, H, W;
  string s;
  cin >> H >> W;
  cin >> h >> w;

  REP(i, H) REP(j, W) t[i][j] = true;

  REP(i, h) REP(j, W) t[i][j] = false;

  REP(i, H) REP(j, w) t[i][j] = false;

  int cnt = 0;
  REP(i, H) REP(j, W) if(t[i][j] == true) cnt++;

  cout << cnt << endl;
  //cout << H*W - h*W - w*H << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a, b, i, arr[999];
	
	arr[0] = 1;
	for (i = 1; i < 999; i++) {
		arr[i] = arr[i-1] + i + 1;
	}
	
	scanf("%d %d", &a, &b);
	
	printf("%d\n", arr[b-a-2]-a);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
 
int main() {
    int H, W, h, w; cin >> H >> W >> h >> w;
    cout << H*W - (h*W+w*H-h*w) << endl;
}

Measured memory_bytes: 764
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
c=[int(x) for x in input().split()]
a.append(0)

ans=0
for i in range(n):
    ans+=b[a[i]-1]
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
print(ans)










Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	int N, L;
	cin >> N >> L;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	bool f = false;
	int last = -1;
	rep(i, N - 1) if (A[i] + A[i + 1] >= L) {
		f = true;
		last = i + 1;
	}
	if (f) {
		cout << "Possible" << endl;
		for (int i = 1; i < last; i++)
			cout << i << endl;
		for (int i = N - 1; i > last; i--)
			cout << i << endl;
		cout << last << endl;
	} else {
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

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

signed main(){
    init();
    run();
    return 0;
}

int modpow(int x,int n,int mod=(int)1e9+7) {
    int result = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            result = (result * x) % mod;
        }
        x = (x * x) % mod;
        n >>= 1;
    }
 
    return result;
}

void run(){
    string l;
    cin>>l;
    int ans=0;
    int c=0;
    rep(i,l.length()){
        int len=l.length()-i-1;
        if(l[i]=='1'){
            ans=(ans+modpow(2,c)*modpow(3,len)%mod)%mod;
            c++;
        }
    }
    ans=(ans+modpow(2,c))%mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import kotlin.math.abs

fun main() = Thread(null, ::abc173e, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc173e() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() }

    if (k == n) return println(aList.takeLast(k).fold(Mint(1), Mint::times))

    val (positives, negatives) = aList
        .sortedByDescending { abs(it) }.partition { it >= 0 }.toList().map { ArrayDeque(it) }

    var answer = Mint(1)

    if (k % 2 != 0) {
        if (positives.isEmpty()) return println(negatives.takeLast(k).fold(Mint(1), Mint::times))
        else answer *= positives.removeFirst()
    }

    repeat(k / 2) {
        when {
            positives.size >= 2 && negatives.size >= 2 -> {
                val pos = positives.take(2).reduce(Long::times)
                val neg = negatives.take(2).reduce(Long::times)
                if (pos > neg) {
                    answer *= pos
                    repeat(2) { positives.removeFirst() }
                } else {
                    answer *= neg
                    repeat(2) { negatives.removeFirst() }
                }
            }
            positives.size >= 2 -> answer *= positives.removeFirst() * positives.removeFirst()
            negatives.size >= 2 -> answer *= negatives.removeFirst() * negatives.removeFirst()
            else -> error("なんで？")
        }
    }

    println(answer)
}

private const val MOD = 1_000_000_007L

@Suppress("unused")
private class Mint(value: Long = 0L) {
    constructor(other: Mint) : this(other.value)

    private val value = if (value < 0) (value % MOD) + MOD else value % MOD
    operator fun unaryPlus() = this
    operator fun unaryMinus() = Mint(MOD - this.value)
    operator fun inc() = this.plus(1)
    operator fun dec() = this.minus(1)
    operator fun plus(other: Long) = Mint(this.value + other)
    operator fun plus(other: Mint) = this.plus(other.value)
    operator fun minus(other: Long) = Mint(this.value - other)
    operator fun minus(other: Mint) = this.plus(-other)
    operator fun times(other: Long) = Mint(this.value * (other % MOD))
    operator fun times(other: Mint) = this.times(other.value)
    operator fun div(other: Long) = this.times(modPow(other, MOD - 2))
    operator fun div(other: Mint) = this.div(other.value)
    fun mod(mod: Long) = Mint(this.value % mod)
    fun modPow(other: Long) = Mint(modPow(this.value, other))
    fun toLong() = this.value
    override fun toString() = this.value.toString()
    override fun hashCode() = value.hashCode()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Mint
        return value == other.value
    }

    companion object {
        private fun modPow(n: Long, p: Long): Long {
            var x = n % MOD
            var y = p
            var result = 1L
            while (y > 0) {
                if (y % 2 == 1L) result = (result * x) % MOD
                y = y shr 1
                x = (x * x) % MOD
            }
            return result
        }
    }
}


Measured memory_bytes: 79032
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#pragma GCC optimize ("O3")
	#define NDEBUG
#endif
// #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<P> a(n);
		REP(i, n) {
			int x;
			cin >> x;
			a[i] = {x, i};
		}
		sort(ALL(a));
		REP(i, n) {
			cout << a[i].S + 1 << (i == n - 1 ? endl : ' ');
		}

	}
	return 0;
}


Measured memory_bytes: 1664
n = int(input())
A = list(map(int, input().split()))

rate = [0 for _ in range(9)]

for a in A:
    if a < 400:
        rate[0] += 1
    elif a < 800:
        rate[1] += 1
    elif a < 1200:
        rate[2] += 1
    elif a < 1600:
        rate[3] += 1
    elif a < 2000:
        rate[4] += 1
    elif a < 2400:
        rate[5] += 1
    elif a < 2800:
        rate[6] += 1
    elif a < 3200:
        rate[7] += 1
    else:
        rate[8] += 1

ans = 0
for i in range(8):
    if rate[i] >= 1:
        ans += 1
if ans == 0:
    print(1, rate[8])
else:
    print(ans, ans + rate[8])

Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)

inline void chmax(int &a, int b) { a = max(a, b); }

int main()
{
  int N, M;
  int A[5005], B[5005];
  int maxv = 0;
  
  cin >> N >> M;
  Rep(i,N) cin >> A[i];
  Rep(i,M) cin >> B[i];

  vector<vector<int> >dp(2,vector<int>(5005,0));
  Rep(i,M) {
    Rep(j,N) {
      if(j) dp[1][j + 1] = dp[1][j];
      if(A[j] == B[i])chmax(dp[1][j + 1], dp[0][j] + 1);
      chmax(maxv,dp[1][j + 1]);
    }
    dp[0] = dp[1];
    fill(dp[1].begin(), dp[1].end(),0);
  }

  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(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 ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int L[N], R[N];
    int y = 0;
    rep(i, N) {

        cin >> L[i] >> R[i];
        y += R[i] - L[i] + 1;
    }
    cout << y << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>
#include<map>
using namespace std;

int main(){
    int n = 5;
    int antenas[n];
    int k,tmp;
    for(int i = 0;i < n;i++){
       cin >> tmp;
       antenas[i] = tmp;
    }
    cin >> k;
    int t = 0;
    for(int i = 0;i < n;i++){
      for(int j= i+1;j < n;j++){
        if(k < (antenas[j]-antenas[i])){
            t = 1;
            break;
        }
      }
      if(t == 1)break;
    }
    

    if(t == 1){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int a, b, h;
  cin >> a >> b >> h;
  int ans = h * (a+b) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll X;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> X;

	map<ll, ll> v;
	rep(x, -1000, 1001) v[1LL * x * x * x * x * x] = x;

	fore(bp, v) {
		ll B5 = bp.first;
		ll B = bp.second;

		if (v.count(X + B5)) {
			ll A = v[X + B5];
			printf("%lld %lld\n", A, B);
			return;
		}
	}
}







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

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

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<int> A(n + 1);
	for (int i = 1; i <= n; ++i)
		cin >> A[i];
	auto B = A;
	vector<int> ans;
	for (int i = n; i > 0; --i)
	{
		if (A[i])
		{
			ans.pb(i);
			int j = i;
			db(j);
			for (int k = 1; k * k <= j; ++k)
			{
				if (j % k == 0)
				{
					if (k == j / k)
					{
						db(k);
						A[k] = (A[k] + 1) % 2;
					}
					else
					{
						db(k, j / k);
						A[k] = (A[k] + 1) % 2;
						A[j / k] = (A[j / k] + 1) % 2;
					}
				}
			}
		}
	}
	vector<int> C = ans;
	// cout << ans.size() << '\n';
	for (int i = 1; i <= n; ++i)
		if (A[i])
		{
			db(i);
			cout << -1;
			return;
		}
	cout << C.size() << '\n';
	for (int x : C)
		cout << x << ' ';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef TIME
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

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

using namespace std;

const int SIZE = 1 << 17;
int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0;
    char ch = Advance();
    while (!isdigit(ch))
        ch = Advance();
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer;
}

const int MAXN = 200000;
const int MAXVAL = 200000;
const int MAXLOG = 57;
const long long INF = 1000000000000000000LL;

int Stack[1 + MAXN], top = 0, v[1 + MAXN];
bool in[1 + MAXVAL];
int last[1 + MAXVAL], first[1 + MAXVAL];
int go[1 + MAXLOG][1 + MAXN];
long long add[1 + MAXLOG][1 + MAXN];

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n;
    long long k;
    scanf("%d%lld", &n, &k);
    k *= n;
    for (int i = 1; i <= n; i++)
        scanf("%d", &v[i]);
    for (int i = n; i >= 1; i--)
        if (!last[v[i]])
            last[v[i]] = first[v[i]] = i;
        else {
            go[0][i] = first[v[i]] % n + 1;
            add[0][i] = first[v[i]] - i + 1;
            first[v[i]] = i;
        }
    for (int i = 1; i <= MAXVAL; i++)
        if (last[i]) {
            go[0][last[i]] = first[i] % n + 1;
            add[0][last[i]] = n - last[i] + first[i] + 1;
        }
    for (int i = 1; i <= MAXLOG; i++)
        for (int j = 1; j <= n; j++) {
            go[i][j] = go[i - 1][go[i - 1][j]];
            add[i][j] = min(INF, add[i - 1][j] + add[i - 1][go[i - 1][j]]);
        }
    int x = 1;
    for (int i = MAXLOG; i >= 0; i--)
        if (add[i][x] <= k) {
            k -= add[i][x];
            x = go[i][x];
        }
    for (int i = 1; i <= k; i++, x = x % n + 1) {
        if (!in[v[x]]) {
            top++;
            Stack[top] = v[x];
            in[v[x]] = true;
        }
        else {
            while (Stack[top] != v[x]) {
                in[Stack[top]] = false;
                top--;
            }
            top--;
            in[v[x]] = false;
        }
    }
    for (int i = 1; i <= top; i++)
        printf("%d ", Stack[i]);
    return 0;
}


Measured memory_bytes: 140800
#include<iostream>
#include<set>
#include<string>
using namespace std;
int main()
{
	set<string>s;
	string t;
	s.insert("a");
	t='a';
	for(;;)
	{
		cout<<"?"<<t<<endl;
		cin>>t;
		if(t[0]!='a'||!s.insert(t).second)
		{
			cout<<"!OUT\n";
			return 0;
		}
		t=*t.rbegin();
		t+="aa";
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    string s;
    cin >> s;
    int ans = 0, g = 0, p = 0, st = 0;
    rep(i, 0, s.size()){
        if(s[i] == 'g'){
            if(st >= 1){
                st--; ans++;
            }else{
                st++;
            }
        }else if(s[i] == 'p'){
            if(st >= 1){
                st--;
            }else{
                st++; ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
// https://atcoder.jp/contests/keyence2020
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

// 終了時間、開始時間 の順にセット
using interval = pair<int, int>;
int interval_scheduling(vector<interval> J) {
    int ret = 0;
    // 終了時間が早い順にソート
    sort(ALL(J));
    // 次の開始時間
    int f = 0;
    for (auto &x : J) {
        if (x.second >= f) {
            ret++;
            f = x.first;
        }
    }
    return ret;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<interval> J;
    REP(i, N) {
        int X, L;
        cin >> X >> L;
        // 終了時間、開始時間の順にセット
        J.push_back({X + L, max(0LL, X - L)});
    }
    cout << interval_scheduling(J) << endl;

    return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s; cin >> s;
    string ans = "";
    rep(i,s.length()) {
        if (s[i] == '0') ans += '0';
        if (s[i] == '1') ans += '1';
        if (ans.length()!=0 && s[i] == 'B') ans.pop_back();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,ans;
int work(int x)
{
	int cnt=0;
	for(int i=1;i<=x;i++)
	if(x%i==0)cnt++;
	return cnt;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{if(i%2==1)ans+=(work(i)==8);}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define between(n,x,m) (((n)<=(x))&&((x)<=(m)))

using namespace std;
string filter,str;

void J(){rotate(str.begin(),str.begin()+(str.length()-1),str.end());}
void C(){rotate(str.begin(),str.begin()+1,str.end());}
void E(){
  int i=(str.length())/2;
  string tmp=str;
  str.replace(0,i,tmp,str.length()-i,i);
  str.replace(str.length()-i,i,tmp,0,i);
}

void A(){reverse(str.begin(),str.end());}

void P(){
  int i=str.length();
  char *p=(char*)str.data();
  for(;i>=0;--i){
    if(between('0',p[i],'9')){
	  p[i]--;
	  if(p[i]=='/')p[i]='9';
	}
  }
}

void M(){
  int i=str.length();
  char *p=(char*)str.data();
  for(;i>=0;--i){
    if(between('0',p[i],'9')){
	  p[i]++;
	  if(p[i]==':')p[i]='0';
	}
  }
}


struct x{
  void operator()(char c){
    switch(c){
	  case 'J': J();break;
	  case 'C': C();break;
	  case 'E': E();break;
	  case 'A': A();break;
	  case 'P': P();break;
	  default:  M();break;
	}
  }
};

int main(){
  int n;
  cin >> n;
  while(n--){
    cin >> filter;
	cin >> str;
	for_each(filter.rbegin(), filter.rend(), x());
	cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#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)
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


int main() {

	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;


}





Measured memory_bytes: 256
function main(arg) {
	arg = arg.trim().split(' ').map(str => parseInt(str, 10));
	var a = arg[0], b = arg[1], k = arg[2];
	if(a <= k) {
		b = b - (k - a)
		a = 0;
		console.log(a, b >= 0 ? b : 0)
	} else {
		console.log(a-k, b)
	}
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 7372
N = int(input())
S = input()

leftWest = 0
rightEast = S.count("E")

ans = 10 ** 6
for i in range(len(S)):
    if S[i] == "E":
        rightEast -= 1
    
    ans = min(ans, leftWest + rightEast)

    if S[i] == "W":
        leftWest += 1

print(ans)

Measured memory_bytes: 3676