akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
struct node{
    int key;
    struct node *parent;
    struct node *left;
    struct node *right;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insertNode(int key){
    Node y = NIL;
    Node x = root;
    Node z;
    
    z = (node *)malloc(sizeof(struct node));
    z->key = key;
    z->left = NIL;
    z->right = NIL;
    
    while(x != NIL){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;
    
    if(y == NIL) root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;
}

Node findNode(Node tree, int key){
    while(tree != NIL){
        if(tree-> key == key) return tree;
        else if(tree->key >= key) tree = tree->left;
        else tree = tree->right;
    }
    
    return tree;
}

void inorederNode(Node tree){
    if(tree->left != NIL) inorederNode(tree->left);
    cout << " " << tree->key;
    if(tree->right != NIL) inorederNode(tree->right);
}

void preorederNode(Node tree){
    cout << " " << tree->key;
    if(tree->left != NIL) preorederNode(tree->left);
    if(tree->right != NIL) preorederNode(tree->right);
}

int main(void){
    int n, key;
    string command;
    Node t;
    
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> command;
        
        if(command[0] == 'p'){
            inorederNode(root);
            cout << endl;
            preorederNode(root);
            cout << endl;
        }
        else if(command[0] == 'i'){
            cin >> key;
            insertNode(key);
        }
        else if(command[0] == 'f'){
            cin >> key;
            t = findNode(root, key);
            if(t != NIL) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 21868
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    char a;
    cin >> a;
    if ('a' <= a && a <= 'z'){
        cout << 'a' << endl;
    }else{
        cout << 'A' << endl;
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int a,b,c,x; cin >> a >> b >> c >> x;
    int ans = 0;

    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(500*i + 100*j + 50*k == x) ans++;
            }
        }
    }

    cout << ans << endl;
}

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

const ll INF = ll(1e18) + 1;

int main() {
	int N;
	ll K;
	cin >> N >> K;

	vector<ll> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());

	ll l = -INF, r = INF;
	while (l + 1 < r) {
		ll x = (l + r) / 2;
		ll tot = 0;
		for (int i = 0; i < N; i++) {
			if (A[i] < 0) {
				int l = -1, r = N;
				while (l + 1 < r) {
					int c = (l + r) / 2;
					if (A[c] * A[i] < x) {
						r = c;
					}
					else {
						l = c;
					}
				}
				tot += N - r;
			}
			else {
				int l = -1, r = N;
				while (l + 1 < r) {
					int c = (l + r) / 2;
					if (A[c] * A[i] < x) {
						l = c;
					}
					else {
						r = c;
					}
				}
				tot += r;
			}
			if (A[i] * A[i] < x) {
				tot--;
			}
		}
		tot /= 2;
		if (tot < K) {
			l = x;
		}
		else {
			r = x;
		}
	}
	cout << l << endl;
}

