akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;

template<typename T>
struct Node {
	Node(const T& value) :value(value), parent(NULL), left(NULL), right(NULL) {}
	Node():Node(T()) {}
	T value;
	Node* parent;
	Node*left;
	Node*right;
};

template<typename T>
class BinarySearchTree
{
public:
	enum VisitOrder {
		ROOT = 0, LEFT = 1, RIGHT = 2
	};
	BinarySearchTree():root(NULL){}
	void insert(const T& value) {
		Node<T>* newNode(new Node<T>(value));
		Node<T>* parent = NULL;
		Node<T>* parentChild = NULL;
		{
			Node<T>* tempRootPtr = root;
			while (tempRootPtr != NULL) {
				parent = tempRootPtr;
				tempRootPtr = value < tempRootPtr->value ? tempRootPtr->left : tempRootPtr->right;
			}
		}
		newNode->parent = parent;
		if (parent == NULL) root = newNode;
		else (value < parent->value ? parent->left : parent->right) = newNode;
	}
	
	void printNodeKeys(const array<int, 3>& order) {
		const array< function< Node<T>*(Node<T>*) >, 3> functionList = {
			  [&](Node<T>* node) {return node; }
			, [&](Node<T>* node) {return node->left; }
			, [&](Node<T>* node) {return node->right; }
		};

		function< void(Node<T>*) > printNodesImpl = [&](Node<T>* node){
			if (node == NULL)return;
			for (const auto& visitTargetIndex : order) {
				Node<T>* visitingNode = (functionList.at(visitTargetIndex))(node);
				if (visitingNode != node) printNodesImpl(visitingNode);
				else cout << " " << visitingNode->value;
			}
		};
		printNodesImpl(root);
	}
private:
	Node<T>* root;
};

template<typename T>
void execute(T& cin) {
	int n;
	cin >> n;
	string command;
	using Tree = BinarySearchTree<int>;
	Tree tree;
	command.reserve(6);//insertが最長で6
	for (int i = 0; i != n; ++i) {
		command.clear();
		cin >> command;
		if (command == "insert") {
			int key;
			cin >> key;
			tree.insert(key);
		}
		else {//print
			tree.printNodeKeys({ Tree::LEFT, Tree::ROOT, Tree::RIGHT });
			cout << endl;
			tree.printNodeKeys({ Tree::ROOT, Tree::LEFT, Tree::RIGHT });
			cout << endl;
		}
	}

}

int main()
{

	execute(cin);



	return 0;
}


Measured memory_bytes: 26432
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

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

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

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int W, H, x, y;
    cin >> W >> H >> x >> y;

    double ans = (1.0 * W * H) / 2.0;
    if (x * 2 == W && y * 2 == H) {
        cout << fixed << setprecision(10) << ans << " " << 1 << endl;
    } else {
        cout << fixed << setprecision(10) << ans << " " << 0 << endl;
    }
    return 0;
}

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

