akhauriyash/Code-Regression huggingface dataset:
N, Q = map(int, input().split())
ss = '#' + input() + '#'
tds = [tuple(input().split()) for _ in range(Q)]

# 左端
iL = 0
for t, d in reversed(tds):
    if t == ss[iL] and d == 'R':
        iL -= 1
    if t == ss[iL+1] and d == 'L':
        iL += 1
    if iL == N:
        break

# 右端
iR = N+1
for t, d in reversed(tds):
    if t == ss[iR] and d == 'L':
        iR += 1
    if t == ss[iR-1] and d == 'R':
        iR -= 1
    if iR == 1:
        break

ans = N - min(N, iL+N+1-iR)
print(ans)


Measured memory_bytes: 17968
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=10050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	int t=0,x=0,y=0;
	for(int i=0;i<N;i++){
		int T,X,Y;
		cin>>T>>X>>Y;
		if(abs(X-x)+abs(Y-y)>T || (abs(T-t)%2)!=((abs(X-x)+abs(Y-y))%2)){
			cout<<"No"<<endl;
			return 0;
		}
		t=T;x=X;y=Y;
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<ll, int> ll_i;
struct edge { int v, w; };
const int INF = INT_MAX;
const int MOD = 1e9 + 114514;

int f(int x, vector<int>& X, vector<int>& d) {
	for (;;) {
		int i = upper_bound(X.begin(), X.end(), x) - X.begin() - 1;
		if (!d[i]) return x;
		int l = X[i], t = (x - l) / d[i] + 1;
		x -= t * d[i];
	}
}

int main() {
	int gomi, A, N, B;
	cin >> gomi >> A >> N >> B;
	vector<int> a(A);
	vector<char> c(A);
	rep(i, A) {
		string s;
		cin >> a[i] >> s;
		a[i]--;
		c[i] = s[0];
	}
	vector<int> X;
	X.pb(0);
	vector<int> d(N + 1);
	for (int i = 1; i < N + 1; i++) {
		int x; x--;
		cin >> x >> d[i], x--;
		if (d[i]) d[i] = x - d[i] + 1;
		X.pb(x);
	}
	X.pb(INF);
	vector<int> b(B);
	rep(i, B) cin >> b[i], b[i]--;
	rep(i, A) a[i] = f(a[i], X, d);
	rep(i, B) b[i] = f(b[i], X, d);
	rep(j, B) {
		char ans = '?';
		rep(i, A) if (a[i] == b[j]) ans = c[i];
		cout << ans;
	}
	cout << endl;
}

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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000007;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main(){
	int n;
	string s;
	string t;
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++) {
		bool isok = true;
		for (int j = i; j < n; j++) {
			if (s[j] != t[j - i])
				isok = false;
		}
		if (isok) {
			cout << i + n << endl;
			return 0;
		}

	}
	cout << n * 2 << endl;
	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;
using P = pair<int, int>;

const int ALP_NUM = 26;
const int INF = 1001001001;
const int TL = 1900;

int main() {
    int d;
    cin >> d;
    vector<int> C(ALP_NUM);
    rep(i, ALP_NUM) cin >> C[i];
    vector<vector<int>> S(d, vector<int>(ALP_NUM));
    rep(i, d) rep(j, ALP_NUM) cin >> S[i][j];
    vector<int> T;
    vector<set<int>> schedules(ALP_NUM);
    rep(i, ALP_NUM) schedules[i].insert(-1);

    auto get_score = [&](vector<int> A, int n) {
        int res = 0;
        vector<int> D(ALP_NUM, -1);
        n = min(d, n);
        rep(i, n) {
            int t = A[i];
            if (t >= 0) {
                res += S[i][t];
                D[t] = i;
            }
            rep(j, ALP_NUM) {
                res -= (i-D[j]) * C[j];
            }
        }
        return res;
    };

    auto change = [&](int nd, int nt) {
        int pt = T[nd];
        int res = S[nd][nt] - S[nd][pt];

        auto it_l = schedules[pt].lower_bound(nd);
        auto it_r = schedules[pt].upper_bound(nd);
        --it_l;
        int pt_ld = *it_l;
        int pt_rd;
        if (it_r != schedules[pt].end()) pt_rd = *it_r;
        else pt_rd = d;
        res -= C[pt] * (nd-pt_ld) * (pt_rd-nd);

        it_l = schedules[nt].lower_bound(nd);
        it_r = schedules[nt].upper_bound(nd);
        --it_l;
        int nt_ld = *it_l;
        int nt_rd;
        if (it_r != schedules[nt].end()) nt_rd = *it_r;
        else nt_rd = d;
        res += C[nt] * (nd-nt_ld) * (nt_rd-nd);

        return res;
    };


    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rand_alp(0, ALP_NUM-1);
    uniform_int_distribution<> rand_day(0, d-1);
    rep(i, d) {
        T.emplace_back(rand_alp(mt));
        schedules[T[i]].insert(i);
    }
    
    auto start = std::chrono::system_clock::now(); 
    auto end = std::chrono::system_clock::now();
    auto dur = end - start;
    auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
    
    while (msec < TL) {
        int nd = rand_day(mt);
        int nt = rand_alp(mt);
        int diff = change(nd, nt);
        if (diff > 0) {
            int old = T[nd];
            T[nd] = nt;
            schedules[old].erase(nd);
            schedules[nt].insert(nd);
        }
        end = std::chrono::system_clock::now();
        dur = end - start;
        msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
    }

    rep(i, d) {
        cout << T[i]+1 << endl;
    }

    //cout << get_score(T, d) << endl;

    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
    cin >> S;
    int N = S.size();
    int ans = S.size();
    for(int i=0;i<N-1;i++){
        if(S[i]!=S[i+1]){
            int t = max(i+1,N-(i+1));
            ans = min(ans,t);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
  
int main() {
    double n, k;
    int cnt = 0;
    cin >> n >> k;
    while(n > 1){
        cnt++;
        n = n/k;
    }
    if(n == 1 || cnt == 0){cnt++;}
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int k, n;
    cin >> k >> n;
    vector<int> as(n); cin >> as;
    as.push_back(k + as[0]);
    int maxi = 0;
    for(int i = 0; i < n; i++){
        maxi = max(maxi, as[i + 1] - as[i]);
    }
    cout << k - maxi << '\n';
}


Measured memory_bytes: 2424
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=3000 +117;
const int MM=3000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
string ans,tp;
int a[NN]={};
int b[NN]={};
string s;
bool vis[2*NN]={};
void update(string &s,string x){
	if(s<x)s=x;
}
void solve(int l,int r){
	tp.clear();
	if(a[l]<b[l]){
		string pre;
		int bef=-1;
		for(int i=l;i<=r;++i){
			if(a[i]>bef){
				pre+="ab";
				update(tp,pre+ans);
				bef=b[i];
			}
		}
	}
	else{
		int ll=min(a[l],b[l]);
		int rr=max(a[r],b[r]);
		for(int i=ll;i<=rr;++i)vis[i]=1;
		for(int i=l;i<=r;++i){
			string pre;
			for(int j=ll;j<=rr;++j){
				if(vis[j])pre+=s[j];
			}
			update(tp,pre+ans);
			vis[a[i]]=0,vis[b[i]]=0;
		}
	}
	update(ans,tp);
	//cerr<<ans<<endl;
}
int main(){
	//open();
	n=read();
	cin>>s;
	int ac=0,bc=0;
	for(int i=0;i<2*n;++i){
		if(s[i]=='a')a[++ac]=i;
		else b[++bc]=i;
	}
	a[0]=-1,b[0]=-1;
	int pos=n;
	int left=min(a[n],b[n]);
	for(int i=n-1;i>=0;--i){
		if(max(a[i],b[i])<left){
			solve(i+1,pos);
			pos=i;
			left=min(a[i],b[i]);
		}
		else{
			left=min(left,min(a[i],b[i]));
		}
	}
	cout<<ans<<endl;
	close();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int x = min(B, D) - max(A, C);
    if(x <= 0) cout << 0 << "\n";
    else cout << x << "\n";
    return 0;
}


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

typedef long long ll;

int main(){
  ll a,b,q;
  cin >> a >> b >> q;
  ll s[a+2],t[b+2],x[q];
  for(int i=1;i<a+1;i++){
    cin >> s[i];
  }
  for(int i=1;i<b+1;i++){
    cin >> t[i];
  }
  for(int i=0;i<q;i++){
    cin >> x[i];
  }
  s[0]=-1e15;
  s[a+1]=1e15;
  t[0]=-1e15;
  t[b+1]=1e15;
  for(int i=0;i<q;i++){
    ll ub=lower_bound(s,s+a+2,x[i])-s;
    ll lb=ub-1;
    ll ub_t=lower_bound(t,t+b+2,x[i])-t;
    ll lb_t=ub_t-1;
    
    ll ans=min({abs(s[lb]-x[i])+abs(t[lb_t]-s[lb]),abs(s[lb]-x[i])+abs(t[ub_t]-s[lb]),abs(s[ub]-x[i])+abs(t[lb_t]-s[ub]),abs(s[ub]-x[i])+abs(t[ub_t]-s[ub]),abs(t[lb_t]-x[i])+abs(s[lb]-t[lb_t]),abs(t[lb_t]-x[i])+abs(s[ub]-t[lb_t]),abs(t[ub_t]-x[i])+abs(s[lb]-t[ub_t]),abs(t[ub_t]-x[i])+abs(s[ub]-t[ub_t])});
    cout << ans << endl;
  }
}


Measured memory_bytes: 3712
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int[][] c = new int[3][3];
    c[0][0] = Integer.parseInt(sc.next());
    c[0][1] = Integer.parseInt(sc.next());
    c[0][2] = Integer.parseInt(sc.next());
    c[1][0] = Integer.parseInt(sc.next());
    c[1][1] = Integer.parseInt(sc.next());
    c[1][2] = Integer.parseInt(sc.next());
    c[2][0] = Integer.parseInt(sc.next());
    c[2][1] = Integer.parseInt(sc.next());
    c[2][2] = Integer.parseInt(sc.next());
    
    int[] a = new int[3];
    int[] b = new int[3];
    a[0] = 0;
    b[0] = c[0][0] - a[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    a[1] = c[1][1] - b[1];
    a[2] = c[2][1] - b[1];
    
    String ans = "Yes";
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        if(c[i][j] != a[i] + b[j]){
          ans = "No";
          break;
        }
      }
    }
    System.out.println(ans);
  }
}

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

long long INF = 1000000000000000000, MOD = 1000000007;

int main() {
	vector<long long> Fib;
	Fib.push_back(1), Fib.push_back(1);
	while (1) {
		Fib.push_back(Fib[Fib.size() - 2] + Fib[Fib.size() - 1]);
		if (Fib[Fib.size() - 1] > INF) {
			Fib.pop_back();
			break;
		}
	}
	vector<vector<pair<long long, long long> > > Pair(Fib.size());
	Pair[1].push_back({ 1, 2 });
	for (int i = 1; i < Fib.size() - 1; i++) {
		for (int j = 0; j < Pair[i].size(); j++) {
			Pair[i + 1].push_back({ Pair[i][j].second, Pair[i][j].first + Pair[i][j].second });
		}
		Pair[i + 1].push_back({ Pair[i][0].first + Pair[i][0].second, Pair[i][0].first + Pair[i][0].first + Pair[i][0].second });
	}
	int Q;
	cin >> Q;
	for (int q = 0; q < Q; q++) {
		long long X, Y;
		cin >> X >> Y;
		if (X > Y) swap(X, Y);
		if (X == 1 || Y == 2) {
			cout << 1 << ' ' << (X * Y) % MOD << endl;
			continue;
		}
		int A = -1;
		for (int i = 0; ; i++) {
			if (Fib[i] <= X && Fib[i + 1] <= Y) A++;
			else break;
		}
		cout << A << ' ';
		long long B = 0;
		for (int i = 0; i < A; i++) {
			long long P = Pair[A][i].first, Q = Pair[A][i].second;
			if (P <= X) B += (Y - Q + P) / P, B %= MOD;
			if (Q <= X) B += (X - Q + P) / P, B %= MOD;
		}
		cout << B << endl;
	}
}

Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, Q;
    cin >> N >> Q;
    ll a[N];
    rep(i, N) cin >> a[i];
    while(Q--){
        ll x;
        cin >> x;
        ll ans = 0, sum = 0; int pos = 0;
        rep(i, N){
            if(i > 0) sum -= a[i-1];
            while(pos < N && sum <= x) sum += a[pos++];
            if(sum <= x) pos = N+1;
            ans += pos-i-1;
        }
        cout << ans << endl;
    }
}


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

