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

int main(void) {

	int p, g, w, y, n;

	std::cin >> n;

	p = g = w = y = 0;

	for (size_t i = 0; i < n; i++) {
		char c;

		std::cin >> c;
		if (c == 'P') {
			p++;
		}
		else if (c == 'G') {
			g++;
		}
		else if (c == 'W') {
			w++;
		}
		else {
			y++;
		}
	}

	if (p > 0 && w > 0 && g > 0 && y > 0) {
		std::cout << "Four" << std::endl;
	}
	else {
		std::cout << "Three" << std::endl;
	}

	return 0;
}

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

int main()
{

    int x,y,a,b,c; cin>>x>>y>>a>>b>>c;
    ll r[a],g[b],n[c];
    for(int i=0;i<a;i++)cin>>r[i];
    for(int i=0;i<b;i++)cin>>g[i];
    for(int i=0;i<c;i++)cin>>n[i];
    sort(r,r+a,[](int l,int m){return l>m;});
    sort(g,g+b,[](int l,int m){return l>m;});
    sort(n,n+c,[](int l,int m){return l>m;});
    ll ans=0,k=0;
   vector<ll>v;
   for(int i=0;i<x;i++){v.push_back(r[i]);}
   cout<<endl;
   for(int j=0;j<y;j++)v.push_back(g[j]);
   sort(v.begin(),v.end(),[](int l,int m){return l>m;});
   for(int i=x+y-1;i>=0;i--){
        if(k<c && v[i]<n[k])ans+=n[k++];
        else ans+=v[i];
   }
   cout<<ans;



}


Measured memory_bytes: 4724
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long N, std::vector<long long> L){
    ll cnt = 0;
    REP(i, N){
        for(ll j = i+1; j < N; j++){
            if(L[i] == L[j]) continue;
            for(ll k = j+1; k < N; k++){
                if(L[k]==L[i] || L[k] == L[j]) continue;
                if(L[i] + L[j] > L[k] && (L[i] + L[k] > L[j]) && (L[k] + L[j] > L[i]))
                    cnt++;
            }
        }
    }
    cout<<cnt<<endl;
}
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,s=0,p=0;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
  {
    a[i]=k+i;
    if(a[i]==0)
      s++;
    else if(a[i]<0)
      p++;
  }
  sort(a,a+n);
  long int b=0;
  for(int i=0;i<n;i++)
  {
    b+=a[i];
  }
  if(s>0)
    cout<<b;
   if(p>0&&s==0)
    cout<<b-a[p-1];
  if(p==0&&s==0)
    cout<<b-a[0];
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a[1000000];
	int n,k;
	int count = 1;
	scanf("%d %d",&n,&k);
	for(int i = 0; i < n ; i++) {
		scanf("%d",&a[i]);
	}