Measured memory_bytes: 1792
<?php
$D = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($N,$M,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
$c = array_map('intval',explode(" ",trim(fgets(STDIN))));
for($i=0;$i<$D;$i++) {
  $s[]=array_map('intval',explode(" ",trim(fgets(STDIN))));
}


for($i=0;$i<$D;$i++) {
  printf("%d\n",rand(1,26));
}


Measured memory_bytes: 16740
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int a, b, ab=1000,temp, ans,sum, n, x;
	int p[105];
	char s[4], t[20];
	scanf("%d %d", &x, &n);
		
	for (int i = 0;i < 102;i++)
		p[i] = i;

	for (int i = 0;i < n;i++) {
		scanf("%d", &a);
		p[a] = 1000;
	}

	ab = abs(x+1);
	ans = -1;

	for (int i = 0;i < 102;i++) {
		temp = abs(x-p[i]);
		if (temp < ab) {
			ans = p[i];
			ab = temp;
		}

	}


	printf("%d",ans);

	return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#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,m; cin >> n >> m;
    priority_queue<P> q;
    vector<int> a(n),b(m),c(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i] >> c[i];
    rep(i,n) q.push(make_pair(a[i],1));
    rep(i,m) q.push(make_pair(c[i],b[i]));
    ll ans = 0;
    rep(i,n){
        auto p = q.top();
        q.pop();//最大を取り除く
        ans += p.first;
        if(p.second > 1){
            p.second--;
            q.push(p);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ll n,m;
    cin>>n>>m;
    int ok[n]={0};
    int h[n];
    for (int j = 0; j < n; ++j) {
        cin>>h[j];
    }
    for (int i = 0; i < m; ++i) {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        if(h[a]<=h[b])ok[a]=1;
        if(h[a]>=h[b])ok[b]=1;
    }
    int ans=0;
    for (int k = 0; k < n; ++k) {
        if(ok[k]==0)ans++;
        //else cout<<k<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
#define RI register int
const int N=200005;
char s[N];int len,js=0,ans;
int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	for(RI i=1;i<=len;++i)
		if(s[i]=='S') ++js;
		else {
			if(js) --js;
			else ++ans;
		}
	printf("%d\n",ans+js);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
    int N,M;
    cin >>N>>M;
    if(abs(N-M)>1)cout<<0<<endl;
    else{
        long long a=1,b=1;
        for(int i=1;i<N+1;i++){
            a=a*i%1000000007;
        }
        for(int i=1;i<M+1;i++){
            b=b*i%1000000007;
        }
        if(M==N)cout<<a*b%1000000007*2%1000000007<<endl;
        else cout<<(a*b)%1000000007<<endl;
    }
}

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

int ans=1e9;
int n,a,b,c;
using msi = multiset<int>;
void dfs(int s, msi& a_g, msi& b_g, msi& c_g, vector<int>& l) {
  if(s==n) {
    int ta=0;
    int tb=0;
    int tc=0;
    int tsugiki_count=0;
    for(auto& x : a_g)ta+=x;
    tsugiki_count+=a_g.size()-1;
    for(auto& x : b_g)tb+=x;
    tsugiki_count+=b_g.size()-1;
    for(auto& x : c_g)tc+=x;
    tsugiki_count+=c_g.size()-1;
    if(ta==0||tb==0||tc==0)
      return;
    //cout << "ta="<<ta<<",tb="<<tb<<",tc="<<tc<<endl;
    ans=min(ans,tsugiki_count*10+abs(ta-a)+abs(tb-b)+abs(tc-c));
    return;
  }
  msi::iterator it;
  a_g.insert(l[s]);
  dfs(s+1,a_g,b_g,c_g,l);
  it=a_g.find(l[s]);
  a_g.erase(it);
  // erase l[s]
  b_g.insert(l[s]);
  dfs(s+1,a_g,b_g,c_g,l);
  it=b_g.find(l[s]);
  b_g.erase(it);
  c_g.insert(l[s]);
  dfs(s+1,a_g,b_g,c_g,l);
  it=c_g.find(l[s]);
  c_g.erase(it);
  dfs(s+1,a_g,b_g,c_g,l);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  cin>>n>>a>>b>>c;
  vector<int> l(n);
  rep(i,n)cin>>l[i];
  multiset<int> a_g;
  multiset<int> b_g;
  multiset<int> c_g;
  dfs(0,a_g,b_g,c_g,l);
  cout << ans << endl;
  return 0;
}


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


int main(){
    int A,B;
    cin >> A >> B;

    int sum = 1;
    int count = 0;

    while(sum < B){
        sum += A-1;
        count++;
    }

    cout << count;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
struct Node{
    Node(){
        left_child = right_child = parent = -1;
    };
    int left_child,right_child,parent;
};
 
void preORDER(Node order[],int id){
    printf(" %d",id);
    if(order[id].left_child != -1) preORDER(order,order[id].left_child );
    if(order[id].right_child != -1) preORDER(order,order[id].right_child );
}
 
void inORDER(Node order[],int id){
    if(order[id].left_child != -1) inORDER(order,order[id].left_child );
    printf(" %d",id);
    if(order[id].right_child != -1) inORDER(order,order[id].right_child );
}
 
void postORDER(Node order[],int id){
    if(order[id].left_child != -1) postORDER(order,order[id].left_child );
    if(order[id].right_child != -1) postORDER(order,order[id].right_child );
    printf(" %d",id);
}
 
int main(){
    int n,id,left,right,root_id;
    scanf("%d",&n);
    Node order[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&id,&left,&right);
        if(left != -1){
            order[id].left_child = left;
            order[left].parent = id;
        }
        if(right != -1){
            order[id].right_child = right;
            order[right].parent = id;
        }
    }
 
    for(root_id = 0; root_id < n; root_id++){
        if(order[root_id].parent == -1) break;
    }
 
    printf("Preorder\n");
    preORDER(order,root_id);
    printf("\n");
 
    printf("Inorder\n");
    inORDER(order,root_id);
    printf("\n");
 
    printf("Postorder\n");
    postORDER(order,root_id);
    printf("\n");
}


Measured memory_bytes: 2744
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline, to_string
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap, pair
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt,ceil,M_PI, pow, sin
#include <sstream>	//stringstream,getline
#include <numeric>	//gcd, accumlate
#include <deque>	//deque
#include <random>	//randam_device

using namespace std;
constexpr long long int D_MOD = 1000000007;

int main() {

	int a, b;
	cin >> a >> b;

	int ans = 0;
	if (a >= b) {
		ans += a;
		a--;
	}
	else {
		ans += b;
		b--;
	}

	ans += max(a, b);

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 3620
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF (1LL<<60)
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
#define MSB(x) (63-__builtin_clzll(x))
#define pcnt(x) (__builtin_popcountll(x))
#define parity(i,j) (i&(1LL<<j))
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n,a,b;
  cin >> n >> a >> b;

  if((b-a)%2==0) cout << (b-a)/2 << endl;
  else{
    int x = a-1 + (b-a+1)/2;
    int y = n-b + (b-a+1)/2;
    cout << min(x,y) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def main():
    s=input()
    if s[0] == "A":
        if (s[2:-1:]).count("C") == 1:
            for i in s[1:]:
                c = False
                if i == "C" and not c:
                    c = True
                    continue
                elif i == "C" and c:
                    break
                elif i.islower():
                    continue
                else:
                    break
            else:
                print("AC")
                return
    print("WA")
    
if __name__ == "__main__":
    main()

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(), b.end());
    int left = b[n/2-1], right = b[n/2];
    if (left == right) {
        for (int i = 0; i < n; i++)
            cout << left << endl;
    } else {
        for (int i = 0; i < n; i++) {
            if (a[i] <= left)
                cout << right << endl;
            else
                cout << left << endl;
        }
    }

}

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


int main()
{
    ll n,k;
  cin>>n>>k;
 ll a[n],i;
  for(i=0;i<n;i++)
    cin>>a[i];
  map<ll,ll>m;
  
  ll count=0;
  i=1;
 // m[i]++;
  while(count<k)
  {
     
    if(m[i])
      break;
      m[i]++;
      //cout<<i<<" **"<<endl;
    count++;
    i=a[i-1];
    
  }
  
  
  
  //cout<<count<<endl;

 if(count==k)
  cout<<i;
  else{
    k=k-count;
     map<ll,ll>m;
    ll aa[n];
    aa[0]=i;
    count=0;
  while(1)
  {
      
    if(m[i])
      break;
      m[i]++;
    count++;
    i=a[i-1];
     aa[count]=i;
  }
  //cout<<count<<endl;
    k=(k)%count;
    //cout<<
    cout<<aa[k];
  }

}

Measured memory_bytes: 22744
import java.util.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S[] = new String[N];
    Integer P[] = new Integer[N]; 
    for(int i=0; i<N; i++){
      S[i] = sc.next();
      P[i] = sc.nextInt();
    }
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(0,0);
    for(int i=1; i<N; i++){
      int j = 0;
      while(true){
        if(j == list.size()){
          list.add(j, i);
          break;
        }else{
          if(S[i].compareTo(S[list.get(j)]) < 0){
            list.add(j, i);
            break;
          }else if(S[i].compareTo(S[list.get(j)]) == 0){
            if(P[i] > P[list.get(j)]){
              list.add(j, i);
              break;
            }else{
              j++;
              continue;
            }
          }else{
            j++;
            continue;
          }
        }
      }
    }
    for(int a: list){
      System.out.println(a+1);
    }
  }
    

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

public class Main {
    public static int quantum;
    public static int currentTime = 0;
    public Main() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int quantum = scan.nextInt();

        Queue queue = new Queue(100000 + n);
        this.quantum = quantum;

        while(scan.hasNext()){
            String pName = scan.next();
            int time = scan.nextInt();
            queue.enqueue(new Data(pName, time));
        }
        while(!queue.isEmpty()){
            Data data = queue.dequeue();
            if(data.time == 0){
                System.out.println(data.pName + " " + currentTime);
            }
        }
    }

    public static void main(String[] args) {
        new Main();
    }

    private class Queue{
        private int head = 0;
        private int tail = 0;
        private Data queue[];

        public Queue(int size){
            queue = new Data[size*2];
        }

        public void enqueue(Data data){
            queue[tail++] = data;
        }

        public Data dequeue(){
            Data data = queue[head++];
            int time = expendedTime(data);
            if(data.time != 0){
                enqueue(data);
            }
            currentTime += time;
            return data;
        }

        public int expendedTime(Data data){
            int time;
            if(data.time > quantum){
                time = quantum;
                data.time -= quantum;
            }else{
                time = data.time;
                data.time = 0;
            }
            return time;
        }

        public boolean isEmpty(){
            return head == tail;
        }

    }

    private class Data{
        public String pName;
        public int time;

        public Data(String pName, int time){
            this.pName = pName;
            this.time = time;
        }
    }
}

Measured memory_bytes: 71740
#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;typedef vector<int> vi;typedef vector<ll> vll;
typedef pair<int,int> ii;typedef map<int,int> mii;
inline void rvi(vi &v, int n){int temp; rep(i,n){cin>>temp;v.pb(temp);}}
inline void rvll(vll &v, int n){ll temp;rep(i,n){cin>>temp;v.pb(temp);}}
inline void prvi(vi &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline void prvll(vll &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline vll prefixsum(vi &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vi &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
inline vll prefixsum(vll &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vll &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
void solve();int main(){ios;solve();return 0;}
//--------SOLVE--------------------------------------------------------------------
void solve()
{
	int n,w;cin>>n>>w;
	vector< ii > items;
	items.pb({-1,-1});
	for(int i=0;i<n;i++)
	{
		int t1,t2;cin>>t1>>t2;
		items.pb({t1,t2});
	}
	//dp[i][j] gives max value for items 1 to i with max allowed weight=j
	vector< vector<long long> > dp;
	dp.resize(102);
	for(int i=0;i<102;i++) dp[i].resize(100005);
	for(int i=0;i<=n;i++) dp[i][0]=0; //0 weight allowed
	for(int i=0;i<=w;i++) dp[0][i]=0; //0 items taken
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(items[i].fi>j) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j],dp[i-1][j-items[i].fi]+items[i].se);
		}
	}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 80256
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int E =scn.nextInt();
        int S=scn.nextInt();
        if(E>8||S>8){
            System.out.println(":(");
        }else{
            System.out.println("Yay!");
        }
    }
}


