akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};
struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card *A,int n,int left,int mid,int right){
  int i,j,k;
  int a = mid - left;
  int b = right - mid;
  for( i = 0;i<a;i++) L[i] = A[left + i];
  for( i = 0;i<b;i++) R[i] = A[mid + i];
  L[a].value = R[b].value = SENTINEL;
  i = j = 0;
  for(k = left;k<right;k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }else{
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card *A,int n,int left,int right){
  int mid;
  if(left+1<right){
    mid = (left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card *A,int n,int p,int r){
  int i,j;
  struct Card t,x;
  x = A[r];
  i = p-1;
  for(j = p;j<r;j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i];A[i] = A[j];A[j] = t;
    }
  }
  t = A[i+1];A[i+1] = A[r];A[r] = t;
  return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}


int main(){
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;

  }
  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit != B[i].suit){
      stable = 0;
    }
  }

  if(stable == 1){
    printf("Stable\n");
  }if(stable == 0){
    printf("Not stable\n");
  }
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);

  }

  return 0;
}



Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  int n;cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; ++i)cin >> s[i];
  vector<map<char, int> >mp(n);
  for(int i = 0; i < n; ++i){
    int m = s[i].size();
    for(int j = 0; j < m; ++j){
      ++mp[i][s[i][j]];
    }
  }
  string ans;
  for(int i = 0; i < 26; ++i){
    char c = (char)(i+'a');
    int tmp = 100;
    for(int j = 0; j < n; ++j){
      tmp = min(tmp, mp[j][c]);
    }
    for(int j = 0; j < tmp; ++j){
      ans+= c;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(auto i=(a); i<(b); i++)
#define dec(i,n,a) for(auto i=(n); i>=(a); i--)
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define EPS 3e-8
#define fcin ios_base::sync_with_stdio(false)
#define db(x) cerr << #x << " == " << x << endl
#define _ << " " <<
#define MAXN 101010
#define LOGN 29
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

int n;
map<ll, ll> qt;
ll ans;

int main(){
	qt[0] = 1;
	scanf("%d", &n);
	ll sum = 0;
	rep(i,0,n){
		ll v;
		scanf("%lld", &v);
		sum += v;
		ans += qt[sum];
		qt[sum]++;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
ll a, b, c;
 
int main(void){
	
	scanf("%lld %lld %lld", &a, &b, &c);
	
	bitset<101> bit;
	for(int i = a; !bit[i % b]; i += a){
	    if(i % b == c) { printf("YES\n"); return 0; }
	    bit[i % b] = true;
	}
	printf("NO\n");
	
    return 0;
}

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

void sol(int n){
    for(int i = -120 ; i <= 120 ; ++i){
        for(int j = -120 ; j <= 120 ; ++j){
            if(pow(i,5) - pow(j,5) == n){
                cout << i << " " << j;
                return;
            }
        }
    }
}

int main(){
    int n;
    cin >> n;
    sol(n);
    return 0;
}

Measured memory_bytes: 4036
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
const int dx2[] = { 1,1, 0, -1, -1,0 }; const int dy2[] = { 0, 1, 1,0,-1, -1 };
struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int t, n;
	while (cin >> t >> n, t | n) {
		set<pii> jama;
		REP(i, n) {
			int x, y;
			cin >> x >> y;
			jama.insert(pii(x, y));
		}
		int sx, sy;
		cin >> sx >> sy;
		queue<pii> Q;
		Q.push(pii(sx, sy));
		set<pii> S;
		S.insert(pii(sx, sy));
		int ans = 1;
		REP(i, t) {
			queue<pii> Q2;
			while (!Q.empty()) {
				pii q = Q.front();Q.pop();
				REP(j, 6) {
					if (/*-30 <= q.first + dx2[j] && q.first + dx2[j] <= 30 && 
						-30 <= q.second + dy2[j] && q.second + dy2[j] <= 30 &&*/
						S.find(pii(q.first + dx2[j], q.second + dy2[j])) == S.end() && 
						jama.find(pii(q.first + dx2[j], q.second + dy2[j])) == jama.end()) {

						S.insert(pii(q.first + dx2[j], q.second + dy2[j]));
						Q2.push(pii(q.first + dx2[j], q.second + dy2[j]));
						ans++;
					}
				}
			}
			Q = Q2;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int n;

	std::cin >> n;

	vector<int> a(n);

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

	int bairitu;
	for (int i = n - 1; i >= 0; i--) {
		bairitu = 2;
		for (int j = (i + 1) * bairitu; j <= n; j = (i + 1) * ++bairitu) {
			a[i] ^= a[j - 1];
		}
	}

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

	cout << count << endl;

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

	return 0;
}

Measured memory_bytes: 2432
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
 
//------show vector---------
template <typename T>
void showV(vector < T > a){
  EACH(i,a){
    cerr << *i << ',';
  }  
  cerr << endl;
}
 
//------show matrix---------
template <typename T>
void showVV(vector < vector < T > > a){
  EACH(i,a){
    showV(*i);
  }  
}
//grobal var
//------------------------------------------
LL dp[2000][2000];
vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  return (ret);
}

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int A, B;
  while(cin >> A >> B){
    if((A+B)%2==0) cout << (A+B)/2 << endl;
    else cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;

int main() {
    int x,y,n,w,h,p,c1=0,c2=0;
      cin>>x>>y>>n;
      int a[x],b[y],i;
      for(i=0;i<x;i++) a[i]=0;
      for(i=0;i<y;i++) b[i]=0;
      while(n--)
      {
          cin>>w>>h>>p;
          if(p==1) for(i=0;i<w;i++) a[i]=1;
          else if(p==2) for(i=w;i<x;i++) a[i]=1;
          else if(p==3) for(i=0;i<h;i++) b[i]=1;
          else if(p==4) for(i=h;i<y;i++) b[i]=1;
      }
    
    
      for(i=0;i<x;i++)
      {
          if(a[i]==0) c1++;
      }
      for(i=0;i<y;i++)
      {
          if(b[i]==0) c2++;
      }
      cout<<c1*c2<<endl;
       return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    char a[200];
    while(~scanf("%s",a))
    {
        char b[2]= {'C','F'};
        int k=0,sum=0;
        for (int i=0; i<strlen(a); i++)
        {
            if (a[i]==b[k])
                k++;
            if (k==2)
            {
                sum++;
                break;
            }
        }
        if (sum!=0)
            printf("Yes\n");
        else
            printf("No\n");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
vector<pair<string, pair<int,int>>> v;

int main(){
	int n; cin >> n;
	FOR(i,1,n){
		string s; int p; cin >> s >> p;
		v.push_back(MP(s,MP(-p,i)));
	}
	sort(ALL(v));
	FOR(i,0,n-1){
		cout << v[i].second.second << endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int dp[505050];
int a[1010][1010];

int toid(int i,int j) {
	if (i > j)return a[j][i];
	return a[i][j];
}

vector<int>TopologicalSort(int n, vector<int>in, vector<int>e[]) {
	stack<int>st;
	for (int i = 0; i < n; i++)if (!in[i])st.push(i);
	vector<int>ret;
	while (st.size()) {
		int i = st.top();
		st.pop();
		ret.pb(i);
		fore(x, e[i]) {
			in[x]--;
			if (!in[x])st.push(x);
		}
	}
	return ret;
}

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

	int N;
	cin >> N;
	vector<int>edge[505050];
	int cnt = 0;
	for (int i = 0; i < N; i++)for (int j = i + 1; j < N; j++) {
		a[i][j] = cnt;
		cnt++;
	}
	int sz = N * (N - 1) / 2;

	vector<int>in(sz);
	for (int i = 0; i < N; i++) {
		int pre;
		for (int j = 0; j < N - 1; j++) {
			if (j == 0) {
				cin >> pre;
				pre--;
			}
			else {
				int temp;
				cin >> temp;
				temp--;
				edge[toid(i,pre)].pb(toid(i,temp));
				in[toid(i,temp)]++;
				pre = temp;
			}
		}
	}


	vector<int>ord = TopologicalSort(sz, in, edge);
	if (ord.size() != sz) {
		puts(-1);
		return 0;
	}

	int ans = 0;
	for (int i = 0; i < sz - 1; i++) {
		int cur = ord[i];
		fore(to, edge[cur]) {
			dp[to] = max(dp[to], dp[cur] + 1);
			ans = max(ans, dp[to]);
		}
	}
	puts(ans + 1);

	return 0;
}


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

using namespace std;
#define int long long
#define rep(i, n) for(int i=0;i<(n);++i)

int N;
int ki, f;

signed main() {
    cin >> N;
    rep(i, N) {
        int a;
        cin >> a;
        if (a % 2)ki++;
        if (a % 4 == 0)f++;
    }
    if (ki <= f || f >= N / 2)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
 
 int a, b;
 
 scanf("%d%d", &a, &b);

 if ( a < b ) {


    printf("a < b\n");

 } else if ( a > b ) {

   printf("a > b\n");

} else {

  printf("a == b\n");

}

 
  
    return 0;
}



Measured memory_bytes: 2104
#![allow(non_snake_case, unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! read_single_value {
	($t:ty) => {
        impl InputValue for $t {
            fn parse(s: &str) -> $t { s.parse().unwrap() }
        }
	}
}
read_single_value!(i32);
read_single_value!(i64);
read_single_value!(f32);
read_single_value!(f64);
read_single_value!(usize);
read_single_value!(String);

macro_rules! read_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
read_tuple!(A, B);
read_tuple!(A, B, C);

// ===

fn main() {
    let s: String = read();
    let c = s.chars().collect::<Vec<char>>();
    let n = s.len();
    let mut i = 0;
    while i < n {
        print!("{}", c[i]);
        i += 2;
    }
    println!();
}


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

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

  for (int i = 0; i < 1009; i++) {
    int t1 = i * 0.08;
    int t2 = i * 0.1;
    if (t1 == A && t2 == B) {
      cout << i << endl;
      return 0;
    }
  }


  cout << "-1" << endl;
}


Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=998244353;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
int dx[8]={0,0,1,1,1,-1,-1,-1};
int dy[8]={1,-1,1,-1,0,1,-1,0};
int main(){
    int n;cin>>n;
    ll a[200010];
    vector<ll> v;
    ll mi=LINF;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        v.push_back(a[i]-i-1);
    }
    sort(all(v));
    ll ans=0;
    ll s=v[n/2];
    for(ll i=0;i<n;i++){
        ans+=abs(a[i]-(i+1+s));
    }
    cout<<ans<<endl;
}


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

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

using namespace std;

template <class T>
void printv(vector<T> v)
{
  cout << '[';
  for (auto vec: v)
  {
    cout << vec << ' ';
  }
  cout << ']' << endl;
}

int main()
{
  string a, b;
  cin >> a >> b;

  for (int i = 0; i < a.length(); i++)
  {
    if (i != b.length())
      cout << a[i] << b[i];
    else
      cout << a[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
mod = 10**9+7
N,X,Y,Z = map(int, input().split())
Num = 1<<(X+Y+Z-1)
ng = ((((1<<X)+1)<<Y)+1)<<(Z-1)

dp = [[0]*Num for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for k in range(Num):
        for j in range(1,11):
            a = (k<<j)|(1<<(j-1))
            if a&ng != ng:
                a &= Num-1
                dp[i+1][a] += dp[i][k]
                dp[i+1][a] %= mod

print((10**N%mod-sum(dp[N])%mod)%mod)

Measured memory_bytes: 62940
#include <iostream>
#include <cstdio>
using namespace std;
int s, a[5];
string t, b[9]={"+++", "++-", "+-+", "+--", "-++", "-+-", "--+", "---"};
int main() {
	int i, j;
	cin>>t;
	for(i=0; i<4; i++) a[i] = t[i] - '0';
	for(i=0; i<8; i++) {
		s = a[0];
		for(j=0; j<3; j++) {
			if(b[i][j]=='+') s += a[j+1];
			else s -= a[j+1];
		}
		if(s == 7) break;
	}
	printf("%d%c%d%c%d%c%d=7", a[0], b[i][0], a[1], b[i][1], a[2], b[i][2], a[3]);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main ()
{
int M,N,w,m;
int num[12]={};
long R;
w=0;m=0;
while(1)
{
w=0;m=0;
scanf("%ld",&R);
if(R==0)break;
for(int i=0;i<12;i++){
scanf("%d %d",&M,&N);
w=w+(M-N);
if(w>=R){num[m]=(i+1);m++;}
}
if(w>=R)printf("%d\n",num[0]);
else printf("NA\n");

}
return 0;
}

Measured memory_bytes: 1040
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner *bufio.Scanner

func nextInt() int {
	scanner.Scan()

	var i, _ = strconv.Atoi(scanner.Text())

	return i
}

func nextString() string {
	scanner.Scan()

	return scanner.Text()
}

func initScanner() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

// math functuon
func maxInt(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}
func minInt(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func main() {
	initScanner()

	var s = nextInt()
	var p = nextInt()
	var q = nextInt()

	var cost = math.MaxInt32

	cost = minInt(cost, s+p)
	cost = minInt(cost, q+p)
	cost = minInt(cost, s+q)

	fmt.Println(cost)
}


Measured memory_bytes: 640
#INF = 10**9 + 1
def merge(A, left, mid, right):
    global count
    L = [A[i] for i in range(left, mid)] + [10**9 + 1]
    R = [A[i] for i in range(mid, right)] + [10**9 + 1]
    i,j = 0,0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    
def mergeSort(A, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

count = 0
n = int(input())
S = list(map(int,input().split()))
mergeSort(S, 0, n)
print(*S)
print(count)


Measured memory_bytes: 63436
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    char S[600],T[10000],G[600];
    cin >> S >> G;
    strcat(T,G);
    strcat(T,G);
    rep(i,strlen(S)){
      int y=0;
      rep(j,strlen(S)){
        if(S[j]!=T[i+j]){
          y++;
          break;
        }
      }
      if(y==0){
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout <<  "No" <<endl;
}

Measured memory_bytes: 256
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
K = INT()

memo = []
for i in range(K):
    memo2 = []
    for j in range(K):
        memo2.append([-1] * K)
    memo.append(memo2)


def memorize(i, j, k, a):
    memo[i-1][j-1][k-1] = a

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            if memo[i-1][j-1][k-1] == -1:
                a = gcd(i, j, k)
                memorize(i,j,k, a)
                memorize(i,k,j, a)
                memorize(j,i,k, a)
                memorize(j,k,i, a)
                memorize(k,i,j, a)
                memorize(k,j,i, a)
                ans += a
            else:
                ans += memo[i-1][j-1][k-1]
print(ans)


Measured memory_bytes: 141908
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<char>s(3);
  for(int i=0;i<3;i++){
      cin>>s.at(i);
  }
  int c=0;
  for(int i=0;i<3;i++){
      if(s.at(i)=='1'){
          c++;
      }
  }
  cout<<c<<endl;
}

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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	int n = s.size();
	string t = "CODEFESTIVAL2016";

	int ans = 0;
	rep(i, n) if(s[i] != t[i]) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list> 
using namespace std;
static const int MAX = 100000;
static const int INFTY = (1 << 29);

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N, indeg[MAX];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	V[s] = true;
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		out.push_back(u);
		for(int i = 0; i < G[u].size(); i++) {
		    int v = G[u][i];
		    indeg[v]--;
            if(indeg[v] == 0 && !V[v]) {
            	V[v] = true;
            	q.push(v);
            }
		}
	}
}

void tsort() {
	for(int i = 0; i < N; i++) {
		indeg[i] = 0;
	}
	
	for(int u = 0; u < N; u++) {
		for(int i = 0; i < G[u].size(); i++) {
			int v =  G[u][i];
			indeg[v]++;
		}
	}
	
	for(int u = 0; u < N; u++) {
		if(indeg[u] == 0 && ! V[u]) bfs(u);
	}
	
	for(list<int>::iterator it = out.begin(); it != out.end(); it++) {
		cout << *it << endl;
	}
}

int main() {
	int s, t, M;
	
	cin >> N >> M;
	
	for(int i = 0; i < N; i++) V[i] = false;

    for(int i = 0; i < M; i++) {
    	cin >> s >> t;
    	G[s].push_back(t);
    }
    
    tsort();
    
    return 0;
} 

Measured memory_bytes: 6124
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<long long int> d(n);
		long long int a = 0;
		for (int i= 0; i < n; i++) {
			cin >> d[i];
			a += d[i];
		}
		int l = 1<<n;
		long long int MIN = a;
		for (int i = 0; i < l; i++) {
			long long int b = 0;
			for (int j = 0; j < n; j++) {
				if ((i & (1<<j)) != 0) {
					b += d[j];
				}
			}
			long long int c = abs(a-b);
			long long int dd = abs(c-b);
			MIN = min(MIN, dd);
		}
		cout << MIN << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string> 

using namespace std;

int main()
{
    string str;
    int cnt = 0;
    int max = 0;
    char ch;

     cin >> str;

     for(int i =0 ;i < (int)str.size(); ++i)
     {
        if(str[i] == 'A' ||
           str[i] == 'G' ||
           str[i] == 'C' ||
           str[i] == 'T')
           {
               cnt ++;
           }
           else
           {
               cnt = 0;
           }
           
        if(cnt > max)
        {
            max = cnt;
        }
     }
     cout << max << endl;

}

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

int main(){
  int N;

  int m;
  int n, n_up;
  string str;
  cin >> N;
  m = int(N / 1.08);
  n = int(m*1.08);
  n_up = int((m+1)*1.08);
  str = ":(";
  if(n!=N and N!=n_up){
    cout << str;
  }else if(m==N/1.08){
    cout << m;
  }else{
    cout << (m+1);
  }
  return 0;
}


Measured memory_bytes: 256
s = input()
lens = len(s)
t = input()
lent = len(t)
ans = 9999999
for j in range(lens-lent+1):
	tmp = 0
	for k in range(lent):
		if s[j+k] != t[k]:
			tmp += 1
	ans = min(tmp, ans)
print(ans)

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

using namespace std;

int main(){
    int n,m,x,y;
    string ans;
    int maxx=INT_MIN;
    int miny=INT_MAX;
    cin>>n>>m>>x>>y;
    vector<int>X(n);
    vector<int>Y(m);
  for(int i=0;i<n;i++){
    cin>>X[i];
    maxx=max(maxx,X[i]);
  }
  for(int i=0;i<m;i++){
    cin>>Y[i];
    miny=min(miny,Y[i]);
   // cout<<miny<<endl;
  }
  for(int z=x+1;z<=y;z++){
    //int z=x+i;
    //cout<<z<<endl;

    if(maxx<z&&miny>=z){
        ans="No War";
       // cout<<z<<endl;
        break;
    }
   else{
    ans="War";
    //cout<<z<<endl;
   }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
inputs = [int(i) for i in input().split()]

ans = 0
tmp = 0
for i in range(1, N):
    if inputs[i-1] <= inputs[i]:
        pass
    else:
        ans += (inputs[i-1] - tmp)
        tmp = inputs[i]

if inputs[-1] > tmp:
    ans += inputs[-1] - tmp

print(ans)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++) {
			if (i % 2 == 0) {
				for (int j = 0; j < W; j++) {
					if (j == W - 1) {
						if (j % 2 == 0) {
							cout << "#" << endl;
						}
						else {
							cout << "." << endl;
						}
						
					}
					else if(j % 2 == 0){
						cout << "#";
					}
					else {
						cout << ".";
					}
				}
			}
			else {
				for (int j = 0; j < W; j++) {
					if (j == W - 1) {
						if (j % 2 == 0) {
							cout << "." << endl;
						}
						else {
							cout << "#" << endl;
						}
						
					}
					else if(j % 2 == 0){
						cout << ".";
					}
					else {
						cout << "#";
					}
				}
			}
		}
		cout << "" << endl;
	}
}

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

vector<int> p;

void QS(int a,int b){
  if(b-a<=1){
    if(p.at(b)<p.at(a)){
      swap(p.at(b),p.at(a));
    }
    return;
  }
  int P=(p.at(a)+p.at(b))/2;
  int i=a,j=b;
  int X,Y;
  while(true){
    while(i<j){
      if(p.at(i)>P){
        break;
      }
      i++;
    }
    while(i<j){
      if(p.at(j)<=P){
        break;
      }
      j--;
    }
    if(i==j){
      X=j-1,Y=j;
    }
    else if(j-i==1){
      swap(p.at(i),p.at(j));
      X=i,Y=j;
    }
    else{
      swap(p.at(i),p.at(j));
      continue;
    }
    break;
  }
  if(X-a<=1){
    if(p.at(X)<p.at(a)){
      swap(p.at(X),p.at(a));
    }
  }
  else{
    QS(a,X);
  }
  if(b-Y<=1){
    if(p.at(b)<p.at(Y)){
      swap(p.at(b),p.at(Y));
    }
  }
  else{
    QS(Y,b);
  }
  return;
}

int main() {
  int N;
  cin>>N;
  p.resize(N);
  for (int i=0;i<N;i++){
    cin>>p.at(i);
  }
  QS(0,N-1);
  cout<<p.at(N/2)-p.at(N/2-1)<<endl;
}





Measured memory_bytes: 7396
#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 int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,x,d;
int m[52];
int par[52];

ll sz[52];
ll cost[52];

int rest[52];

ll dp[252521];

int main(){
  scanf("%d%d%d",&n,&x,&d);
  scanf("%d",m+0);par[0]=-1;
  FOR(i,1,n)scanf("%d%d",m+i,par+i),par[i]--;
  FORR(i,0,n){
    sz[i] += 1;
    cost[i] += m[i];
    if(i==0)break;
    sz[par[i]] += sz[i];
    cost[par[i]] += cost[i];
  }
  // naive
  int befx = x;
  int naiveans = 0;
  fill(rest,rest+n,d);
  rest[0] = 1<<30;
  while(x > 0){
    // best cost-performance
    int bestid = -1;
    REP(i,n)if(rest[i]>0 && x>=cost[i]){
      if(bestid==-1 || cost[i]*sz[bestid] < cost[bestid]*sz[i]){
        bestid = i;
      }
    }
    if(bestid==-1)break;
    ll num = x/cost[bestid];
    CHMIN(num,(ll)rest[bestid]);
    rest[bestid] -= num;
    x -= num*cost[bestid];
    naiveans += num*sz[bestid];
  }
  // dp part
  fill(rest,rest+n,d);
  rest[0] = 1<<30;
  ll ans = 0;
  x = befx;
  while(naiveans>=125252){
    int bestid = -1;
    REP(i,n)if(rest[i]>0){
      if(bestid==-1 || (x>=cost[i] && cost[i]*sz[bestid] < cost[bestid]*sz[i])){
        bestid = i;
      }
    }
    if(bestid==-1)break;
    ll num = x/cost[bestid];
    CHMIN(num,(ll)rest[bestid]);
    CHMIN(num,(naiveans-125252)/sz[bestid]+1);
    rest[bestid] -= num;
    x -= num*cost[bestid];
    ans += num*sz[bestid];
    naiveans -= num*sz[bestid];
  }
  fill(dp,dp+252521,1ll<<60);
  dp[0] = 0;
  REP(id,n){
    int v = rest[id];
    ll step = 1;
    while(step <= v){
      ll width = sz[id] * step;
      ll cval = cost[id] * step;
      FORR(i,0,252521){
        if(i+width>=252521)continue;
        CHMIN(dp[i+width], dp[i]+cval);
      }
      v -= step;
      step <<= 1;
    }
    if(v>0){
      ll step = v;
      ll width = sz[id] * step;
      ll cval = cost[id] * step;
      FORR(i,0,252521){
        if(i+width>=252521)continue;
        CHMIN(dp[i+width], dp[i]+cval);
      }
    }
  }
  // DEBUG(ans);
  // REP(i,n)DEBUG(rest[i]);
  // REP(i,n)DEBUG(cost[i]);
  // DEBUG(x);
  ll vans = ans;
  REP(i,252521)if(dp[i]<=x)vans = ans+i;
  printf("%lld\n",vans);
  return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
#include<numeric>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i <= (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	ll N, M;
	cin >> N >> M;

	vector<bool> isac(N+1);
	vector<ll> wacount(N+1);
	rep(i, M){
		ll p;
		string S;
		cin >> p >> S;

		if(S == "AC"){
			isac[p] = true;
		}
		else{
			if(!isac[p]){
				wacount[p]++;
			}
		}
	}

	ll accnt = 0;
	rep(i, N+1){
		if(isac[i]){
			accnt++;
		}
	}
	ll wacnt = 0;
	rep(i,N+1){
		if(isac[i]){
			wacnt += wacount[i];
		}
	}

	cout << accnt << " " << wacnt << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


typedef long long ll;


using namespace std;

int main()
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0) break;

		vector<int> order;
		map<int, ll> sale;
		while (n--)
		{
			int no, value, num;
			scanf("%d %d %d", &no, &value, &num);
			if (!sale[no])
				order.push_back(no);

			sale[no] += (ll)value * num;
		}
		bool any = false;
		for (int i = 0; i < order.size(); ++i)
		{
			if (sale[order[i]] >= 1000000)
			{
				printf("%d\n", order[i]);
				any = true;
			}
		}
		if (!any)
			printf("NA\n");
	}

	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 1e5+5;

int a[N], dp[N], n;

int solve (int i) {
	if (i > n) return inf;
	if (i == n) return 0;
	if (i == n-1) return abs (a[n] - a[n-1]);
	if (dp[i] >= 0) return dp[i];
	int ans = inf;
	for (auto j: {i+1, i+2}) {
		ans = min(ans, solve(j)+abs(a[j]-a[i]));
	}
	dp[i] = ans;
	return ans;
}

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    cin >> n;
   	memset(dp, -1, sizeof (dp));
    for (int i = 1; i <= n; i++)
    	cin >> a[i];
    cout << solve(1);
    return 0;
}

Measured memory_bytes: 4992
import sys
sys.setrecursionlimit(10 ** 9)

import numpy as np
from heapq import heappush, heappop

N, M, = map(int, input().split())
graph = [[] for _ in range(N+1)] # graph[0]は使わない

for _ in range(M):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))

def dijkstra(start, c):
    INF = float('inf')
    dist = [-INF] * (N+1) # dist[0]は使わない
    dist[start] = 0
    que = [(start, 0, c)]
    while que:
        place, score, count = heappop(que) # placeは現在地
        if score < dist[place] or count > 2000: # 前来た時より点数が悪いか、無限ループしている場合continue
            continue
        for next_node, weight in graph[place]:
            score2 = score + weight
            if next_node == N and count > 1000: # いくらでも大きくなる場合
                print('inf')
                exit()
            if dist[next_node] < score2: # 点数が良くなるなら、データを更新
                dist[next_node] = score2
                heappush(que, (next_node, score2, count+1))
    return dist

d1 = np.array(dijkstra(1, 0))
print(int(d1[N]))


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

int main() {
  vector<int> p;
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int b;
    cin >> b;
    p.push_back(b);
  }
  int max = 0;
  for (int i = 0; i < K; i++) max += p.at(i);

  int px = max;
  for (int i = K; i < N; i++) {
    px = px + p.at(i) - p.at(i - K);
    if (max < px) max = px;
  }
  cout << fixed << setprecision(8) << (double)(max + K) / 2 << "\n";
  return 0;
}

Measured memory_bytes: 1400
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

int main() {
	string s;
	cin >> s;
	if ((int)s.size() == 26) {
		string t = s;
		if (next_permutation(t.begin(), t.end())) {
			int i = 0;
			while (s[i] == t[i]) ++i;
			while ((int)t.size() > i + 1) t.pop_back();
			cout << t << endl;
		} else print(-1);
	} else {
		map<char, bool> v;
		for (char c : s) v[c] = 1;
		for (char i = 'a'; i <= 'z'; i++)
			if (!v[i]) {
				cout << s + i << endl;
				break;
			}
	}
	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
const int N = 2e5 + 20;
int a[N], taj[22][N] = {0};
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 22; j++) {
            taj[j][i] = taj[j][i - 1];
            if (a[i] & (1 << j))
                taj[j][i]++;
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int mn = n + 1;
        for (int j = 0; j < 22; j++) {
            int up = upper_bound(taj[j], taj[j] + n + 1, taj[j][i - 1] + 1) - taj[j] - i;
            mn = min(mn, up);
        }
        ans += mn;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 36352
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

// U, D, L, R
const vll dx = {0, 0, -1, 1};
const vll dy = {-1, 1, 0, 0};

const ll mod = 998244353;

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

    ll n;
    cin >> n;
    vll d(n);
    vvll x(n);
    REP(i, n) {
        cin >> d[i];
        x[d[i]].push_back(i);
    }

    if (d[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    if (x[0].size() != 1) {
        cout << 0 << endl;
        return 0;
    }
    ll res = 1;
    REP(i, n - 1) {
        ll tmp = x[i].size();
        for (auto p : x[i + 1]) {
            res *= tmp;
            res %= mod;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6528
package main

import (
	"fmt"
	"strings"
)

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

	l := strings.Split(s, "-")
	if len(l[0]) == a && len(l[1]) == b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    cin >> N;
    vector<string> W(N);
    rep(i,0,N) cin >> W[i];

    set<string> st;
    st.insert(W[0]);
    rep(i,1,N){
        if(W[i].front()!=W[i-1].back() or st.find(W[i])!=st.end()){
            cout << "No" << endl;
            return;
        }
        st.insert(W[i]);
    }

    cout << "Yes" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b; 
    r=a%b;
    f=1.00000*a/b;
    printf("%d %d %f\n",d,r,f);
    return 0;
}


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

// input
int N, M;

const ll MOD = 1e9 + 7;


void input() {
    cin >> N >> M;
}


ll perm(int x) {
    ll ret = 1;
    rep(i, x) ret = ret * (i + 1) % MOD;
    return ret;
}


int main() {
    input();
    if (abs(N - M) >= 2) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = perm(N) * perm(M) % MOD;
    if (N == M) ans = 2 * ans % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define MAXN	600005
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, k;
bool a[MAXN], x[MAXN], y[MAXN];
char s[MAXN];
void print(bool *a) {
	for (int i = 1; i <= n; i++)
		if (a[i]) printf("A");
		else printf("B");
	printf("\n");
}
int main() {
	read(n), read(k);
	scanf("%s", s + 1);
	for (int i = 1; i <= n; i++)
		a[i] = s[i] == 'A';
	bool tag = false;
	int start = 1;
	if (k <= 2 * n) {
		for (int i = 1; i <= k; i++) {
			if (tag ^ a[start]) {
				a[start] = !a[start];
				continue;
			}
			tag = !tag;
			a[start + n] = !tag;
			start++;
		}
		for (int i = start; i < start + n; i++)
			if (tag ^ a[i]) printf("A");
			else printf("B");
		printf("\n");
		return 0;
	}
	for (int i = 1; i <= 2 * n + 1; i++) {
		if (tag ^ a[start]) {
			a[start] = !a[start];
			continue;
		}
		tag = !tag;
		a[start + n] = !tag;
		start++;
	}
	for (int i = start; i < start + n; i++)
		x[i - start + 1] = tag ^ a[i];
	for (int i = 2 * n + 2; i <= 2 * n + 2; i++) {
		if (tag ^ a[start]) {
			a[start] = !a[start];
			continue;
		}
		tag = !tag;
		a[start + n] = !tag;
		start++;
	}
	for (int i = start; i < start + n; i++)
		y[i - start + 1] = tag ^ a[i];
	k -= 2 * n;
	if (k & 1) print(x);
	else print(y);	
	return 0;
}

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

int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int count=0;
  for(int i=0;i<A+1;i++){
    for(int j=0;j<B+1;j++){
      for(int k=0;k<C+1;k++){
        if(500*i+100*j+50*k==X) count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
/** MIT License Copyright (c) 2018-2019 Vasilev Daniil **/
#include <bits/stdc++.h>
using namespace std;
template<typename T> using v = vector<T>;
#define int long long
typedef double ld;
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
const long double EPS = 1e-11;
#if 0  //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt"  : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin >>
#define put fout <<
#else
#define get cin >>
#define put cout <<
#endif
#define eol put endl
void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg)     ;read(args...) ;}
void print(){} template<typename Arg,typename... Args> void print(Arg  arg,Args...  args){put (arg)<<" ";print(args...);}
int getInt(){int a; get a; return a;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//code starts here

void run() {
	int n, d;
	read(n, d);
	int x[n][d];
	rep(i, 0, n)
		rep(j, 0, d)
			get x[i][j];
			
	int ans = 0;
	rep(i, 0, n)
		rep(j, i + 1, n) {
			int sum = 0;
			rep(k, 0, d)
				sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			int z = sqrt(sum);
			if (z * z == sum)
				ans++;
		}
	put ans;
}
signed main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); put fixed << setprecision(12); run();}


Measured memory_bytes: 256
#include<cstdio> 
int F[50]={1,1};

int fib(int i){
	if(F[i]) return F[i];
	return F[i] = fib(i-1) + fib(i-2);
}
int main(){
	int n;
	scanf("%d",&n);
	printf("%d\n",fib(n));
}


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

#define MAX 200000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];

ll merge(int A[], int n, int left, int mid, int right) {
  int i, j, k;
  ll cnt = 0;
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  i = 0;
  j = 0;
  for (k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
      cnt += n1 - i;
    }
  }
  return cnt;
}

ll mergeSort(int A[], int n, int left, int right) {
  int mid;
  ll v1, v2, v3;
  if (left + 1 < right) {
    mid = (left + right) / 2;
    v1 = mergeSort(A, n, left, mid);
    v2 = mergeSort(A, n, mid, right);
    v3 = merge(A, n, left, mid, right);
    return v1 + v2 + v3;
  } else {
    return 0;
  }
} 

int main() {
  // int N;
  // cin >> N;
  // ll K;
  // cin >> K;
  // int A[N];
  // for (int i = 0; i < N; i++) {
  //   cin >> A[i];
  // }
  int A[MAX], n, i;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  ll ans = mergeSort(A, n, 0, n);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4636