akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <vector>
#include <chrono>

using namespace std;

constexpr int D = 365;
constexpr int LIMIT = 1950;
std::chrono::system_clock::time_point start;

int score(const vector<int>& c, const vector<vector<int>>& s, const vector<int>& t) {
	int S = 0;

	vector<int> last(26, 0);
	for (size_t i = 0; i < t.size(); i++) {
		S += s[i][t[i]-1];

		last[t[i] - 1] = i+1;
		for (size_t j = 0; j < 26; j++) {
			S -= c[j] * (i+1 - last[j]);
		}
	}

	return S;
}

int score_alpha(const vector<int>& c, const vector<vector<int>>& s, const vector<int>& t, const int& k) {
	int S = 0;

	vector<int> last(26, 0);
	for (size_t i = 0; i < t.size(); i++) {
		S += s[i][t[i] - 1];

		last[t[i] - 1] = i + 1;
		for (size_t j = 0; j < 26; j++) {
			S -= c[j] * (i + 1 - last[j]);
		}
	}

	for (size_t i = t.size(); i < min(int(t.size() + k), D); i++) {
		for (size_t j = 0; j < 26; j++) {
			S -= c[j] * (i + 1 - last[j]);
		}
	}
	return S;
}

vector<int> greedy(const vector<int>& c, const vector<vector<int>>& s, const int& k) {
	vector<int> t;
	t.reserve(D);

	for (size_t i = 0; i < D; i++) {
		int mscore = INT32_MIN, idx = 1;
		
		for (size_t j = 0; j < 26; j++) {
			t.push_back(j+1);
			int dscore = score(c, s, t);
			dscore = score_alpha(c, s, t, k);

			if (dscore > mscore) {
				mscore = dscore;
				idx = j+1;
			}
			t.pop_back();
		}

		t.push_back(idx);
	}

	return t;
}

vector<int> local(const vector<int>& c, const vector<vector<int>>& s, const vector<int>& init) {
	vector<int> t(init);
	int mscore = score(c, s, t);

	auto end = std::chrono::system_clock::now();
	while (std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() < LIMIT) {
		vector<int> nt(t);

		if (rand() % 2 == 0) {
			int rl = rand() % D;
			int rr = rand() % D;

			swap(nt[rl], nt[rr]);
		} else {
			int ri = rand() % D;
			int rc = rand() % 26;

			nt[ri] = rc + 1;
		}
		int nscore = score(c, s, nt);

		if (mscore < nscore) {
			mscore = nscore;
			copy(nt.begin(), nt.end(), t.begin());
		}
		end = std::chrono::system_clock::now();
	}
	return t;
}

int main() {
	start = std::chrono::system_clock::now();
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int ig;
	cin >> ig;

	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	
	for (int i = 0; i < 26; i++) {
		cin >> c[i];
	}

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}

	vector<int> bt = greedy(c, s, 0);
	int sc = score(c, s, bt);

	for (int i = 1; i < 10; i++) {
		auto t = greedy(c, s, i);
		auto tsc = score(c, s, t);
		if (sc < tsc) {
			sc = tsc;
			bt = t;
		}
	}
	
	bt = local(c, s, bt);

	for (size_t i = 0; i < D; i++) cout << bt[i] << endl;
	
	return 0;
}

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

int main()
{
	char c;
	cin >> c;
	if((c == 'a')||(c == 'e')||(c == 'i')||(c == 'o')||(c == 'u'))
		printf("vowel");
	else
		printf("consonant");

	return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B) {
    cout << C << endl;
  } else if (B == C) {
    cout << A << endl;
  } else if (C == A) {
    cout << B << endl;
  }
}

Measured memory_bytes: 256
//by the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char str[7];

    fgets(str,7, stdin);
    getchar();
    



        if( (str[2]==str[3]) && (str[4]==str[5]) ) {
                cout<< "Yes"<<endl;


        }
        else
            cout<< "No"<<endl;




    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    string s;
    cin >> s;
    stack<char> st;
    
    REP(i,s.size()) {
        if (s[i] == 'T') {
            if (!st.empty() && st.top() == 'S') {
                st.pop();
            } else {
                st.push('T');
            }
        } else {
            st.push('S');
        }
    }
    cout << st.size() << endl;
}


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