Measured memory_bytes: 21844
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}


ll getSumDigit(ll N){
    string s=to_string(N);
    ll ret=0;
    for(int i=0;i<s.size();i++)ret+=(s[i]-'0');
    return ret;
}

int main(){
  init();
  ll X,Y;cin>>X>>Y;
  ll ans=1;
  while(X*2<=Y){
    X*=2;
    ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
#define ll long long
double a,b,x;
int main()
{
	scanf("%lf%lf%lf",&a,&b,&x);
	double v=a*b*a*0.5;
	double pi=asin(1.0)*2.0;
	double zh=180.0/pi;
	if(x>v)
	{
		double v1=a*b*a-x;
		double g=v1*2/a/a;
		printf("%lf",90-zh*atan(a/g));
	}
	else
	{
		double v1=x;
		double g=v1*2/b/a;
		printf("%lf",zh*atan(b/g));
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  string s, t;
  cin >> s >> t;

  cout << t << s << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	rem := n % k
	if rem < k-rem {
		fmt.Printf("%d\n", rem)
	} else {
		fmt.Printf("%d\n", k-rem)
	}
}


Measured memory_bytes: 512
const lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function nextLine(k::Int32)
    x,y,c=split(input())
    intSub(x)%2k+1,(intSub(y)+(c=="W")k)%2k+1
end
function main()
    n,k=intLine()
    g=Array{Int32,1}[[0for j in 1:2k]for i in 1:2k]
    for i in 1:n
        x,y=nextLine(k)
        g[x][y]+=1
    end
    g=cumsum(map(cumsum,g))
    m=0
    for i in 1:2k
        for j in 1:2k
            a=0
            for x in -2:2
                for y in -2:2
                    if (x+y)%2!=0;continue;end
                    v,w=i+x*k,j+y*k
                    if v>0<w;a+=g[min(2k,v)][min(2k,w)];end
                    if v>k&&w>0;a-=g[min(2k,v-k)][min(2k,w)];end
                    if w>k&&v>0;a-=g[min(2k,v)][min(2k,w-k)];end
                    if v>k<w;a+=g[min(2k,v-k)][min(2k,w-k)];end
                end
            end
            m=max(m,a)
        end
    end
    println(m)
end
main()

Measured memory_bytes: 205556
import sys
import math
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


@lru_cache(maxsize=None)
def solve(x, y):
    return math.gcd(x, y)


def main():
    N = int(input())

    ans = 0
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            x = math.gcd(i, j)
            for k in range(1, N + 1):
                ans += math.gcd(x, k)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 87188
n,m,R=map(int,input().split())
r=[int(i) for i in input().split()]
inputs=[]
d=[[10**100 for i in range(n+1)] for i in range(n+1)]
for i in range(m):
    a,b,c=map(int,input().split())
    d[a][b]=c
    d[b][a]=c

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n+1):
        for i in range(n+1):
            for j in range(n+1):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
d=warshall_floyd(d)
ans=10**100
import itertools
for x in itertools.permutations(r):
    p=0
    for i in range(1,R):
        p+=d[x[i-1]][x[i]]
    ans=min(ans,p)
print(ans)

Measured memory_bytes: 57176
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

// http://arc082.contest.atcoder.jp/tasks/arc082_d

void run()
{
  int64_t a;
  size_t k;
  cin >> a >> k;
  vector<int64_t> r(k);
  cin >> r;

  // the slopping portion
  int64_t x1 = 0, x2 = a, y1 = 0;

  bool flag = false;
  size_t i = 0, q;

  for(cin >> q; q; --q, cout << '\n')
  {
    int64_t t, s;
    cin >> t >> s;

    for(; i < r.size() && r[i] < t; ++i, flag = !flag)
    {
      const auto dy = r[i] - (i ? r[i - 1] : 0);

      if(flag) // increasing
      {
        if(a <= y1 + dy)
        {
          x1 = x2 = 0;
          y1 = a;
        }
        else if (y1 + x2 - x1 + dy <= a)
          y1 += dy;
        else
        {
          const auto dx = a - y1 - dy;
          x2 = x1 + dx;
          y1 += dy;
        }
      }
      else  // decreasing
      {
        if (dy <= y1)
          y1 -= dy;
        else if (y1 + x2 - x1 <= dy)
        {
          x1 = x2 = 0;
          y1 = 0;
        }
        else
        {
          const auto dx = dy - y1;
          x1 += dx;
          y1 = 0;
        }
      }
    }
#ifdef BUG
    cerr << ":: " << x1 << ' ' << y1 << ' ' << x2 << '\n';
#endif
    const auto dy = t - (i ? r[i - 1] : 0);
    if (flag ) // increasing
    {
      if(s < x1)
        cout << min(a, y1 + dy);
      else
        cout << min(a, y1 + min(s, x2) - x1 + dy);
    }
    else  // decreasing
    {
      if(s < x1)
        cout << max((int64_t)0, y1 - dy);
      else
        cout << max((int64_t)0, y1 + min(s, x2) - x1 - dy);
    }

  }
}

int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  run();

  return EXIT_SUCCESS;
}


Measured memory_bytes: 2048
#include <stdio.h>
#define SIZE 100
#define INF 100000000

int q[SIZE];
int head=0,tail=1,n,M[SIZE][SIZE];
int d[SIZE]; //?????¢??§????¨??????¶?????????????????????

void enqueue(int x){ //?????\??????????£?
  q[tail++]=x;
}

int dequeue(){
  int x=q[head++];
  return x;
}

int isEmpty(){
  return (head==tail);
}

void bfs(int s){
  int i,j;
  int u,k,v;
  int deq;

  enqueue(s); //?????\????????¶?????????(push)
  for(i=0;i<n;i++){
    d[i]=INF;
  }
  d[s]=0;

  while(!isEmpty()){ //?????\????????????????????§?????????
    deq=dequeue();
    for(v=0;v<n;v++){
    if(M[deq][v]==0) continue;
    if(d[v]!=INF) continue;
    d[v]=d[deq]+1;
    enqueue(v);
  }
}
for(i=0;i<n;i++){
  printf("%d ",i+1);
  if(d[i]==INF) printf("-1\n");
  else printf("%d\n",d[i]);
  }
}

int main(){
  int u,k,v;
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
}
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);

  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    	long long n,p,one=0,zero=0,a,ans;
    	cin>>n>>p;
    	for(int i=0;i<n;i++){
    		cin>>a;
    		if(a%2==0){
    			zero++;
    		}
    		else{
    			one++;
    		}
    	}
    	if(p==1 && one==0){
    		cout<<"0"<<endl;
    	}
		else if(p==0 && one==0){
			ans=pow(2,n);
			cout<<ans<<endl;
		}
    	else{
    		zero=pow(2,zero);
    		one=pow(2,one-1);
    		ans=zero*one;
    	cout<<ans<<endl;
    	}
      return(0);
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define tracev(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define trace2v(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n'; cerr << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifndef ONLINE_JUDGE
    freopen("errlog", "w", stderr);
#endif
    int n, h; cin >> h >> n;
    int ans = (h / n) + (h % n ? 1 : 0);
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int uint;
typedef long double ld;
//#define ll __int128
#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<pii> vpi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = atan2(1, 0) * 2;

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    for (auto x : a) out << x << " ";
    return out << "}";
}

void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


#ifdef ART_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef ART_HOME
    cout << "\n\n\n";
    cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
}


