akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node{
  int key;
  struct node *prev;
  struct node *left;
  struct node *right;
};
typedef struct node *NodePointer;
void insert(NodePointer);
void delete(NodePointer);
NodePointer Successor(NodePointer);
NodePointer treeMinimum(NodePointer);
NodePointer makenode(int);
void InorderPrint(NodePointer);
void PreorderPrint(NodePointer);
NodePointer Search(NodePointer, int);
NodePointer Node; 
int m;
NodePointer root = NULL;

int main()
{
  int i, key;
  char order[7];
  NodePointer NewNode;
  
  scanf("%d",&m);

  for(i = 0 ; i < m ; i++){
    scanf("%s",order);
    
    if(strcmp(order,"insert") == 0){
      scanf("%d",&key);
      NewNode = makenode(key);
      insert(NewNode); }
    if(strcmp(order,"print") == 0){
      InorderPrint(root);
      printf("\n");
      PreorderPrint(root);
      printf("\n"); }
    if(strcmp(order,"find") == 0){
      scanf("%d",&key);
      if(Search(root,key) != NULL) printf("yes\n");
      if(Search(root,key) == NULL) printf("no\n");}
    if(strcmp(order,"delete") == 0){
      scanf("%d",&key);
      delete(Search(root,key)); }
  }
  
  return 0;
}