int main()
{
  int n;
  cin >> n;
  
  int l[n],r[n];
  rep(i,n) cin >> l[i] >> r[i];
  
  ll ans = 0;
  rep(i,n){
    ans += r[i] - l[i] + 1;
  }
  
  cout << ans << endl;
  
  
}

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

int main(void){
    int n = 0, m = 0;
    int ans = 0;

    scanf("%d%d", &n, &m);

    if(n > 1){
        ans = n * (n -1);
    }

    if(m > 1){
        ans += m * (m - 1);
    }

    printf("%d\n", ans/2);
    return 0;

} 


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

int main(){
  int n,cnt=0;
  cin >> n;
  for(int i=1;i<=n;i++){
  	string s;
    s = to_string(i);
    if(s.size()%2!=0){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.Collection;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FiveEverywhere solver = new FiveEverywhere();
        solver.solve(1, in, out);
        out.close();
    }

    static class FiveEverywhere {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            boolean[] prime = eratos(55_556);

            List<Integer> nums = new ArrayList<>();
            for (int i = 0; i < prime.length; i++) {
                if (prime[i] && i % 5 == 1) {
                    nums.add(i);
                }
                if (nums.size() == n) {
                    break;
                }
            }

            out.print(nums.stream().map(Object::toString).collect(Collectors.joining(" ")));

        }

        static boolean[] eratos(int n) {
            boolean[] results = new boolean[n + 1];
            Arrays.fill(results, true);

            results[0] = false;
            results[1] = false;

            for (int i = 2; i <= n; i++) {
                int j = i + i;
                while (j <= n) {
                    results[j] = false;
                    j = j + i;
                }
            }
            return results;
        }

    }
}