const int N = 401;
int used[N][N];
vs maps;
int n, m;


pii steps[4] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};


bool may(int i, int j)
{
    return i >= 0 && i < n && j >= 0 && j < m && !used[i][j];
}


pii dfs(int i, int j)
{
    pii cur = {0, 0};
    used[i][j] = 1;

    if (maps[i][j] == '#')
        cur.first++;
    else
        cur.second++;

    for (auto p : steps)
    {
        if (may(i + p.first, j + p.second) && maps[i][j] != maps[i + p.first][j + p.second])
        {
            pii ncur = dfs(i + p.first, j + p.second);
            cur.first += ncur.first;
            cur.second += ncur.second;
        }
    }

    return cur;
}


void smain() {
    cin >> n >> m;
    maps.resize(n);

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

    int ans = 0;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            if (!used[i][j] && maps[i][j] == '#')
            {
                pii p = dfs(i, j);
                ans += p.first * p.second;
            }

    cout << ans << '\n';
}

Measured memory_bytes: 19200
def main():
    N=int(input())
    
    Array=list(map(int, input().split(' ')[:N]))
    if 0 in Array:
        print(0)
        return
    mul=1
    for i in Array:
        mul*=i
        if mul > 1000000000000000000:
            print(-1)
            return
    
    print(mul)
