akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	if(s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
	} else if (s.size() < 26) {
		map <char, int> cnt;
		for(auto i : s) {
			cnt[i] += 1;
		}
		for(char i = 'a'; i <= 'z'; i++) {
			if(cnt[i] == 0) {
				s += i;
				break;
			} 
		}
		cout << s << endl;
	} else {
		int opt = -1;
		for(int i = 25; i >= 1; i--) {
			if(s[i-1] < s[i]) {
				opt = i-1;
				break;
			}
		}
		char good = 'z';
		for(int i = opt + 1; i < 26; i++) {
			if(s[i] > s[opt]) good = min(good, s[i]);
		}
		s[opt] = good;
		for(int i = 0; i <= opt; i++) {
			cout << s[i];
		}
		cout << endl;
	}
	return 0;
}
/*
abcdefghijklmnopqrstuvwzyx
abcdefghijklmnopqrstuvx
*/

Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    A = list(map(int, input().split()))

    ret = 0
    for i in range(1,N):
        if A[i]==A[i-1]:
            ret+=1
            A[i]=1000

    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

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

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}


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

int main(){
    int r,c,i,j;
    cin >> r >> c;
    int excel[101][101]={0};

    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            cin >> excel[i][j];
            //全体の合計を計算
            excel[r][c] += excel[i][j];

            //r+1番目の行列を計算
            excel[r][j] += excel[i][j];
            
            //c+1番目の行列を計算
            excel[i][c] += excel[i][j];
        }
    }
    for(i=0;i<=r;i++){
        for(j=0;j<=c;j++){
            //空白の作り方。前？後？
            cout << excel[i][j];
            if (j != c){
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
    int a[5];
    int add = 0;
    for(int i = 0; i < 5; i++) {
        cin >> a[i];
        if(a[i] <= 40) {
            a[i] = 40;
        }
        add += a[i];
    }
    cout << add / 5 << endl;
    return 0;
}


Measured memory_bytes: 3092
def main():
    _ = int(input())
    *A, = map(int, input().split())
    A += [0]

    money = 1000
    stock = 0
    for a, b in zip(A, A[1:]):
        money += stock * a
        stock = 0
        if a < b:
            buy, rest = divmod(money, a)
            stock = buy
            money = rest
    print(money)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int main(){
    	ll h,w,c[10][10],cnt=0;
    	cin>>h>>w;
    	for(int i=0; i<10;i++)for(int j=0; j<10; j++)cin>>c[i][j];
    	for(int j=0; j<=9; j++){
    		for(int k=0; k<=9; k++){
    			for(int p=0; p<=9; p++){
    				c[k][p]=min(c[k][p],c[k][j]+c[j][p]);
    			}
    		}
    	}
    	
    	for(int i=0; i<h; i++){
    		for(int j=0; j<w; j++){
    			int t;
    			cin>>t;
    			if(t!=-1)cnt+=c[t][1];
    		}
    	}
    	cout<<cnt<<endl;
    }


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
const int maxn = 100010;
char s[maxn], t[maxn];
void solve() {
	scanf("%s%s", s, t);
	strcat(t, s);
	printf("%s\n", t);
}
int main() {

	solve();

	return 0;
}

Measured memory_bytes: 128
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

class SegmentTree():
    def __init__(self, init_val, N):
        """
        Parameters
        ----------
        init_val:int
            identity element
        N:int
            the number of nodes
        """
        self.init_val=init_val
        # Range Minimum Query
        self.N0 = 2**(N-1).bit_length()
        # 0-indexedで管理
        self.data = [self.init_val] * (2 * self.N0)

    def _segfunc(self, left, right):
        res= left | right
        return res

    def update(self,k, x):
        """
        Parameters
        ----------
        k:int
            target index(0-index)
        x:any
            target value
        """
        k += self.N0-1
        self.data[k] = x
        while k > 0:
            k = (k - 1) // 2
            self.data[k] = self._segfunc(self.data[2*k+1], self.data[2*k+2])

    def query(self, l, r):
        """
        Parameters
        ----------
        l,r:int
            target range [l,r)

        Return
        ----------
        res:any
            val
        """
        L = l + self.N0
        R = r + self.N0
        s = self.init_val
        while L < R:
            if R & 1:
                R -= 1
                s = self._segfunc(s, self.data[R-1])
    
            if L & 1:
                s = self._segfunc(s,self.data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

n=inp()
s=input()
st = SegmentTree(0,n)
for i in range(n):
    st.update(i,1<<(int.from_bytes(s[i].encode(),'little')-int.from_bytes('a'.encode(),'little')))
q = inp()
ans = []
for i in range(q):
    mode, first, second = input().split()
    if mode == "1":
        st.update(int(first)-1,1<<(int.from_bytes(second.encode(),'little')-int.from_bytes('a'.encode(),'little')))
    else:
        ans.append(bin(st.query(int(first) - 1, int(second))).count("1"))
for i in ans:
    print(i)


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

const int N = 100 * 1000 + 5;
long long ans;

int a[5][N];
int mark[N];

set <pair <int, int> > s[5][5];
void chng(int x, int c) {
	int pc = mark[x];
	for (int i = 1; i <= 3; i++) {
		s[pc][i].erase({a[pc][x] - a[i][x], x});
	}
	ans -= a[pc][x];
	ans += a[c][x];
	mark[x] = c;
	for (int i = 1; i <= 3; i++) {
		s[c][i].insert({a[c][x] - a[i][x], x});
	}
}
int main() {
	ios :: sync_with_stdio(false);
	int x, y, z;
	cin >> x >> y >> z;
	int n = x + y + z;
	for (int i = 1; i <= x; i++) {
		cin >> a[1][i] >> a[2][i] >> a[3][i];
		s[1][2].insert({a[1][i] - a[2][i], i});
		s[1][3].insert({a[1][i] - a[3][i], i});
		mark[i] = 1;
		ans += a[1][i];
	}
	for (int i = x + 1; i <= x + y; i++) {
		cin >> a[1][i] >> a[2][i] >> a[3][i];
		s[2][1].insert({a[2][i] - a[1][i], i});
		s[2][3].insert({a[2][i] - a[3][i], i});
		mark[i] = 2;
		ans += a[2][i];
	}
	for (int i = x + y + 1; i <= n; i++) {
		cin >> a[1][i] >> a[2][i] >> a[3][i];
		s[3][1].insert({a[3][i] - a[1][i], i});
		s[3][2].insert({a[3][i] - a[2][i], i});
		mark[i] = 3;
		ans += a[3][i];
	}
	while (true) {
//		cout << "73 " << ans << endl;
		bool b = false;
		for (int i = 1; i <= 3; i++) {
			for (int j = 1; j < 3; j++) {
				pair <int, int> p1 = *s[i][j].begin(), p2 = *s[j][i].begin();
				if (p1.first + p2.first < 0) {
					chng(p1.second, j);
					chng(p2.second, i);
					b = true;
				//	continue;
				}
			}
		}
		pair <int, int> p1 = *s[1][2].begin(), p2 = *s[2][3].begin(), p3 = *s[3][1].begin();
		if (p1.first + p2.first + p3.first < 0) {
			chng(p1.second, 2);
			chng(p2.second, 3);
			chng(p3.second, 1);
			b = true;
		}
		p1 = *s[1][3].begin(), p2 = *s[2][1].begin(), p3 = *s[3][2].begin();
		if (p1.first + p2.first + p3.first < 0) {
			chng(p1.second, 3);
			chng(p2.second, 1);
			chng(p3.second, 2);
			b = true;
		}
		if (!b) {
			break;
		}
	}
//	for (int i = 1; i <= n; i++) {
//		cout << "49 " << mark[i] << endl;
//	}
	cout << ans << endl;
	return 0;
}


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

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

    reverse(N.begin(), N.end());

    vector<vector<int64_t>> dp(N.length() + 1, vector<int64_t>(2, INT_MAX));
    dp.at(0).at(0) = 0;
    dp.at(0).at(1) = INT_MAX;
    for (int i = 0; i < N.length(); i++)
    {
        char c = N.at(i) - '0';
        dp.at(i + 1).at(0) = min(dp.at(i).at(0) + c, dp.at(i).at(1) + c);
        dp.at(i + 1).at(1) = min(dp.at(i).at(0) + (10 - c) + 1, dp.at(i).at(1) + (9 - c));
    }
    cout << min(dp.at(N.length()).at(0), dp.at(N.length()).at(1)) << endl;
}

Measured memory_bytes: 55940
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Foldable
import Data.Char
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [n,x,y] <- r'
    let v = map (f x y) [(i,j) | i<-[1..n-1], j<-[i+1..n] ]
    let mp = IM.fromListWith (+) (zip v (repeat 1))
    let mp' = foldr (\k m -> IM.insertWith (flip const) k 0 m) mp [1..n-1] 
    forM_ (IM.toAscList mp') (\(_,a)->print a)


f :: Int -> Int -> (Int,Int) -> Int
f x y (i,j) = minimum [d i j, d i x + 1 + d y j, d i y + 1 + d x j]


d i j = abs (i-j)




Measured memory_bytes: 2428
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
 
signed main(){
 
	lli n;
	cin>>n;

	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	lli ans=(a[0]-1);
	lli now=2;
	REP(i,1,n){
		//if(now>=a[i])continue;
		if(DEBUG)cout<<"i="<<i<<"ans[i]="<<ans<<"now="<<now<<endl;
		if(now>a[i])continue;
		if(now==a[i]){
			now = a[i]+1;
			continue;
		}
		if(a[i]%now==0){
			a[i] -= (now+1);
			ans ++ ;
		}
		ans += (a[i]-1)/now;
	}
	cout<<ans<<endl;

	return 0;
 
}

Measured memory_bytes: 1024
import numpy as np

def factor(N):
    ans = []
    for i in range(1,int(np.sqrt(N))+1):
        if N%i == 0:
            ans.append(i)
            if N//i != i:
                ans.append(N//i)
    return ans

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a, b):
    return (a * b)//gcd(a,b)

N,M = map(int,input().split())
p = factor(M)

p.sort()

for i in reversed(range(len(p))):
    if p[i] <= M/N:
        print(p[i])
        break

Measured memory_bytes: 20888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    vector<int> a(3);
    rep(i, 3) cin >> a[i];

    sort(rALL(a));
    cout << a[0] * 10 + a[1] + a[2] << endl;
}

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

ll modpower(ll a, ll r, ll mod){ //a^r
    ll x = 1;
    a %= mod;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

int main() {
    ll mod = 998244353;
    int N;
    string S;
    cin >> N;
    cin >> S;
    vector<ll> div;
    for (int i = 1; i <= N*2; i++) {
        if (2*N%i == 0 && N%i != 0) {
            div.push_back(i);
        }
    }
    map<ll, ll> mp;
    for (ll d : div) {
        ll x = 0;
        for (int i = 0; i < d/2; i++) {
            x *= 2;
            if (S[i] == '1') x += 1;
            x %= mod;
        }
        x++;
        bool check = true;
        for (int i = d/2; i < N; i++) {
            int period = i/(d/2);
            int digit = (int)(S[i%(d/2)] - '0');
            if (period%2 == 1) digit = 1-digit;
            if (digit < (int)(S[i]-'0')) {
                break;
            }else if (digit > (int)(S[i]-'0')) {
                check = false;
                break;
            }
        }
        if (!check) x--;
        mp[d] += x;
        for (int i = d*2; i <= N*2; i += d) {
            mp[i] += mod-mp[d];
            mp[i] %= mod;
        }
    }
    ll ans = 0;
    for (ll d : div) {
        ans += mp[d] * d % mod;
    }
    cout << (ans%mod+mod)%mod << endl;
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n, k;
    cin >> n >> k;
    vi h(n);
    rep(i, n){
        cin >> h[i];
    }

    sort(all(h));

    ll ans = 0;
    rep(i, n-k){
        ans += h[i];
    }

    cout << ans << endl;

    return 0;
}



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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T &t, const U &u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T &t, const U &u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = 0;
    V<ll> X(N);
    rep(i, N) cin >> X[i];
    for (int i = 1; i < N; ++i) {
        ans += min(B, A * (X[i] - X[i - 1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define inf 0x3f3f3f3f
#define mp pair<int, int>
#define MOD (ll)(1e9+7)
#define M(x) ((x+MOD)%MOD)
#define MAX 3010
#define eps 1e-8


int main()
{
	fast;
	ll s;
	cin >> s;
	ll num = sqrt(s);
	if (num*num == s)
		cout << "0 0 " << num << " 0 0 " << num << endl;
	else if(s<=1e9)
		cout << "0 0 1 0 0 " << s << endl;
	else
	{
		ll y2 = (ll)1e9 - s % (ll)1e9;
		ll x2 = (ll)1e9, x3  = 1;
		ll y3 = s / (ll)1e9 + 1;
		cout << "0 0 " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

void sort(int a[], int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < i; j++)
		{
			if (a[i] < a[j])
			{
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
}

int main()
{
	
	int task[3] = { 0,0,0 };

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

	sort(task, 3);

	int ans = (task[1] - task[0]) + (task[2] - task[1]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int n;
int am[100],bm[100];
int ax[100],ay[100],bx[100],by[100];
vector<int> adj[100];
int vis[100];

bool dfs(int a) {
	if(vis[a]) return false;
	vis[a]=1;
	for(auto &b:adj[a]) if(bm[b] == -1 || dfs(bm[b])) {
		am[a]=b;
		bm[b]=a;
		return true;
	}
	return false;
}
int match() {
	int tf=0;
	fill(am,am+n,-1);
	fill(bm,bm+n,-1);
	for(int i=0;i<n;i++) {
		fill(vis,vis+n,0);
		if(dfs(i)) tf++;
	}
	return tf;
}
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d%d",ax+i,ay+i);
	for(int i=0;i<n;i++) scanf("%d%d",bx+i,by+i);
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(ax[i]<bx[j] && ay[i]<by[j]) {
		adj[i].push_back(j);
	}

	printf("%d\n",match());
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 998244353

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long bipow(long long n, long long m) {
    if (m == 0) return 1;
    if (m % 2 == 0) {
        n = (n * n) % MOD;
        return bipow(n, m / 2) % MOD;
    } else
        return (n * bipow(n, m - 1)) % MOD;
}

long long dp[3333][3333];

void add(long long &x, long long y){
    x = (x + y) % MOD;
}

int main(){
    long long N, S;
    cin >> N >> S;
    vector<long long> A(N);
    long long inv2 = bipow(2, MOD-2);

    REP(i, N) cin >> A[i];
    dp[0][0] = bipow(2, N);
    for(long long i=0; i<N; i++){
        for(long long j=0; j<=S; j++)
            dp[i+1][j] = dp[i][j];
        for(long long j=0; j<=S; j++){
            if(j+A[i] > S) continue;
            add(dp[i+1][j+A[i]], (dp[i][j] * inv2) % MOD);
        }
    }
    long long ans = dp[N][S];
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, Q;
std::string S;
int ks[80];
std::vector<int> Ds;
ll cnt[80];
ll A[1000100], B[1000100], C[1000100];

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

    std::cin >> N >> S >> Q;
    for(int i=0;i<Q;++i){
        std::cin >> ks[i];
    }

    ll a = 0, b = 0, c = 0;
    for(int i=0;i<N;++i){
        if(S[i] == 'D'){
            c += 1;
        }else if(S[i] == 'M'){
            a += c;
            b += 1;
        }
        
        A[i] = a; B[i] = b; C[i] = c;

        if(S[i] == 'C'){
            for(int j=0;j<Q;++j){
                int s = std::max(i - ks[j] + 1, 0),
                    t = i;
                cnt[j] += (A[t] - (s > 0 ? A[s - 1] : 0)) - (B[t] - (s > 0 ? B[s - 1] : 0)) * (s > 0 ? C[s - 1] : 0);
            }
        }
    }

    // for(int i=0;i<N;++i){
    //     std::cout << A[i] << ", " << B[i] << ", " << C[i] << std::endl;
    // }
    
    for(int i=0;i<Q;++i){
        std::cout << cnt[i] << std::endl;
    }
}


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

int n, a[100010];

int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sum ^= a[i];
    a[i] ^= a[i] - 1;
  }
  sort(a, a + n, greater<int>());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if ((sum ^ a[i]) < sum)
      sum ^= a[i], ans++;
  }
  printf("%d\n", sum == 0 ? ans : -1);
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  long double A;
  long double B;
  cin >> A >> B;
  /*
  int tmp = (int) B / 1;
  printf("%d\n", tmp);
  double tmp1 = B - tmp;
  printf("%lf\n", tmp1);
  // double tmp = A * B;
  ll ans = A * tmp;
  printf("%lld\n", ans);
  ll tmp2 = A * tmp1;
  printf("%lld\n", tmp2);
  ans += tmp2;
  printf("%lld\n", ans);
  */
  long double tmp = A * B;
  // long double ans = tmp;
  ll ans = tmp;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3732
class in{struct It{int it;const bool rev;explicit constexpr It(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(It& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const It i,n;public:explicit constexpr in(int n):i(0),n(n<0?0:n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const It& begin(){return i;}const It& end(){return n;}};

#include <bits/stdc++.h>
using namespace std;

using P = complex<double>;
const double EPS = 1.0e-11, INF = 1.0e12;


bool ok(const vector<vector<double>>& dist, int ln, double maxDist) { // adj: [0,ln)->inL [ln,n)->inR
    int n = dist.size();
    vector<bool> used(n);
    vector<int> matchTo(n, -1);
    function<bool(int)> dfs = [&](int v) {
        int l = (v >= ln ? 0 : ln);
        int r = (v >= ln ? ln : n);
        for(int nv : in(l, r)) {
            if(v == nv || used[nv]) continue;
            if(dist[v][nv] >= (maxDist + EPS)) continue;
            used[nv] = true;
            if(matchTo[nv] < 0 || dfs(matchTo[nv])) {
                matchTo[v] = nv;
                matchTo[nv] = v;
                return true;
            }
        }
        return false;
    };
    int ans = 0;
    for(int v : in(ln)) if(matchTo[v] < 0) {
        used.assign(n, false);
        if(dfs(v)) ++ans;
    }
//    cout << maxDist << ' ' << ans << endl;
    return ans == min(ln, (n - ln));
}

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

    int n, m;
    while(cin >> n >> m && n) {
        vector<P> ca(n);
        vector<double> v(n);
        for(int i : in(n)) {
            double a, b;
            cin >> a >> b >> v[i];
            ca[i] = P(a, b);        
        }
        vector<vector<double>> dist(n + m, vector<double>(n + m, INF));
        for(int j_ : in(m)) {
            int j = j_ + n;
            double a, b;
            cin >> a >> b;
            P tmp(a, b);
            for(int i : in(n)) {
                double d = abs(ca[i] - tmp);
                dist[i][j] = dist[j][i] = d / v[i];
            }
        }
        
        double l = 0.0, r = 1.0e5;  // (l, r]
        while(fabs(r - l) >= EPS) {
            double mid = (r + l) / 2.0;
            (ok(dist, n, mid) ? r : l) = mid;
        }
        cout << fixed << setprecision(11) << r << endl;
    }
    return 0;
}

Measured memory_bytes: 3472
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int N, K;
LL a[1111];
unordered_set<LL> se;

int main(void) {
    cin >> N >> K;
    REP(i, N) cin >> a[i];
    REP(i, N) {
        LL sum = 0;
        FOR(j, i, N) {
            sum += a[j];
            se.emplace(sum);
        }
    }
    LL ans = 0;
    RREP(i, 62) {
        unordered_set<LL> nse;
        FORE(e, se) {
            if (e & (1LL << i)) {
                nse.emplace(e);
            }
        }
        if (nse.size() >= K) {
            se = nse;
            ans |= (1LL << i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 25460
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long LL;
const int INF = int(1e9);

int main()
{
    int N,M;
    cin>>N>>M;
    if(M<N)
    {
        cout<<(M*2-N)<<endl;
    }
    else
        cout<<(M*2-N)<<endl;

   return 0;
}


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

int main() {
    ll n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q);
    for (int i = 0; i < q; i++) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> p(n, k);
    for(int i = 0; i < q; i++) {
        p[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
        bool win = p[i] > q;
        string out = win ? "Yes" : "No";
        cout << out << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

N,M = LI()
AB = [LI() for _ in range(M)]

ans = 0

par = [0]*N
# rank = [0]*N

def init(n):
    for i in range(n):
        # 親のID or 属する頂点の数
        par[i]=-1
        # rank[i] = 0

# rootを返す
def find(x):
    # 根
    if par[x] < 0:
        return x
    # 節の親
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    if (x==y):
        return
    if (par[x] > par[y]):
        x,y = y,x
    # rootの頂点数を結合
    par[x] += par[y]
    # yの親をxに
    par[y] = x
    return

    # if (rank[x]<rank[y]):
    #     par[x]=y
    # else:
    #     par[y]=x
    #     if rank[x] == rank[y]:
    #         rank[x] += 1

def same(x,y):
    return find(x)==find(y)

def size(x):
    return -par[find(x)]

init(N)

for r in AB:
    f = r[0]-1
    t = r[1]-1
    unite(f,t)
    # print(par)

for i in range(N):
    # print(size(i))
    ans = max(ans,size(i))

print(ans)

Measured memory_bytes: 108188
import sys


fin = sys.stdin.readline
N = int(fin())
H_list = [int(elem) for elem in fin().split()]
cur_max = H_list[0]
for h in H_list[1:]:
    if cur_max - h > 1:
        print("No")
        exit(0)
    cur_max = max(cur_max, h)
print("Yes")


Measured memory_bytes: 59632
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

"""
Considering mod K, we may assume K = 1.
Thus we first consider this case.
"""
def func(hand):
    if hand == "r":
        return P
    elif hand == "s":
        return R
    elif hand == "p":
        return S
    else:
        return 0

def maxValue(lst):
    l = len(lst)
    score = 0
    prev = None
    repeat = 0

    for hand in lst:
        if prev != hand:
            if repeat % 2 == 1:
                score += func(prev) * (repeat + 1) // 2
            else:
                score += func(prev) * (repeat // 2 + 1)
            prev = hand
            repeat = 0
        else:
            repeat += 1
    if repeat % 2 == 1:
        score += func(lst[-1]) * (repeat + 1) // 2
    else:
        score += func(lst[-1]) * (repeat // 2 + 1)

    return score


ans = 0
for i in range(K):
    lst = []
    l = (N - 1 - i) // K
    for j in range(l + 1):
        lst.append(T[i + j * K])
    val = maxValue(lst)
    #print("list={}, value={}".format(lst, val))
    ans += val

print(ans)


Measured memory_bytes: 56944
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int dp[3100][3100] = {0};

int main()
{
  string s,t;
  cin >> s >> t;
  rep(i,s.size())
  {
    rep(j,t.size())
    {
      if(s[i]==t[j]) chmax(dp[i+1][j+1],dp[i][j]+1);
      chmax(dp[i+1][j+1],dp[i+1][j]);
      chmax(dp[i+1][j+1],dp[i][j+1]);
    }
  }
  string res = "";
  int i = s.size();
  int j = t.size();
  while(i>0&&j>0)
  {
    if(dp[i][j]==dp[i-1][j]) i--;
    else if(dp[i][j]==dp[i][j-1]) j--;
    else{
      res = s[i-1] + res;
      i--;
      j--; 
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 39824
//
// !!!WARNING!!!
// AUTO SUBMITTION TEST ALERT
// !!!WARNING!!!
//

#include <stdio.h>

#define MAX(x, y) ((x)>=(y) ? (x):(y))
#define MIN(x, y) ((x)<=(y) ? (x):(y))

int main(int argc, char **argv) {
    int n;
    scanf("%d", &n);
    // init sufficiently small value
    int ans = -1 << 30;
    // minr: minimum rate
    int minr;
    scanf("%d", &minr);
    for(int i = 1; i < n; ++i) {
        int r;
        scanf("%d", &r);
        ans = MAX(ans, r - minr);
        minr = MIN(minr, r);
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 2140
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n,T,cas=0;
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC";
    else cout<<"ABC";
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
				
int32_t main() {
	fast_cin();  
	int n; cin >> n;
	int k, q; cin >> k >> q;
	vector<int> a(n);
	for (int &i : a) {
		cin >> i;
	}
	int ans = 1e9 + 7;
	for (int bound : a) {
		vector<int> final;
		for (int i = 0, j = 0; i < n; i = j) {
			if (a[i] < bound) {
				++j;
				continue;
			}
			vector<int> temp;
			while (j < n && a[j] >= bound) {
				temp.push_back(a[j]);
				++j;
			}
			if (temp.size() >= k) {
				sort(temp.begin(), temp.end());
				for (int l = 0; l < (int)temp.size() - k + 1; ++l) {
					final.push_back(temp[l]);
				}
			}
		}
		sort(final.begin(), final.end());
		if ((int)final.size() < q) continue;
		ans = min(ans, final[q - 1] - final[0]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
cnt = sorted(cnt.items(), key = lambda x: x[0], reverse = True)
#cnt = sorted(cnt ,key = lambda x: x[1], reverse = True)

c = []
for i in range(len(cnt)):
    if cnt[i][1] == 2 or cnt[i][1] == 3:
        c.append(cnt[i][0])
    elif cnt[i][1] >= 4:
        c.append(cnt[i][0])
        c.append(cnt[i][0])

c = sorted(c, reverse = True)

if len(c) >= 2:
    print(c[0] * c[1])
    exit()
else:
    print(0)
    exit()


Measured memory_bytes: 22436
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * 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);
        TaskAFG011B solver = new TaskAFG011B();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskAFG011B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();

            long[] a = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
            }
            Arrays.sort(a);

            long[] psum = new long[n];
            psum[0] = a[0];
            for (int i = 1; i < n; i++) {
                psum[i] = a[i] + psum[i - 1];
            }

            int start = 0;
            int end = n - 1;
            int firstPossible = n - 1;

            while (start <= end) {
                int mid = (start + end) / 2;

                if (possible(mid, a, psum)) {
                    firstPossible = mid;
                    end = mid - 1;
                } else {
                    start = mid + 1;
                }
            }
            System.out.print(n - firstPossible);
        }

        private boolean possible(int pos, long[] a, long[] psum) {
            long startSize = psum[pos];

            int index = pos + 1;
            while (index < a.length) {
                if (startSize * 2 < a[index]) {
                    return false;
                }
                startSize += a[index];
                index++;
            }
            return true;
        }
    }
}



Measured memory_bytes: 50232
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Data.Maybe

main = do
  n <- fst . fromJust . BS.readInt <$> BS.getLine
  as <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let bs = sort $ zipWith (-) as [1 ..]
  let c = bs !! (div n 2)
  print $ sum $ map (\x -> abs (x - c)) bs

Measured memory_bytes: 35296
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

bool dp[60][2510][2510];

int main(){
    int n; cin>>n;
    vector<int> t(n);
    for(int i=0; i<n; i++) cin>>t[i];

    dp[0][0][0] = true;
    for(int i=0; i<n; i++){
        for(int j=0; j<=2500; j++){
            for(int k=0; k<=2500; k++){
                if(!dp[i][j][k]) continue;

                if(j + t[i] <= 2500) dp[i + 1][j + t[i]][k] = dp[i][j][k];
                if(k + t[i] <= 2500) dp[i + 1][j][k + t[i]] = dp[i][j][k];
                dp[i + 1][j][k] = true;
            } 
        }
    }

    int ans = 1e9;
    for(int i=0; i<=2500; i++){
        for(int j=0; j<=2500; j++){
            if(dp[n][i][j]){
                ans = min(ans, max({i, j, accumulate(t.begin(), t.end(), 0) - i - j}));
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 117448
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pii> tmp;
typedef pair<int, tmp> state;

int H, W, K;
int sx, sy, ex, ey;
// U, R, D, L
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
priority_queue<state, vector<state>, greater<state> > pq;

int main() {
  scanf("%d%d%d", &H, &W, &K);
  scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
  sx--; sy--; ex--; ey--;
  vector<vector<char> > mat(H, vector<char>(W, '.'));
  vector<vector<int> > dist(H, vector<int>(W, -1));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf(" %c", &mat[i][j]);
    }
  }

  dist[sx][sy] = 0;
  pq.push(state(0, tmp(-1, pii(sx, sy))));
  while (pq.size()) {
    int d = pq.top().first;
    int prv = pq.top().second.first;
    int x = pq.top().second.second.first, y = pq.top().second.second.second;
    pq.pop();
    if (d != dist[x][y]) continue;
    if (x == ex && y == ey) {
      break;
    }
    for (int i = 0; i < 4; i++) {
      if ((i + 2) % 4 == prv || i == prv) continue;
      for (int k = 1; k <= max(H, W); k++) {
        int nx = x + dx[i] * k, ny = y + dy[i] * k;
        if (nx < 0 || ny < 0 || nx >= H || ny >= W) break;
        if (mat[nx][ny] == '@') break;
        int nd = d + (k + K - 1) / K;
        if (dist[nx][ny] == -1 || dist[nx][ny] > nd) {
          dist[nx][ny] = nd;
          pq.push(state(nd, tmp(i, pii(nx, ny))));
        } 
      }
    }
  }
  printf("%d\n", dist[ex][ey]);
}

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

int main(){
    int L, n;
    while(cin >> L >> n) {
        vector<pair<int, int>> vp(n);
        REP(i, n) {
            int a, b;
            cin >> a >> b;
            vp[i] = make_pair(a, b);
        }
        sort(vp.begin(), vp.end());
        long long ans = L + 1;
        if(n == 0) {
            cout << ans << endl;
            continue;
        }
        int begin = vp[0].first, end = vp[0].second;
        for(int i = 1; i < n; i++) {
            if(vp[i].first <= end) {
                end = max(end, vp[i].second);
            } else {
                ans += 2 * (end - begin);
                begin = vp[i].first;
                end = vp[i].second;
            }
        }
        ans += 2 * (end - begin);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long M = 998244353;

int n;
int a[N];

int q[N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    if (a[1] != 0)
    {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 2; i <= n; ++i)
    {
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    q[0] = 1;
    sort(a + 2, a + n + 1);
    long long ans = 1;
    for (int i = 2; i <= n; ++i)
    {
        ans = (ans * (q[a[i] - 1])) % M;
        q[a[i]]++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
    int N, K;
    string S;
    cin >> N >> K >> S;

    if(S[K-1]=='A')S[K-1] = 'a';
    else if(S[K-1]=='B')S[K-1] = 'b';
    else if(S[K-1]=='C')S[K-1] = 'c';

    cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> siz;
    UnionFind(int N) : par(N),siz(N,1) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        if(siz[rx] < siz[ry])swap(rx,ry);
        siz[rx] += siz[ry];
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){
      return siz[root(x)];
    }
};

// TODO: write
int main() {   
  int n,m;cin>>n>>m;

  vector<int> a(m);
  vector<int> b(m);
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
  }
  int ans = 0;
  rep(i,m){
    auto tree = new UnionFind(n);
    rep(j,m){
      if(i != j)tree->unite(a[j],b[j]);
    }

    bool isOk = true;
    rep(j,n){
      isOk &= tree->same(0,j);
    }
    if(!isOk)ans++;
  }

  print(ans);
  return 0;
}



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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, tmp=0;
vector<ll> A, ans;
string S = "abcdefghijklmnopqrstuvwxyz";
/*
signed main(){
    cin >> N;
    N--;
    while(N>=0) {
        ans.push_back(N%26);
        if(N<26) break;
        N /= 26;
    }
    for(int i=ans.size()-1;i>=0;i--) {
        if(i==0) cout << S[ans[i]];
        else cout << S[ans[i]-1];
    }
    cout << endl;
    return 0;
}
*/

signed main(){
    cin >> N;
    while(N>=0) {
        N--;
        //cout << "while " << N%26 << endl;
        ans.push_back(N%26);
        if(N<26) break;
        N /= 26;
    }
    for(int i=ans.size()-1;i>=0;i--) {
        cout << S[ans[i]];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3656
/*
=============================================================

------------------Welcome To My Code-------------------------

---------Ankit Kumar || IIITBH || CSE || 2018-2022-----------

=============================================================
*/

#include <bits/stdc++.h>
using namespace std;

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
map<ll, ll>::iterator itr;
vector<ll>::iterator it, it1;
const double PI = 3.141592653589793238;

int main()
{
	FASTIO;
	ll t;


        ll i,j,k,x,y,z,m,n,a,b,c,c1=0,c2=0,flag=0,sum=0;
        string s,s1,str;

        cin>>x>>y>>z;
        cin>>k;





    while(k--)
    {

        if(x>=y)
            y=y*2;


        else if(y>=z)
            z=z*2;
    }
if(z>y&&y>x)
    cout<<"Yes";
else
    cout<<"No";
        nl;



}


Measured memory_bytes: 3656
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,K;
struct Node { int a,b; }e[N];
inline bool cp(Node x,Node y) { return x.a<y.a; }
signed main()
{
    n=read(), K=read();
    for(ri int i=1;i<=n;i++) e[i].a=read(), e[i].b=read();
    sort(e+1,e+1+n,cp);
    for(ri int i=1;i<=n;i++)
    {
        if(K<=e[i].b) { printf("%lld\n",e[i].a); return 0; }
        K-=e[i].b;
    }
    return 0;
}

Measured memory_bytes: 5260
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include <string>
#include <math.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
  int n,k; cin >>n>>k;
  if(k==1){
    cout << 0 << endl;
    return 0;
  }
  cout<< (n-k+1)-1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<string.h>
using namespace std;
#define maxn 100010
typedef long long ll;
#define cle(n) memset(n,0,sizeof(n))

int n,m,k;
char a[10000];
string s;
int b[8];
int main()
{
    while(cin>>n)
    {
        s="";
     cin>>a;
    int len=0;
    int i=0;
   int sum=0;
   for(int i=0;i<n;i++)
   {
       if(a[i]=='(')
            sum++,s+="(";
       else if(a[i]==')')
        sum--,s+=")";
        while(sum<0)
        {
            sum++;
            s="("+s;
        }
   }
    while(sum<0)
      {
          sum++;
        s="("+s;
      }
while(sum>0)
{
    sum--;
    s=s+")";
}
cout<<s<<endl;





    }
    return 0;
}


Measured memory_bytes: 256