Measured memory_bytes: 36108
N,C = map(int,input().split())
D = [[int(i) for i in input().split()] for _ in range(C)]
c = [[int(i) for i in input().split()] for _ in range(N)]
modl = [[0 for i in range(C)] for i in range(3)]
for i in range(N):
    for j in range(N):
        modl[((i+1)+(j+1))%3][c[i][j]-1] += 1
ans = float('inf')
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i==j or i==k or j==k:
                continue
            total = 0
            for l in range(C):
                total += D[l][i]*modl[0][l]+D[l][j]*modl[1][l]+D[l][k]*modl[2][l]
            ans = min(ans,total)
print(ans)


Measured memory_bytes: 46812
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    dif = 0
    while True:
        if not x - dif in p:
            a = x - dif
            break
        elif not x + dif in p:
            a = x + dif
            break
        dif += 1
    print(a)

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

#define N 998244353

int main(){
    ll n;
    cin >> n;
    
    vector<ll> d(n);
    ll d_max = 0;
    rep(i,n){
        cin >> d.at(i);
        if(d_max<d.at(i)) d_max = d.at(i);
    }
    // count tree depth
    vector<ll> dep(d_max+1, 0);
    rep(i,n) dep.at(d.at(i))+=1;
    
    if(d.at(0)!=0 or dep.at(0)>1){
        cout << 0 << endl;
        return 0;
    }

    ll ans =1;
    for(ll i=1;i<n;i++){
        ans*=dep.at(d.at(i)-1);
        ans %= N;
    }
    cout << ans % N << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<random>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#define endl "\n"
#define fi first
#define se second
#define db double
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) (x & (-x))
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << endl
#define rep(i, a, b) for(__typeof(b) i = a; i <= (b); i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template<class T> inline T qmin(T a, T b) { return a < b ? a : b; }
template<class T> inline T qmax(T a, T b) { return a > b ? a : b; }
typedef long long ll;
typedef unsigned long long ull;
const db eps = 1e-9;
const db PI = acos(-1);
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)3e2 + 5;//remember to modify it, No RE or MLE
const ll INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;