main()

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

const int INF = 1001001001;

void Main(){
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    vvi d(H, vi(W, 0));
    rep(i, H) {
        cin >> s[i];
        rep(j, W){
            if(s[i][j] == '#') d[i][j] = 1;
        }
	}
	
	/*
	rep(i, H){
	    rep(j, W){
	        cout << d[i][j] << " ";
	    }
	    cout << endl;
	}
    //*/
    
	vvi dp(H, vi(W, 0));
	// 0 <-> 1 入れ替えで +1
	rep(i, H){
	    rep(j, W){
	        if(i == 0 && j == 0) dp[i][j] = d[i][j];
	        else{
	            int t1, t2;
	            t1 = t2 = INF;
            	if(i-1 >= 0) t1 = dp[i-1][j] + int(d[i][j] ^ d[i-1][j]);
            	if(j-1 >= 0) t2 = dp[i][j-1] + int(d[i][j] ^ d[i][j-1]);
                dp[i][j] = min(t1, t2);
                // cout << i << " " << j << " " << dp[i][j] << endl;
    	    }
	    }
	}
    if(d[H-1][W-1] == 1) dp[H-1][W-1]++;
	cout << dp[H-1][W-1]/2 << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

void solve(long long N, long long K, std::vector<long long> V) {
    ll ans = 0;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; i + j <= K; j++) {
            int k = K - i - j;
            auto d = deque<ll>(V.begin(), V.end());
            int I = i;
            int J = j;
            deque<int> aa;
            while (d.size() && I) {
                aa.push_back(d.front());
                d.pop_front();
                I--;
            }
            while (d.size() && J) {
                aa.push_back(d.back());
                d.pop_back();
                J--;
            }
            sort(aa.begin(), aa.end());
            int G = k;
            while( G && aa.size() && aa.front() < 0 ){
                aa.pop_front();
                G--;
            }
            ll tot = 0;
            for(auto w : aa){
                tot += w;
            }
            ans = max(tot, ans);
        }
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> V(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &V[i]);
    }
    solve(N, K, std::move(V));
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
char ao[10];
char bo[11];
int main() {
	string a, b;
	string c = "Yes";
	cin >> a >> b;
	for (int i = 0; i < (int)a.size(); i++)ao[i] = a[i];
	for (int i = 0; i < (int)a.size(); i++)bo[i] = b[i];
	for (int i = 0; i < (int)a.size(); i++) {
		if (ao[i] != bo[i])c = "No";
	}
	cout << c << endl;
}