void insert(NodePointer z)
{
  NodePointer y, x;
    
  y = NULL; /* xの親 */
  x = root;

  while(x != NULL){   
    y = x; /* 親を設定 */
    if(z->key < x->key) x = x->left;
    else x = x->right; }

  z->prev = y;

  if(y == NULL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
    
}

void delete(NodePointer z)
{
  NodePointer y, x;
  if(z->left == NULL || z->right == NULL) y = z;
  else y = Successor(z); 

  if(y->left != NULL) x = y->left;
  else x = y->right;

  if(x != NULL) x->prev = y->prev;
  if(y->prev == NULL) root = x;
  else if(y == y->prev->left) y->prev->left = x;
  else y->prev->right = x;

  if(y != z) z->key = y->key;

}

NodePointer Successor(NodePointer x)
{
  NodePointer y;
  
  if(x->right != NULL) return treeMinimum(x->right);

  y = x->prev;

  while(y != NULL && x == y->right){
    x = y;
    y = y->prev; }

  return y;
}

NodePointer treeMinimum(NodePointer x)
{
  while(x->left != NULL) x = x->left;

  return x;
}

NodePointer makenode(int key)
{
  NodePointer NewNode;

  NewNode = (NodePointer)malloc(sizeof(struct node));

  NewNode->key = key;
  NewNode->left = NULL;
  NewNode->right = NULL;
  
  return NewNode;
}

void InorderPrint(NodePointer u)
{
  if(u == NULL) return; 

  InorderPrint(u->left);
  printf(" %d",u->key);
  InorderPrint(u->right);
}

void PreorderPrint(NodePointer u)
{
  if(u == NULL) return;
  
  printf(" %d",u->key);

  PreorderPrint(u->left);
  PreorderPrint(u->right);
}

NodePointer Search(NodePointer x, int k)
{
  if(x == NULL || k == x->key){
    if(x == NULL) return NULL;
    else return x; }
  if(k < x->key) return Search(x->left,k);
  else return Search(x->right,k);
}



Measured memory_bytes: 20492
#include <iostream>

using namespace std;


int main(){
    int m, d, cnt=0;
    cin >> m >> d;
    for(int i=1; i<=m; i++){
        for(int j=1; j<=d; j++){
            int d1 = j%10;
            int d2 = j/10;
            if(d1 >= 2 && d2 >= 2 && d1*d2==i){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;

#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

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

ll mod = 1e9 + 7;
int main()
{
	speed;
	//rw();

	ull c = 0;
	ll n, sum = 0;
	cin >> n;

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

	for (int i = 0; i < n - 1; i++)
	{
		sum -= a[i];
		c += ((sum % mod) * (a[i] % mod) ) % mod;
	}

	cout << c % mod;

	return 0;
}


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

int n;

char ask(int k) {
  cout << "?";
  for (int i = k; i < k + n; i++) {
    cout << ' ' << i;
  }
  cout << endl;
  string s;
  cin >> s;
  return s[0];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int lo = 1, hi = n, k;
  char t = ask(1);
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (ask(mid) == t) {
      k = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  string ans(2 * n, '$');
  ans[k - 1] = t;
  ans[k + n - 1] = (t == 'R' ? 'B' : 'R');
  for (int j = k + 1; j < k + n; j++) {
    cout << "? " << j;
    for (int i = 1; i < k; i++) {
      cout << ' ' << i;
    }
    for (int i = k + n + 1; i <= 2 * n; i++) {
      cout << ' ' << i;
    }
    cout << endl;
    string s;
    cin >> s;
    ans[j - 1] = s[0];
  }
  for (int j = 1; j < k; j++) {
    cout << "? " << j;
    for (int i = k + 1; i < k + n; i++) {
      cout << ' ' << i;
    }
    cout << endl;
    string s;
    cin >> s;
    ans[j - 1] = s[0];
  }
  for (int j = k + n + 1; j <= 2 * n; j++) {
    cout << "? " << j;
    for (int i = k + 1; i < k + n; i++) {
      cout << ' ' << i;
    }
    cout << endl;
    string s;
    cin >> s;
    ans[j - 1] = s[0];
  }
  cout << "! " << ans << endl;
  return 0;
}


Measured memory_bytes: 724
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int A, B; cin >> A >> B;
	if (A > B  && B != 1 || (A != B && A == 1))cout << "Alice" << endl;
	else if (B > A && A != 1|| (A != B && B == 1))cout << "Bob" << endl;
	else cout << "Draw" << endl;
}

Measured memory_bytes: 256
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end

N = inputs[0]
As = inputs[1].split(" ").map(&:to_i)

def getGCDAll(as, excludeIndex: -1)
  gcd = nil
  as.each.with_index do |a, index|
    next if index == excludeIndex
    if !gcd
      gcd = a
      next
    end
    gcd = gcd.gcd(a)
    return 1 if gcd == 1
  end
  gcd
end

# 除く数を求める
def getRejectedIndex(as)
  # 互いに素な数を見つける
  tmp = as.min
  tmp_index = -1;
  as.each_with_index do |a, index|
    tmp_index = index if tmp == a
  end
  as.each_with_index do |a, index|
    # 互いに素の場合、a or tmp のどちらかが reject される数
    return [tmp_index, index] if a % tmp != 0
  end
  # 全て 互いに素でない場合は 最小の数が除かれる数
  return [tmp_index]
end

rejctedIndexes = getRejectedIndex(As)

gcds = rejctedIndexes.map do |index|
  getGCDAll(As, excludeIndex: index)
end

res = gcds.max
puts res


Measured memory_bytes: 8656
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
vector<vector<char> >tmp;
vector<vector<int> >scr;
int main(){
	string s;
	string nagai;
	int naga=0;
	map<string,int>m;
	while(cin>>s){
		if(naga<s.size()){naga=s.size();nagai=s;}
		//cout<<naga<<" "<<s.size()<<endl;
		m[s]++;
	}
	int ma=-1;
	string mas;
	map<string,int>::iterator it=m.begin();
	
	for(;it !=m.end();it++){
		string t=it->first;
		if(ma<m[t]){ma=m[t];mas=t;}
	}
	cout<<mas<<" "<<nagai<<endl;
}

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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;

const int INF = 1000000007;
const LL INFLL = 1000000000000000007;

#define st first
#define nd second
#define pb push_back
#define _boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// ***************************** CODE ***************************** //

const int MAX = 1e5 + 7;

int tab[MAX];
bool dp[MAX];

int main() {
    _boost;

    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> tab[i];

    for(int i = 0; i <= k; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(i+tab[j] <= k)
            {
                if(dp[i] == 0 && dp[i+tab[j]] == 0)
                    dp[i+tab[j]] = 1;
            }
        }
    }

    (dp[k]) ? cout << "First"    : cout << "Second";
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int sum = 0;
  cin >> n;
  int data[100];
  for(int i = 0;i < n;i++){
    cin >> data[i];
  }
  for(int i = 0;i < n - 1;i++){
    for(int j = 0;j < n - i - 1;j++){
      if(data[j] > data[j + 1]){
	swap(data[j],data[j + 1]);
	sum++;
      }
    }
  }
  for(int i = 0;i < n - 1;i++){
    cout << data[i] << " ";
  }
  cout << data[n - 1] << endl;
  cout << sum << endl;
  return 0;
}

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

using namespace std;

char pie[9][4], dat[3][3][4];
bool used[9];
int ans, T;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

void rec(int y, int x){
  //cout << y << ' ' << x << endl;
  if(y == 3){ ans++; return; }
  for(int i=0;i<9;i++){
    if(used[i]) continue;
    used[i] = true;
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++) dat[y][x][k] = pie[i][(j+k)%4];
      bool f = true;
      for(int k=0;k<4;k++){
        int ny = y + dy[k];
        int nx = x + dx[k];
        if(min(ny, nx) < 0 || max(ny, nx) >= 3) continue;
        char nc = dat[ny][nx][(k+2)%4];
        char c = dat[y][x][k];
        //cout << i << ' ' << j << ' ' << k << endl;
        //cout << c << ' ' << nc << endl;
        if('a' <= c && c <= 'z'){
          if(!(nc == 'A' + (c - 'a') || nc == '@')) f = false;
        }else if('A' <= c && c <= 'Z'){
          if(!(nc == 'a' + (c - 'A') || nc == '@')) f = false;
        }
      }
      if(f) rec((y*3+x+1)/3, (y*3+x+1)%3);
      for(int k=0;k<4;k++) dat[y][x][k] = '@';
    }
    used[i] = false;
  }
}

main(){
  cin >> T;
  while(T--){
    for(int i=0;i<9;i++) for(int j=0;j<4;j++) cin >> pie[i][j];
    ans = 0;
    fill(dat[0][0], dat[3][0], '@');
    fill(used, used+9, false);
    rec(0, 0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n;
    cin >> n;
    int v[n];
    fore(i,0,n) {
        cin >> v[i];
        v[i] -= i+1;
    }
    sort(v, v+n);
    ll ans = 0;
    fore(i,0,n) {
        ans += abs(v[i]-v[n/2]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n, c = 0;
int v[5][5][5], v2[5][5][5];
bool a[30], b[30];

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

bool can(int x,int y,int z) {
	if(0 <= x && x < 5 && 0 <= y && y < 5 && 0 <= z && z < 5) return true;
	return false;
}

int main() {
	while(cin >> n && n) {
		memset(v, 0, sizeof(v));
		memset(v2, 0, sizeof(v2));

		rep(i, 5) {
			rep(j, 5) {
				string s;
				cin >> s;

				rep(k, 5) {
					v[i][j][k] = s[k] - '0';
				}
			}
		}

		int m1;
		cin >> m1;

		memset(a, 0, sizeof(a));
		rep(i, m1) {
			int x;
			cin >> x;
			a[x] = true;
		}

		int m2;
		cin >> m2;
		memset(b, 0, sizeof(b));
		rep(i, m2) {
			int x;
			cin >> x;
			b[x] = true;
		}

		rep(q, n) {
			rep(i, 5) rep(j, 5) rep(k, 5) v2[i][j][k] = v[i][j][k];
			rep(i, 5) {
				rep(j, 5) {
					rep(k, 5) {
						int sum = 0;

						rep(l, 26) {
							int x = i + dx[l];
							int y = j + dy[l];
							int z = k + dz[l];

							if(can(x, y, z)) sum += v[x][y][z];
						}

						if(v[i][j][k] == 0) {
							if(a[sum]) {
								v2[i][j][k] = 1;
							}
						} else {
							if(!b[sum]) {
								v2[i][j][k] = 0;
							}
						}
					}
				}
			}

			rep(i, 5) rep(j, 5) rep(k, 5) v[i][j][k] = v2[i][j][k];
		}

		if(c) cout << endl;
		cout << "Case " << c + 1 << ":" << endl;
		c++;

		rep(i, 5) {
			if(i) cout << endl;
			rep(j, 5) {
				rep(k, 5) {
					cout << v[i][j][k];
				}
				cout << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1216
import sys


def solve(a, b, c, d):
    """ Lv.i の中央の■を、上下(a,c)に迂回する """
    for i in range(30, 0, -1):
        # ここに到達している時点で、Lv.i 盤面の同じ横ならびに位置することは保証されている
        d3i = d3[i - 1]
        da, ma = divmod(a, d3i)
        dc, mc = divmod(c, d3i)
        if da != dc:
            return abs(a - c) + abs(b - d)
        if da != 1:
            a, c = ma, mc
            continue
        db, mb = divmod(b, d3i)
        dd, md = divmod(d, d3i)
        if (abs(db - dd) < 2):
            a, c = ma, mc
            continue
        return min(ma + mc + 2, 2 * d3i - (ma + mc)) + abs(b - d)
    return abs(a - c) + abs(b - d)


d3 = [pow(3, i) for i in range(31)] + [0]

q = int(input())
buf = []
for line in sys.stdin:
    a, b, c, d = map(int, line.split())
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    ans = max(solve(a, b, c, d), solve(b, a, d, c))
    buf.append(ans)
print('\n'.join(map(str, buf)))


Measured memory_bytes: 4264
#include<cstdio>
const long long mod = 1e9+7;
long long a[200005];
long long suffix[200005];

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%lld",&a[i]);
    suffix[n+1] = 0;
    for(int i = n; i >= 1; i--){
        suffix[i] = (suffix[i+1]+a[i])%mod;
    }
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        long long add = a[i]*suffix[i+1]%mod;
        ans += add; if(ans>=mod) ans -= mod;
    }
    printf("%lld\n",ans);
    return 0;
}


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

#define sysp system("pause")

typedef long long ll;

int n,ans;
map<int,int> m;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int dis;
		cin>>dis;
		if(m.count(dis)==0){
			m.insert(make_pair(dis,1));
		}else{
			m[dis]++;
		}
	}
	for(auto ite=m.begin();ite!=m.end();ite++){
		if(ite->first>ite->second){
			ans+=ite->second;
		}else{
			ans+=ite->second-ite->first;
		}
	}
	cout<<ans<<endl;
	sysp;
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 1000;

ll calc(ll a, ll b) {
    ll bb = b;
    ll aa = a;
    for(int i = 1; i < 5; i++) bb *= b, aa *= a;
    return aa-bb;
}

int main() {
    ios_base::sync_with_stdio(false);
    ll x; cin >> x;
    for(ll i = -T; i <= T; i++)
        for(ll j = -T; j <= T; j++) {
            if(calc(i,j)==x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    return 0;
}



Measured memory_bytes: 3564
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc080.contest.atcoder.jp/tasks/abc080_d>
問題文============================================================
 joisinoお姉ちゃんは、録画機を用いて N 個のテレビ番組を録画しようとしています。
 
 テレビが受信できるチャンネルは C 個あり、1 から C までの番号がついています。
 
 joisinoお姉ちゃんの録画したいテレビ番組のうち、i 個目のテレビ番組は、
 時刻 si から時刻 ti まで、チャンネル ci で放送されます。(ただし時刻 si を含み、時刻 ti を除く)
 
 ただし、同じチャンネルで複数のテレビ番組が同時に放送されることはありません。
 
 また、録画機は、あるチャンネルの時刻 S から時刻 T までを録画するとき、
 時刻 S−0.5 から時刻 T までの間、他のチャンネルの録画に使うことができません。
 (ただし時刻 S−0.5を含み、時刻 T を除く)
 
 N 個のテレビ番組の全ての放送内容が含まれるように録画するとき、必要な録画機の最小個数を求めてください。
=================================================================

解説=============================================================

================================================================
*/
ll N,C;
vector<pair<pll,ll>> M;
vector<int> comp;
bool check(ll maxc){
    fill(comp.begin(),comp.end(),0);
    ll pret,prec;
    for(int i = 0; i < maxc;i++){
        pret = -1; prec = -1;
        for(int i = 0; i < N;i++){
            if(comp[i] == 1) continue;
            if(pret < M[i].first.first){
                comp[i] = 1;
                pret = M[i].first.second;
                prec = M[i].second;
            }else if(pret == M[i].first.first){
                if(prec == M[i].second){
                    comp[i] = 1;
                    pret = M[i].first.second;
                    prec = M[i].second;
                    continue;
                }
            }
        }
    }
    for(auto f:comp){
        if(f == 0) return false;
    }
    return true;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> C;
    comp.resize(N);
    M.resize(N);
    for(int i = 0; i < N;i++) cin >> M[i].first.first >> M[i].first.second >> M[i].second;
    sort(M.begin(),M.end());
    
    for(int i = 1; i <= C;i++){
        if(check(i)){
            cout << i << endl;
            break;
        }
    }
	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string odd,even;
  cin >> odd >> even;
  int o_size = odd.size();
  int e_size = even.size();
  for(int i=0;i<e_size;i++){
    cout << odd[i] << even[i];
  }
  if(o_size>e_size){
    cout << odd[o_size-1];
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG b.cpp
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define scint(x) scanf("%d", &x)
#define sclng(x) scanf("%ld", &x)
typedef long long ll;

string S;
ll num_black = 0;
ll ans = 0;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    
    cin >> S;
    int n = S.size();
    // cout << n << "\n";
    rep(i, n){
        if(S[i] == 'B'){
            num_black++;
        }else if(S[i] == 'W'){
            ans += num_black;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

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


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[30],b[30],c[30];
  int ans=0;
  rep(i,n){cin>>a[i];a[i]--;}
  rep(i,n) cin>>b[i];
  repi(i,1,n) cin>>c[i];
  rep(i,n){
    if(i==0) ans+=b[a[i]];
    else if(a[i]==a[i-1]+1){
      ans+=b[a[i]];
      ans+=c[a[i]];
    }
    else ans+=b[a[i]];
  }
  cout<<ans<<endl;

  return 0;
}


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

struct Node{
  int key;
  Node *prev, *next;
};

Node *nil;

void init(){
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void insert(int key){
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

Node* listSearch(int key){
  Node *cur = nil->next;
  while ( cur != nil && cur->key != key ){
  	cur = cur->next;
  }
  return cur;
}

void deleteNode(Node *t){
  if ( t == nil ) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void listPrint(){
  Node *cur = nil->next;
  while ( cur != nil ){
    if ( cur->prev != nil ) printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}
  

int main(){
  int n, x;
  char order[15];
  init();
  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ){
  	scanf("%s", order);
  	if ( strcmp(order, "insert") == 0 ){
      scanf("%d", &x);
      insert(x);
    } else if ( strcmp(order, "delete") == 0 ){
      scanf("%d", &x);
      deleteKey(x);
    } else if ( strcmp(order, "deleteFirst") == 0 ){
      deleteFirst();
    } else if ( strcmp(order, "deleteLast") == 0 ){
      deleteLast();
    }
  }
  listPrint();
  return 0;
}


Measured memory_bytes: 33856
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define int long long
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max((int)0,a-c)<<" "<<max(min(a+b-c,b),(int)0)<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int K = scan.nextInt();
		int S = scan.nextInt();
		int ans = 0;
		int z = 0;
		for(int x = 0; x <= K; x++) {
			for(int y = 0; y <= K; y++) {
				z = S - x - y;
				if(0 <= z && z <= K) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		scan.close();
	}

}


Measured memory_bytes: 21844
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> V(N);
  rep (i, N) cin >> V[i];

  deque<ll> treasures;
  rep (i, N) treasures.push_back(V[i]);
  ll ans = numeric_limits<ll>::min();
  // for (ll numpop = 0; numpop <= min(N, K); numpop++) {
  for (ll numpopL = 0; numpopL <= min(N, K); numpopL++) {
    // ll numpush = K - numpop;
    // for (ll numpopL = 0; numpopL <= numpop ; numpopL++) {
    for (ll numpopR = 0; numpopR <= min(N, K) - numpopL ; numpopR++) {
      // ll numpopR = numpop - numpopL;
      ll numpush = K - numpopR - numpopL;
      // cerr << numpush <<" "<< numpop <<" "<< numpopL <<" "<< numpopR << endl;
      vector<ll> mytreasures;
      rep (i, numpopL) {
        mytreasures.push_back(treasures.at(i));
        // cerr <<"L"<< mytreasures.back() << endl;
      }
      rep (i, numpopR) {
        mytreasures.push_back(treasures.at(N - i - 1));
        // cerr <<"R"<< mytreasures.back() << endl;
      }
      ll sum = 0;
      for (const auto mytreasure : mytreasures) {
        sum += mytreasure;
      }
      sort(mytreasures.begin(), mytreasures.end());
      // rep (i, numpush < mytreasures.size() ? numpush : mytreasures.size()) {
      for (ll i = 0; i < mytreasures.size() && i < numpush && mytreasures.at(i) < 0;
             ++i) {
        // cerr << i <<" "<< mytreasures.back() << endl;
        // if (mytreasures.back() < 0) mytreasures.pop_back();
        sum -= mytreasures.at(i);
      }
      ans = max(ans, sum);
    }
  }
      // cerr << ans << endl;
  cout << ans << endl;
  return 0;
}



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

ans = 0

for i in range(N):
    if i+1 == p[i] and i != N-1:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
    elif i == N-1:
        if i+1 == p[i]:
            p[i],p[0] = p[0],p[i]
            ans += 1
        
print(ans)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> favo(M + 1, 0);
    for (int i = 0; i < N; i++)
    {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++)
        {
            int a;
            cin >> a;
            favo[a]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < M + 1; i++)
    {
        if (favo[i] == N)
        {
            ++ans;
        }
    }
    cout << ans << endl;
}

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

#define MOD_1_000_000_007 (1000000007LL)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll N, K, a[20];

  void init() {
    scanf("%d %d", &N, &K);
    rep(i, N) scanf("%d", &a[i]);
  }

  void solve() {
    ll minv = 20000000000ll;
    rep(k, 1<<(N-1)) {
      ll prev = a[0], current = 0ll, count = 1ll;
      rep(i, N-1) {
        if(prev < a[i+1]) {
          count++;
          prev = a[i+1];
        } else if(k & (1<<i)) {
          current += prev + 1 - a[i+1];
          count++;
          prev++;
        }
      }
      if(K <= count) minv = min(minv, current);
    }
    printf("%lld\n", minv);
  }
}


int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

string generate(ll i){
    stringstream ss;
    if(i>>0 & 1){
        ss << 'A';
    }
    ss << "KIH";
    if(i>>1 & 1){
        ss << 'A';
    }
    ss << 'B';
    if(i>>2 & 1){
        ss << 'A';
    }
    ss << 'R';
    if(i>>3 & 1){
        ss << 'A';
    }
    return ss.str();
}

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

    // input
    string s;
    cin >> s;

    FOR(i, 0, 1<<4){
        if(s==generate(i)){
            p_yes();
            return 0;
        }
    }
    
    p_no();

    return 0;
}

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

int main() {
	int a, b, val, ans;
	cin >> a >> b;
	if(b == 1) {
		cout << 0;
		return 0;
	}
	ans = 1;
	val = a;
	while(val<b) {
		++ans;
		val = (ans-1)*(a-1) + a;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int H,W; cin>>H>>W;
    vector<string> a(H);
    REP(i,H) cin>>a[i];

    set<int> sti;
    REP(i,H){
        bool all=true;
        REP(j,W)
            if(a[i][j]!='.') all=false;
        if(all) sti.insert(i);
    }
    set<int> stj;
    REP(j,W){
        bool all=true;
        REP(i,H)
            if(a[i][j]!='.') all=false;
        if(all) stj.insert(j);
    }

    REP(i,H){
        if(sti.count(i)) continue;
        REP(j,W){
            if(stj.count(j)) continue;
            cout<<a[i][j];
        }
        cout<<endl;
    }

}


Measured memory_bytes: 256
s=input()
s=s.split(' ')
maisuu = int(s[0])
maney  = int(s[1])
 
minn_man = int(maney/10000)+1
minn_go  = int(maney / 5000) +1
for man in range(0,minn_man):
	for go in range(0,minn_go):
		# for sen in range(0,minn_sen):
		sen = maisuu - go - man
		if sen>=0:
			if man*10000+ go*5000 + sen*1000 == maney:
				print(str(man)+" "+str(go)+" "+str(sen))
				exit()
print('-1 -1 -1')

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

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

#define mem0(x) memset(x, 0, sizeof(x))
#define asort(x) sort(x.begin(), x.end());
#define dsort(x, t) sort(x.begin(), a.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back

const int mod = 1000000007;
class mint {
    long long x;
  public:
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint &a) {
        if((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint &a) {
        if((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint &a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint &a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint &a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if(!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if(t & 1)
            a *= *this;
        return a;
    }
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
    mint operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream &os, const mint &m) {
        os << m.x;
        return os;
    }
};

ll modpow(ll x, ll n, ll mod) {
    if(n == 0)
        return 1;
    ll res = modpow(x * x % mod, n / 2, mod);
    if(n & 1)
        res = res * x % mod;
    return res;
}

mint nCk(ll n, ll k) {
    mint res = 1;
    for(ll i = 0; i < k; i++) {
        res *= n - i;
    }
    for(ll i = 1; i <= k; i++) {
        res /= i;
    }
    return res;
}

int main() {
    ll n, a, b;
    mint ans;
    cin >> n >> a >> b;
    ans = modpow(2, n, mod) - 1;
    ans -= nCk(n, a);
    ans -= nCk(n, b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b){
	return b != 0 ? gcd(b, a%b) : a;
}

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

#define N_MAX 310
#define MOD 1000000007

void solv()
{
	lli A, B, K; scanf("%lld%lld%lld", &A, &B, &K);
	if (K >= A){
		K -= A;
		A = 0;
	}
	else{
		A -= K;
		K = 0;
	}

	if (K >= B){
		B = 0;
	}
	else{
		B -= K;

	}

	printf("%lld %lld", A, B);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define sz(a) a.size()

int main(){
	int N;
    cin >> N;
  
  	map<string,int> mp;
  	
  	string pre;
  	cin >> pre;
  	mp[pre]++;
  
  	for(int i = 0;i < N-1;i++){
      string s;
      cin >> s;
      if(mp[s] || pre[sz(pre)-1] != s[0]){
		cout << "No" << endl;
		return 0;
      }else{
		mp[s]++;
      }
      pre = s;
    }
  
  	cout << "Yes" << endl;
}
      


Measured memory_bytes: 256
a=input()
a=int(a)
b=input()
lis=[]
c=b[0]
flag=0
for i in range(a-1):
    if i>0:
        c=b[i]
    if b[i+1]==c:
        continue
    else:
        lis.append(b[i])
if len(lis)>1:
   flag=1
else:
    lis={"a"}
if flag==1:
     if lis[-1]!=b[-1]:
        lis.append(b[-1])

print(len(lis))

Measured memory_bytes: 3956
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def resolve():
    readline=sys.stdin.readline
    mod=10**9+7
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    binArr = [[0 for i in range(60)] for j in range(n)]
    cnt=[0]*60
    for i in range(n):
        b = bin(arr[i])[2:]
        lenb = len(b)
        for j in range(lenb):
            binArr[i][j] = int(b[lenb-1-j])
            cnt[j]+=binArr[i][j]
    ans=[0]*60
    answer = 0
    for i in range(n):
        for j in range(60):
            # 1: cnt[j]
            # 0: n-cnt[j]
            cnt[j]-=binArr[i][j]
            if binArr[i][j] == 0:
                ans[j] += cnt[j]
            else:
                ans[j] += (n-cnt[j]-i-1)
    x=1
    for i in range(60):
        answer += ans[i]*x
        answer %= mod
        x*=2
        x%=mod
    print(answer)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 290780
//再帰を使ってみる
using System; 
public class Factorial 
{
	public static long Fac(long i) 
	{
		return ((i <= 1) ? 1 : (i * Fac(i-1))); 
	} 
}
class MainClass 
{
	public static void Main() 
	{
		string s = Console.ReadLine();
		long num = Int64.Parse(s);
		Console.WriteLine(Factorial.Fac(num)); 
	}
}

Measured memory_bytes: 5600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int a = sc.nextInt();
		int num = h / a;
		int amari = h % a;
		System.out.println(amari == 0 ? num : num + 1);
	}


}



Measured memory_bytes: 35716
#include<iostream>

using namespace std;

int main()
{

	int S,W;
	
	cin >> S >> W ;
	
	if(S<=W){
	
	cout << "unsafe" << endl;	
		
	}

	else {
	
	cout << "safe" << endl;	
 
	}

	return 0;	

}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int n;
      cin >> n;
      pint x[n],y[n];
      rep(i,n){
        cin >> x[i].first;
        x[i].second=i;
      }
      sort(x,x+n);
      int leftmid=n/2-1;
      int rightmid=n/2;
      int leftnum=x[leftmid].first;
      int rightnum=x[rightmid].first;
      rep(i,n){
        if(leftmid-i>=0)x[i].first=rightnum;
        if(leftmid-i<0){
          x[i].first=leftnum;
        }
      }
      rep(i,n){
       y[i].first=x[i].second;
        y[i].second=x[i].first;
      }
      sort(y,y+n);
      rep(i,n){
       cout << y[i].second << endl; 
      }
      return 0;}

Measured memory_bytes: 5248
#include<stdio.h>
int main(void){
	int n;
	int i;
	int mat,eng,jpn;
	while(scanf("%d",&n)){
		if(n == 0){
			break;
		}
		for(i = 0;i < n;i++){
			scanf("%d %d %d",&mat,&eng,&jpn);
			if(mat == 100 || eng == 100 || jpn == 100 || (mat + eng) / 2 >= 90 || (eng + mat + jpn) / 3 >= 80){
				printf("A\n");
			}
			else if((mat + eng + jpn) / 3 >= 70 || ((mat + eng + jpn) / 3 >= 50 && (mat >= 80 || eng >= 80))){
				printf("B\n");
			}
			else{
				printf("C\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
  int l;
  struct Node *ri;
  struct Node *le;
  struct Node *pa;
};

struct Node *root, *NIL;

void Insert(int);
void Inorder(struct Node *);
void Preorder(struct Node *);
struct Node * Find(struct Node *,int);


int main(){
  int i,h,valu,findnum;
  char C1[10];

  scanf("%d",&h);

  for(i=0;i<h;i++){

    scanf("%s",C1);

    if(strcmp(C1,"insert")==0){
      scanf("%d",&valu);
      Insert(valu);
    }
    else if(strcmp(C1,"print")==0){
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
    else if(strcmp(C1,"find")==0){
      scanf("%d",&findnum);
      struct Node *F = Find(root,findnum);
      if(F !=NIL)printf("yes\n");
      else printf("no\n");
    }
  }
  
  return 0;
}

void Insert(int h){
  struct Node *x = root;
  struct Node *y= NIL;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z -> l = h;
  z -> le = NIL;
  z -> ri = NIL;

  while(x != NIL){
    y = x;
    if(z->l < x->l){
      x = x-> le;
    }
    else{
      x = x-> ri;
    }
  }

  z -> pa=y;
  if( y == NIL){
    root = z;
  }
  else{
    if(z->l < y->l){
      y -> le = z;
    }
    else{
      y -> ri = z;
    }
  }
}


void Inorder(struct Node *x){
  if(x == NIL)return;
  Inorder(x -> le);
  printf(" %d",x -> l);
  Inorder(x -> ri);
}

void Preorder(struct Node *y){
  if(y==NIL)return;
  printf(" %d",y -> l);
  Preorder(y->le);
  Preorder(y->ri);
}

  struct Node * Find(struct Node *x, int h){
    while(x != NIL && h!= x -> l){
      if(h < x -> l ) x = x -> le;
      else x = x -> ri;
    }
    return x;
  }



Measured memory_bytes: 20460
#include<iostream>
#include<cstdio>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int main(){
	n=read();
	if(n%2==0)printf("%d\n",n/2-1);
	else printf("%d\n",n/2);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char S[4],T[4];
    int i,ans=0;
    scanf("%s",S);
    scanf("%s",T);
    for(i=0;i<3;i++){
        if(S[i]==T[i]){
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

struct {
    int N;
    vector<long long> dat;

    void init(int n) {
      N = 1;
      while(N < n) N *= 2;
      dat.resize(2*N-1, LLONG_MAX);
    }

    // update k-th element
    void update(int k, long long a) {
      k += N-1;
      dat[k] = a;
      while(k > 0) {
        k = (k-1)/2;
        dat[k] = min(dat[k*2+1], dat[k*2+2]);
      }
    }

    // add k-th element by a
    void add(int k, long long a) {
      k += N-1;
      dat[k] += a;
      while(k > 0) {
        k = (k-1)/2;
        dat[k] = min(dat[k*2+1], dat[k*2+2]);
      }
    }

    // return k-th element
    long long get(int k) {
      return dat[k+N-1];
    }

    // return min[a, b)
    long long query(int a, int b) {
      return query(a, b, 0, 0, N);
    }
    long long query(int a, int b, int k, int l, int r) {
      if (r <= a || b <= l) return LLONG_MAX;
      if (a <= l && r <= b) return dat[k];
      int m = (l+r)/2;
      return min(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
    }
} S;

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

  int n; cin >> n;
  S.init(n+1);
  vector<int> b(n);
  int zero = 0;
  rep(i, n) {
    cin >> b[i];
    if (b[i]==0) zero++;
  }
  int q; cin >> q;
  vector<P> ra(q);
  rep(i, q) {
    ll l, r; cin >> l >> r;
    ra[i].first = l;
    ra[i].second = r;
  }
  sort(ra.begin(), ra.end());
  S.update(0, 0);
  int j = 0;
  for(int i=1; i<=n; i++) {
    while(j < q && ra[j].first==i) {
      int l = ra[j].first;
      int r = ra[j].second;
      auto mi = S.query(l-1, r);
      if (mi < S.get(r)) {
        S.update(r, mi);
      }
      j++;
    }
    auto p = (b[i-1]==0) ? -1 : 1;
    auto mi = S.get(i-1)+p;
    if (mi < S.get(i)) {
      S.update(i, mi);
    }
  }
  cout << zero+S.get(n) << endl;
}

Measured memory_bytes: 8448
#include<iostream>
#include<vector>
using namespace std;
#define max 10000
#define infty 1<<21

int n;
int d[max];
int color[max];
vector<vector<int> > v(max);

void soya() {
	d[0] = 0;
	while (1) {
		int x = infty;
		for (int i = 0; i < n; i++) {
			if (x != infty) {
				if (d[i] < d[x] && color[i] != 2) {
					x = i;
				}
			}
			else {
				if (d[i] < x && color[i] != 2) {
					x = i;
				}
			}
		}

		if (x == infty) break;
		else {
			color[x] = 2;
			for (int i = 0; i < v[x].size() / 2; i++) {
				if (d[x] +v[x][(2 * i) + 1] < d[v[x][2 * i]]) {
					d[v[x][2 * i]] = d[x] + v[x][(2 * i) + 1];
				}
			}
		}
	}
}

int main() {
	for (int i = 0; i < max; i++) {
		color[i] = 0;
		d[i] = infty;
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		int id;
		int k;
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			int num1;
			int kyori;
			cin >> num1 >> kyori;
			v[id].push_back(num1);
			v[id].push_back(kyori);
		}
	}

	soya();

	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 7900
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
  int a1,a2,a3;
  int sum=0;
  
  scanf("%d %d %d",&a1,&a2,&a3);
  sum = a1+a2+a3;
  
  if( sum>21 ){
    printf("bust\n");
  }
  else{
    printf("win\n");
  }
  
  
  return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
 
using namespace std;
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

void dfs(const vvi& G, const int v, vi& connected, const int label) {
    connected[v] = label;

    for (auto next_v: G[v]) {
        if (connected[next_v] != -1) { continue; }
        dfs(G, next_v, connected, label);
    }
}

int main() {
    int N, M, K;
    scanf("%d %d %d", &N, &M, &K);

    vvi FR(N);
    vvi BL(N);
    vi connected(N, -1);
    vi size(N, 0);
    vi num_fr(N, 0);

    rep(i, 0, M) {
        int a, b;
        scanf("%d %d", &a, &b);
 
        FR[a-1].push_back(b-1);
        FR[b-1].push_back(a-1);
        ++num_fr[a-1];
        ++num_fr[b-1];
    }

    rep(i, 0, K) {
        int c, d;
        scanf("%d %d", &c, &d);

        BL[c-1].push_back(d-1);
        BL[d-1].push_back(c-1);
    }

    int label = 0;
    rep(i, 0, N) {
        if (connected[i] != -1) { continue; }
        dfs(FR, i, connected, label++);
    }

    rep(i, 0, N) {
        size[connected[i]]++;
    }

    rep(i, 0, N) {
        int ans = size[connected[i]] - num_fr[i] - 1;
        for (auto v: BL[i]) {
            if (connected[v] == connected[i]) { --ans; }
        }

        cout << ans;

        if (i != N - 1) { cout << " "; }
        else { cout << endl; }
    }

    return 0;
}

Measured memory_bytes: 13440
n = int(input())

def change_n_shinsu(x, n):
    ans = []
    while True:
        shou = x // n
        amari = x % n
        if shou == 0 and amari == 0:
            break
        ans.append(amari)
        x = shou
    return ans

end = [26]
for i in range(2, 100):
    end.append(26**i+end[-1])
    if end[-1] > 1000000000000001:
        break
start = [1]
for i in end[:-1]:
    start.append(i+1)

i = 0
while n > end[i]:
    i += 1
keta = i+1
n -= start[i]

ret = change_n_shinsu(n, 26)
ans = ''
for i in ret:
    ans = chr(i+ord('a')) + ans
ans = 'a'*(keta-len(ret)) + ans
print(ans)

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

	const double pi = acos(-1.0);

	cout << 2 * pi * r << endl;
}

Measured memory_bytes: 3800
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int main() {
	string s;cin>>s;
	if(s=="ABC")puts("ARC");
	else puts("ABC"); 
	return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>  

using namespace std;

int main(){
    string S;
    int i, l, zero=0, one=0;
    cin >> S;
    l = S.length();

    for (i=0; i<l; i++){
        if (S[i]=='0') zero++;
        else one++;
    }

    cout << min(zero, one) * 2 << '\n';
}

   

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second

const int INF = 1e9+5;


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	forn(i, n) cin >> h[i];
	vector<int> dp(n, INF);
	dp[0] = 0;
	dp[1] = abs(h[0]-h[1]);
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j <= i+k; j++){
			if(j < n)
				dp[j] = min(dp[i]+abs(h[i]-h[j]), dp[j]);
		}
	}
		
	cout << dp[n-1] << endl;
	return 0;

}



Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func print(msg string) {
	fmt.Println(msg)
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if (a*b)%2 == 0 {
		print("Even")
	} else {
		print("Odd")
	}
}


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

double PI = acos(-1);
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  double rad = (double)c / 180 * PI;
  cout << setprecision(10) << fixed;
  cout << 0.5 * a * b * sin(rad) << endl;
  double e = sqrt(a * a + b * b - 2 * a * b * cos(rad));
  cout << a + b + e << endl;
  cout << a * b * sin(rad) / a << endl;
}


Measured memory_bytes: 3600