ll qpow(ll x, ll y) { ll ret = 1; for( ; y; y >>= 1, x = (x * x) % mod) if(y & 1) ret = (ret * x) % mod; return ret; }

inline int read(){
	char ch = getchar();
	int x = 0, f = 1;
	while(ch < '0' || ch > '9'){
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9'){
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

int n;
db dp[305][305][305];

db dfs(int a, int b, int c){
	if(dp[a][b][c] >= 0) return dp[a][b][c];
	db t = a + b + c;
	db ret = n / t;
	if(a) ret += dfs(a - 1, b, c) * a / t;
	if(b) ret += dfs(a + 1, b - 1, c) * b / t;
	if(c) ret += dfs(a, b + 1, c - 1) * c / t;
	return dp[a][b][c] = ret;
}

int main()
{
	memset(dp, -1, sizeof dp);
	n = read();
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	dp[0][0][0] = 0;
	rep(i, 1, n){
		int x = read();
		if(x == 1) cnt1++;
		else if(x == 2) cnt2++;
		else cnt3++;
	}
	printf("%.10f\n", dfs(cnt1, cnt2, cnt3));
	return 0;
}

Measured memory_bytes: 222080
S = input()

if 0 < int(S[:2]) <= 12 and 0 < int(S[2:]) <= 12:
    print('AMBIGUOUS')
    exit()
elif 0 < int(S[:2]) <= 12:
    print('MMYY')
    exit()
elif 0 < int(S[2:]) <= 12:
    print('YYMM')
    exit()
else:
    print('NA')
    exit()


Measured memory_bytes: 9176
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
const long long mod = 1000000007;
//const long long mod = 998244353;
int gettop(int n) {
	while (n / 10) {
		n /= 10;
	}
	return n;
}
int main() {
	int N;
	scanf("%d", &N);
	long long res = 0;
	long long tb[100] = {};
	for (int i = 1; i <= N; i++) {
		tb[10 * gettop(i) + (i % 10)]++;
	}
	for (int i = 0; i < 100; i++) {
		res += tb[i] * tb[10 * (i % 10) + i / 10];
	}
	printf("%lld", res);
	return 0;
}

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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;

int main() {
  string S;
  cin >> S;
  int N = S.size();
  string str1, str2;
  for (int i = 0; i < N; ++i) {
    str1 += to_string(i % 2);
    str2 += to_string((i + 1) % 2);
  }
  int cnt1 = 0;
  int cnt2 = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] != str1[i]) cnt1++;
    if (S[i] != str2[i]) cnt2++;
  }
  cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <math.h>