Measured memory_bytes: 3088
#include<stdio.h>
int main(){
 
int N,k,a[100],m,tmp,A=0,min;
 
scanf("%d",&N);
 
for(k=0;k<N;k++)
scanf("%d",&a[k]);


 
for(m=0;m<=N-1;m++){
 
min=m;
for(k=m;k<=N-1;k++){
if(a[min]>a[k])
   min=k;
}

if(m != min){
tmp=a[m];
a[m]=a[min];
a[min]=tmp;

A++;
}

}
 
for(k=0;k<N;k++){
printf("%d",a[k]);
if(k!=N-1)
printf(" ");
}
 
printf("\n");
printf("%d\n",A);
 
}



Measured memory_bytes: 1932
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

int main()
{
    int N; cin >> N;
    vector<int> slimes(N);
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        slimes[i] = a;
    }

    map<int, int> dict;
    int cnt = 0;
    int same_colors = 0;
    for (int i = 1; i < N; i++) {
        if (slimes[i] == slimes[i - 1]) {
            dict[slimes[i]]++;
            same_colors++;
        }
        else {
            same_colors = same_colors == 0 ? 0 : same_colors + 1;
            cnt += same_colors / 2;
            same_colors = 0;
        }
    }
    if (same_colors != 0) {
        same_colors = same_colors == 0 ? 0 : same_colors + 1;
        cnt += same_colors / 2;
    }

    //for (auto p : dict) {
    //    int same_colors = p.second + 1;
    //    cnt += same_colors / 2;
    //}
    cout << cnt << endl;
}

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

