akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)
    x=x->left;
  return x;
}

Node treeSearch(Node x, int k){
  while(x!=NIL && k!=x->key){
  if(k < x->key)
    x=x->left;
  else
    x=x->right;
  }
  return x;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL)
    return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL)
    y=z;
  else
    y=treeSuccessor(z);
  if(y->left != NIL)
    x=y->left;
  else
    x=y->right;
  if(x != NIL)
    x->parent=y->parent;
  if(y->parent==NIL)
    root=x;
  else if(y==y->parent->left)
    y->parent->left=x;
  else
    y->parent->right=x;
  if(y!=z)
    z->key=y->key;

}





void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x ->key)
      x=x->left;
    else
      x=x->right;
  }
  z->parent=y;
  if(y==NIL)
    root=z;
  else if(z->key < y->key)
    y->left=z;
  else
    y->right=z;
}
      


void inorder(Node u){
  if(u==NIL)
    return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)
    return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}



int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

int s , t;
bool used[MAXX];

int main()
{
    _FastIO;
    cin >> s;
    int ans = 0;
    used[s] = true;
    t = 1;
    while(true){
            t++;
        if(s % 2 == 0)
            s /= 2;
        else
            s = s * 3 + 1;
        if(used[s]){
            ans = t;
            break;
        }
        used[s] = true;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.List (group)

main :: IO ()
main = do
  let
    f :: Int -> Int -> Int
    f k m = (2 * k) `min` (m - 1)
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    step :: Char -> [Bool] -> [Bool]
    step 'L' rest = False : rest
    step 'R' rest = True : rest
    step _ _ = []
  ds <- foldr step [] <$> getContents :: IO [Bool]
  let
    (m, s) = ((,) <$> length <*> sum . map (pred . length)) . group $ ds :: (Int, Int)
  print $ s + f k m

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
int A, B, C;
	cin >> A >> B >> C;
	if (A==B&&B!=C|| A == C && B != C|| C == B && B != A) {
		cey;
	}
	else {
		cen;
	}

    return 0;
}



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

void countsort(int A[],int n){
    int B[MAX+1]={0},C[n];
    rep(i,n)B[A[i]]++;
    rep(i,MAX)B[i+1]+=B[i];
    rep(i,n){
        int k=A[i];
        B[k]--;
        C[B[k]]=k;
    }
    rep(i,n)A[i]=C[i];
    return;
}

int main(){
    int n;cin>>n;
    int A[n];
    rep(i,n)scanf("%d",&A[i]);
    countsort(A,n);
    rep(i,n){
        if(i!=0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


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

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 1e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

vector<int> A;
vector<pii> B;
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
	int res = 0;

    cin>>n;
	
	A = vector<int> (n);
	
    for(int i=0;i<n;i++)
    	cin>>A[i];
	
	sort(A.begin(),A.end());
	
	cur = A[0];
	cnt = 0;
	
	for(int i=0;i<n;i++){
		if(A[i]==cur)cnt++;
		else {
			B.push_back(pii(cur,cnt));
			cur = A[i];
			cnt = 1;
		}
	}
	
	B.push_back(pii(cur,cnt));
	
	int sz = B.size();
	
	if(sz>=4){
		cout<<"No\n"; return 0;
	}
	else if(sz==3){
		
		if((B[0].f^B[1].f)!=B[2].f)cout<<"No\n";
		else {
			if(n%3)cout<<"No\n";
			else {
				for(int i=0;i<3;i++){
				if(B[i].s!=n/3){
					cout<<"No\n"; return 0;
					}
				}
				cout<<"Yes\n";
			}
			return 0;
		}
	}
	else if(sz==2){
		if(B[0].f)cout<<"No\n";
		else {
			if(n%3)cout<<"No\n";
			else if(B[0].s!=n/3)cout<<"No\n";
			else cout<<"Yes\n";
		}
	}
	else {
		if(B[0].f)cout<<"No\n";
		else cout<<"Yes\n";
	}
	
    return 0;
}



Measured memory_bytes: 1656
#define _USE_MATH_DEFINES
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int num(char c){
	switch(c){
	case 'I':
		return 1;
	case 'V':
		return 5;
	case 'X':
		return 10;
	case 'L':
		return 50;
	case 'C':
		return 100;
	case 'D':
		return 500;
	case 'M':
		return 1000;
	}

	return 0;
}


int main(){
	string str;
	while(cin >> str){
		int pre = num(str[0]);
		int sum = pre;
		//int sum = 0;
		for(int i=1;i<str.size();i++){
			if(pre>=num(str[i])){
				sum+=num(str[i]);
			}else{
				sum+=-pre+num(str[i])-pre;
			}
			pre = num(str[i]);
			//cout << sum <<" ";
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    int N, now = 0, next, count = 0;

    cin >> N;

    vector <int> an(N);

    for (int i = 0; i < N; i++) {
        cin >> an.at(i);
    }

    while (now != 1) {
        count++;
        now = an.at(now) - 1;
        if (count >= N) {
            count = -1;
            break;
        }
    }

    cout << count << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }

  int c=0;
  for (int i = 0; i < N; i++) {
    if(c+1==a.at(i)){
      c++;
    }
  }
  if(c==0){
    cout<<"-1"<<endl;
  }
  else{
    cout <<N-c<< endl;
  }
}




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

int main() {
     int n ,count = 0 , num = 0 ;

     cin >> n ;


     for( int i =0 ; i < n ; i++){

          cin >> num ;

          if( num % 2 !=0 && ( i + 1 ) % 2 != 0 )count+= 1 ;
     }

     cout << count  ;
}


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

 int A[4];

int main()
{
   int a, b;

   cin >> a >> b;

   A[a]++;
   A[b]++;
   for(int i=1; i<4; i++)
   {
       if(A[i]==0)
       {
           cout << i << endl;
       }
   }

}


Measured memory_bytes: 256
def Judge(dx, dy):
    for x, y in star:
        mx = x + dx
        my = y + dy
        if (mx, my) not in pic:
            return False
    return True

def search():
    for sx, sy in star:
        for px, py in pic:
            dx = px-sx
            dy = py-sy
            if Judge(dx, dy):
                print dx, dy
                return
while True:
    m = input()
    if m==0: break
    star = set([tuple(map(int, raw_input().split())) for i in range(m)])
    n = input()
    pic = set([tuple(map(int, raw_input().split())) for i in range(n)])
    search()

Measured memory_bytes: 4472
//
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false)
using namespace std;

string gs(char x){
    string s(1,x);
    return s;
}

int main()
{
	speed;
	
	ll r;
	cin>>r;
	if(r<1200)
		cout<<"ABC";
	else if(r<2800)
		cout<<"ARC";
	else
		cout<<"AGC";


	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define mset(a,x) memset(a,x,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define mp make_pair

ll n;
ll x;
vector<int> a;

int main() {
    cin>>n>>x;
    a.resize(n);
    rep(i,n) scanf("%d", &a[i]);
    
    ll ans = 0;
    rep(i,n-1){
        ll sum = a[i] + a[i+1];
        if(sum <= x) continue;

        ll sub = sum - x;
        if(sub <= a[i+1]) {
            a[i+1] -= sub;
        }
        else {
            a[i+1] = 0;
            sub -= a[i+1];
            a[i] -= sub;
        }
        ans += sub;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
/**
  *  @Author: Pranta Sarker
  *
  */

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define pfn(x , k) printf(k , x)
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
#define clr clear()

typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;

const int mod = 1000007;
const int high = 1e5+2;

mpii mp;

int main()
{
	fast;
	int N , x;
	cin >> N;
	int i=0 , cnt=0;
	for(i=0; i<N; i++)
	{
		cin >> x;
		mp[x]++;
		if(mp[x] == 1) cnt++;
		else cnt--, mp[x] = 0;
	}

	cnt = cnt < 0 ? 0 : cnt;

	outn(cnt);

	return 0;
}


Measured memory_bytes: 4992
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
r=a[n-1]*2+1
l=0
while r-l>=2:
	mid=(l+r)//2
	#mid以上はいくつあるか
	#答えはl以上r未満
	cnt=0
	for i in range(n):
		cnt+=n-bisect.bisect_left(a,mid-a[i])
	if cnt>=k:
		l=mid
	else:
		r=mid
#lだとk個以上　rだとk個未満
ans,p,=0,0
b=[0]
for i in range(n):
	p+=a[i]
	b.append(p)
for i in range(n):
	q=bisect.bisect_left(a,r-a[i])
	ans+=b[n]-b[q]
	ans+=a[i]*(n-q)
	k-=n-q
ans+=l*k
print(ans)


Measured memory_bytes: 14204
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N-1), b(N-1);
    for ( int i = 0; i < N-1; ++i){
        cin >> a.at(i) >> b.at(i);
    }
    
    vector<vector<int>> G(N); //隣接リストによるグラフの表現
    vector<pair<int,int>> E_in; //辺の入力の順番を保持
    for ( int i = 0; i < N-1; ++i){
        int x = a.at(i);
        int y = b.at(i);
        --x; --y;
        G.at(x).push_back(y);
        G.at(y).push_back(x);
        pair<int,int> p = make_pair(x,y);
        E_in.push_back(p);
    }
    
    
    
    queue<int> que;
    vector<int> used(N,0);
    vector<int> parent(N,0); //親との間いある辺の色
    int max_color = 0;
    map<pair<int,int>,int> E_num; //辺に割り振った色
    que.push(0);
    used[0] = 1;
    while ( que.size() != 0 ){
        int state = que.front(); que.pop();
        int color_num = 0;
        for ( auto next: G[state] ){
            if ( used[next] != 1 ){
                ++color_num;
                used[next] = 1;
                if ( color_num == parent[state] ){
                    ++color_num;
                }
                pair<int,int> p = make_pair(state,next);
                E_num[p] = color_num;
                parent[next] = color_num;
                que.push(next);
            }
        }
        max_color = max(max_color,color_num);
    }
    
    cout << max_color << endl;
    for ( auto i : E_in ){
        cout << E_num[i] << endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 14580
#include <stdio.h>

int main(void){

  int n,k;
  scanf("%d %d", &n, &k);
  int d[k], a[k][n];
  for (int i = 0; i < k; i++) {
    scanf("%d", &d[i]);
    for (int j = 0; j < d[i]; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int check[n];
  for (int i = 0; i < n; i++) {
    check[i] = 0;
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < d[i]; j++) {
      check[a[i][j]-1]++;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (check[i] == 0) {
      count++;
    }
  }
  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 1744
ht, st, ha, sa = map(int, raw_input().split())
turn = 0
while ha > 0 and ht > 0:
  if turn == 0:
    ha -= st
  else:
    ht -= sa
    
  turn = 1 - turn
  
if ht > 0:
  print 'Yes'
else:
  print 'No'


Measured memory_bytes: 84540
#include <iostream>
using namespace std;
int main(void){
   // Your code here!
   int a,b;
   cin>>a>>b;
   
    if (a==b)
      cout<<"Draw"<<endl;
    else if (a==1<b)
      cout<<"Alice"<<endl;
    else if (b==1<a)
      cout<<"Bob"<<endl;
    else if (a<b)
      cout<<"Bob"<<endl;
    else cout<<"Alice"<<endl;  
}

Measured memory_bytes: 256
items = []
dp = []

def knapsack(n, e):
    for i in range(0, n + 1):
        res = 0
        for j in range(0, e):
            v, w = items[j]
            if i >= w:
                dp[j + 1][i] = max(dp[j][i - w] + v, dp[j][i])
            else:
                dp[j + 1][i] = dp[j][i]
    return

line = input()
E, W = list(map(int, line.split()))
for _ in range(0, E):
    line = input()
    v, w1 = list(map(int, line.split()))
    items += [[v, w1]]
dp = [[0] * (W + 1) for _ in range(0, E + 1)]
knapsack(W, E)
print(dp[E][W])


Measured memory_bytes: 42028
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    const int MAXV = (int)1e3;
    int N, W; cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    vector<vector<int>> dp(N + 1, vector<int>(N * MAXV + 1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) for (int val = 0; val <= i * MAXV; val++) {
        chmin(dp[i + 1][val], dp[i][val]);
        chmin(dp[i + 1][val + v[i]], dp[i][val] + w[i]);
    }
    int ans = 0;
    for (int val = 0; val <= N * MAXV; val++) if (dp[N][val] <= W) {
        chmax(ans, val);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
long double dist(long long x,long long y){
    return sqrt(x*x+y*y);
}
int main(){
    int n;
    cin>>n;
    long long d;
    cin>>d;

    long long ans=0;
    rep(i,n){
        long long x,y;
        cin>>x>>y;
        if(dist(x,y)<=d){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;

}
/*


*/


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

#define INF_LL (int64)1e18
#define INF (int64)1e9
#define REP(i, n) for(int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for(int64 i = (a); i < (b); i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint32_t;
using int64 = int64_t;
using uint64 = uint64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

template<typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; }
template<typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; }

int main(void) {
  int32 n,t;
  cin >> n >> t;
  int32 mx = -1;
  int64 sum = 0;
  REP(i,n){
    int32 h;
    cin >> h;
    if(sum >= t){
      cout << 1 << endl;
      continue;
    }
    if(mx <= h){
      cout << (t - sum + 1 + h - 1) / h << endl;
    }else{
      cout << (t - sum + mx - h + 1 + mx - 1) / mx << endl;
    }
    sum += h;
    mx = max(mx, h);
  }
}



Measured memory_bytes: 3080
# include <bits/stdc++.h>
using namespace std;
int main(){
	int n, x, ans = 0, minn = 1e9;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x;
		if(x <= minn){
			ans++;
			minn = x;
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
import sys
import collections
n = int(input())
s = [input() for i in range(n)]
s = sorted(s)
c = collections.Counter(s)
li = []
max_v = -1
for k,j in c.items():
    li.append([k,j])
    if max_v<j:
        max_v = j
li = sorted(li)
for i in range(len(li)):
    if li[i][1] == max_v:
        print(li[i][0])

Measured memory_bytes: 54112
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int read() { return readln.chomp.to!int; }
int[] reads() { return readln.split.to!(int[]); }

struct Pair {
    int left;
    int right;
}

void main() {
    int n, m; readf("%d %d\n", &n, &m);
    auto pairs = new Pair[m];
    foreach (ref p ; pairs)
        readf("%d %d\n", &p.left, &p.right);
    pairs.sort!("a.right < b.right");

    int r, ans;
    foreach (p ; pairs) {
        with (p) {
            if (left < r) continue;
            r = right;
            ans++;
        }
    }
    writeln(ans);
}

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define F first
#define S second
using namespace std;
typedef long long ll;


int main(){
    int n;
    string s;
    cin >> n >> s;
    int r = 0, b = 0;
    for(int i=0; i<n; i++){
        if(s[i] == 'R') r++;
        else b++;
    }
    if(r > b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
var
s:ansistring;
n,i,j,root :longint;
begin
 readln(s);
 n:=length(s);

 if (s[1]='0')or(s[n]='1') then
 begin
  writeln('-1');
  exit;
  end;

 for i:=2 to n-1 do
  begin
    if s[i]='1' then  if s[n-i]='0' then  begin writeln('-1'); exit; end;
    if s[i]='0' then  if s[n-i]='1' then  begin writeln('-1'); exit; end;
  end;
   root:=1;
 // writeln(1,' ',2);

  for i:=1 to n-1 do
   begin
    writeln(root,' ',i+1);
    if s[i]='1' then root:=i+1;
   end;
end.


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long n,m,k;
  cin >> n >> m >> k;
  vector<long> a(n);
  vector<long> b(m);
  for(long i=0;i<n;i++)cin >> a[i];
  for(long i=0;i<m;i++)cin >> b[i];
  long total = 0;
  long c = 0;
  long cnt = 0;
   while(true){
          if(total + a[c] <= k){
              total += a[c];
              c++;
              cnt++;
              if(c == n)break;
          }else break;
      }
    long A = cnt;
  long e = 0;
  while(true){
          if(total + b[e] <= k){
              total += b[e];
              e++;
              cnt++;
              if(e == m)break;
          }else break;
      }
       long B = cnt-A;
long ans = cnt;
  for(int i=0;i<A;i++){
      total -= a[A-1-i]; cnt--;
      while(true){
          if(B == m)break;
          if(total + b[B] <= k){
              total += b[B];
              B++;
              cnt++;
          }else break;
      }
      if(cnt > ans)ans = cnt;
  }
 cout << ans << endl;
}


Measured memory_bytes: 6408
a, b, c, d = gets.strip.split.map(&:to_i)
lcm = c.lcm(d)

c_count = b/c-(a-1)/c
d_count = b/d-(a-1)/d
lcm_count = b/lcm-(a-1)/lcm

puts ((b-a + 1)-(c_count + d_count - lcm_count)).to_s

Measured memory_bytes: 1788
import sys
import math
s = input()
k = int(input())

li = [0 for i in range(len(s)+1)]
wrd = [i for i in s]
wrd.append(wrd[0])


if len(s)==1:
    print(k//2)
    sys.exit()


if k == 1:
    for i in range(len(s)-1):
        if wrd[i]==wrd[i+1] and li[i]==0:
            li[i+1] = 1
    ans = 0    
    for i in range(len(s)+1):
        if li[i] == 1:
            ans += 1
    print(ans)
    sys.exit()


for i in range(len(s)):
    if wrd[i]==wrd[i+1] and li[i]==0:
        li[i+1] = 1

ans = 0    
for i in range(len(s)+1):
    if li[i] == 1:
        ans += 1
ans1 = ans
ans *= k

if li[len(s)]!=1:
    print(ans)
    sys.exit()

ans1 -= 1
    
""""""

li = [0 for i in range(len(s)+1)]
li[0] = 1
wrd = [i for i in s]
wrd.append(wrd[0])

for i in range(len(s)):
    if wrd[i]==wrd[i+1] and li[i]==0:
        li[i+1] = 1

ans2 = 0  
ans = 0  
for i in range(len(s)+1):
    if li[i] == 1:
        ans2 += 1

if li[len(s)] == 0:
    ans += ans1*(math.ceil(k/2))
    ans += ans2*(k//2)
    print(ans)
    sys.exit()

ans2 -= 1
ans += ans1
ans += ans2*(k-1)

print(ans)


    


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

int crs[128] = {0};

void check()
{
	for(int i=3; i<128; i++)
	{
		if(crs[i]%2!=0)
		{
			cout << "NG" << endl;
			return;
		}
	}
	if(crs[1]%2==1 && crs[2]%2==1)
	{
		cout << "OK" << endl;
	}
	else
	{
		cout << "NG" << endl;
	}
}

int main()
{
	int a,b;
	while(cin >> a >> b)
	{
		if(a==0 && b==0)
		{
			check();
			memset(crs,0,sizeof(crs));
			continue;
		}
		crs[a]++; crs[b]++;
	}

}

Measured memory_bytes: 0
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ar array


void solve(){
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0;i < (int)n; i++){
      cin >> arr[i];
    }
    int ans = 0,prev = arr[0];
    for(int i = 1;i < (int)n; i++){
        if(arr[i]<arr[i-1]) {ans +=abs(arr[i]-arr[i-1]);
        arr[i] += abs(arr[i]-arr[i-1]);} 
    }
    cout << ans << "\n";
}

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

    int TC = 1;
    while(TC--)
        solve();        
    
    return 0;
}



Measured memory_bytes: 4748
import collections


n = input()
s = input().split(' ')

even = collections.Counter(s[1::2])
odd = collections.Counter(s[0::2])
maxeven = even.most_common()[0]
maxodd = odd.most_common()[0]
ans = 0
if maxeven[0] != maxodd[0]:
    ans = len(s) - maxeven[1] - maxodd[1]
else:
    if len(s) == maxeven[1] + maxodd[1]:
        ans = len(s) - maxeven[1]
    else:
        if maxeven[1] == maxodd[1]:
            nextodd = odd.most_common()[1]
            nexteven = even.most_common()[1]
            ans = len(s) - maxeven[1] -max(nextodd[1], nexteven[1]) 

        elif maxeven[1] > maxodd[1]:
            nextodd = odd.most_common()[1]
            ans = len(s) - maxeven[1] - nextodd[1]
        else:
            nexteven = even.most_common()[1]
            ans = len(s) - maxodd[1] - nexteven[1]

print(ans)

Measured memory_bytes: 22372
# https://atcoder.jp/contests/abc125/tasks/abc125_d
n = gets.to_i
$nums = gets.split.map(&:to_i)

DP = [Array.new(10**7, nil), Array.new(10**7, nil)]
DP[0][0] = 0
DP[1][0] = -1 * 10**9

1.upto(n) do |idx|
  num = $nums[idx - 1]
  [0, 1].each do |reversed|
    if reversed == 1
      DP[reversed][idx] = [ DP[0][idx - 1] - num, DP[1][idx - 1] + num ].max
    else
      DP[reversed][idx] = [ DP[0][idx - 1] + num, DP[1][idx - 1] - num ].max
    end
    # puts "DP[#{reversed}][#{idx}] = #{DP[reversed][idx]}"
  end
end

puts DP[0][n]


Measured memory_bytes: 165388
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,m,n,h,w,a,b,c
    integer(8),allocatable :: x(:),y1(:),y2(:)
  
    read(*,*) h,w

    allocate(x(w),y1(w),y2(w))
    
    read(*,*)s
    if(s(1:1) .eq. '#')then
        x(1)=1
    else
        x(1)=0
    end if
    do j=2,w
        if(s(j:j) .ne. s(j-1:j-1))then
            x(j)=x(j-1)+1
        else
            x(j)=x(j-1)
        endif
    end do
    
    t=s

    do i=2,h
        read(*,*)s
        do j=1,w
            if(s(j:j) .ne. t(j:j))then
                y1(j)=x(j)+1
            else
                y1(j)=x(j)
            end if
        end do
        y2(1)=y1(1)
        x(1)=y1(1)
        do j=2,w
            if(s(j:j) .ne. s(j-1:j-1))then
                y2(j)=x(j-1)+1
            else
                y2(j)=x(j-1)
            endif
            x(j)=min(y1(j),y2(j))
        end do
        t=s
        
    enddo
    write(*,*)(x(w)+1)/2

    stop
end program sample
  



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

int main(){
    int n;
    cin >> n;
    vector<int> a(n, 0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<int> rate(9, 0);
    for(int x : a){
        int ite = 0, b = 400;
        while(ite < 8){
            if(x < b){
                rate[ite] = 1;
                break;
            }
            ite++;
            b += 400;
        }
        if(ite == 8) rate[8] += 1;
    }
    int sum = 0;
    for(int i = 0; i < 8; i++){
        sum += rate[i];
    }
    cout << max(1, sum) << ' ' << sum + rate[8] << endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>


int main( int argc, char** argv )
{
  int N, L;
  std::cin >> N;
  std::cin >> L;
  std::vector< std::string > s( N );
  for( int i = 0; i < N; ++i ) {
    std::cin >> s[ i ];
  }
  
  std::sort( s.begin(), s.end() );
  
  for( int i = 0; i < N; ++i ) {
  	std::cout << s[ i ];
  }
  
  return 0;
  
  
}

Measured memory_bytes: 256
/* In the name of God */

#include<bits/stdc++.h>

using namespace std;
//#define int long long
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Dec cout<<fixed<< setprecision
#define endl "\n"
#define nlp printf("\n")
#define nl cout << "\n"
#define Sz(x) (int) x.size()
#define tc() int t; cin >> t ; while (t--)
#define debug(x) cout << "### x is : " << x << " ###" << endl
#define clr(a) memset(a , 0 , sizeof a)
#define endl "\n"
#define bit(i , x) ((x >> i) & 1)
#define all(v) v.begin() , v.end()
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }
inline int in(){int32_t x ; scanf ("%d" , &x) ; return x ; }
inline ll lin(){ll x ; scanf ("%I64d" , &x) ; return x ; }
inline void out(int x){printf("%d " , x) ; }
inline void lout(ll x){printf("%I64d " , x) ; }

const int MOD = 1e9 + 7 ;
const int INF = 1e9 + 10 ;
const ll LINF = 1e18 ;
const int N = 1e3 + 10 ;
const int maxn = 1e4 + 10 ;
const int MAXN = 1e5 + 10 ;
const int MN = 1e6 + 10 ;

int n ;
string s , st ;

bool ok(string x , char c){
	for(int i=0 ; i < Sz(x) ; i++)
		if(s[i] != c )
			return false ;
	return true ;
}

int32_t main (){
	IOS() ;
	cin >> st ;
	char c ;
	int ans = INF , cnt = 0 ;
	for(int i=0 ; i < 26 ; i++){
		c = char(i+'a') ;
		s = st ;
		cnt= 0 ;
		while(!ok(s , c)){
			string t= "" ;
//			cout << s << endl ;
			cnt++ ;
			for(int j=0 ; j < Sz(s)-1 ; j++){
				if(s[j] == c || s[j+1] == c)
					t+= c ;
				else
					t+= s[j] ;
			}
			s = t ;
		}
		smin(ans , cnt) ;
	}
	cout << ans << endl ;
	return 0 ;
}


Measured memory_bytes: 256
from fractions import gcd
a, b, c, d = map(int, input().split())
cnt = b - a + 1
li = []

# 1..A..B % C == 0
li.append(b//c)
cnt -= (b // c)
# 1..A % C == 0
li.append((a-1) // c)
cnt += ((a-1) // c)

# 1..A..B % D == 0
li.append(b//d)
cnt -= (b // d)
# 1..A % D == 0
li.append((a-1) // d)
cnt += ((a-1) // d)

# 1..A..B % (CD) == 0
div = (c * d) // gcd(c, d)
li.append(b // div)
cnt += (b // div)
# 1..A % (CD) == 0
li.append((a-1) // div)
cnt -= ((a-1) // div)

print(cnt)

Measured memory_bytes: 5048
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      // 取得
	  double A = sc.nextInt();
      double B = sc.nextInt();
      double H = sc.nextInt();
      double M = sc.nextInt();
      double theta = (double)Math.abs((H*30+0.5*M)-M*6);
      if(theta>=180){
        theta=(double)360.0-theta;
      }
      double ans = A*A+B*B-2*A*B*Math.cos(Math.toRadians(theta));
      ans = Math.sqrt(ans);
      System.out.println(ans);
    }
}

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

int main(){
    ll n;
    cin>>n;
    ld sum=0;
    ld a[n];
    for(ll i=0;i<n;++i){
        cin>>a[i];
        sum += a[i];
    }
    ll ave;
    ld flag=sum/n;
    ll x=flag;
    flag -= x/1;
    //cout<<flag<<endl;
    if(flag<0.5){
        ave = sum/n;
    }else{
        ave = sum/n+1;
    }
    ll ans=0;
    for(ll i=0;i<n;++i){
        ans += (a[i]-ave)*(a[i]-ave);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int main(){
    string s,t;
    cin >> s >> t;
    int cnt=0;
    rep(i,3)if(s[i]==t[i])cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 764
a,b,c = (int(x) for x in input().split())

if a == 5:
    if b == 5:
        if c == 7:
            print("YES")
        else:
            print("NO")
    elif b == 7:
        if c == 5:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
elif a == 7:
    if b == 5:
        if c == 5:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 9096
using System;
using System.Text;

namespace atCodeTest
{
    class Program
    {
        static void Main(string[] args)
        {
            int input = Convert.ToInt32(Console.ReadLine());
            string strings = Console.ReadLine();

            string str1 = strings.Split(' ')[0];
            string str2 = strings.Split(' ')[1];
            StringBuilder builder = new StringBuilder();
            for(int i = 0; i < input; i++)
            {
                builder.Append(str1[i]);
                builder.Append(str2[i]);
            }
            Console.WriteLine(builder.ToString());
        }
    }
}


Measured memory_bytes: 11220
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include <wchar.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
*/

int dp[3010][3010],before[3010][3010],x,y;
string s,t,ans="";

int main(void){
	cin>>s>>t;
	rep(i,s.size())rep(j,t.size())dp[i][j]=0;
	rep(i,s.size())rep(j,t.size())before[i][j]=0;
	reg(i,0,s.size()){
		reg(j,0,t.size()){
			if(i+1<=s.size()){
				if(dp[i+1][j]<=dp[i][j]){
					dp[i+1][j]=dp[i][j];//sを無視
					before[i+1][j]=1;
				}
			}
			if(j+1<=t.size()){
				if(dp[i][j+1]<=dp[i][j]){
					dp[i][j+1]=dp[i][j];//tを無視
					before[i][j+1]=2;
				}
			}
			if(i+1<=s.size() && j+1<=t.size() && s[i]==t[j]){
				if(dp[i+1][j+1]<=dp[i][j]+1){
					dp[i+1][j+1]=dp[i][j]+1;//s,tが一致
					before[i+1][j+1]=3;
				}
			}
			// cout<<dp[i][j]<<" ";
		}
		// cout<<endl;
	}
	// reg(i,0,s.size()){
	// 	reg(j,0,t.size()){
	// 		cout<<before[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	x=s.size();
	y=t.size();
	while(x>0 || y>0){
		if(before[x][y]==1){
			x--;
		}else if(before[x][y]==2){
			y--;
		}else{
			x--;
			y--;
			ans=s[x]+ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef pair<int,int> P;

int n;

int main() {
	cin >> n;

	unordered_map<int,int> mp[2];
	vector<P> vr[2];

	for(int i = 0; i < n; i++) {
		int v;
		cin >> v;
		mp[i%2][v]++;
	}

	for(P p : mp[0]) vr[0].push_back(P(p.second,p.first));
	for(P p : mp[1]) vr[1].push_back(P(p.second,p.first));
	vr[0].push_back(P(0,0));
	vr[1].push_back(P(0,0));
	sort(vr[0].begin(),vr[0].end(),greater<P>());
	sort(vr[1].begin(),vr[1].end(),greater<P>());

	if(vr[0][0].second!=vr[1][0].second) {
		cout << (n-(vr[0][0].first+vr[1][0].first)) << endl;
	}else {
		int res = max((vr[0][0].first+vr[1][1].first),(vr[0][1].first+vr[1][0].first));
		cout << (n-res) << endl;
	}

	return 0;
}


Measured memory_bytes: 5524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(int A, int B, int C)
        {
            var s = new Tuple<int, int, int>(A, B, C);
            var set = new HashSet<Tuple<int, int, int>>();
            int i;
            for (i = 0; true; ++i)
            {
                set.Add(s);
                int a = s.Item1;
                int b = s.Item2;
                int c = s.Item3;
                if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) { break; }
                int x = b / 2 + c / 2;
                int y = c / 2 + a / 2;
                int z = a / 2 + b / 2;
                var t = new Tuple<int, int, int>(x, y, z);
                if (set.Contains(t)) { return -1; }
                s = t;
            }
            return i;
        }
        static void Main(string[] args)
        {
            var V = ReadInts();
            Console.WriteLine(Solve(V[0], V[1], V[2]));
        }
    }
}


Measured memory_bytes: 11348
a=int(input())
b=[]
b.append(a)
while True:
    if a%2==0:
        a=a/2
        if a in b:
            print(len(b)+1)
            break
        else:
            b.append(a)
    elif a%2!=0:
        a=3*a+1
        if a in b:
            print(len(b)+1)
            break
        else:
            b.append(a)

Measured memory_bytes: 9188
n=int(input())
s=[input() for i in range(n)]
b_b=0
e_a=0
ba=0
ab=0
for i in range(n):
    for j in range(len(s[i])-1):
        if s[i][j:j+2]=='AB':
            ab+=1
    if s[i][0]=='B' and s[i][-1]=='A':
        ba+=1
    elif s[i][0]=='B':
        b_b+=1
    elif s[i][-1]=='A':
        e_a+=1
if ba>0:
    ab+=ba-1
    if e_a>0:
        b_b+=1
    if b_b>0:
        e_a+=1
print(ab+min(b_b,e_a))

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

int main(){
    char S[100000];
    int s_len,i,change=0,max=0;
    cin >> S;
    s_len = strlen(S);
    if(S[0]=='1'){
        change++;
    }
    for(i=1;i<s_len-max;i++){
        if(change==0){
            if(S[i]=='1'){
                max = i;
                change++;
            }
        }else{
            if(S[i]=='0'){
                max = i;
                change--;
            }
        }
    }
    if(max < s_len - max){
        max = s_len - max;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<stack>
#include<string.h>
#include<functional>
#include<limits.h>
using namespace std;

bool dp[10001];
signed main() {
	dp[0] = true;
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		int c; cin >> c;
		for (int d = 10000; d >= c; d--) {
			if (dp[d - c])dp[d] = true;
		}
	}
	for (int i = 10000; i >= 0; i--) {
		if (dp[i] && i % 10) {
			cout << i << endl;
			return 0;
		}
	}
	puts("0");
}

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

using namespace std;
using ll = long long;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    bool check = 0;

    for(int i = 0; i < B; i++) {
        if((i*A)%B == C) {
            check = 1;
        }
    }
    
    if(check) {
    cout << "YES" << endl;
    } else {
    cout << "NO" << endl;
    }

    return 0;
}

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int t = (c+b-1)/b;
	int s = (a+d-1)/d;
	if(t <= s){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
    return 0;
}



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

int main(){
  long k;
  cin >> k;
  if(k%2==0 || k%5==0){
    cout << "-1\n";
    return 0;
  }
  long tmp;
  if(k%7==0)tmp = 9*k/7;
  else tmp = 9*k;
  long ans = 1;
  long bsi = 10;
  while(1){
    if(bsi%tmp==1)break;
    bsi %= tmp;
    bsi *= 10;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <cctype>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <cmath>

using namespace std;

int main(){
  int m,d,mm,dd,ans;
  cin >> m >> d >> mm >> dd;
  if(m == 1||m == 3||m == 5||m == 7||m == 8||m == 10||m == 12){
    if(d == 31){
      ans = 1;
    }else{
      ans = 0;
    }
  }else if(m == 2){
    if(d == 28){
      ans = 1;
    }else{
      ans = 0;
    }
  }else{
    if(d == 30){
      ans = 1;
    }else{
      ans = 0;
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");

  var N = ~~input[0];
  var d = input.slice(1,N+1).map(x => ~~x);

  var Mochis = function(d){
    this.mochis = d;
  }

  var Kagamimochi = function(){
    this.kagamimochi = [];
  }

  var Runrun = function(){};

  Runrun.prototype = {
    createKagamimochi: function(mochis, kagamimochi){
      var mochiNum = mochis.length;
      for(i=0; i < mochiNum; i++){
        var maxMochi = Math.max(...mochis);
        mochis = mochis.map(x => {
          if(x == maxMochi){
            return 0;
          }else{
            return x;
          }
        })
        if(maxMochi != 0) kagamimochi = kagamimochi.concat(maxMochi);
      }
      return kagamimochi.length;
    }
  }

  var mochis = new Mochis(d);
  var kagamimochi = new Kagamimochi();

  var runrun = new Runrun();

  console.log(runrun.createKagamimochi(mochis.mochis, kagamimochi.kagamimochi));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main () {
    ios::sync_with_stdio(0); 
    int n; cin >> n;
    vector<int> h(1e5+10); 
    for (int i = 1; i <= n; i++) cin >> h[i]; 
    int dp[(int)1e5+10]; 
    dp[0] = 0, dp[1] = 0; 
    dp[2] = abs(h[2]-h[1]); 
    for (int i = 3; i <= n; i++) {
        dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]); 
    }

    cout << dp[n] << "\n";

}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
int n,x,y,z;
long long dp[41][1<<17];
long long ans;
int s;
const long long md=1e9+7;
bool ok(int k)
{
	if(!(k&(1<<(z-1))) || !(k&(1<<(s-x-1))) || !(k&(1<<(s-1))))return true;
	return false;
}
int main()
{
	scanf("%d%d%d%d",&n,&x,&y,&z);
	s=x+y+z;
	for(int i=0;i<10;i++)dp[1][(1<<i)&((1<<s)-1)]++;
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<(1<<s);j++)
		{
			if(!dp[i][j])continue;
			for(int dig=0;dig<10;dig++)
			{
				int k=((j<<(dig+1))|(1<<dig))&((1<<s)-1);
				if(!ok(k))continue;
				dp[i+1][k]+=dp[i][j];
				if(dp[i+1][k]>=md)dp[i+1][k]-=md;
			} 
		}
	}
	ans=1LL;
	for(int i=1;i<=n;i++)ans=ans*10LL%md;
	for(int i=0;i<(1<<s);i++)
	{
		ans=ans+md-dp[n][i];
		if(ans>=md)ans-=md;
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 40192
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int N;
	int[] s;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		N = sc.nextInt();
		s = nextIntArray(sc, N);

		sc.close();

		int sum = 0;
		int min = Integer.MAX_VALUE;

		for (int i = 0; i < N; i++) {
			sum += s[i];
			if (s[i] % 10 != 0) {
				min = Math.min(min, s[i]);
			}
		}

		int ans = sum;

		if (ans % 10 == 0) {
			if (min == Integer.MAX_VALUE) {
				ans = 0;
			} else {
				ans -= min;
			}
		}

		out.println(ans);

	}

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

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 22996
using System;

namespace abc114_c
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int[] arr = new int[25];
			int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
			for (int i = 2; i <= n; i++)
			{
				int x = i;
				for (int j = 0; j < 25; j++)
				{
					while (x % primes[j] == 0) { arr[j]++; x /= primes[j]; }
				}
			}
			int ret = 0;
			for (int i = 0; i < 25; i++)
			{
				for (int j = i + 1; j < 25; j++)
				{
					for (int k = 0; k < 25; k++)
					{
						if (i == k || j == k) continue;
						if (arr[i] >= 4 && arr[j] >= 4 && arr[k] >= 2)
							ret++;
					}
				}
			}
			for (int i = 0; i < 25; i++)
			{
				for (int j = 0; j < 25; j++)
				{
					if (i == j) continue;
					if (arr[i] >= 4 && arr[j] >= 14) ret++;
					if (arr[i] >= 2 && arr[j] >= 24) ret++;
				}
			}
			for (int i = 0; i < 25; i++) if (arr[i] >= 74) ret++;
			Console.WriteLine(ret);
		}
	}
}


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

#define DEBUG 1

static int gcd(int a, int b, int c);

static int gcd(int a, int b, int c)
{
  int __gcd = 0;
  int __min = min({a, b, c});

  for (int i = __min; i >= 1; i--) {
    if ((a % i == 0) && (b % i == 0) &&(c % i == 0)) {
      __gcd = i;
      break;
    }
  }

  return __gcd;
}

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

  int64_t ans = 0;
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
	ans += gcd(a, b, c);
      }
    }
  }


  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int n,m,i,j,x,y;
    int a[7]= {1,3,5,7,8,10,12};
    int b[4]= {4,6,9,11};
    while(~scanf("%d %d",&x,&y))
    {
        if(x==2&&y==2)
        {
            printf("Yes\n");
        }
        else
        {
            j=0;
            for(i=0; i<7; i++)
            {
                if(a[i]==x)
                {
                    j++;
                }
                if(a[i]==y)
                {
                    j++;
                }
            }
            m=0;
            for(n=0; n<4; n++)
            {
                if(b[n]==x)
                {
                    m++;
                }
                if(b[n]==y)
                {
                    m++;
                }
            }

            if(m==2||j==2)
            {
                printf("Yes\n");
            }
            else
                printf("No\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(c)  c.begin(),c.end()

int main()
{
    //freopen("in.txt","r",stdin);
    bool flag = false;
    ll a,b,x = 0;
    cin >> a >> b;
    for(ll i=a;(i<=b);i++){
        if(i%4 == 2){
            flag = true;
            break;
        }
        x ^= i;
    }
    if(flag == true){
        for(ll i=b;i>=a;i--){
            if(i%4 == 1){
                break;
            }
            x ^= i;
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 256
L, R = map(int, input().split())
ans = []
if R - L <= 2019:
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            ans.append(i * j % 2019)
else:
    for i in range(L, L + 2019):
        for j in range(i + 1, L + 2019 + 1):
            ans.append(i * j % 2019)
print(min(ans))


Measured memory_bytes: 75416
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll n,k; cin >> n >>k;
  double ans = 0;
  for (int i=1; i<=n; i++) {
    int r = ceil(log2(k) - log2(i));
    if (r<0) {
      ans += 1.0/n;
      continue;
    }
    ans += 1.0/n * pow(0.5, r); 
  }
  printf("%.15f\n", ans);
  return 0;
}

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

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

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> H) {
  for(int i = 0 ; i + 1 < N ; i++){
    if( H[i] >= H[i+1] && (i == 0 || H[i-1] < H[i])){
      H[i]--;
    }
  }
  if( is_sorted(H.begin(), H.end())){
    cout << YES << endl;
  }else{
    cout << NO << endl;
  }
}

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


Measured memory_bytes: 1024
N, K = map(int, input().split())

if K % 2 == 1:
  a = N // K
  print(a**3)
else:
  a = N // K
  if K*a + K//2 <= N:
    b = a + 1
  else:
    b = a
  print(a**3 + b**3)

Measured memory_bytes: 61792