int main(void) {
    int n, i;
    double data[1000], m, alpha;
 
    while (1) {
        scanf("%d ", &n);
        if (n == 0)
            break;
 
        for (m = 0.0, i = 0; i < n; i++) {
            scanf("%lf ", data+i);
            m += data[i];
        }
        m /= n;
        for (alpha = 0.0, i = 0; i < n; i++) {
            data[i] -= m;
            alpha += data[i] * data[i];
        }
        printf("%.4lf\n", sqrt(alpha / n));
    }
    return 0;
}


Measured memory_bytes: 2148
#include<cstdio>
#include<map>
using namespace std;int x[144],m,n,w,ch;int z[]={-12,-1,1,12};map<int,int>y;int func(int p,int d,int u){while(1){int h=x[p];if(h>=0){int s=0;x[p]=-1;w^=1<<h;if(u>12){for(int i=0;i<4;i++)s+=func(p+z[i],z[i],u-1);}else{int mi=h<<23|w;map<int,int>::iterator it=y.find(mi);if(it==y.end()){for(int i=0;i<4;i++)s+=func(p+z[i],z[i],u-1);y[mi]=s;}else{s=it->second;}}w|=1<<h;x[p]=h;return s;}if(h==-9)break;p+=d;}return 0;}int main(){int i,j,p,t;for(;scanf("%d%d",&m,&n),m;y.clear()){w=0;for(i=0;i<144;i++)x[i]=-9;for(i=1;i<=n;i++)for(j=1;j<=m;j++){p=i*12+j;scanf("%d",&t);switch(t){case 2:ch=p;case 0:x[p]=-1;break;case 1:y[w<<23]=0;x[p]=w++;break;}}for(i=0;i<4;){t=z[i++];for(j=ch;x[j+=t]!=-9;x[j]>=0?y[x[j]<<23]=1:0);}j=w;w=(1<<w)-1;t=0;for(i=-1;++i<4;)t+=func(ch+z[i],z[i],j);printf("%d\n",t);}}

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


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

    set<int> s;

    for(int i=0;i<n;i++){
        int d;
        cin >> d;
        s.insert(d);
    }

    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
cache = {}
def culc(n):
    if n == 0:
        c = 2
    elif n == 1:
        c = 1
    else:
        if n-1 not in cache:
            cache[n-1] = culc(n-1)
        a = cache[n-1]
        if n-2 not in cache:
            cache[n-2] = culc(n-2)
        b = cache[n-2]
        c = a + b
    return c

print(culc(N))

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

class UnionFind
{
    private int[]Par,Rank;
    public UnionFind(int max)
    {
        Par=new int[max];
        Rank=new int[max];
        for(int i=0;i<max;i++)
        {
            Par[i]=i;
        }
    }
    
    private int Find(int n)
    {
        if(Par[n]==n)
        {
            return n;
        }
        else
        {
            return Find(Par[n]);
        }
    }
    
    public bool Same(int a,int b)
    {
        return Find(a)==Find(b);
    }
    
    public void Union(int a,int b)
    {
        a=Find(a);
        b=Find(b);
        if(a==b)return;
        if(Rank[a]<Rank[b])
        {
            Par[a]=b;
        }
        else
        {
            Par[b]=a;
            if(Rank[a]==Rank[b])Rank[a]++;
        }
    }
}

class Program
{
    private int N,M;
    private UnionFind U;
    private void Scan()
    {
        var l=Console.ReadLine().Split(' ');
        N=int.Parse(l[0]);
        M=int.Parse(l[1]);
        U=new UnionFind(N+M);
        for(int i=0;i<N;i++)
        {
            l=Console.ReadLine().Split(' ');
            int k=int.Parse(l[0]);
            for(int j=1;j<=k;j++)
            {
                int lang=int.Parse(l[j])+N-1;
                U.Union(i,lang);
            }
        }
    }
    
    public void Solve()
    {
        Scan();
        for(int i=0;i<N-1;i++)
        {
            if(!U.Same(i,i+1))
            {
                Console.WriteLine("NO");
                return;
            }
        }
        Console.WriteLine("YES");
    } 
    
    static void Main()
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 23380
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int H, W, now[1005][1005];
const int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};
char A[1005][1005];
queue <Pii> que;