typedef long long ll;

ll arr[100010];
int counter[100010];

int main() {
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> arr[i];
    }

    int nrem = 0;
    for (int i = 1; i <= N; i++) {
        if (arr[i] <= 100000) {
            counter[arr[i]]++;
        } else {
            nrem++;
        }
    }

    for (int i = 1; i <= 100000; i++) {
        if (counter[i] < i) {
            nrem += counter[i];
        } else {
            nrem += counter[i] - i;
        }
    }

    cout << nrem << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, x, a, z;
    cin >> n >> x >> a;
    z = abs(x - a);
    for (int i = 1; i < n; i++) cin >> a, z = __gcd(z, abs(x - a));
    cout << z;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> x(n), y(n), w(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> w[i];
  }

  vector<vector<int>> dis_x(n, vector<int>(1 << n));
  vector<vector<int>> dis_y(n, vector<int>(1 << n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (1 << n); j++) {
      dis_x[i][j] = abs(x[i]);
      dis_y[i][j] = abs(y[i]);
      for (int k = 0; k < n; k++) {
        if (j & (1 << k)) {
          dis_x[i][j] = min(dis_x[i][j], abs(x[i] - x[k]));
          dis_y[i][j] = min(dis_y[i][j], abs(y[i] - y[k]));
        }
      }
    }
  }

  
  vector<long long> ans(n + 1, 5e16);
  auto solve = [&](int mx, int my, int mz) {
    assert((mx | my | mz) == (1 << n) - 1); 
    long long res = 0;
    for (int i = 0; i < n; i++) {
      res += 1LL * w[i] * min(dis_x[i][mx], dis_y[i][my]);
    }
    int used = __builtin_popcount(mx | my);
    ans[used] = min(ans[used], res);
  };
  
  for (int i = 0; i < (1 << n); i++) { // mask x
    int mask = ((1 << n) - 1) ^ i;
    for (int j = mask; j > 0; j = (j - 1) & mask) { // mask y
      int k = ((1 << n) - 1) ^ i ^ j;
      solve(i, j, k);
    }
    solve(i, 0, mask);
  }

  for (auto i : ans) {
    cout << i << '\n';
  }

  return 0;
}


Measured memory_bytes: 7240
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 505
#define M 200005
#define seed 23333

using namespace std;
int i,j,m,n,p,k,flag;
char c[N][N];
int main()
{
	scanf("%d",&n);
	for (i=0;i<n;++i)
	{
			scanf("%s",c[i]); 
			for (j=0;j<n;++j) if (c[i][j]=='#') flag=1;
	}
	if (!flag)
	{
			puts("-1");
			return 0;
	}
	int Max=n+2;
	for (i=0;i<n;++i)
	{
			for (j=0;j<n;++j) if (c[j][i]=='#') break;
			int cnt=0; 
			if (j==n) cnt=1;
			//int cnt=0;
			for (j=0;j<n;++j) if (c[i][j]=='.') ++cnt;
			Max=min(Max,cnt);
	}
	if (Max==n+2)
	{
		 puts("-1");
	}
	else 
	{
			for (i=0;i<n;++i)
			{
					for (j=0;j<n;++j) if (c[j][i]=='.') break;
					if (j==n) continue;
					++Max;
			}
			printf("%d\n",Max); 
	}
}