int main() {
	int a, b, c, d, e;
	while(cin >> a >> b >> c >> d >> e, a|b|c|d|e) {
		int na, nb, nc;
		cin >> na >> nb >> nc;
		int sum = na*a + nb*b + nc*c;
		int psum = sum;
		int res = sum;
		for(int i = 0; i < na+nb+nc; i++) {
			if(i<nc)
				psum -= c;
			else if(i<nc+nb)
				psum -= b;
			else
				psum -= a;
			res = min(res ,min(max(i+1,d)*e, sum-psum) + psum);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	long long a,b,c,d,e;scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e);
	long long ans=0;
	if(a>0&&d>0&&e>0)
	{
		a--;d--;e--;ans=max(ans,a/2*2+b+d/2*2+e/2*2+3);a++;d++;e++;
	}
	ans=max(ans,a/2*2+b+d/2*2+e/2*2);
	printf("%lld",ans);
	return 0;
 } 

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	ll n, m; cin >> n >> m;
	ll ans = 0;
	ans += min(n, m / 2);
	if (n + n < m) {
		m -= 2 * n;
		ans += m / 4;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> a(60),b(60);
  for(int i=1;i<=M;i++){
    cin >> a.at(i);
    cin >> b.at(i);
  }
  int s=0;
  for(int j=1;j<=N;j++){
    s=0;
    for(int i=1;i<=M;i++){
      if(j==a.at(i)){
        s++;}
      if(j==b.at(i)){
        s++;}
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for y500 in range(a + 1):
    for y100 in range(b + 1):
        for y50 in range(c + 1):
            if 500 * y500 + 100 * y100 + 50 * y50 == x:
                ans += 1
print(ans)

Measured memory_bytes: 3060
import java.util.*;
class Main
{
  public static void main(String Args[])
  {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int A[] = new int[n];
    int B[] = new int[n];
    for(int i = 0;i<n-1;i++)
      B[i] = in.nextInt();
    B[n-1] = B[n-2];
    int sum  = B[0];
    for(int i = 1;i<=n-1;i++)
    {
      sum += Math.min(B[i-1],B[i]);
    }
    // sum += B[n-1];
     System.out.println(sum);
  }
}

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

int lcm(int a,int b)
{
    return a/__gcd(a,b)*b;
}

int f(int N,int C,int D)
{   
    int res=(N/C+1)+(N/D+1)-(N/lcm(C,D)+1);
    return (N+1)-res;
}

signed main()
{
    int A,B,C,D; cin>>A>>B>>C>>D;
    cout<<f(B,C,D)-f(A-1,C,D)<<endl;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
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 main() {
  string s;cin>>s;
  int l=stoi(s.substr(0,2));
  int r=stoi(s.substr(2));
  bool mmyy=false,yymm=false;
  bool isValid=true;
  if(0<l&&l<=12){
    mmyy=true;
  }else{
    mmyy=false;
    if(0==r||12<r){
      isValid=false;
    }
  }
  if(0<r&&r<=12){
    yymm=true;
  }else{
    yymm=false;
    if(0==l||12<l){
      isValid=false;
    }
  }
  string ans;
  if(!isValid){
    ans="NA";
  }else if(yymm && mmyy){
    ans="AMBIGUOUS";
  }else if(yymm){
    ans="YYMM";
  }else if(mmyy){
    ans="MMYY";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
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);
}
/*-------------------------------------------*/

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

    int n;
    cin >> n;
    bool c[100];

    rep(i, n) {
        int a, b;
        cin >> a >> b;
        c[i] = (a == b);
    }

    rep(i, n - 2) if(c[i] && c[i + 1] && c[i + 2]) {
        cout << "Yes\n";
        return 0;
    }

    cout << "No\n";

    return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int cost[200][200];
int tim[200][200];


int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        double data[200][200];
        rep(i,n){
            rep(j,n){
                cin>>data[i][j];
            }
        }
        double dp[200][200];
        rep(i,200)rep(j,200)dp[i][j]=-1;
        rep(i,n){
            dp[i][1]=1;
        }
        for(int i=2;i<=m;i++){
            rep(j,n){
                rep(k,n){
                    dp[j][i] = max(dp[j][i],dp[k][i-1]*data[k][j]);
                }
            }
        }
        double ans=-1;
        rep(i,n){
            ans=max(ans,dp[i][m]);
        }
        printf("%.2lf\n",ans);

    }
}

Measured memory_bytes: 1716
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif
#define MAXN 100000

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

int a[MAXN+5];
ll val[MAXN+10], dif[MAXN+10], dif2[MAXN+10];

void add_arith_seq(int l, int r, int start_val)
{
    if (l <= r) {
        int end_val = start_val + (r-l);
        dif2[l] += start_val;
        dif2[l+1] += 1-start_val;
        dif2[r+1] += -end_val-1;
        dif2[r+2] += end_val;
    }
}

int32_t main()
{
    #ifdef DEBUG
    freopen("C.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int n,m;
    read(n); read(m);
    for0(i,n) {
        read(a[i]);
        a[i]--;
    }
    ms(dif,0);
    ms(dif2,0);

    ll def = 0;
    for (int i=1; i<n; i++) {
        int dist = (a[i]-a[i-1]+m)%m;
        def += dist;
        if (a[i-1] < a[i]) {
            add_arith_seq(a[i-1]+2, a[i], 1);
        }
        else {
            if (a[i-1]+2 < m) {
                add_arith_seq(a[i-1]+2, m-1, 1);
            }
            add_arith_seq(0, a[i], m-a[i-1]-1);
        }
        printa(dif2,m+2)
    }
    prl(def)

    dif[0] = dif2[0];
    for (int i=1; i<=m; i++) {
        dif[i] = dif[i-1] + dif2[i];
    }
    printa(dif,m+1);
    val[0] = dif[0];
    for (int i=1; i<m; i++) {
        val[i] = val[i-1] + dif[i];
    }
    printa(val,m)

    ll best = def;
    for0(i,m) {
        best = min(best,def-val[i]);
    }
    cout<<best<<endl;
    return 0;
}


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

bool check(int n){
    for (int i=2; i*i<=n; i++){
        if (n % i == 0) return false;
    }
    return true;
}

vi vec(100010);
void primes(void){
    REP(i,2,100001){
        if (check(i) && check((i+1)/2)) vec[i+1] = vec[i] + 1;
        else vec[i+1] = vec[i];
        //printf("%d ", vec[i]);
    }
    //printf("\n");
}


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

    primes();
    vec[1] = 1;
    rep(i,60){
        //printf("i:%d vec[i]:%d\n", i, vec[i]);
    }
    rep(i,q){
        int l, r;
        cin >> l >> r;
        int ans = vec[r+1] - vec[l];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector <pair <int, int> > ab(n);
  for (int i = 0; i < n; i++) {
	  int a, b;
	  cin >> a >> b;
	  ab[i] = make_pair(a, b);
	}
  sort(ab.begin(), ab.end());

  int k   = 0;
  int ans = 0;
  priority_queue <int> a;
  for (int i = 1; i <= m; i++) {
	  while (k < n && ab[k].first == i) {
		  a.push(ab[k].second);
		  k++;
		}
	  if (a.size() > 0) {
		  ans += a.top();
		  a.pop();
		}
	}
  cout << ans << endl;
  return 0;
}


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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<int, int> pint;
typedef pair<long, long> plong;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

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;
}
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> ll sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

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

int main() {
    ll n = in();
    ll y = in();
    y /= 1000;
    ll arange = y / 10;
    bool flag = 1;
    REP(a, arange + 1) {
        REP(b, (y - a * 10) / 5 + 1) {
            int c = y - a * 10 - b * 5;
            if (flag && a + b + c == n && a * 10 + b * 5 + c == y) {
                printf("%d %d %d", a, b, c);
                flag = 0;
            }
        }
    }
    if (flag)
        printf("-1 -1 -1\n");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int p,q,r,s;
    scanf("%d%d%d",&p,&q,&r);
    if(p>=q && p>=r)
    {
        s=q+r;
        printf("%d\n",s);
    }
    else if(q>=p && q>=r)
    {
        s=p+r;
        printf("%d\n",s);
    }
   else if(r>=q && r>=p)
    {
        s=q+p;
        printf("%d\n",s);
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

char str[110] ;
int i , j , k , l , m , n ;
int n , e , s , w ;
int a[105][7] , b[105][7] ;
int t ;

void input(){
    
    scanf("%d" , &n) ;
    
    for(j = 0 ; j < n ; j++){
        for(i = 0 ; i < 6 ; i++){
            scanf("%d" , &a[j][i + 1]) ;
            b[j][i + 1] = a[j][i + 1] ;
            
        }
    }
}

void N(){
    t = a[m][1] ;
    a[m][1] = a[m][2] ;
    a[m][2] = a[m][6] ;
    a[m][6] = a[m][5] ;
    a[m][5] = t ;
}

void S(){
    t = a[m][1] ;
    a[m][1] = a[m][5] ;
    a[m][5] = a[m][6] ;
    a[m][6] = a[m][2] ;
    a[m][2] = t ;
}

void E(){
    t = a[m][1] ;
    a[m][1] = a[m][4] ;
    a[m][4] = a[m][6] ;
    a[m][6] = a[m][3] ;
    a[m][3] = t ;
}

void W(){
    t = a[m][1] ;
    a[m][1] = a[m][3] ;
    a[m][3] = a[m][6] ;
    a[m][6] = a[m][4] ;
    a[m][4] = t ;
}

void UF(){
    
    if(a[k][1] == a[m][1]){
        
        if(a[k][2] == a[m][3])strcpy(str , "NWS") ;
        else if(a[k][2] == a[k][5])strcpy(str , "NEES") ;
        else if(a[k][2] == a[k][4])strcpy(str , "NES") ;
        
    }
    else if(a[k][1] == a[m][2]){
        
        if(a[k][2] == a[m][3])strcpy(str , "NWS") ;
        else if(a[k][2] == a[m][1])strcpy(str , "NEES") ;
        else if(a[k][2] == a[m][4])strcpy(str , "NES") ;
        N() ;

    }
    else if(a[k][1] == a[m][3]){
        
        if(a[k][2] == a[m][6])strcpy(str , "NWS") ;
        else if(a[k][2] == a[m][5])strcpy(str , "NEES") ;
        else if(a[k][2] == a[m][1])strcpy(str , "NES") ;
        W() ;
        
    }
    else if(a[k][1] == a[m][4]){
        if(a[k][2] == a[m][1])strcpy(str , "NWS") ;
        else if(a[k][2] == a[m][5])strcpy(str , "NEES") ;
        else if(a[k][2] == a[m][6])strcpy(str , "NES") ;
        E() ;
    
    }
    else if(a[k][1] == a[m][5]){
        if(a[k][2] == a[m][3])strcpy(str , "NWS") ;
        else if(a[k][2] == a[m][6])strcpy(str , "NEES") ;
        else if(a[k][2] == a[m][4])strcpy(str , "NES") ;
        S() ;
        
    }
    else if(a[k][1] == a[m][6]){
        if(a[k][2] == a[m][3])strcpy(str , "NWS") ;
        else if(a[k][2] == a[m][2])strcpy(str , "NEES") ;
        else if(a[k][2] == a[m][4])strcpy(str , "NES") ;
        N() ;
        N() ;
    }
    

}


void output(){
    
    if(l == 6)printf("No\n") ;
    else printf("Yes\n") ;
}

void IF(){
    
    for(i = 0 ; i < strlen(str) ; i++){
        
        if(str[i] == 'N')N() ;
        else if(str[i] == 'S')S() ;
        else if(str[i] == 'W')W() ;
        else if(str[i] == 'E')E() ;
    }
}

int main(void){
    
    
    input() ;
    
    for(k = 0 ; k < n ; k++){
        for(m = 0 ; m < n ; m++){
            
            UF() ;
            
            IF() ;
            
            l = 0 ;
            
            if(k != m){
                for(i = 1 ; i <= 6 ; i++){
                    if(a[k][i] == a[m][i])l++ ;
                    
                }
            }
            
            if(l == 6)break ;
            
        }
        if(l == 6)break ;
    }
    
    
    output() ;
    
    return 0 ;
}



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

int main() {
  int N, sum, lower{100001};
  cin >> N;
  for (int A = 1; A < N; ++A) {
    sum = 0;
    for (int i = A; i > 0; i /= 10) sum += (i % 10);
    for (int i = N - A; i > 0; i /= 10) sum += (i % 10);
    if (lower > sum) lower = sum;
  }
  cout << lower << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N; cin >> N;
  v<int> A(N);
  unordered_map<int,int> mp;
  int sum=0;
  rep(i,N){
    cin >> A[i];
    mp[A[i]]++;
    sum+=A[i];
  }
  int Q; cin >> Q;
  rep(i,Q){
    int B,C; cin >> B >> C;
    sum=sum-B*mp[B]+C*mp[B];
    cout << sum << endl;
    mp[C]+=mp[B];
    mp[B]=0;
  }
  return 0;
}


Measured memory_bytes: 7928
#include <iostream>
#include "bits/stdc++.h"

using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i, a, b) for(ll i=a;i<b;i++)
#define REP(i, a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i, a) for(ll i=a;i>0;i--)
#define rrep(i, a, b) for(ll i=a-1;i>=b;i--)
#define printall(n, array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
typedef vector<vector<ll>> VVE;
const ll mod = 1e9 + 7; //10^9+7

int main() {
    ll H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;
    ll ans = H * W;
    ans -= h * W;
    ans -= w * H - h * w;
    print(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    for(int i=0; ; i++){
        int a,b;
        string op;
        cin >>a>>op>>b;
        if(op == "+")cout<< a+b<<endl;
        else if(op == "-")cout << a-b << endl;
        else if(op == "*")cout << a*b << endl;
        else if(op == "?")return 0;
        else cout << a/b <<endl;
    }
}


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

int main() {
    int n,d;
    cin >> n >> d;
    int ans = 0;
    int sum = 0;

    for (int i = 0; sum < n; i++) {
        sum += 2 * d + 1;
        ans++;
    } 

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> v{1, 2, 3, 5, 6, 9, 10, 13, 17};
    auto itr = find(v.begin(), v.end(), n);
    if( itr != v.end() ) {
		cout << "No" << endl;
    } else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
typedef long long int ll;

using namespace std;


int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    bool comp = false;
    while (a > 0 && c > 0) {
        // Takahoshi
        c = c - b;
        // Aoki
        a = a - d;
    }

    cout << (c <= 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i,n){
    int a;
    cin >> a;
    while(!(a&1)){
      ++ans;
      a >>= 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. ATCODER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  indata PIC X(100).
       01  a1 PIC S9(08).
       01  a2 PIC S9(08).
       01  a3 PIC S9(08).
       01  r1 PIC S9(08).
       01  r2 PIC S9(08).
       01  r3 PIC S9(08).
       01  g1 pic S9(08).
       01  g2 pic S9(08).
       01 disp pic Z(20)9.
       PROCEDURE DIVISION.
        ACCEPT a1.
        

        divide a1 by 3 giving g1 remainder r1

        MOVE FUNCTION TRIM(g1) to disp
        DISPLAY disp
 
 
       STOP RUN.


Measured memory_bytes: 764
S=input()
cnt=0
if S[0]==S[1]:
  cnt=cnt+1
if S[0]==S[2]:
  cnt=cnt+1
if S[0]==S[3]:
  cnt=cnt+1
if S[1]==S[2]:
  cnt=cnt+1
if S[1]==S[3]:
  cnt=cnt+1
if S[2]==S[3]:
  cnt=cnt+1
if cnt==2:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner (System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		int sum = A+B;
		int difference = A-B;
		int product = A*B;

		if (sum>=difference&&sum>=product) {
			System.out.println(sum);
		} else if (difference>=sum&&difference>=product) {
			System.out.println(difference);
		} else {
			System.out.println(product);
		}

		sc.close();
	}
}

Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> g[maxn];
int n, m;
int mark[maxn];
int color = 1;

void dfs(int u, int c) {
	mark[u] = c;
	for(int v: g[u]) {
		if(!mark[v])
			dfs(v, c);
	}
}

int main() {
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int u, v, x;
		cin >> u >> v >> x;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i = 0; i < n; i++) {
		if(!mark[i]) {
			dfs(i, color);
			color++;
		}
	}
	cout << color - 1;
}

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

int main(){
  string s;cin >> s;
  int ans = 0;
  rep(i,s.length()/2){
    if(s[i] != s[s.length()-1-i])ans += 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
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);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N, ll D){
    return devc(N,(2*D+1));
}

int main(){
    ll N,D; cin >> N >> D;
    pr(solve(N,D));
    return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int n,k;
  string s;

  cin >> n;
  cin >> s;
  cin >> k;
  k--;

  REP(i,n) {
    if(s[i] != s[k]) {
      s[i] = '*';
    }
  }

  cout << s << endl;
}



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

#define ll long long int
#define pi pair<int,int> 
#define fi first
#define se second
#define pb push_back
#define mod 20000000000007

int a[26];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    
    string s;
    cin>>s;
    if(s.size() < 26){
        for(int i = 0; i < s.length(); i++)
            a[s[i]-'a'] = 1;
        for(int i = 0; i < 26; i++){
            if(a[i] == 0){
                cout<<s+char('a'+i);
                return 0;
            }
        }
    }
    string t = s;
    next_permutation(t.begin(),t.end());
    if(t[0] < s[0]){
        cout<<-1;
        return 0;
    }
    for(int i = 0; i < 26; i++){
        if(s[i] != t[i]){
            cout<<t[i];
            return 0;
        }
        cout<<s[i];
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str):
    n = len(S)
    print('x' * n)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define dbg(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

template <typename Arg1> ostream& operator << (ostream& out, const vector<Arg1> &a) {out<<"[ ";for(const auto &x:a)out<<x<<" ";return out<<"]";}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;
    if((b-a-1)%2 == 0){
        cout<<"Borys\n";
    } else {
        cout<<"Alice\n";
    }

    timer();
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <numeric>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <deque>
#include <fstream>
#include <stdlib.h>  

using namespace std;

#define int  long long 
vector< vector<int> > vv;
 


signed  main()
{
	int n, m;
	cin >> n >>m;
	vv.resize(n, vector<int>(m));
 for(int i=0;i<n;i++)
	 for (int j = 0; j < m; j++)
	 {
		 char c;
		 cin >> c;
	if(c!='.')
		 vv[i][j]=-1;
	 }

 vv[0][0] = 1;
 for (int i = 1; i < n; i++)
	{
	 if (vv[i][0] != -1)
		 vv[i][0] = max(vv[i][0], vv[i - 1][0]);
	}
 for (int j = 1; j < m; j++)
	{
	 if (vv[0][j] != -1)
		 vv[0][j] = max(vv[0][j], vv[0][j-1]);
	}
 for(int i=1;i<n;i++)
	 for (int j = 1; j < m; j++)
	 {
		 if (vv[i][j] != -1)
			 vv[i][j] = max(vv[i - 1][j], 0 * 1ll) + max(vv[i][j - 1], 0 * 1ll);
		 vv[i][j] %= 1000000000 + 7;
	 }
	 cout << vv[n - 1][m - 1];
}




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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

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

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    int A=in();
    int B=in();
    int C=in();
    if(gcd(A,B)==1){
        print("YES");
        return 0;
    }else{
        if(C%gcd(A,B)==0){
            print("YES");
            return 0;
        }else{
            print("NO");
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int H, W, h, w, i, j, cnt=0;
    int a[100][20] = {};
    scanf("%d %d %d %d", &H, &W, &h, &w);
    for(i=0; i<h; i++)
        for(j=0; j<W; j++)
            a[i][j] = 1;
    for(j=0; j<w; j++)
        for(i=0; i<H; i++)
            a[i][j] = 1;
    for(i=0; i<H; i++)
        for(j=0; j<W; j++)
            if(a[i][j] == 0)
                cnt++;
    printf("%d\n", cnt);
    return 0;
}

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

int main()
{
	deque<char>s;
	string st;
	int q;
	cin>>st>>q;

	for(int i=0;i<(int)st.length();i++)
	{
		s.push_back(st[i]);
	}

	int f;
	char c;
	bool r = 0;
	for(int i=0;i<q;i++)
	{	
		cin>>f;
		if(f == 1)
		{
			r = !r;
		}
		else
		{
			int t;
			cin>>t>>c;

			if(t == 1)
			{
				if(r)
				{
					s.push_back(c);
				}
				else
				{
					s.push_front(c);
				}
			}
			else
			{
				if(r)
				{
					s.push_front(c);
				}
				else
				{
					s.push_back(c);
				}
			}
		}
	}

		string res = "";
		for(auto x:s)
		{
			res += x;
		}
		
		if(r)
		{
			reverse(res.begin(),res.end());
		}
		cout<<res;

	return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num,init) vector<ll> name((num),(init));
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define mat(name,fnum,snum,init); vector<vector<ll>> name((fnum),vector<ll>((snum),(init)));
#define debugP int debug_point; cin>>debug_point;


int main(){
    string s,t;
    cin>>s>>t;
    if(s.size()<t.size()){
        op("UNRESTORABLE");
        return 0;
    }
    for(int i=s.size()-1;i>=(t.size()-1);i--){
        for(int j=t.size()-1;j>=0;j--){
            if(s[i-(t.size()-1-j)]==t[j]||s[i-(t.size()-1-j)]=='?'){
                if(j==0){
                    s.replace(i-t.size()+1,t.size(),t);
                    rep(i,s.size()){
                        if(s[i]=='?')s[i]='a';
                    }
                    op(s);
                    return 0;
                }
            }else break;
        }
    }
    op("UNRESTORABLE");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll a[110];
int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		a[t]++;
	}
	ll ans=0;
	rep(i,0,105)ans+=!!a[i];
	printf("%lld",ans);
}

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

int h = 0;
const long long nil = -2000000001;
vector<long long> a;

void mH(vector<long long> &a, int i) {
	int lg = 0;
	int l = 2 * i + 1;
	int r = 2 * i + 2;

	if (l < h && a[l] > a[i])
		lg = l;
	else
		lg = i;
	if (r < h && a[r] > a[lg])
		lg = r;

	if (lg != i) {
		swap(a[i], a[lg]);
		mH(a, lg);
	}
}

int main()
{
	cin >> h;

	a.assign(h, nil);

	for (int i = 0; i < h; i++)
		cin >> a[i];

	for (int i = h / 2 - 1; i > -1; i--)
		mH(a, i);

	for (int i = 0; i < h; i++)
		cout << " " << a[i];
	cout << endl;

	return 0;
}



Measured memory_bytes: 6628
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  string S;
  cin >> S;

  int mn = 999;
  rep(i, S.size() - 2)
  {
    string s = S.substr(i, 3);
    int X = std::stoi(s);
    int diff = std::abs(X - 753);
    if (mn > diff)
      mn = diff;
  }

  cout << mn << endl;

  return 0;
}


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

int main() {
  
  char A;
  int num;
  num = 0;
  cin >> A;
  string Al;
  Al = "abcdefgfijklmnopqrstuvwxyz";
  
  for(int i = 0; i < Al.size(); i++){
    if(A == Al.at(i)){
      num = i;
    }
  }
  
  cout << Al.at(num + 1) << endl;
    
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define F first
#define S second
#define debug(x) cout << #x << ": " << x << '\n';

#if 1

enum class LCSPrev : u8 {
  Null, Left, Up, LeftUp,
};

struct LCSInfo {
  LCSPrev Prev;
  int Length;
  LCSInfo(LCSPrev prev = LCSPrev::Null, int length = 0) :
    Prev(prev), Length(length) {

  }
};

string getLCS(const string &a, const string &b) {

  // string dp[a.size() + 1][b.size() + 1]はメモリが爆発するので
  // string dp[2][b.size() + 1] にするか、もしくは
  // <方向, 部分文字列長> dp[a.size() + 1][b.size() + 1] にする

  vector<vector<LCSInfo>> dp(a.size() + 1, vector<LCSInfo>(b.size() + 1));

  FOR(i, 1, a.size() + 1) {
    FOR(j, 1, b.size() + 1) {
      if (a[i - 1] == b[j - 1]) {
        //dp[i][j] = dp[i - 1][j - 1] + a[i - 1];
        dp[i][j] = LCSInfo(LCSPrev::LeftUp, dp[i - 1][j - 1].Length + 1);
      }
      else {
        if (dp[i - 1][j].Length > dp[i][j - 1].Length) {
          //dp[i][j] = dp[i - 1][j];
          dp[i][j] = LCSInfo(LCSPrev::Up, dp[i - 1][j].Length);
        }
        else {
          //dp[i][j] = dp[i][j - 1];
          dp[i][j] = LCSInfo(LCSPrev::Left, dp[i][j - 1].Length);
        }
      }
    }
  }

  string result = "";
  int i = a.size(), j = b.size();
  while (true) {
    switch (dp[i][j].Prev) {
    case LCSPrev::Null:
      return result;
    case LCSPrev::Left:
      j--;
      break;
    case LCSPrev::Up:
      i--;
      break;
    case LCSPrev::LeftUp:
      result = a[i - 1] + result;
      i--; j--;
      break;
    }
  }
  return result;
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string s, t;
  cin >> s >> t;

  cout << getLCS(s, t);
}
#endif


Measured memory_bytes: 70784
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;


int main()
{
    ll n;
    string s;
    cin >> n >> s;
    vector<int> v(n);
    rep(i, n){
        if(s[i] == 'E') v[i] = 1;
        else v[i] = 0;
    }
    rep(i, n){
        if(i != 0) v[i] += v[i-1];
    }
    ll m = INF;
    rep(i, n){
        ll right = v[n-1] - v[i];
        ll left = 0;
        if(i != 0) left = i - v[i-1];
        m = min(m, right+left);
    }

    cout << m;
}

Measured memory_bytes: 1796
#include<iostream>

using namespace std;

void insertionSort(int A[], int n);
void trace(int A[], int n);

int main()
{
    int n;
    int A[1000];

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> A[i];

    insertionSort(A, n);

    return 0;
}

void insertionSort(int A[], int n)
{
    int v;
    int j;

    for (int i = 0; i < n; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j+1] = v;

        trace(A, n);
    }
}

void trace(int A[], int n)
{
    for (int i = 0; i < n - 1; i++) {
        cout << A[i] << ' ';
    }

    cout << A[n - 1] << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string S, T;
int q;
int a[100010], b[100010], c[100010], d[100010];
int cs[100010], ct[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> S >> T >> q;
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'A') cs[i+1] = 1;
    else cs[i+1] = 2;
  }
  for (int i = 0; i < T.size(); i++) {
    if (T[i] == 'A') ct[i+1] = 1;
    else ct[i+1] = 2;
  }
  for (int i = 0; i+1 < 100010; i++) {
    cs[i+1] += cs[i];
    ct[i+1] += ct[i];
  }
  for (int i = 0; i < q; i++) {
    int aa = cs[b[i]] - cs[a[i]-1];
    int bb = ct[d[i]] - ct[c[i]-1];
    cout << (aa % 3 == bb % 3 ? "YES" : "NO") << endl;
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string s;
    int w;
    cin >> s >> w;
    for (int i = 0; i < s.length(); i += w) 
        cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    ll n,c;cin>>n>>c;
    vector<ll> x(n),v(n),sv(n),isv(n),sx(n),isx(n);
    rep(i,n) cin>>x[i]>>v[i];
    
    ll tmp=v[0];
    sv[0]=max(v[0]-x[0],(ll)0);
    if(sv[0]==v[0]-x[0])sx[0]=x[0];
    else sx[0]=0;
    
    rep(i,n){
        if(i==0)continue;
        tmp+=v[i];
        sv[i]=max(sv[i-1],tmp-x[i]);
        if(sv[i]==tmp-x[i]) sx[i]=x[i];
        else sx[i]=sx[i-1];
    }
    reverse(x.begin(),x.end());
    reverse(v.begin(),v.end());
    
    isv[0]=max(v[0]-c+x[0],(ll)0);
    if(isv[0]==v[0]-c+x[0])isx[0]=c-x[0];
    else isx[0]=0;
    tmp=v[0];
    rep(i,n){
        x[i]=c-x[i];
        if(i==0)continue;
        tmp+=v[i];
        isv[i]=max(isv[i-1],tmp-x[i]);
        if(isv[i]==tmp-x[i]) isx[i]=x[i];
        else isx[i]=isx[i-1];
    }
    reverse(isv.begin(),isv.end());
    reverse(isx.begin(),isx.end());
    ll res=0;
    rep(i,n){
        ll now=0;
        if(i==0){
            now=max(sv[i]+isv[i+1]-min(sx[i],isx[i+1]),isv[i]);
        }else if(i==n-1){
            now=max(sv[i-1]+isv[i]-min(sx[i-1],isx[i]),sv[i]);
        }else{
            now=max(sv[i]+isv[i+1]-min(sx[i],isx[i+1]),sv[i-1]+isv[i]-min(sx[i-1],isx[i]));
        }
        res=max(res,now);
    }
    cout<<res<<endl;
}


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

int main(){
    long long N,M;
    cin >> N >> M;
    long long h[N];
    for(int i =0; i < N; i++){
        cin >> h[i];
    }
    int kouho[N];
    for(int i =0; i < N; i++){
        kouho[i] = 1;
    }
    for(int i =0; i < M; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        if(h[a] > h[b]) kouho[b] = 0;
        else if(h[a] < h[b]) kouho[a] = 0;
        else kouho[a] = kouho[b] = 0;
    }
    int ans = 0;
    for(int i =0; i < N; i++){
        ans += kouho[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4764
#include "bits/stdc++.h"
using namespace std;
const long long INF = (long long)(1e18) + 1;
int main() {
	int N,K;
	cin >> N >> K;
	vector<int>P(N);
	for (int n = 0;n<N;++n) {
		cin >> P[n]; 
		P[n]++;
	}
	int ans = 0;
	int tmp = 0;
	for (int n = 0;n<K;++n) {
		tmp += P[n];
	}
	ans = tmp;
	for (int n = 1;n <= N - K;++n) {
		tmp = tmp - P[n - 1] + P[n - 1 + K];
		ans = max(tmp, ans);
	}
	double dans = ans;
	dans /= 2;
	printf("%.10f\n", dans);
	//cout << (ans)/2.0<<endl;
	return 0;
}

Measured memory_bytes: 3972
#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++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vii;

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; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

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

int main()
{
	int n;
	cin >> n;
	
	vi a(n);
	In(a);

	ll x;
	
	ll hoge = 0;

	for(int i = n - 1; i >= 0; i--)
	{
		ll tmp = 0;

		if (i % 2 == 0)
			tmp = -a[i];
		else
			tmp = a[i];

		hoge += tmp;
	}

	x = hoge / -2;
	cout << x * 2 << " ";

	for (int i = 0; i < n - 1; i++)
	{
		x = a[i] - x;
		cout << x * 2 << " ";
	}
	cout << endl;
}

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

signed main(){
	int N, K, i, j;
	scanf("%lld%lld", &N, &K);
	vector<int> A(N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	vector<int> AA(2 * N);
	for(i = 0; i < N; i++){
		AA[i] = A[i];
		AA[N + i] = A[i];
	}
	vector<int> next(2 * N), table(200001, 2 * N);
	for(i = 2 * N - 1; i >= 0; i--){
		next[i] = table[AA[i]];
		table[AA[i]] = i;
	}
	int f = 0;
	for(i = 0, j = 0; j < K; ){
//		printf("(i, j) = (%lld, %lld)\n", i, j);
		if(i == 0){
			if(f == 1){
				j = K - K % j;
				if(j == K){
					printf("\n");
					return 0;
				}
			}
			f = 1;
		}
		int nexti = next[i];
		if(nexti < N){
			i = nexti;
		}
		else{
			if(j == K - 1){
				printf("%lld ", AA[i]);
				if(i == N - 1){
					printf("\n");
					return 0;
				}
			}
			else{
				i = nexti % N;
				j++;
			}
		}
		if(i == N - 1){
			i = 0;
			j++;
		}
		else{
			i++;
		}
	}
}

Measured memory_bytes: 10880
#include<iostream>

using namespace std;

int main() {
    int n,m, l,r;
    int dum_l, dum_r;
    cin >>n>>m;
    dum_l=1;
    dum_r = 200000;
    for (int i=0; i<m;i++) {
        cin >>l>>r;
        dum_l = max(l, dum_l);
        dum_r = min(r, dum_r);
    }
    if (dum_r-dum_l < 0) cout << 0 << endl;
    else cout << dum_r-dum_l +1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using ll = long long;
using namespace std;

void monmo(){
    
}

int main() {
    int n,p;
    int pmin=0;
    int c=0;
    cin>>n>>p;
    pmin=p;c=1;
    for(int i=1;i<n;i++){
        cin>>p;
        if(pmin>=p){
            pmin=p;c++;
        }
    }
    cout<<c;
}


Measured memory_bytes: 384