int main(){
  cin >> H >> W;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
      if (A[i][j] == '#') que.push(make_pair(i, j));
      else now[i][j] = -1;
    }
  }
  
  int ans = 0;
  while (!que.empty()){
    Pii Q = que.front(); que.pop();
    ans = max(ans, now[Q.first][Q.second]);

    for (int k = 0; k < 4; k++){
      int I = Q.first + di[k], J = Q.second + dj[k];

      if (0 <= I && I < H && 0 <= J && J < W){
        if (now[I][J] == -1){
          now[I][J] = now[Q.first][Q.second] + 1;
          que.push(make_pair(I, J));
        }
      }
    }
  }
  
  cout << ans << endl;


  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i<n;i++){
      cin >> a.at(i);
  }
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for(int i = 0; i < q; i++){
      cin >> b.at(i) >> c.at(i);
  }
  vector<int> d(1000000,0);
  unsigned long long s = 0;
  for(int i:a){
      d.at(i)++;
      s += i;
  }
  for(int i = 0;i < q;i++){
      s = s + d.at(b.at(i)) * (c.at(i) - b.at(i));
      cout << s << endl;
      d.at(c.at(i)) += d.at(b.at(i));
      d.at(b.at(i)) = 0;
  }

}

Measured memory_bytes: 8268
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;
const int maxn = 100 + 10;
int n, x, a[maxn];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> x;
	for (int i = 1; i <= n; i++)
		cin >> a[i], a[i] += a[i - 1];
	a[n + 1] = max(x + 1, a[n]);
	cout << upper_bound(a, a + n + 2, x) - a << '\n';
	return 0;
}


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

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

  vector<long long> x(N),y(N);
  for(int i = 0;i < N;i++) {
    cin >> x.at(i) >> y.at(i);
  }

  int ans = 10000;
  for(int i = 0;i < N;i++) {
    for(int j = 0;j < N;j++) {
      if(i == j) continue;
      long long p = x.at(j)-x.at(i),q = y.at(j)-y.at(i);
      int num = 0;
      for(int k = 0;k < N;k++) {
        for(int l = 0;l < N;l++) {
          if(k == l) continue;
          if(x.at(l)-x.at(k) == p && y.at(l)-y.at(k) == q) num++;
        }
      }
      ans = min(ans,N-num);
    }
  }
  
  if(N != 1) cout << ans << endl;
  else cout << 1 << endl;
}


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