Measured memory_bytes: 512
s = input()
count = {"N":0, "W":0, "S":0, "E":0}
for i in s:
    count[i] += 1

if ((count["N"] != 0 and count["S"] != 0) or (count["N"] == count["S"] == 0))and ((count["W"] != 0 and count["E"] != 0) or (count["W"] == count["E"] == 0)):
    print("Yes")

else:
    print("No")


Measured memory_bytes: 3060
n = str(input())
N = n
ans = 0
for i in range(2 ** int(len(n)-1)):
    n = N
    tmplist = []
    for j in range(1,len(n)):
        if (i >> j-1) & 1:
            #print(j-tmp,n)
            tmplist.append(int(n[:j]))
            n = n[j:].zfill(len(n))
    if not n == "":
        tmplist.append(int(n))

    ans += sum(tmplist)
    #print(tmplist)
    #print(i,sum(tmplist),tmplist)
print(ans)

Measured memory_bytes: 41356
#include <iostream>

using namespace std;
using ll = long long;

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int xa = min(a, k);
  int xb = min(b, k - xa);
  int xc = k - (xa + xb);

  cout << xa - xc << '\n';

  return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<vector<int>> t;
  vector<int> d, odd, even;
  Solver(LL n) : n(n), t(n), d(n, -1){};

  void solve() {
    for (int i = 0; i < n - 1; ++i) {
      int a, b;
      cin >> a >> b;
      t[--a].push_back(--b);
      t[b].push_back(a);
    }
    d[0] = 0;
    queue<int> Q;
    Q.push(0);
    while (!Q.empty()) {
      int now = Q.front();
      Q.pop();
      for (auto v : t[now]) {
        if (d[v] < 0) {
          Q.push(v);
          d[v] = d[now] + 1;
        }
      }
    }
    vector<int> cnt(2);
    for (int i = 0; i < n; ++i) {
      cnt[d[i] % 2]++;
    }
    vector<int> ans(n);

    if (cnt[0] * 3 <= n) {
      deque<int> deq;
      for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0)
          deq.push_front(i);
        else
          deq.push_back(i);
      }
      for (int i = 0; i < n; ++i) {
        int tmp;
        if (d[i] % 2 == 0) {
          tmp = deq.front();
          deq.pop_front();
        } else {
          tmp = deq.back();
          deq.pop_back();
        }
        ans[i] = tmp;
      }
    } else if (cnt[1] * 3 <= n) {
      deque<int> deq;
      for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0)
          deq.push_front(i);
        else
          deq.push_back(i);
      }
      for (int i = 0; i < n; ++i) {
        int tmp;
        if (d[i] % 2 == 1) {
          tmp = deq.front();
          deq.pop_front();
        } else {
          tmp = deq.back();
          deq.pop_back();
        }
        ans[i] = tmp;
      }
    } else {
      deque<int> deq;
      for (int i = 3; i <= n; i += 3) {
        deq.push_back(i);
      }
      for (int i = 1; i <= n; ++i) {
        if (i % 3 == 1) {
          deq.push_front(i);
        } else if (i % 3 == 2) {
          deq.push_back(i);
        }
      }
      DBG(deq)

      for (int i = 0; i < n; ++i) {
        int tmp;
        if (d[i] % 2 == 1) {
          tmp = deq.front();
          deq.pop_front();
        } else {
          tmp = deq.back();
          deq.pop_back();
        }
        ans[i] = tmp;
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << ans[i] << ' ';
    }
    cout << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 15472
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N;
    ll a[MAX_N];
    map<ll, ll> cnt;
    ll answer = 0;

    cin >> N;
    rep(i, N){
        cin >> a[i];
        if (a[i] <= N) cnt[a[i]] = 0;
    }
    rep(i, N){
        if (a[i] > N) answer ++;
        else cnt[a[i]] ++;
    }

    for(auto& kv: cnt){
        if (kv.first <= kv.second) answer += kv.second - kv.first;
        else answer += kv.second;
    }


    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 1024