int main() {
  
  int N;
  cin >> N;
  int sum=0;
  
  for (int i=0; i<N; i++) {
  
    int l,r;
    cin >> l >> r;
    sum+=(r-l+1);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans=3;
    if(a==b){
        if(b==c){
            ans=1;
        }else{
            ans=2;
        }
    }else if(b==c){
        ans=2;
    }else if(c==a){
        ans=2;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
//38
#include<iostream>
#include<string>
#include<cctype>

using namespace std;

int main(){
  for(string s;getline(cin,s);){
    for(;;){
      for(int i=0;i<s.size();i++){
	if(isalpha(s[i])){
	  s[i]++;
	  if(s[i]>'z'){
	    s[i]='a';
	  }
	}
      }
      if(s.find("the")!=string::npos||s.find("this")!=string::npos||s.find("that")!=string::npos)break;
    }
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main() {

	int n, m,i;

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

	for(i=0;i<m;i++){
		n -= a[i];
	}

	if (n < 0) { printf("-1\n"); }
	else printf("%d\n", n);

	return 0;
}

Measured memory_bytes: 1756
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int N;
    cin >> N;
    // スペース区切りの整数の入力
    int a[N-1];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int b[N-1];
    for(int i=0;i<N;i++){
        cin >> b[i];
    }
    int c[N-1];
    for(int i=0;i<N-1;i++){
        cin >> c[i];
    }
    
    int point=0;
    for(int i=0;i<N;i++){
        point += b[a[i]-1];
        if(i >= 1 && a[i] == a[i-1] + 1){
            point += c[a[i-1]-1];
        }
    }
    cout << point <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

ll dp[100010] = {0};
bool isBroken[100010] = {false};
void solve(long long N, long long M, std::vector<long long> a)
{
    for (int i = 0; i < M; i++)
    {
        isBroken[a[i]] = true;
    }
    dp[0] = 1;
    for (int i = 1; i <= N; i++)
    {
        if (isBroken[i])
        {
            continue;
        }
        else
        {
            if (i == 1)
            {
                dp[i] = 1;
            }
            else
            {
                dp[i] = dp[i - 1] % MOD + dp[i - 2] % MOD;
            }
        }
    }

    cout << dp[N]%MOD << endl;
}

// Generated by 1.1.4 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()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> a(M);
    for (int i = 0; i < M; i++)
    {
        scanf("%lld", &a[i]);
    }
    solve(N, M, std::move(a));
    return 0;
}


Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;

namespace Contest
{
    class ABC
    {
        static void Main()
        {
            Solve();
        }

        private static void Solve()
        {
            int[] INPUT = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] NUM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var list = new List<int>();
            while(list.Count != 10)
            {
                list.Add(list.Count);
            }
            for(int i = 0; i < NUM.Length; i++)
            {
                list.Remove(NUM[i]);
            }
            long start = INPUT[0];
            while (true)
            {
                bool exists = false;
                string str = start.ToString();

                foreach(var s in str)
                {
                    if(!list.Exists(a => a.ToString() == s.ToString()))
                    {
                        exists = true;
                        break;
                    }
                }
                if (!exists)
                {
                    break;
                }
                start++;

            }
            Console.WriteLine(start);
            Console.ReadLine();
        }

    }
}


Measured memory_bytes: 15428
#include<stdio.h>
#define MAX 100001
#define SENTINEL 2000000000

typedef struct{
  char suit;
  int value;
}CARD;

CARD left[MAX / 2 + 2], right[MAX / 2 + 2];

void merge(CARD a[],int n,int lef,int mid,int rig){
  int i,j,k;
  int n1 = mid - lef;
  int n2 = rig - mid;
  for(i = 0;i < n1;i++)left[i] = a[lef + i];
  for(i = 0;i < n2;i++)right[i] = a[mid + i];
  left[n1].value = right[n2].value = SENTINEL;
  i = j = 0;
  for(k = lef;k < rig;k++){
    if(left[i].value <= right[j].value){
      a[k] = left[i++];
    }else{
      a[k] = right[j++];
    }
  }
}

void print(CARD a[],int datanum){
  int i;
  for(i=0;i<datanum;i++){
    printf("%c %d\n",a[i].suit,a[i].value);
  }
}

void mergesort(CARD a[],int n,int lef,int rig){
  int mid;
  if(lef + 1 < rig){
    mid = (lef + rig)/2;
    mergesort(a,n,lef,mid);
    mergesort(a,n,mid,rig);
    merge(a,n,lef,mid,rig);
  }
}

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

void quicksort(CARD a[],int n,int p,int r){
  int q;
  if(p < r){
  q = partition(a,n,p,r);
  quicksort(a,n,p,q -1);
  quicksort(a,n,q+1,r);
  }
}

int main(){
  int datanum,i,temp;
  CARD a[MAX],b[MAX];
  char c;
  int flag = 1;
  scanf("%d",&datanum);
  
  for(i=0;i<datanum;i++){
    scanf(" %c %d",&a[i].suit,&a[i].value);
    b[i].suit = a[i].suit;
    b[i].value = a[i].value;
    // printf("i=%d %c %d\n",i,b[i].suit,b[i].value);
  }
  
  mergesort(a,datanum,0,datanum);
  quicksort(b,datanum,0,datanum-1);

  for(i=0;i<datanum;i++)
    {
      if(a[i].suit != b[i].suit || a[i].value != b[i].value){
	flag = 0;
	break;
      }
    }
  if(flag != 1)printf("Not stable\n");
  else printf("Stable\n");
  print(b,datanum);
  return 0;
}



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

int main()
{
	int n;
	int i, j, k, l, m;
	int tmp;
	int count=0;
	
	cin >> n;
	int Dice[n][6];
	
	for(i=0;i<n;i++){
		for(j=0;j<6;j++){
			cin >> Dice[i][j];
		}
	}

	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			for(k=0;k<4;k++){
				tmp=Dice[j][0];
				Dice[j][0]=Dice[j][1];
				Dice[j][1]=Dice[j][5];
				Dice[j][5]=Dice[j][4];
				Dice[j][4]=tmp;
				if(Dice[j][1]==Dice[i][1])
					goto Break;
				else{
					for(l=0;l<4;l++){
						tmp=Dice[j][0];
						Dice[j][0]=Dice[j][3];
						Dice[j][3]=Dice[j][5];
						Dice[j][5]=Dice[j][2];
						Dice[j][2]=tmp;
						if(Dice[j][0]==Dice[i][1]){
							tmp=Dice[j][0];
							Dice[j][0]=Dice[j][4];
							Dice[j][4]=Dice[j][5];
							Dice[j][5]=Dice[j][1];
							Dice[j][1]=tmp;
							goto Break;
						}
					}
				}
			}
			Return:;
		}
	}
	goto Exit;
	
	Break:;
	for(m=0;m<4;m++){
		tmp=Dice[j][0];
		Dice[j][0]=Dice[j][3];
		Dice[j][3]=Dice[j][5];
		Dice[j][5]=Dice[j][2];
		Dice[j][2]=tmp;
		if(Dice[j][0]==Dice[i][0]){
			if(Dice[i][0]==Dice[j][0]&&Dice[i][1]==Dice[j][1]&&Dice[i][2]==Dice[j][2]&&Dice[i][3]==Dice[j][3]&&Dice[i][4]==Dice[j][4]&&Dice[i][5]==Dice[j][5]){
				cout << "No" << endl;
				return 0;
			}
			else{
				goto Return;
			}
		}
	}
	goto Return;
	
	Exit:;
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	bool f = true;
	ll res = 0;
	if(a[0] > 0) f = false;
	FOR(i,1,n) {
		if(a[i]-a[i-1] > 1) {
			f = false;
		}
		else if(a[i]-a[i-1] <= 0) {
			res += a[i-1];
		}
	}
	res += a[n-1];
	if(f)
		cout << res << endl;
	else
		cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 1024
use std::cmp::min;

/// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
    use std::fs::File;
    use std::io::Read;
    let mut s = String::new();
    match option_env!("LOCAL") {
        Some(_) => File::open("src/_in.txt")
            .expect("File not found")
            .read_to_string(&mut s)
            .unwrap(),
        None => std::io::stdin().read_to_string(&mut s).unwrap(),
    };
    s
}

fn solve(n: i32) -> i32 {
    let n = n as usize;
    let mut withdraws = vec![];
    for i in 0..10 {
        if usize::pow(6, i) <= n {
            withdraws.push(usize::pow(6, i));
        }
        if usize::pow(9, i) <= n {
            withdraws.push(usize::pow(9, i));
        }
    }

    let mut dp = vec![i32::pow(10, 9); n as usize + 1];
    dp[0] = 0;
    for i in 0..n {
        for w in &withdraws {
            if i + w <= n {
                dp[i + w] = min(dp[i + w], dp[i] + 1)
            }
        }
    }
    dp[n]
}

fn main() {
    let s = read_input();
    let mut ws = s.split_whitespace();
    let in_n: i32 = ws.next().unwrap().parse().unwrap();
    let ans = solve(in_n);
    println!("{:?}", ans);
}


Measured memory_bytes: 4352
from time import time
import random

start = time()

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]