int main(){
  string S;
  cin >> S;
  if(S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(2) != S.at(0)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>

#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000
using namespace std;

void C(){
  int N,K;
  cin >> N >> K;
  vector<int> torch(N);
  vector< pair<int,int> > left_right(N - K + 1);
  rep(i,N){
    cin >> torch[i];
  }
  int ans = INF;
  int temp;
  rep(i,N - K + 1){
    left_right[i].first = torch[i];
    left_right[i].second = torch[i + K - 1];
    temp = min(abs(left_right[i].first),abs(left_right[i].second)) + abs(left_right[i].first - left_right[i].second);
    temp < ans ? ans = temp: 1;
  }
  cout << ans << endl;
}

int main() {
  C();
}


Measured memory_bytes: 1024
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    k = int(input())
    from collections import deque
    que = deque(range(1, 10))
    for i in range(k):
        now = que.popleft()
        r = now%10
        nx = now*10
        if r == 0:
            for j in [0, 1]:
                que.append(nx+r+j)
        elif r == 9:
            for j in [-1, 0]:
                que.append(nx+r+j)
        else:
            for j in [-1, 0, 1]:
                que.append(nx+r+j)
    print(now)

if __name__ == '__main__':
    main()

Measured memory_bytes: 18952
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int ii = a; ii <= (b); ++ii) 
#define mREP(a,b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　　　 　 _... ..._
	　　　　　 , ´⌒ ⌒ヽ
	　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
	　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
	　　　　　　△ﾑ,8ﾑﾌつ
	　　　　　/(ﾝ_/＿ヽ＼
	　　　　 ～～i_ﾌ_ﾌ～´
	*/
	string a, b;
	cin >> a >> b;
	string sum;
	int n = a.length() + b.length() - 1;
	rep0(i, n) {
		if (i % 2 != 0) {
			sum += b.front();
			b.erase(0,1);
		}
		else {
			sum += a.front();
			a.erase(0,1);
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc081/tasks/arc086_a
"use strict";
function Main(input) {
  const params = input.trim().split("\n");
  const [N, K] = params[0].trim().split(" ").map(Number);
  const A = params[1].trim().split(" ").map(Number);
  const numTypes = Array(N + 1).fill(0);

  for (let i = 0; i < N; i++) {
    numTypes[A[i]] = numTypes[A[i]] + 1;
  }
  const filterd = numTypes.sort((a, b) => a - b).filter((a) => a);
  if (filterd.length <= K) {
    console.log(0);
    return;
  }

  let rewriteCount = 0;
  let change = filterd.length - K;

  for (let i = 0; i < change; i++) {
    rewriteCount += filterd[i];
  }
  console.log(rewriteCount);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 52924
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
#define what(x) cerr << #x << " is " << x << endl;
const int INF = 2147483647;

// 0-indexed RMQ segment tree
class SegTree {
  private:
    int n;
    vector<int> dat;

  public:
    SegTree(int n_) {
        n = 1;
        while (n < n_)
            n *= 2;
        dat = vector<int>(2 * n - 1, INF);
    }
    void update(int k, int a) {
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    // get min in [a, b)
    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r == -1)
            r = n;
        if (r <= a || b <= l)
            return INF;
        if (a <= l && r <= b)
            return dat[k];
        else {
            int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    SegTree seg(n);
    vector<int> com(q), x(q), y(q);
    for (int i = 0; i < q; ++i) {
        cin >> com[i] >> x[i] >> y[i];
    }
    for (int i = 0; i < q; ++i) {
        if (com[i] == 0) {
            seg.update(x[i], y[i]);
        } else {
            cout << seg.query(x[i], y[i] + 1) << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 4956
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£????????????
		Scanner sc = new Scanner(System.in);
		//a
		int a = sc.nextInt();
		//b
		int b = sc.nextInt();
		//c
		int c = sc.nextInt();
		//?????¶??? a < b < c????????°Yes
		if(a < b && b < c){
			System.out.println("Yes");
		}else{
			//????????§???????????°No
			System.out.println("No");
		}
		
	}
}

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

int main() {
    string S;
    cin >> S;
    if (S == "AAA" || S == "BBB") {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int a[110];

int main() {
	int n;
	cin >> n;
	
	for (int i = 1; i <= n; ++i) cin >> a[i];
	
	sort(a + 1, a + n + 1);
	
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			for (int k = j + 1; k <= n; ++k) {
				if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) {
					if (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]) cnt++;
				}
			}
		}
	}
	
	cout << cnt << '\n';
	
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main()
{
  unsigned short *A,*B;

  int C[VMAX+1];
  int n,i,j,x = 0,k;

  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);


  for(i = 1;i <= n;i++){
    scanf("%hu",&A[i]);
    if(x < A[i]) x = A[i];
  }

  k = x;

  for( i = 0;i <= k;i++)
    C[i] = 0;

     /* C[i] に i の出現数を記録する */
  for( j = 1 ; j <= n;j++)
    C[A[j]]++;

     /* C[i] に i 以下の数の出現数を記録する*/
  for (i = 1 ;i <= k;i++)
    C[i] = C[i] + C[i-1];

  for (j = n;j > 0;j--){
	      
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  printf("%u",B[1]);
  for(i = 2;i <= n;i++){
    printf(" %u",B[i]);
  }
  printf("\n");
  


  return 0;
}




Measured memory_bytes: 9552
import sys
def main():
    H,W,*B=sys.stdin.read().split()
    H,W=int(H),int(W)
    A=[]
    for b in B: A+=list(b)
    from collections import Counter
    C=Counter(A)
    a4,a2,a1=0,0,0
    for v in C.values():
        d,m=divmod(v,4)
        a4+=d
        d,m=divmod(v,2)
        a2+=d
        a1+=m
    if a4 * 4 >= (H-(H&1))*(W-(W&1)) and a1 <= H&W&1:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()



Measured memory_bytes: 39280
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int p[15],c[15];
long long g;
int main(){
	int d;
	cin>>d>>g;
	for(int i=0;i<d;i++)cin>>p[i]>>c[i];
	int ans=1e9+5;
	for(int i=0;i<1024;i++){
		int sum=0;
		long long tot=0;
		for(int j=0;j<d;j++){
			if(((1<<j)&i)>0){
				tot+=p[j]*100*(j+1);
				tot+=c[j];
				sum+=p[j];
			}
		}
		if(tot>=g){
			ans=min(ans,sum);
			continue;
		}
		bool f=false;
		for(int j=d-1;j>=0;j--){
			if(f)break;
			if(((1<<j)&i)==0){
				for(int k=0;k<p[j];k++){
					tot+=100*(j+1);
					sum++;
					if(tot>=g){
						f=true;
						break;
					}
				}
				if(!f){
					tot+=c[j];
					if(tot>=g)f=true;
				}
			}
		}
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
}

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

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  ll res = -INF;
  for (int a = 0; a <= min(n, k); a++) {
    for (int b = 0; a + b <= min(n, k); b++) {
      ll sum = 0;
      priority_queue<int, vector<int>, greater<int>> left;
      rep(i, a) {
        sum += v[i];
        left.push(v[i]);
      }
      rep(i, b) {
        sum += v[n - i - 1];
        left.push(v[n - i - 1]);
      }
      int remove_num = k - a - b;
      while (!left.empty() and remove_num > 0) {
        ll temp = left.top();
        left.pop();
        if (temp > 0) break;
        sum -= temp;
        remove_num--;
      }
      chmax(res, sum);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll N;
cin>>N;
ll ans=1;
while(ans<=N) {
  ans*=2;
}
ans/=2;
cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int A[15],n,m,q,a[55],b[55],c[55],d[55],res,ans;
int main(){
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	for(int i=1;i<=n;i++)
		A[i]=1;
	while(!A[0]){
		int res=0;
		for(int i=1;i<=q;i++){
			if(A[b[i]]-A[a[i]]==c[i]) res+=d[i];
		}
		ans=max(res,ans);
		for(int i=n;i>=0;i--){
			if(A[i]<m){
				A[i]++;
				for(int j=i+1;j<=n;j++)
					A[j]=A[i];
				break;
			}
		}		
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll f[1001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x1,x2;
    cin>>n;
    int nr=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x1>>x2;
        if(x1==x2)
            nr++;
        if(x1!=x2||i==n)
        {
            if(nr>=3)
            {
                cout<<"Yes";
                return 0;
            }
            nr=0;
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3628
n,m,x=map(int,input().split())
A=[]
for _ in range(n):
  A.append(list(map(int,input().split()))) 
yeen=[]  
for i in range(2**n):
  rikai=[0]*m
  yen=0
  for j in range(n):
    if ((i>>j)&1):
      yen+=A[j][0]
      for w in range(1,m+1):
        rikai[w-1]+=A[j][w]
    if min(rikai)>=x:
      yeen.append(yen)
if yeen==[]:
  print(-1)
else:
  print(min(yeen))     

Measured memory_bytes: 9804
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll N, M;
    cin >> N >> M;
    ll use[10]={};
    ll cost[10]={0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    ll i, j;
    
    for(i=1; i<=M; i++) {
        ll a;
        cin >> a;
        use[a]=1;
    }
    
    string dp[11111];
    for(i=0; i<=N; i++) dp[i]="";
    
    for(i=1; i<10; i++)
        if(use[i]) dp[cost[i]]=(char)(i+'0');
    
    for(i=0; i<=N; i++) {
        if(dp[i]=="") continue;
        for(j=1; j<10; j++) {
            if(use[j]==0) continue;
            if(i+cost[j]>N) continue;
            string s=dp[i]+(char)(j+'0');
            if(dp[i+cost[j]].size()<dp[i].size()+1) dp[i+cost[j]]=s;
            else if(dp[i+cost[j]]<s) dp[i+cost[j]]=s;
        }
    }
    
    pt(dp[N]);
}





Measured memory_bytes: 43648
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string ans = "";
    ll n;
    cin >> n;
    n--;
    while(n>=0){
        ans.push_back((char)(n%26 +'a'));
        n/=26;
        n--;
    }
    for(int i=ans.size()-1;i>=0;i--)cout << ans[i];
    cout << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

long d[kMax5][13];

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

  int n;
  cin >> n;

  int ans = 0;
  if (n <= 9) ans = n;
  else if (n <= 99) ans = 9;
  else if (n <= 999) ans = (n / 100 - 1) * 100 + n % 100 + 1 + 9;
  else if (n <= 9999) ans = 909;
  else if (n <= 99999) ans = (n / 10000 - 1) * 10000 + n % 10000 + 1 + 909;
  else ans = 90909;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {
  val Array(n, a, b) = readLine().split(" ").map(_.toInt)

  var sum = (1 to n).foldLeft(0)((acc, i) => {
    val sumOfDigits = i.toString.split("").tail.map(_.toInt).sum
    if (a <= sumOfDigits && sumOfDigits <= b) acc + i
    else acc
  })

  println(sum)
}

Measured memory_bytes: 41384
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (size_t i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (size_t k = 1; k < v.size(); k++)
	{
		for (size_t j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

int main()
{
	int n, m;
	cin >> n >> m;
	int l = -1, r = INT_MAX;
	rep(i, m)
	{
		int tmp_l, tmp_r;
		cin >> tmp_l >> tmp_r;
		l = max(l, tmp_l);
		r = min(r, tmp_r);
	}
	cout << max(min(r, n) - l + 1, 0) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A;
  cin >> N >> A;
  int S;
  S = N % 500;
  if (A < S) {
    cout << "No" <<endl;
  } 
  else if (A >= S) {
    cout << "Yes" <<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n;
    cin >> n;
    ll ans = 1;
    vector<ll>t(n);
    rep(i,n){
        cin >> t[i];
        ans = ans/__gcd(ans,t[i]) * t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256