int s=k;
int i=1;
while (n>0){
    if (s>=n){
        printf("%d",i);
        break;
    }
    i=i+1;
    s=s+k-1;
}
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);cerr<<fixed<<setprecision(5);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
/* VARIABLE DECLARATION START */
int globe[int(1e6)];
/*  FUCNTION TEMPLATE STARTS  HERE */
double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
inline int maxm(const int &a,const int &b)
{
  if(a>b)return a;
  else return b;
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
/*  FUCNTION TEMPLATE ENDS HERE */

int main()
{
   VALHALLA
   int h,w;cin>>h>>w;
   char arr[h+1][w+1];
   for(int i=1;i<=h;++i)
   {
    for(int j=1;j<=w;++j)
    {
      cin>>arr[i][j];
    }
   }
   for(int i=1;i<=2*h;++i,cout<<endl)
   {
    for(int j=1;j<=w;++j)
    {
      int h1=(i+1)/2;
      cout<<arr[h1][j];
    }
   }

}



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

int main() {

    string s;
    cin >> s;

    int slen = s.size();

    int firstE = (slen - 1) / 2;
    int secondF = (slen + 3) / 2;

    string firstS;
    string secondS;

    for(int i = 0; i < firstE ; i++){
        firstS += s.at(i);
    }

    for(int i = secondF-1; i < slen ; i++){
        secondS += s.at(i);
    }

    if(firstS == secondS) cout << "Yes" << endl;
    else                  cout << "No"  << endl;

    //cout << firstS << endl;
    //cout << secondS << endl;

}

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

using namespace std;
typedef long long ll;

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

  vector<int> D(n);
  map<int, int> mpd;
  for (int i = 0; i < n; i++) {
    cin >> D[i];
    mpd[D[i]]++;
  }

  int m;
  cin >> m;

  vector<int> T(m);
  map<int, int> mpt;
  for (int i = 0; i < m; i++) {
    cin >> T[i];
    mpt[T[i]]++;
  }

  bool yes = true;
  for (auto i : mpt) {
    if (mpd[i.first] < i.second) yes = false;
  }

  cout << (yes ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 20608
#include<stdio.h>
int main()
{
    int a,b,c,max,hi;
    // 整数の入力
    scanf("%d %d %d", &a,&b,&c);
  
	if(a>=b && a>=c){
      max=10*a+b+c;
    }else if(b>=a && b>=c){
      max=a+10*b+c;
    }else{
      max=a+b+10*c;
    }
    // 出力
    printf("%d \n",max);
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		Scanner sc=new Scanner(System.in);
		//白色区域的横坐标与纵坐标和黑点的个数
		int W=sc.nextInt();
		int H=sc.nextInt();
		int N=sc.nextInt();
		int S=H,Y=W,X=0,Z=0,mianji;//分别为白色区域的上下左右
		int x,y,T;//点的横坐标和纵坐标
		//输入点的横坐标和纵坐标和操作指令
		for(int i=0;i<N;i++) {
			x=sc.nextInt();
			y=sc.nextInt();
			T=sc.nextInt();
			if(T==1&&x>Z) {//1位取白色区域左边，如果x比Z大，Z赋值x
				Z=x;
			}
			if(T==2&&x<Y) {
				Y=x;
			}
			if(T==3&&y>X) {
				X=y;
			}
			if(T==4&&y<S) {
				S=y;
			}
		}
		if((Y-Z)>0&&(S-X)>0){
			mianji=(Y-Z)*(S-X);
			System.out.println(mianji);
		}else {
			System.out.println("0");
		}
        }
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;

int main(){
  int n; cin>>n;
  vector<int> h(n);
  rep(i,n) cin>>h[i];

  int ans=0;
  while(1){
    int y=0;
    bool c=0;
    int yy=0;
    rep(i,n){
      if(!(c)&&h[i]>0){
        y++;
        c=1;
      }
      if(c&&h[i]<=0){
        c=0;
      }
      if(h[i]<=0)
      yy++;
      h[i]--;
    }
    // cout<<y<<endl;
    ans+=y;
    if(yy==n)
    break;
  }
  cout<<ans<<endl;

  return 0;
}


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

int main(){
    int x,a,b;

    cin >> x;
    cin >> a;
    cin >> b;

    int I,J;
    
    I = abs(x-a);

    J = abs(x-b);

    

    if(I<J){
        cout << "A"<<endl;
    }else{
        cout <<"B"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
vector<long> divisor;
vector<long> counter;

void sosu(long long x){
    long long xq = round(sqrtl(x))+1;
    long count = 0;
    long long xx = x;
    bool flag = false; 
    for(auto i=2;i<=xq;i++){
        count = 0;
        //cout << i << ": ";
        while (xx%i==0){
            xx = xx/i;
            count ++;
            if(xx==1){
                flag = true;
                break;
            }
        }
        if(count != 0){
            divisor.push_back(i);
            counter.push_back(count);
            xq = round(sqrt(xx));
        }
    }
    if((!flag)&&(xx>1)){
        divisor.push_back(xx);
        counter.push_back(1);
    }
}
int cc(long x){
    int count =0;
    for(auto i=1;i<=x;i++){
        if(i<=x){
            count++;
            x -= i;
        } 
    }
    return count;
}

int main(){
    long long n,z;
    cin >> n;
    long count = 0, sum =0;
    sosu(n);
    /*
    cout << "(divisor, counter)";
    for(auto i=0;i<divisor.size();i++){
        cout << "(" << divisor.at(i) << "," << counter.at(i) << "), "; 
    }
    */
    if(divisor.size()==0){
        cout << ((n==1) ? 0 : 1) << endl;
        return 0;
    }else{
        for(auto i=0;i<divisor.size();i++){
            sum += cc(counter.at(i)); 
        }
    }
    cout << sum << endl;
    //*/
}    

Measured memory_bytes: 3692
N = int(input())
h_list = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    h_i = h_list[i]
    for j in range(i+1):
        h_j = h_list[j]
        if h_j > h_i:
            break
    else:        
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = 1000000000;
const int MAX = 300000;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    int N;
    cin >> N;
    int dp[100010];
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    dp[1] = 0;
    dp[2] = abs(h[1] - h[0]);
    for (int i = 2; i < N; i++) {
        dp[i + 1] =
            min(dp[i] + abs(h[i] - h[i - 1]), dp[i - 1] + abs(h[i] - h[i - 2]));
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

// 300 * 2
#define BUF_SIZE 1000

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define NUM_MAX 300
#define max(a,b) ((a) > (b) ? (a) : (b))
#define max3(a,b,c) max(max(a,b),c)
#define min(a,b) ((a) > (b) ? (b) : (a))
#define min3(a,b,c) min(min(a,b),c)

int asc(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

struct tuple {
    int t1, t2, t3;
};

int dist[3][3] = {
    {-1, 0, 0},
    {1, -1, 0},
    {0, 1, -1},
};

int is_valid(int *np) {
    return np[0]>=0 && np[1]>=0 && np[2]>=0;
}

int is_equal(int *p1, int *p2) {
    int flag = 1;
    int i;
    for(i = 0; i < 3; i++) {
        if(p1[i] != p2[i]) flag = 0;
    }
    return flag;
}

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX];
    static int cnt_map[3];
    int i, j;
    fget_array(arr, num);
    for(i = 0; i < num; i++) cnt_map[arr[i]-1]++;
    int ans[3] = {cnt_map[0], cnt_map[1], cnt_map[2]};

    static double dp[NUM_MAX+1][NUM_MAX+1][NUM_MAX+1];
    dp[0][0][0] = 0;

    int size, d;
    for(size = 1; size <= num; size++) {
        for(i = size; i >= 0; i--) {
            for(j = size-i; j >= 0; j--) {
                int k = size-i-j;
                int p[3] = {i, j, k};
                //if(is_equal(p, ans)) goto finish;
                double res = 0;
                double sum = 0;
                for(d = 0; d < 3; d++) {
                    int np[3] = {
                        i+dist[d][0],
                        j+dist[d][1],
                        k+dist[d][2]
                    };
                    if(!is_valid(np)) continue;
                    res += p[d];
                    sum += dp[np[0]][np[1]][np[2]]*p[d];
                }
                dp[i][j][k] = (num*1.0/res) + sum/res;
#ifdef DEBUG
                printf("%d %d %d -> %lf\n", i, j, k, dp[i][j][k]);
#endif
            }
        }
    }
    printf("%.10lf\n", dp[ans[0]][ans[1]][ans[2]]);

    return 0;
}

Measured memory_bytes: 213120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

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

const int mod = 1000000007;

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

  int n;
  cin >> n;

  if (n%2) {
    int res = (n-1)*((n-3)/2+1);
    cout << res << endl;
    rep(i, n-1) {
      for(int j = i+1; j < n; j++) {
        if(i+j != n-2) {
          cout << (i+1) << " " << (j+1) << endl;
        }
      }
    }
  } else {
    int res = n*(n-2)/2;
    cout << res << endl;
    rep(i, n) {
      for(int j = i+1; j < n; j++) {
        if(i+j != n-1) {
          cout << (i+1) << " " << (j+1) << endl;
        }
      }
    }
  }
}


Measured memory_bytes: 512
#include <iostream>
#include <cctype>
#include <stdio.h>

using namespace std;

int main() {
	char ch;
	int num, i;
	int counter[26] = {};

	while (cin >> ch) {
		if (isupper(ch)) {
			num = ch - 'A';
			counter[num]++;
		}
		else if (islower(ch)) {
			num = ch - 'a';
			counter[num]++;
		}
	}

	for (i = 0; i < 26; i++) {
		printf("%c : %d\n", 'a' + i, counter[i]);
	}

	return 0;
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <math.h>
using namespace std;



int main(){
  int N;

  cin >> N;

  vector<int64_t> A(N);
  vector<int64_t> R(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }

  int64_t sum=0;

  for(int i=0;i<N;i++){
    sum+=A.at(i);
  }
  //cout << sum <<endl;

  for(int i=0;i<=N-3;i=i+2){
    sum-=2*A.at(i);
  }

  R.at(N-1)=sum;
  //cout << R.at(N-1) <<endl;

  for(int i=N-2;i>=0;i--){
    R.at(i)=2*A.at(i)-R.at(i+1);
  }

  for (int i = 0; i < N; i++){
        cout << R.at(i) << " ";
    }
    cout << "" << endl;



  

}

Measured memory_bytes: 2944
#include <stdio.h>

int main(){

  int n,i,j,count=0,tmp;
  int A[100];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n;i++){
    for(j=n-1;j>0;j--){
      if(A[j]<A[j-1]){
	tmp = A[j-1];
	A[j-1] = A[j];
	A[j] = tmp;
	count++;
      }
    }
  }
    for(i=0;i<n;i++){
      printf("%d",A[i]);
      if(i == n-1){
	printf("\n");
	break;
      }
      else printf(" ");
    }
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2140
// you can use includes, for example:
#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <unordered_map>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <sstream>
#include <set>
#include <cassert>
#include <map>

using namespace std;

constexpr int64_t kMod = 1e9 + 7;

int main(void) {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;

  auto calc = [](int n) {
    int64_t cur_x = 0;
    int64_t cur_sum_x = 0;
    for (int i = 0; i < n; i++) {
      int64_t x;
      cin >> x;
      if (i) {
        cur_sum_x += x * (i) - cur_x;
      }
      cur_x += x;
      cur_x %= kMod;
      cur_sum_x %= kMod;
    }
    return (cur_sum_x + kMod) % kMod;
  };

  auto x_sum = calc(n);
  auto y_sum = calc(m);
  cout << x_sum * y_sum % kMod << endl;
}


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

int main() {
    string S;
    cin >> S;
    deque<int> dq;
    for(int i=0;i<S.size();i++){
        if(S[i] =='B'){
            if(dq.empty()){
                continue;
            }
            dq.pop_back();
        }else{
            dq.push_back(S[i]-'0');
        }
    }
    while(!dq.empty()){
        cout <<dq.front();
        dq.pop_front();
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 3636
program main;
var
    thp, tatk, ahp, aatk : integer;
begin
    readln(thp, tatk, ahp, aatk);

    if ((((ahp - 1) div tatk) - 0.5) < ((thp - 1) div aatk)) then
        writeln('Yes')
    else 
        writeln('No');
end.

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

using namespace std;

using ll = long long;
using ld = long double;

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

#define MX 200007
int n;
int A[MX];
int cl[MX][22];
int J[MX];

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n;
    F(n) cin >> A[i];
    FF(20)cl[n-1][j]=n;
    J[n-1]=n;
    for(ll i=n-2; i>=0; i--) {
        FF(20) {
            if(A[i+1] & (1<<j)) cl[i][j]=i+1;
            else cl[i][j] = cl[i+1][j];
        }
        int jmp=n;
        FF(20) if(A[i]&(1ll<<j)) jmp=min(jmp, cl[i][j]);
        J[i] = min(jmp, J[i+1]);
    }
    ll ret = 0;
    F(n) ret += J[i]-i;
    cout << ret << endl;
    return 0;
}


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

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair



int main() {
	
	ll n,m;
	cin >> n >> m;
	ll a[m],sum=0;
	for(int i=0;i<m;i++) {
		cin >> a[i];
		sum+=a[i];
	}
	ll ans = n-sum;
	if(ans>=0) {
		cout << ans;
	} else {
		cout << -1;
	}

	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


LL dp[52][52][52 * 52];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N, A; cin >> N >> A;
	// i枚選択して合計A*iになっていれば平均はA
	dp[0][0][0] = 1;
	FOR(i, 0, N) {
		LL a; cin >> a;
		FOR(k, 0, N) {
			FOR(pa, 0, 2500 - a + 1) {
				dp[i + 1][k][pa] += dp[i][k][pa];
				dp[i + 1][k + 1][pa + a] += dp[i][k][pa];
			}
		}
	}
	LL ans = 0;
	FOR(i, 1, N + 1) {
		ans += dp[N][i][i*A];
	}
	cout << ans << endl;


	return 0;
}


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

#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];

//最大積載量Pのトラックk台で何個(i)の荷物を詰めるかを出力
int check (llong P) {
        int i =0;
        for ( int j = 0; j < k; j++ ) {
                llong s = 0; //i番目のトラックに現在積んでいる荷物の総量ｓ
                while ( s + T[i] <= P ) {
                        s += T[i];
                        i++;
                        if ( i == n) return n;
                }
        }
        return i;
}

int solve(){
        llong left = 0;
        llong right = 100000 * 10000;
        llong mid;
        while ( right - left > 1) {
                mid = ( right + left ) / 2;
                int v = check(mid);
                if ( v >= n ) right = mid;
                else left = mid;
        }
        return right;
}

int main(){
        cin >> n >> k;
        for ( int i = 0; i < n; i++ ) cin >> T[i];
        llong ans = solve();
        cout << ans << endl;
}



Measured memory_bytes: 3860
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    ll n, x; cin >> n >> x;

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

    ll cnt = 0;
    for(int i=0; i<n; i++){
        if( a[i] > x ){
            cnt += a[i] - x;
            a[i] = x;
        }
    }

    for(int i=0; i<n-1; i++){
        if(a[i] + a[i+1] > x){
            cnt += a[i] + a[i+1] - x;
            a[i+1] = x - a[i];
        }
    }

    cout << cnt;


    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  st a,b,c;
  	ci(a>>b>>c);
  ll A=a.sz;
  ll B=b.sz;
  ll C=c.sz;
  ch now=a[0];
  	A--;
  	a.erase(a.bgn);
  FOR(i,0,300){ 
    
    if(now=='a'){
      if(A==0){
        co('A')
          break;
      }
      else{
      now=a[0];
      a.erase(a.bgn);
      A--;
      }
    }
    
    else if(now=='b'){
      if(B==0){
        co('B')
          break;
      }
      else{
      now=b[0];
      b.erase(b.bgn);
      B--;
      }
    }
    
    else{
      if(C==0){
        co('C')
          break;
      }
      else{
      now=c[0];
      c.erase(c.bgn);
      C--;
    }
    }
    
    
  }
}

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

#define ll long long
#define ld long double
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);


// ABC 166 A
// https://atcoder.jp/contests/abc165/tasks/abc165_a
int main()
{
	uint32_t k, a, b;
	cin >> k >> a >> b;

	for (uint32_t i = a; i <= b; i++) {
		if (i % k) { continue; }
		printf("OK\n");
		return 0;
	}

	printf("NG\n");
	return 0;
}


Measured memory_bytes: 3632
n = int(input())
par_kid = {}
not0 = []
for i in range(n):
    a = list(map(int, input().split()))
    if (a[1] != -1 or a[2] != -1):
        par_kid[a[0]] = a[1:]
        not0 += a[1:]
for i in range(n):
    if (i not in not0):
        first_node = i
        break
par_dep = {first_node:(-1,0)}
def pd(f):
    if (len(par_kid) == 0):
        return 0
    A = par_kid[f]
    c = 0
    for a in A:
        if (a == -1):
            c += 1
            continue
        par_dep[a] = (f, par_dep[f][1]+1)
        if (a not in par_kid.keys()):
            c += 1
            continue
        pd(a)
    if (c == len(A)):
        return 0
s = pd(first_node)
height = {}
for i in range(n):
    if (i not in par_kid.keys()):
        k = i
        height[k] = 0
        while True:
            par = par_dep[k][0]
            if (par in height.keys()):
                height[par] = max(height[par], height[k] + 1)
            else:
                height[par] = height[k] + 1
            if (par == -1):
                break
            k = par
for i in range(n):
    if (n == 1):
        print('node 0: parent = -1, sibling = -1, degree = 0, depth = 0, height = 0, root')
    elif (i == first_node):
        if (-1 in par_kid[i]):
            print('node {}: parent = -1, sibling = -1, degree = 1, depth = 0, height = {}, root'.format(i,height[i]))
        else:
            print('node {}: parent = -1, sibling = -1, degree = 2, depth = 0, height = {}, root'.format(i,height[i]))
    elif(i in par_kid.keys()):
        par = par_dep[i][0]
        dep = par_dep[i][1]
        h = height[i]
        A = par_kid[par]
        for a in A:
            if (a != i):
                sib = a
        if (-1 in par_kid[i]):
            print('node {}: parent = {}, sibling = {}, degree = 1, depth = {}, height = {}, internal node'.format(i,par,sib,dep,h))
        else:    
            print('node {}: parent = {}, sibling = {}, degree = 2, depth = {}, height = {}, internal node'.format(i,par,sib,dep,h))
    else:
        par = par_dep[i][0]
        dep = par_dep[i][1]
        h = height[i]
        A = par_kid[par]
        for a in A:
            if (a != i):
                sib = a
        print('node {}: parent = {}, sibling = {}, degree = 0, depth = {}, height = {}, leaf'.format(i,par,sib,dep,h))
        


Measured memory_bytes: 5624
import sys
sys.setrecursionlimit(10**7)
n,m = map(int,input().split())
graph = [[]for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
pre = [0]+[-1]*(n-1)
low = [10**9]*n
def dfs(now,last,pre,low,cnt,bri):
    cnt+=1
    pre[now] = cnt
    low[now] = pre[now]
    for next in graph[now]:
        
        
    
        if pre[next] == -1:
            low[now] = min(low[now],dfs(next,now,pre,low,cnt,bri))
            if low[next] == pre[next]:
                bri.append((now,next))
        else:
            if next == last:continue
            low[now] = min(low[now],low[next])
    return low[now]        
          
      
bri = []
cnt = 0
dfs(0,-1,pre,low,cnt,bri)
print(len(bri))

Measured memory_bytes: 3064
N, A = map(int, input().split())
X = [int(x) for x in input().split()]

m = {}
def f(rv, k, rest):
    if k == 0:
        if rv == 0:
            return 1
        else:
            return 0
    if rv < 0 or len(rest) < k:
        return 0
    
    def r(rv, k, rest):
        fp = (rv, k, len(rest))
        if fp in m: return m[fp]
        ret = f(rv, k, rest)
        m[fp] = ret
        return ret
    ans  = r(rv          , k    , rest[1:])
    ans += r(rv - rest[0], k - 1, rest[1:])
    return ans

print(sum([f(k * A, k, sorted(X)) for k in range(1, N + 1)]))

Measured memory_bytes: 66416
#include<bits/stdc++.h>
#define N 205
using namespace std;
typedef pair<int,int> P;
vector<int> memo[N][N];
int p,d[N],dlen;
string s;
 
int getNum(){
  int res=0;
  while('0'<=s[p]&&s[p]<='9')
    res=res*10+s[p++]-'0';
  return res;
}
 
void comp(){
  int slen=s.size(),idx=0;
  while(s[p]!='x'){
    if('0'<=s[p]&&s[p]<='9')
      d[idx++]=getNum(),p--;
    if(s[p]=='(')d[idx++]=-1;
    if(s[p]==')')d[idx++]=-2;
    if(s[p]=='+')d[idx++]=-3;
    if(s[p]=='-')d[idx++]=-4;
    if(s[p]=='*')d[idx++]=-5;
    if(s[p]=='/')d[idx++]=-6;
    p++;
  }
  d[idx++]=-7;
  dlen=idx;
}
 
void dfs(){
  vector<int> v2;
  vector<P> v;
  int S=max(0,p-1);
  while(d[p]!=-2&&d[p]!=-7){
    if(d[p]>=0)v.push_back(P(p,p)),p++;
    else if(d[p]==-1){
      int b=p++;
      dfs();
      v.push_back(P(b,p));
      p++;
    }
    else if(d[p]==-3)p++,v2.push_back(-3);
    else if(d[p]==-4)p++,v2.push_back(-4);
    else if(d[p]==-5)p++,v2.push_back(-5);
    else if(d[p]==-6)p++,v2.push_back(-6);
  }
  int E=p;
  if(d[S+1]==-1&&d[E-1]==-2)
    for(int i=0;i<memo[S+1][E-1].size();i++)
      memo[S][E].push_back(memo[S+1][E-1][i]);
  if(S+1==E-1)memo[S][E].push_back(memo[S+1][E-1][0]);
  for(int l=2;l<=v.size();l++){
    for(int i=0;i<=v.size()-l;i++){
      int j=i+l-1;
      for(int k=i;k<j;k++){
	int A=v[i].first,B=v[k].second;
	int C=v[k+1].first,D=v[j].second;
	for(int n=0;n<memo[A][B].size();n++){
	  int num1=memo[A][B][n];
	  for(int m=0;m<memo[C][D].size();m++){
	    int num2=memo[C][D][m];
	    if(v2[k]==-6&&!num2)continue;
	    if(l!=v.size()){
	      if(v2[k]==-3)memo[A][D].push_back(num1+num2);
	      if(v2[k]==-4)memo[A][D].push_back(num1-num2);
	      if(v2[k]==-5)memo[A][D].push_back(num1*num2);
	      if(v2[k]==-6)memo[A][D].push_back(num1/num2);
	    }else{
	      if(v2[k]==-3)memo[S][E].push_back(num1+num2);
	      if(v2[k]==-4)memo[S][E].push_back(num1-num2);
	      if(v2[k]==-5)memo[S][E].push_back(num1*num2);
	      if(v2[k]==-6)memo[S][E].push_back(num1/num2);
	    }
	  }
	}
      }
    }
  }
}
 
int main(){
  while(true){
    cin>>s;
    if(s=="#")break;
    s='('+s+')'+'x';
    p=0; comp();
    for(int i=0;i<dlen;i++)
      if(d[i]>=0)
	memo[i][i].push_back(d[i]);
    p=0; dfs();
    set<int> ans;
    for(int i=0;i<memo[0][dlen-2].size();i++)
      ans.insert(memo[0][dlen-2][i]);
    cout<<ans.size()<<endl;
    ans.clear();
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	memo[i][j].clear();
  }
  return 0;
}

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

int main() {
	int x, y;
	int gx = 2, gy = 2;
	cin >> x >> y;
	int a0[7] = {1, 3, 5, 7, 8, 10, 12};
	int a1[4] = {4, 6, 9, 11};
	for (int i = 0; i < 7; i++) {
		if (a0[i] == x) gx = 0;
		if (a0[i] == y) gy = 0;
	}
	for (int i = 0; i < 4; i++) {
		if (a1[i] == x) gx = 1;
		if (a1[i] == y) gy = 1;
	}
	if (gx == gy) 
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, = map(int, input().split())
L = [int(v) for v in input().split()]

ans = 10 ** 18
a = sum(L)
b = 0

for i in range(N):
    index = (i + 1) * -1
    a -= L[index]
    b += L[index]

    if a == b:
        print(0)
        exit()

    ans = min(ans, abs(a - b))

print(ans)

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int a,b;
  cin>>a>>b;
  int m;
  if(a<b){
    m=b-a;
    if(m%2==0){
      cout<<a+m/2<<endl;
    }else{
      cout<<"IMPOSSIBLE"<<endl;
    }
  }else{
    m=a-b;
    if(m%2==0){
      cout<<b+m/2<<endl;
    }else{
      cout<<"IMPOSSIBLE"<<endl;
    }
  }
}

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

using namespace std;

int main() {

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

	char mins='z', maxt='a';

	sort(s.begin(), s.end());
	sort(t.begin(), t.end(),greater<int>());

	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
import decimal
from decimal import Decimal
decimal.getcontext().prec = 10

from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque 

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# ---------------------------------------

n = inp()
cnt = 0
mx = 0
for i in range(n):
    d1, d2 = inpl()
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    mx = max(mx, cnt)

if mx >= 3:
    print("Yes")
else:
    print("No")



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

int main() {
	int n;
	cin >> n;
	vector<int> a(n, 0);
	vector<int> b(n, 0);
	int fst = 0;
	fst = n - 1;
	for (int i = 0; i < n; ++i) {
		int ai;
		cin >> ai;
		a[i] = ai;
	}
	int cur = fst;
	int cnt = 0;
	while (cur >= 0) {
		if (cur != fst)cout << " ";
		cout << a[cur];
		cnt++;
		cur -= 2;
	}
	cur++;
	while (cur < 0)cur += 2;
	while (cur < n) {
		cout << " " << a[cur];
		cnt++;
		cur += 2;
	}
	cout << endl;
	return 0;
}


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

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

  vector<int> f(q,-1);
  vector<char> c(q);

  for (int i = 0; i < q; i++)
  {
    int t;
    cin >> t;
    if(t==1) continue;
    int fi;
    cin >> fi >> c[i];
    f[i] = fi-1;
  }

  int flg = 0;
  string head="",tail="";
  for (int i = q-1; i >= 0; i--)
  {
    if(f[i]==-1) flg = 1-flg;
    else{
      if((flg+f[i])%2){
        tail = c[i] + tail;
      }
      else{
        head = head + c[i];
      }
    }
  }
  if(flg) reverse(s.begin(),s.end());
  string ans = head + s + tail;
  cout << ans << endl;
}

Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int n;
  string s;
  string sub="ABC";
  cin >> n >> s;
  int res=0;
  int pos = s.find(sub);
  if(pos!=string::npos) res++;

  while(pos != string::npos){
    pos=s.find(sub, pos+sub.length());
    if(pos!=string::npos) res++;
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) begin(x), end(x)
#define VI vector<int>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int mod = 1e9+7;
int n;
char cand[4] = {'A', 'T', 'G', 'C'};
map<pair<int, string>, LL> M;
// ng: *AGC, *ACG, *GAC, A*GC, AG*C
bool ok(string last4) {
    if(last4[1]=='A' && last4[2]=='G' && last4[3]=='C') return false;
    if(last4[1]=='A' && last4[2]=='C' && last4[3]=='G') return false;
    if(last4[1]=='G' && last4[2]=='A' && last4[3]=='C') return false;
    if(last4[0]=='A' && last4[2]=='G' && last4[3]=='C') return false;
    if(last4[0]=='A' && last4[1]=='G' && last4[3]=='C') return false;
    return true;
}

LL dfs(int m, string last3) {
    if(m == n) return 1LL;
    if(M.count({m, last3})) return M[{m, last3}];

    LL res = 0;
    for(int i = 0; i < 4; i++) {
        string t = last3 + cand[i];
        if(!ok(t)) continue;
        (res += dfs(m+1, t.substr(1))) %= mod;
    }
    return M[{m, last3}] = res;
}

int main() {
    scanf("%d", &n);
    LL ans = dfs(0, "TTT");
    printf("%lld\n", ans % mod);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

const Int MOD = 998244353;
const Int MAX = 200010;

Int fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i=2; i<MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

Int COM(Int n, Int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

Int modpow(Int a, Int n) {
    Int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main(){ 

    COMinit();

    Int N, M, K;
    cin >> N >> M >> K;

    vector<Int> a(K+1);

    a[0] = modpow(M-1, N-K-1) * M % MOD;
    rep1(i,K) {
        a[i] = (a[i-1] * (M-1)) % MOD;
    }

    Int ans = 0;

    rep(i,K+1) {
        Int temp;
        temp = COM(N-1,K-i) * a[i] % MOD;
        ans = (ans + temp) % MOD;
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 9532
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t a,b,c,k,ans=0;
  cin>>a>>b>>c>>k;
  if(a<=k){
    ans+=a;
    k-=a;
    if(b<=k){
      k-=b;
      ans-=k;
    }
  }
  else ans+=k;
  cout<<ans<<endl;
}

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

int main() {
  vector<vector<pair<int, bool>>> card(3, vector<pair<int, bool>>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      int a;
      cin >> a;
      card[i][j] = make_pair(a, false);
    }
  }
  int N;
  cin >> N;
  for (int k = 0; k < N; k++) {
    int b;
    cin >> b;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (card[i][j].first == b) {
          card[i][j].second = true;
        }
      }
    }
  }
  
  bool bingo = false;
  
  for (int i = 0; i < 3; i++) {
    if (card[i][0].second && card[i][1].second && card[i][2].second) {
      bingo = true;
      break;
    }
    if (card[0][i].second && card[1][i].second && card[2][i].second) {
      bingo = true;
      break;
    }
  }
  if (card[0][0].second && card[1][1].second && card[2][2].second) {
    bingo = true;
  }
  if (card[0][2].second && card[1][1].second && card[2][0].second) {
    bingo = true;
  }
  
  if (bingo) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

#define MAX_N 500000
#define INF 1000000001

void print_array(int A[], int n) {
  for(int i=0; i<n; i++) {
    printf("%d", A[i]);
    if(i != n-1) {
      printf(" ");
    }
  }
  printf("\n");
}

int merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int* L = (int*)malloc((n1+1) * sizeof(int));
  int* R = (int*)malloc((n2+1) * sizeof(int));
  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] = INF;
  R[n2] = INF;

  int li = 0;
  int ri = 0;
  for(int i=left; i<right; i++) {
    if(L[li] <= R[ri]) {
      A[i] = L[li];
      li++;
    } else {
      A[i] = R[ri];
      ri++;
    }
  }

  free(L);
  free(R);
  return li+ri;
}


int mergeSort(int A[], int left, int right) {
  if(left+1 < right) {
    int mid = (left + right) / 2;
    int x1 = mergeSort(A, left, mid);
    int x2 = mergeSort(A, mid, right);
    int x3 = merge(A, left, mid, right);
    return x1 + x2 + x3;
  }
  return 0;
}

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

  int cmpNum = mergeSort(A, 0, n);
  print_array(A, n);
  printf("%d\n", cmpNum);
}

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


void solve(std::vector<long long> x){
  for(long long i = 0; i < x.size(); i++){
    if(x[i] == 0) {
      cout << (i+1) << endl;
      break;
    }
  }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::vector<long long> x(5);
  for(int i = 0 ; i < 5 ; i++){
    scanf("%lld",&x[i]);
  }
    solve(std::move(x));
    return 0;
}


Measured memory_bytes: 3680
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		scanf("%d",&a[i]);
	}
	sort(all(a));
	int count = 1;
	int ans = 0;
	rep(i, n-1) {
		if (a[i] == a[i + 1]) {
			count++;
		}
		else {
			if (count >= a[i]) {
				ans += count - a[i];
			}
			else {
				ans +=count;
			}
			count = 1;
		}
	}
	if (count >= a[n-1]) {
		ans += count - a[n-1];
	}
	else {
		ans += count;
	}
	cout << ans << endl;

}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
string did,nid;
void solve(){
    nid.erase(nid.size()-1);
    if(nid==did) {
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

int main(){
    cin>>did>>nid;

    solve();
    return 0;
}


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

int main() {
    vector<string> s(3);
    cin >> s[0];
    s[1] = s[0].substr(0, (s[0].size() - 1) / 2);
    s[2] = s[0].substr((s[0].size() + 3) / 2 - 1);
    bool b = true;
    for (int i = 0; i < 3; ++i) {
        if (s[i] != string(s[i].rbegin(), s[i].rend()))
            b = false;
    }
    cout << (b ? "Yes" : "No");
}


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

int main()
{
	map<string,int> a;
	string s;
	int n,i,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>s;
		if(a[s]==0)
		{
			a[s]=1;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 19176