def cal_score(t):
  S = 0
  last = [-1] * 26
  score = 0
  for d in range(D):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(26):
        S -= c[i] * (d - last[i])
    score += max(10 ** 6 + S, 0)
  return score
    
def main():
  t = [random.randint(0, 25) for _ in range(D)]
  score = cal_score(t)
  while time()-start + 0.2 < 2:
    d = random.randint(0, D-1)
    q = random.randint(0, 25)
    old = t[d]
    t[d] = q
    new_score = cal_score(t) 
    if new_score < score:
      t[d] = old
    else:
      score = new_score
  return t

if __name__ == "__main__":
  ans = main()
  for t in ans:
    print(t+1)

Measured memory_bytes: 9884
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
int main()
{
	long long int n,a,b;
	cin>>n>>a>>b;
	long long int full=n/(a+b);
	long long int rem=n%(a+b);
	long long int count=0;
	count=count+full*a;
	if(rem>=a)
	{
		count=count+a;
	}
	else{
		count=count+rem;
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
//ABC103A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int ans = max({a,b,c})-min({a,b,c});
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  3 23:09:02 2019

@author: Yamazaki Kenichi
"""

N, M, X = map(int,input().split())
A = list(map(int,input().split()))

A.sort()
map_ = [0 for i in range(N+1)]

for a in A:
    map_[a] = 1

ans = min(sum(map_[0:X]),sum(map_[X+1:N+1]))
print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll k,n;cin>>k>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll ma=k-a[n-1]+a[0];
    rep(i,n-1){
        ma=max(a[i+1]-a[i],ma);
    }
    cout<<k-ma<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

vector <int> Vv[200050];

priority_queue <int, vector<int>, greater<int>> Hx;
vector <int> Vu;
ll getv(int a, int M) {
	int i;
	while (!Hx.empty()) Hx.pop();
	Vu.clear();
	for (i = 1; i <= M; i++) {
		for (auto it : Vv[i]) Hx.push(it);
		if (i >= M - a + 1) {
			if (Hx.empty()) return -LL_INF;
			Hx.pop();
		}
	}
	for (auto it : Vv[M + 1]) Hx.push(it);
	while (!Hx.empty()) {
		Vu.push_back(Hx.top());
		Hx.pop();
	}

	int st = 1, en = min((int)Vu.size(), M - a), mi, rv = 0;
	while (st <= en) {
		mi = (st + en) / 2;

		for (i = 0; i < mi; i++) if (Vu[Vu.size() - mi + i] < i + 1) break;
		if (i >= mi) {
			rv = mi;
			st = mi + 1;
		}
		else en = mi - 1;
	}
	return a + rv;
}
int main() {
	int N, M, i, j;
	scanf("%d %d", &N, &M);
	//N = 200000, M = 199999;
	for (i = 1; i <= N; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		//t1 = 1, t2 = 2;
		Vv[t2].push_back(t1);
	}
	
	int st = 0, en = min(N, M), mi;
	while (st < en) {
		int mi1 = (st + en) / 2;
		int mi2 = mi1 + 1;
		
		ll v1 = getv(mi1, M);
		ll v2 = getv(mi2, M);
		if (v1 >= v2) en = mi2 - 1;
		else st = mi1 + 1;
	}
	ll v = getv(st, M);
	return !printf("%lld\n", N - v);
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  string s, t;
  cin >> s >> t;
  bool ok = false;
  rep(i, 100) {
    s = s.substr(s.size() - 1, 1) + s.substr(0, s.size() - 1);
    if (s == t) {
      ok = true;
      break;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n,m;
    cin >>n;
  
  	if((n/100)==(n%10))flag=true;

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << dig(n) << endl;

    if(flag)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  string s;
  char c;
  int n,k,ans=0;
  int count[26]={0};
  bool flag=true;
    
  cin >> n >> k;

  for(int i=0;i<n;i++){
    cin >> s;
    c=s[0];
    count[c-'A']++;
  }
  while(flag){
      sort(count,count+26,std::greater<int>());
      for(int i=0;i<k;i++){
        count[i]--;
        if((i != k) && count[i]<0) flag=false;
      }
      if(flag) ans++;
  }
  cout << ans << endl;
}

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

int main(){
	int n,m;
	int data[] = {1000,500,100};
	int ans[3];
	while(cin >> n >> m , n && m){
		int s = m - n;
		for(int i=0;i<3;i++){
			ans[i] = s / data[i];
			s -= data[i] * ans[i];
		}
		int flg = 0;
		for(int i=2;i>=0;i--){
			if(flg) cout << " ";
			cout << ans[i];
			flg = 1;
		}
		cout << endl;
	}
}

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

using namespace std;

int main(){
  string a, b;
  while(cin >> a >> b){
    while(a.size() > b.size()) b = "0" + b;
    while(a.size() < b.size()) a = "0" + a;
    int c = 0;
    for(int i=a.size()-1;i>=0;i--){
       c = (a[i]-'0'+b[i]-'0'+c)/10;
    }
    cout << a.size() + c << endl;
  }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
int n,m;
LL a[1000];
int b[1000];
LL dp[1<<12];
LL big = 100000000;

int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

int main(){
  REP(i,1<<12)dp[i]=big;
  dp[0]=0;
  cin>>n>>m;
  REP(i,m){
    cin>>a[i]>>b[i];
    int sum = 0;
    REP(j,b[i]){
      int tmp;
      cin>>tmp;
      sum += (1<<(tmp-1));
    }
    dp[sum] = min(dp[sum],a[i]);
  }
  for (int bit_ = 1; bit_ <= n; ++bit_){
    for (int bit = (1<<bit_)-1;bit < (1<<n); bit = next_combination(bit)) {
      for (int bit2_ = 1; bit2_ <= n; ++bit2_){
	for (int bit2 = (1<<bit2_)-1;bit2 < (1<<n); bit2 = next_combination(bit2)) {
	  dp[bit | bit2] = min(dp[bit | bit2],dp[bit]+dp[bit2]);
	}
      }
    }
  }
  if(dp[(1<<n)-1] == big){
    cout<<-1<<endl;
    return 0;
  }
  cout<<dp[(1<<n)-1]<<endl;
  return 0;
}


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

int A[100][100],dk[100],L[100];

void BFS(int n,int u){
    int k;
    queue<int> Q;
    Q.push(u);
    dk[u]=0;L[u]=1;
    while(!Q.empty()){
        k=Q.front();Q.pop();
        for(int i=0;i<n;i++){
            if(A[k][i]==1&&L[i]==-1){
                Q.push(i);L[i]=1;dk[i]=dk[k]+1;
            }
        }
    }
}

int main(){
    int n,v,u,k;
    cin>>n;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)A[i][j]=-1;
    for(int i=0;i<n;i++){L[i]=-1;dk[i]=-1;}

    for(int i=0;i<n;i++){
        scanf("%d %d",&v,&u);
        v--;
        for(int j=0;j<u;j++){
            scanf("%d",&k);
            k--;
            A[v][k]=1;
        }
    }
    BFS(n,0);
    for(int i=0;i<n;i++){
        printf("%d %d\n",i+1,dk[i]);
    }
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
 
#define all(n) n.begin(),n.end()
#define ll long long
 
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>
#define ff first
#define ss second
 
using namespace std;
const ll maxn=2e6+120;
const ll maxx=1e16;
const ll mod=1e9+7;
const ll mod1=998244353;
vector<ll> adj[maxn];
ll dp[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("TEAMS.INP","r"))
    {
        freopen("TEAMS.INP", "r", stdin);
        freopen("TEAMS.OUT", "w", stdout);
    }
    ll x;
    cin>>x;
    for (int i=1;i<maxn;i++)
    {
        if ((x*i)%360==0)
        {
            cout <<i;
            return 0;
        }
    }
 
 
 
}

Measured memory_bytes: 50496
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
int N;
cin >> N;
vector<tuple<string, int, int>> A;
for (int i = 1; i <= N; i++) {
  string S;
  int P;
  cin >> S >> P;
  A.push_back(make_tuple(S, -P, i));
}
sort(A.begin(), A.end());
rep(i, N) {
  cout << get<2>(A[i]) << '\n';
}
return 0;
}

Measured memory_bytes: 3616
/** @Date    : 2017-07-09 16:02:00
  * @FileName: D 循环节 dfs.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;

int n;
int a[N];
int tmp[N];
int b[N];
int vis[N];
vector<int>edg[N];

void dfs(int x)
{
	if(vis[x])
		return ;
	vis[x] = 1;
	for(auto i: edg[x])
		dfs(i);
	return ;
}
int main()
{
	while(cin >> n)
	{
		MMF(vis);
		int x , y;
		int flag = 0;
		map<int, int>q;
		for(int i = 1; i <= n; i++)
		{
			scanf("%d", a + i);
			tmp[i] = a[i];
			x ^= a[i];
			q[a[i]]++;
		}
		q[x]++;
		for(int i = 1; i <= n; i++)
		{
			scanf("%d", b + i);
			y ^= b[i];
			q[b[i]]--;
			if(q[b[i]] < 0)
				flag = 1;
		}
		a[0] = tmp[0] = x;
		b[0] = y;
		if(flag)
		{
			printf("-1\n");
			continue;
		}

		LL ans = 0;
		sort(tmp, tmp + n + 1);
		int pos = unique(tmp, tmp + n + 1) - tmp;
		for(int i = 1; i <= n; i++)
		{
			if(b[i] != a[i])
			{
				int p = lower_bound(tmp, tmp + pos, a[i]) - tmp;
				int np = lower_bound(tmp, tmp + pos, b[i]) - tmp;
				edg[p].PB(np);
				ans++;
			}
		}
		for(auto i:q)
		{
			if(i.se != 0)
			{
				int p = lower_bound(tmp, tmp + pos, a[0]) - tmp; 
				int np = lower_bound(tmp, tmp + pos, i.fi) - tmp;
				edg[p].PB(np);
				ans++;
			}
		}
		for(int i = 0; i < pos; i++)
		{
			if(vis[i])
				continue;
			dfs(i);
			if(edg[i].size() != 0)
				ans++;
		}
		printf("%d\n", ans - 2);
	}
    return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <cassert>

using ll = long long;

using namespace std;

// 和以外はseg木でよくねという発想の元、和のみを実装
template <typename T>
class BIT {
    const int n;
    vector<T> tree;

public:
    BIT(int _n) : n(_n), tree((size_t)_n, 0) {}

    // v[a] += w
    template <typename ID>
    void add(ID a, T w) {
        assert(0 <= a && a < n);
        for (int i = (int)a; i < n; i |= (i + 1)) 
            tree[(size_t)i] += w;
    }

    // v[0] + v[1] + ... + v[a-1]
    template <typename ID>
    T sum(ID a) {
        assert(0 <= a && a < n);
        T res = 0;
        for (int i = (int)a - 1; i >= 0; i = (i & (i + 1)) - 1)
            res += tree[(size_t)i];
        return res;
    }

    // v[0] + v[1] + ... + v[a] >= w なる最小のa
    int lower_bound(T w) {
        int x = 0, beki = 1;
        for (int _n=n; _n>0; _n>>=1) beki <<= 1;
        for (int k=beki; k>0; k>>=1) {
            if (x + k <= n && tree[(size_t)(x + k - 1)] < w) {
                w -= tree[(size_t)(x + k - 1)];
                x += k;
            }
            //cerr << k << ' ' << x << ' ' << tree[x] << '\n';
        }
        return x;
    }

    // set(被りなし)としての機能を見やすく
    // ただし同じものをたとえば二回pushする場合、値が+2となって一回のpopでは消えないというバグあり
    template <typename ID>
    void push(ID a) { add(a, 1); }

    template <typename ID>
    void pop(ID a) { add(a, -1); }
};

using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int cnt[26] = {0};
    for (auto &c:s) cnt[c-'a']++;
    queue<int> pos[26];
    vector<P> r;
    int move[n], m=0;
    fill(move, move+n, -1);
    for (int i=0; i<n; i++) {
        int ci = s[i] - 'a';
        if (pos[ci].size() < cnt[ci] / 2) {
            pos[ci].push(m);
            move[i] = m;
            m++;
        }
        else
            r.push_back({ci, i});
    }
    reverse(r.begin(), r.end());
    bool even = (n%2 == 0);
    for (auto p:r) {
        if (pos[p.first].empty()) {
            if (even) {
                cout << -1 << '\n';
                return 0;
            }
            even = true;
            move[p.second] = n / 2;
        } else {
            int tar = pos[p.first].front();
            pos[p.first].pop();
            move[p.second] = n - 1 - tar;
        }
    }
    BIT<int> bit(n);
    long ans = 0;
    for (int i=0; i<n; i++) {
        ans += i - bit.sum(move[i]);
        bit.push(move[i]);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3452
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
    if(Math.abs(a - c) <= d || Math.abs(a - b) <= d && Math.abs(b - c) <= d){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 22996
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()

	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = nextInt()
	}

	ng, ok := 0, int(1e18)
	for ok-ng > 1 {
		mid := (ok + ng) / 2
		if check(as, mid) <= k {
			ok = mid
		} else {
			ng = mid
		}
	}
	fmt.Println(ok)
}

func check(as []int, x int) int {
	c := 0
	for _, a := range as {
		b := (a - 1) / x
		c += b
	}

	return c
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 5856
N,M = map(int,input().split())
P = list(map(int,input().split()))
XY = [tuple(map(int,input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def check(self, x, y):
        return self.find(x) == self.find(y)

# 交換可能な頂点でグルーピング
A = UnionFind(N)
for (x,y) in XY:
    A.unite(x,y)

# 頂点の数字(P[i]) と頂点番号(i+1) が同じグループかどうか
ans = 0
for i in range(N):
    if A.check(i+1,P[i]):
        ans += 1

print(ans)

Measured memory_bytes: 25220
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N;
    cin >> N;
    vl d(N);
    rep(i, N){
        cin >> d[i];
    }
    ll ans = 0;
    rep(i, N-1){
        FOR(j, i+1, N){
            ans += d[i]*d[j];
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
# coding:utf-8

import sys
from collections import Counter


input = sys.stdin.readline
INF = float('inf')
MOD = 10 ** 9 + 7


def inpl(): return list(map(int, input().split()))


A, B, C = inpl()

if A + B >= C - 1:
    print(B + C)
else:
    print((A + B) + 1 + B)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define MEM(x) memset(x,0,sizeof(x))
#define vc vector<int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define inf 0x3f3f3f3f
#define t_case int tt; cin>>tt; while (tt--)
#define lnginf 9223372036854775807
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
#define out(x); { for (auto i : x) cout<<i<<' ' ; }
#define PI 3.14159265359
const long long LL_INF = (long long) 2e18 + 5;
using namespace std;
void solve() {
	int n, m, k; cin >> n >> m >> k;
	vector<string> v(n);
	in(v)
	int ans = 0;
	For(mask, 0, 1ll << n)
	For(mask2, 0, 1ll << m) {
		int ct = 0;
		For(i, 0, n)For(j, 0, m)
		if ((mask & (1ll << i) ) == 0 and (mask2 & (1ll << j)) == 0 and v[i][j] == '#')ct++;
		ans += ct == k;
	}
	cout << ans << '\n';


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


	fastio  solve();


}


Measured memory_bytes: 3652
def main():
    N = int(input())
    S = {int(i) for i in input().split()}
    q = int(input())
    T = (int(i) for i in input().split())
    ans = 0
    for t in T:
        if t in S:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16200
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int C[100001];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		C[a]++;
	}
	int ans = C[0] + C[1] + C[2];
	for (int i = 0; i <= 100000-2; i++) {
		ans = max(ans,C[i] + C[i + 1] + C[i + 2]);
	}
	cout << ans << endl;
}


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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=1e6 +10, M=(ll)1e9+1 ;
const int mod =998244353 ,sz=5, MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";

void work(){
	ll n,k,c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	// ll l[k],r[k];
	vl l(k,-1),r(k,-1);
	ll ind=0;
	for(ll i=0;i<n;i++){
		if(s[i]=='o'){
			l[ind++]=i;
			i+=c;
		}

		if(ind==k)
			break;
	}

	ind=k-1;
	for(ll i=n-1;i>=0;i--){
		if(s[i]=='o'){
			r[ind--]=i;
			i-=c;
		}

		if(ind==-1)
			break;
	}

	for(ll i=0;i<k;i++){
		// cout << l[i] << " " << r[i] << "\n";
		if(l[i]==r[i]){
			cout << l[i]+1 << "\n";
		}
	}
	return;

}

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


	ll t;
	// cin >> t;
	t=1;
	while(t--){
	        work();
	
	}
return 0;
}
	

Measured memory_bytes: 5012
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    ll n, m;
    cin >> n >> m;
    VI a(m);
    ll sum = 0;
    for (auto &x : a)
        cin >> x, sum += (ll)x;
    if (sum > n)
        cout << -1 << "\n";
    else
        cout << n - sum << "\n";
}



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

int main()
{
    string n;
    cin >> n;
    int sum = 0;
    for(int i=0; i<n.length(); i++){
        sum += (n[i]-'0');
    }
    if(sum%9==0)
    cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3756
module Main where

import Control.Applicative

data Dice = Dice {
    top :: Int,
    south :: Int,
    east :: Int,
    west :: Int,
    north :: Int,
    bottom :: Int
}

rotateWest Dice {top=a,south=b,east=c,west=d,north=e,bottom=f} =
    Dice c b f a e d 

rotateEast Dice {top=c,south=b,east=f,west=a,north=e,bottom=d} =
    Dice a b c d e f

rotateSouth Dice {top=a,south=b,east=c,west=d,north=e,bottom=f} =
    Dice e a c d f b

rotateNorth Dice {top=e,south=a,east=c,west=d,north=f,bottom=b} =
    Dice a b c d e f

rotate dice 'W' = rotateWest dice
rotate dice 'E' = rotateEast dice
rotate dice 'S' = rotateSouth dice
rotate dice 'N' = rotateNorth dice

execRotation dice instructions =
    foldl rotate dice instructions

main = do
    (a:b:c:d:e:f:[]) <- (map read . words) <$> getLine
    instructions <- getLine
    print $ top $ execRotation (Dice a b c d e f) instructions



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

int main() {
	int n, k; cin >> n >> k;
	vector<int> a(n + 1), f(n + 1, 2e9); f[1] = 0;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 2; i <= n; i++)
	for (int j = 1; j <= min(i - 1, k); j++) {
		f[i] = min(f[i], f[i - j] + abs(a[i] - a[i - j]));
	}
	cout << f[n] << '\n';
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define nmax 100001
using namespace std;

int arr[nmax][4],a,b,c,n;

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a>>b>>c;
        arr[i][1]=max(arr[i-1][2]+a,arr[i-1][3]+a);
        arr[i][2]=max(arr[i-1][1]+b,arr[i-1][3]+b);
        arr[i][3]=max(arr[i-1][2]+c,arr[i-1][1]+c);
    }
    int aux=max(arr[n][2],arr[n][3]);
    aux=max(aux,arr[n][1]);
    cout<<aux;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  if(s[k-1]=='A') s[k-1]='a';
  if(s[k-1]=='B') s[k-1]='b';
  if(s[k-1]=='C') s[k-1]='c';
  cout<<s<<endl;
}


Measured memory_bytes: 256
N = int(input())
C = []
for i in range(N):
  A, B = map(int, input().split())
  C.append([B, A])
C.sort()
a = 0
ans = 'Yes'
for i in range(N):
  if a + C[i][1] <= C[i][0]:
    a += C[i][1]
  else:
    ans = 'No'
    break
print(ans)
  

Measured memory_bytes: 38352
n,k=map(int,input().split())
H=[int(i) for i in input().split()]
H.extend([0 for i in range(k+1)])

dp=[1e10 for i in range(n+1)]
dp.extend([0 for i in range(k+1)])
dp[0]=0

for i in range(n-1):
    for q in range(1,k+1):
        dp[i+q]=min(dp[i+q],dp[i]+abs(H[i+q]-H[i]))
   

print(dp[n-1])

Measured memory_bytes: 59744
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> d(n + 1);
  d[0] = 0;
  rep(i, n) {
    int l;
    cin >> l;
    d[i + 1] = d[i] + l;
  }
  int ans = lower_bound(d.begin(), d.end(), x + 1) - d.begin();
  cout << ans << endl;
  return 0;
}

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

#define ran 111

int n, k;
int a[ran];
int v[ran], lv;

int main() {
	scanf("%d%d", &n, &k);
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	
	int ans=0;
	for(int i=0;i<=k;i++)
	for(int j=0;i+j<=n && i+j<=k;j++)
	for(int dec = 0; dec<=i+j && i+j+dec<=k; dec++) {
		//printf("%d %d %d\n", i, j, dec);
		lv=0;
		for(int x=0;x<i;x++) v[lv++] = a[x];
		for(int x=0;x<j;x++) v[lv++] = a[n-x-1];
		sort(v, v+lv);
		int cur=0;
		for(int x=dec;x<lv;x++) cur+=v[x];
		//printf("%d\n", cur);
		ans = max(ans, cur);
	}
	printf("%d\n", ans);
	
	return 0;
}

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

using namespace std;



void solver() {
    int n; string s; cin >> n >> s;

    int w = 0;
    for(int i = 0; i < n; ++i)
        w += (s[i] == 'W');

    int ans = 0;

    for(int i = n - 1; i >= 0; --i) {
        if (w == 0) break;

        if (s[i] == 'R') {
            ++ans;
        }
        
        --w;
    }

    cout << ans << '\n';

}

int main() {

    ios_base :: sync_with_stdio(0); cin.tie(NULL);

    int t;
    //cin >> t;
    t = 1;

    while(t--)
        solver();

    return 0;
}

Measured memory_bytes: 3744
a,b = map(int,input().split())
s = input()
number = ('0','1','2','3','4','5','6','7','8','9')
if s[a] != '-':
        print('No')
        exit()
for i in range(a + b + 1):
        if i == a:
                i += 1
        if s[i] not in number:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
/*
#include <bits/stdc++.h>
//*/
//*
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
//*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
    const long long INF = LLONG_MAX / 10;
#else
    const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

int N, M, K;

signed main()
{
    cin >> N >> M >> K;

    for (int x=0; x<=N; x++) {
        for (int y=0; y<=M; y++) {
            if (x*M + y*N - 2*x*y == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

int n;
vi h;
int memo[100050];

int dp(int at){
    if(memo[at] != -1) return memo[at];
    if(at == n-1) return 0;
    int ans = dp(at + 1) + abs(h[at] - h[at + 1]);
    if (n - at - 1 > 1) ans = min(ans, dp(at + 2) + abs(h[at] - h[at + 2]));
    return memo[at] = ans;
}

int main(){
    cin >> n;
    h = vi(n);
    memset(memo, -1, sizeof(memo));
    for (int i = 0; i < n; ++i){
        cin >> h[i];
    }
    cout << dp(0) << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>

int main(){
  int n, t;  scanf("%d %d", &n, &t);
  long long int ans = 0;
  int pre, nex;
  scanf("%d", &pre);
  for(int i=1; i<n; i++){
    scanf("%d", &nex);
    if(nex - pre < t)
      ans += (nex - pre);
    else
      ans += t;
    pre = nex;
  }
  printf("%lld\n", ans+t);
  return 0;
}


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

int main(){
  int n ;
  cin >> n ;
  if(n%2 != 0)
    cout << "No" << endl ;
  else{
    string s ;
    cin >> s ;
    for(int i=0; i<n/2; i++){
      if(s.at(i) != s.at(i+n/2)){
        cout << "No" << endl ;
        return 0 ;
      }
    }
    cout << "Yes" << endl ;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<iomanip>
#define int long long
using namespace std;
double dp[3001][3001];
double func(double a[], int i, int x)
{
	if (x == 0)
	{
		return 1;
	}
	if (i == 0)
	{
		return 0;
	}
	if (dp[i][x] > -0.9)
	{
		return dp[i][x];
	}
	return dp[i][x] = a[i] * func(a, i - 1, x - 1) + (1 - a[i]) * (func(a, i - 1, x));
}
int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n;
	cin >> n;
	double a[n + 1];
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	memset(dp, -1, sizeof(dp));
	double ans = func(a, n, (n + 1) / 2);
	cout << fixed << setprecision(12) << ans << "\n";
}

Measured memory_bytes: 74344
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);
int main() {
    long double a, b;
    cin>>a>>b;
    cin>>N>>M;
    long double r1, r2;
    r1 = N * 30 + (long double)0.5 * M;
    r2 = 6 * M;
    long double d = abs(r1 - r2);
    cout<<fixed<<setprecision(10)<<sqrt(a * a + b * b - 2.0 * a * b * cos(d * M_PI / 180.0));
}

Measured memory_bytes: 4168