akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
 
#include <bits/stdc++.h>
 
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;
#define y1 sfasfd 
using namespace std;
 
mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
 
typedef pair < int , int > pii ;
const int N = 1e5 + 123;
int a[N] , n , t;
int Max_ = 0;
bool can[N];
map < int , int > bad;

main(){
	scanf("%d%d" , &n , &t);
	set < int > st;
	for(int i = 1; i<= n; i++){
		scanf("%d" , &a[i]);
		st.insert(a[i]);
		Max_ = max(a[i] - (*st.begin()) , Max_);
	}
	st.clear();
	set < int > hav;
	for(int i = 1; i <= n; i++){
		st.insert(a[i]);	
		if(st.find(a[i] - Max_) != st.end()){
			bad[a[i]]++;
			hav.insert(a[i]);			
		}
	}
	st.clear();
	for (int i = n ; i > 0 ; i--){
		st.insert(a[i]);
		if(st.find(a[i] + Max_) != st.end()){
			bad[a[i]]++;
		}
	}
	int ans = 0;
	for(auto x : hav){
		ans += min(bad[x] , bad[x - Max_]);
	}
	cout << ans;
}

Measured memory_bytes: 12416
#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
#include<fstream>
const ll INF=9223372036854775807;
const ll mod=1000000007;
int  MOD(int  a, int  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
int main()
{
    int n;
    cin>>n;
    vi h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    h[0]--;
    for(int j=1;j<n;j++)
    {
        if(h[j]>h[j-1])
        {
            h[j]--;
        }
    }
    auto g=h;
    sort(all(g));
    if(g==h)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    string s;
    cin >> s;
    ll K;
    cin >> K;
    int a[s.size()];
    for(int i = 0; i < s.size();i++){
        a[i] = s[i] - 'a';
    }
    for(int i = 0; i < s.size(); i++){
        if(i == s.size() - 1){
            a[i] = (K + a[i]) % 26;
            continue;
        }
        if(a[i] == 0){
            continue;
        }
        if(K >= 26 - a[i]){
            K -= (26 - a[i]);
            a[i] = 0;
        }
    }
    for(int i = 0; i < s.size(); i++){
        cout << (char)('a' + a[i]);
    }
    cout << endl;
}


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

using namespace std;

#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define W(x)        cout<<x<<endl
#define WW(x,y)     cout<<x<<' '<<y<<endl;
#define in(x)       cin>>x
#define v(x)        vector<x>
#define int         long long
#define ar(x,y)     array<x,y>
const ll mod1 = 998244353;
const ll mod2 = 1e9+7;
/* template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; */

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}

struct dsu{
  unordered_map<int,int> pr,sz;
  dsu(){
    (this->pr).clear();
    (this->sz).clear();
  }
  void make(int x){
    pr[x] = x;
    sz[x] = 1;
  }
  int getpar(int x){
    if(pr[x] == x)return x;
    return pr[x] = getpar(pr[x]);
  }
  void merge(int x,int y){
    x = getpar(x);
    y = getpar(y);
    if(sz[x]<sz[y])swap(x,y);
    pr[y] = x;
    sz[x]+=sz[y];
    sz[y] = 0;
  }
};
int mxn = 10000000;
v(int) dp(mxn);
void fill(){
  dp[0] = 1,dp[1] = 1;
  for(int i = 2; i<mxn; i++){
    dp[i] = (dp[i-1]*i)%mod1;
  }
}

int power(int x,int y,int m){
  int res = 1;
  x%=m;
  while(y>0){
    if(y&1)res = (res*x)%m;
    y>>=1;
    x = (x*x)%m;
  }
  return res;
}

void solve(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  v(v(int)) dp(c-a+1,v(int)(d-b+1,0));
  dp[0][0] = 1;
  for(int i = 0; i<=c-a; i++){
    for(int j = 0; j<=d-b; j++){
      if(i == 0&&j == 0)continue;
      dp[i][j]=(((i-1>=0?dp[i-1][j]:0)*(b+j))%mod1+((j-1>=0?dp[i][j-1]:0)*(a+i))%mod1-((((i-1)>=0&&(j-1)>=0)?dp[i-1][j-1]:0)*(a+i-1)*(b+j-1))%mod1+mod1)%mod1;
    }
  }
  cout<<dp[c-a][d-b]<<"\n";
}

signed main(){
    fastio();
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 151660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

int     main()
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		a[i] = s[i] - '0';
	}
	int c = 0;
	if (a[0] == 0)
		c = 1;
	int max = 0;
	int r = 0;
	for (int l = 0; l < n; l++) {
		while(r < n && c <= k)
		{
			if (r+1 < n && a[r] == 1 && a[r+1] == 0)
				c++;
			r++;
		}
		if (r - l > max)
			max = r - l;
		if (l+1 < n && a[l] == 0 && a[l+1] == 1)
			c--;
	}
	cout << max << endl;
}



Measured memory_bytes: 3840
#include <stdio.h>
#pragma warning(disable:4996)

int main(void){
	int n = 0, x = 0;

	scanf("%d", &n);

	for (int i = 1; i <= n; i++){
		if (i % 3 == 0 || i % 10 == 3 || i /10 % 10 == 3 || i / 100 % 10 == 3 || i / 1000 % 10 == 3){
			printf(" %d", i);
		}
	}
	printf("\n");
}

Measured memory_bytes: 2688
#include <iostream>
#include <stack>
#include <stdio.h>
using namespace std;
#define maxx 110000
typedef long long ll;
string a;
int b[100010];

int main()
{
    int n,k;
    cin>>n>>k;
    cin>>a;
    int j=0;
    char pre = '0';
    int maxn = 0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=pre)
        {
            pre=a[i];
            b[j++]=i;
        }
        if(a[i]=='1')
        {
            maxn = max(i+1-(j>=2*k+1?b[j-2*k-1]:0),maxn);
        }
        else
        {
            maxn = max(i+1-(j>=2*k?b[j-2*k]:0),maxn);
        }
    }
    cout<<maxn<<endl;
    return 0;
}

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define pb push_back
#define fst first
#define snd second

typedef long long ll;

int main() {
    int n; cin >> n;
    set<pair<int, int>> s;
    if(n % 2) {
        fore(i, 1, n / 2 + 1) {
            s.insert({i, n - i});
        }
    } else {
        fore(i, 1, n / 2 + 1) {
            s.insert({i, n + 1 - i});
        }
    }

    vector<pair<int, int>> res;

    fore(i, 1, n + 1) {
        fore(j, i + 1, n + 1) {
            if(s.find({i, j}) == s.end()) {
                res.pb({i, j});
            }
        }
    }
    cout << res.size() << endl;
    for(auto x : res) {
        cout << x.fst << " " << x.snd << endl;
    }
    return 0;
}

Measured memory_bytes: 512
fun main(args : Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }

    val probability = (1..N).map { i ->
        var ans = 0.0
        if (i >= K) {
            ans = 1.0 / N.toDouble()
        } else {
            val x = Math.ceil(log2((K.toDouble() / i.toDouble())))
            ans = 1 / (Math.pow(2.toDouble(), x) * N.toDouble())
        }
        ans
    }.sum()

    println(probability)
}

fun log2(value: Double) : Double {
    return Math.log(value)/Math.log(2.0)

}

Measured memory_bytes: 40564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

int n, x;
set<ll> s;
int main(){

cin >> n;
rep(i, 0, n-1){
cin >> x;
auto k = s.find(x);
if(k == s.end())s.insert(x);
else s.erase(k);
}
cout << s.size() << endl;

return 0;}


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

#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    int n;cin >> n;
    vector<long long> v(n);
    int cnt = 0;
    long long sum = 0;
    rep(i,n){
        cin >> v[i];
        if(v[i]<0){
            cnt++;
            v[i] = -v[i];
        }
        sum += v[i];        
    }

    long long ans = sum;
    if(cnt&1){
        ans -= 2*(*min_element(v.begin(),v.end()));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int a, b;
  cin >> a >> b;
  if (a + b >= 10) P("error");
  else P(a + b);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 2002;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n, a[maxn];
int edge[maxn][maxn];
struct cmp {
	inline int operator () (int x,int y) const {
		return a[x] < a[y];
	}
};
std::priority_queue<int, std::vector<int>, cmp> q;
int vis[maxn];
std::vector<int> to[maxn];
inline void dfs(int x) {
	vis[x] = 1;
	for(int j = 1;j <= n;++j) if(edge[x][j] && !vis[j]) {
		dfs(j); to[x].push_back(j);
	}
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n; 
	rep(i, 1, n) cin >> a[i];
	std::sort(a + 1,a + n + 1);
	rep(i, 1, n) rep(j, 1, n) edge[i][j] = std::__gcd(a[i], a[j]) > 1;
	rep(i, 1, n) if(!vis[i]) dfs(i), q.push(i);
	for(;!q.empty();) {
		int t = q.top(); q.pop();
		cout << a[t] << ' ';
		for(int j : to[t]) q.push(j);
	}
}


Measured memory_bytes: 16256
#include<iostream>
using namespace std;
int n,ans;
int a[3][110];
void dfs(int x,int y,int z){
    if(y>n||x>2) return ;
    if(x==2&&y==n){
        ans=max(ans,z);
        return ;
    }
    dfs(x+1,y,z+a[x+1][y]);
    dfs(x,y+1,z+a[x][y+1]);
}
int main(){
    cin>>n;
    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
        }
    }
    dfs(1,1,a[1][1]);
    cout<<ans<<endl;
    return 0;
}

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int x, y;
	sf("%d %d", &x, &y);
	int a = x * 2;
	while (a < y && x > 0) {
		a += 2;
		--x;
	}
	puts(a == y ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <cstring>
#include <vector>

#define int long long
using namespace std;

signed main () {
    int n, m; cin >> n >> m;
    vector<int> x(n), y(n), z(n);

    for(int i = 0; i < n; i++)
        cin >> x[i] >> y[i] >> z[i];

    int ans = 0;
    for (int i = 0; i < (1<<3); i++) {
        int x_coef = (i & (1<<0)) ? -1 : 1;
        int y_coef = (i & (1<<1)) ? -1 : 1;
        int z_coef = (i & (1<<2)) ? -1 : 1;

        int dp[n + 1][m + 1];
        for (int i = 0; i <= n; i++) {
            dp[i][0] = 0;
            for (int j = 1; j <= m; j++) {
                dp[i][j] = -1e13;
            }
        }

        for (int i = 0; i < n; i++) {
            int value = x[i] * x_coef + y[i] * y_coef + z[i] * z_coef;
            for (int j = 1; j <= m; j++) {
                if (dp[i][j - 1] < -1e12) dp[i + 1][j] = dp[i][j];
                dp[i + 1][j] = max(dp[i][j], dp[i][j - 1] + value);
            }
        }
        ans = max(ans, dp[n][m]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int P = 1e9 + 7; 
typedef long long ll;
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
struct BinaryIndexTree {
	int n, a[MAXN];
	void init(int x) {
		n = x;
		memset(a, 0, sizeof(a));
	}
	void modify(int x, int d) {
		for (int i = x; i <= n; i += i & -i)
			update(a[i], d);
	}
	int query(int x) {
		int ans = 0;
		for (int i = x; i >= 1; i -= i & -i)
			update(ans, a[i]);
		return ans;
	}
} BIT;
int n, m, t, x[MAXN], y[MAXN];
pair <int, int> a[MAXN];
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++)
		read(x[i]);
	for (int i = 1; i <= m; i++)
		read(y[i]);
	for (int i = 1; i <= n; i++) {
		int pos = upper_bound(y + 1, y + m + 1, x[i]) - y;
		if (pos == m + 1 || pos == 1) continue;
		a[++t] = make_pair(x[i] - y[pos - 1], y[pos] - x[i]);
	}
	if (t == 0) {
		cout << 1 << endl;
		return 0;
	}
	n = t; int cnt = 0;
	set <int> st; map <int, int> home;
	for (int i = 1; i <= n; i++)
		st.insert(a[i].second);
	for (auto x : st) home[x] = ++cnt;
	for (int i = 1; i <= n; i++)
		a[i].second = home[a[i].second];
	BIT.init(cnt), BIT.modify(1, 1);
	sort(a + 1, a + n + 1);
	n = unique(a + 1, a + n + 1) - a - 1;
	int ans = 1; static int dp[MAXN];
	for (int i = 1, nxt; i <= n; i = nxt + 1) {
		nxt = i; while (nxt + 1 <= n && a[nxt + 1].first == a[i].first) nxt++;
		for (int j = i; j <= nxt; j++) {
			dp[j] = BIT.query(a[j].second);
			update(ans, dp[j]);
		}
		for (int j = i; j <= nxt; j++)
			BIT.modify(a[j].second + 1, dp[j]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12544
n, k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))

bits_k = len(bin(k)) - 2
forma = '0%db' % bits_k
data = [0 for i in range(bits_k)]

for an in a:
    anb = format(an, forma)
    #print(anb)
    for i in range(bits_k):
        if anb[-i-1] == '0':
            data[i] += 1
        else:
            data[i] -= 1

#print(data)
ans = 0
for i in range(bits_k - 1, -1, -1):
    if data[i] > 0:
        ans |= (1 << i)
        if ans > k:
            ans &= ~(1 << i)

#print(ans)
b = sum([ans ^ an for an in a])
print(b)


Measured memory_bytes: 14984
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n,k; cin >> n >> k;
    vector<int> a(n);
    vector<int> sum(n);
    map<int,int> mp;
    map<int,int> mp2;
    if(k==1){
        cout << 0 << endl;
        return 0;
    }
    mp[0]++;
    ll ans=0;
    rep(i,n){
        cin >> a[i];
        if(i==0) sum[0]=a[0]%k;
        else{
            sum[i]=(sum[i-1]+a[i])%k;
            mp[(i-sum[i-1]+k)%k]++;
            if(i-k+1>=0) mp2[(i-k+1-sum[i-k]+k)%k]++;
        }
        int fin=(i+1-sum[i]+k)%k;
        ans+=mp[fin];
        if(i-k+1>=0)ans-=mp2[fin];
    }
    cout << ans << endl;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	double n, k;
	cin >> n >> k;

	int ans = 1;

	while (n>=k) {
		n /= k;
		ans++;
	}

	cout << ans << endl;
	return 0;
}


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

struct book{
    int price;
    int a[12];
};

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

    int n,m,x;

    cin>>n>>m>>x;

    struct book b[n];

    for(int i=0; i<n; i++){
        cin>>b[i].price;
        for(int j=0; j<m; j++){
            cin>>b[i].a[j];
        }
    }

    int total = 1 << n;
    int ans = INT_MAX;

    for(int mask=0; mask<total; mask++){
        int cost=0;
        int temp[m]={0};
        for(int i=0; i<n; i++){
            int f = 1 << i;
            if((mask & f) != 0){
                cost += b[i].price;
                for(int k=0; k<m; k++){
                    temp[k] += b[i].a[k];
                }
            }
        }
        bool flag = true;
        for(int i=0; i<m; i++){
            if(temp[i] < x)flag = false;
        }
        if(flag){
            ans = min(cost,ans);
        }
    }
    if(ans == INT_MAX){
        cout<<-1<<"\n";
    }
    else{
        cout<<ans<<"\n";
    }

    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n){
    cin >> a[i];
  }
  int o;
  int ans=0;
  rep(i,n){
    if(a[i]==i+1){
      o=a[i];
      a[i]=a[i+1];
      a[i+1]=o;
      ans++;
    }
  }
  cout << ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef int ll;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
int main()
{
    fast;
   ll p=1;
   //std::cin >> t;
   while(p--)
   {
       string s,t;
       std::cin >> s>>t;
       ll mini=1000,n=s.length(),nt=t.length();
       fr(i,0,n)
       {
           ll x=0;
           fr(j,i,i+nt)
           {
               if(j>=n)
               {
                   x=1000000007;
                   break;
               }
               if(t[j-i]!=s[j])
               x++;
           }
           mini=min(mini,x);
       }
       cout<<mini<<"\n";
   }
}


Measured memory_bytes: 3660
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<i64>();
    let m = input::<i64>();
    let mut ab = (0..n)
        .map(|_| {
            let a = input();
            let b = input();
            (a, b)
        })
        .collect::<Vec<(i64, i64)>>();
    ab.sort_by_key(|x| x.0);

    let mut ans = 0;
    let mut bought = 0;
    for (a, b) in ab {
        if bought + b < m {
            ans += a * b;
            bought += b;
        } else {
            ans += a * (m - bought);
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
using System;
class Program{
  static void Main(string[] args){
    int n = int.Parse(Console.ReadLine());
    double p=0;
    for(int i=0;i<n;i++){
      string[] tmp = Console.ReadLine().Split(' ');
      if(tmp[1]=="JPY"){
        p+=int.Parse(tmp[0]);
      }else{
        p+=(double.Parse(tmp[0])*380000.0);
      }
    }
    Console.WriteLine(p);
  }
}

Measured memory_bytes: 11220
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10 ** 7)


def solve(r: int):
    print(3 * r ** 2)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    r = int(next(tokens))  # type: int
    solve(r)


if __name__ == '__main__':
    main()


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

int main(int argc, const char * argv[]) {
    int x;
    vector<int> v(3);
    for (int i = 0; i < 3; i++) {
        cin >> x;
        v[i] = x;
    }
    sort(v.begin(), v.end());
    int cnt = 0;
    while (!(v[0] == v[1] && v[0] == v[2])) {
        if (v[2] != v[1] && v[2] != v[0]) {
            v[1]++;
            v[0]++;
            cnt++;
            /*
            if (v[1] - v[0] >= 2) {
                v[0]++;
                v[0]++;
                cnt++;
            }else{
                v[1]++;
                v[0]++;
                cnt++;
            }
             */
        }else if (v[2] == v[1] && v[2] != v[0]) {
            v[0]++;
            v[0]++;
            cnt++;
        }
        //cout << "cnt: " << cnt << endl;
        //cout << v[0] << " " << v[1] << " " << v[2] << endl;
        sort(v.begin(), v.end());
    }
    cout << cnt << endl;
    return 0;
}

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

const ll INF = 1e9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int H, W;
vector<string> S;  // 0-indexed

vector<vector<int>> bfs(int si, int sj) {
  vector<vector<int>> dist(H, vector<int>(W, INF));
  queue<P> que;
  dist[si][sj] = 0; que.push(P(si, sj));
  while (!que.empty()) {
    int ci = que.front().first;
    int cj = que.front().second; que.pop();
    int cd = dist[ci][cj];
    for (int k = 0; k < 4; k++) {
      int ni = ci + dx[k];
      int nj = cj + dy[k];
      if (0<=ni && ni<H && 0<=nj && nj<W && (S[ni][nj] != '#')) {
        if (dist[ni][nj] != INF) continue;
        dist[ni][nj] = cd + 1;
        que.push(P(ni, nj));
      }
    }
  }
  return dist;
}

int main() {
  cin >> H >> W;
  S = vector<string> (H);
  rep(i, H) cin >> S[i];
  int ans = 0;  
  rep(si, H) rep(sj, W) {
    if (S[si][sj] == '#') continue;
    vector<vector<int>> dist = bfs(si, sj);
    rep(i, H) rep(j, W) {
      if (dist[i][j] == INF) continue;
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <stack>
#include <utility>

using namespace std;

using Point = pair<int,int>;

int main(){
  int W,H;
  while((cin>>W>>H)&&W>0&&H>0){
    int map[22][22]={0};
    int sy,sx;
    for(int i=1;i<=H;++i){
      for(int j=1;j<=W;++j){
        char c;
        cin >> c;
        if(c=='.'){
          map[i][j] = 1;
        }else if(c=='@'){
          map[i][j] = 1;
          sy = i ; sx = j;
        }
      }
    }

    stack<Point> s;
    s.push(make_pair(sy,sx));
    int tile = 0;
    while(!s.empty()){
      auto p = s.top();s.pop();
      int y = p.first , x = p.second;
      if(map[y][x]){
        map[y][x] = 0;
        tile++;
      }else{
        continue;
      }

      s.push(make_pair(y-1,x));
      s.push(make_pair(y+1,x));
      s.push(make_pair(y,x-1));
      s.push(make_pair(y,x+1));
    }

    cout << tile << endl;
  }
  return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <stdio.h>

int main(void) {
    int a, b, c, x, y;
    std::cin >> a >> b >> c >> x >> y;
    if (a + b < 2 * c) {
        std::cout << a * x + b * y << std::endl;
    } else {
        int cost = 0;
        if (x == y ) {
            cost += x * 2 * c;
        } else if ( x < y ){
            cost += x * 2 * c;
            if (2*c < b) {
                cost += (y-x) * 2 * c;
            } else {
                cost += (y-x) * b;
            }
        } else {
            cost += y * 2 * c;
            if (2*c < a) {
                cost += (x-y) * 2 * c;
            } else {
                cost += (x-y) * a;
            }
        }
        std::cout << cost << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
s = input()

stack = [s[0]]
ans = 0
for i in range(1, len(s)):
    if len(stack) == 0:
        stack.append(s[i])
        continue
    if s[i] == "0":
        if stack[-1] == "1":
            del stack[-1]
            ans += 2
        else:
            stack.append("0")
    else:
        if stack[-1] == "0":
            del stack[-1]
            ans += 2
        else:
            stack.append("1")

print(ans)

Measured memory_bytes: 9484
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll Mid(ll(a), ll(b), ll(c)) {
	return a+b+c-Max(a,b,c)-Min(a,b,c);
}

int gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {
	int N;
	string s, t;
	cin >> N >> s >> t;
	
	int i = N;
	while (s.substr(N - i, i) != t.substr(0, i) &&i>0) {
		i--;
		
	}

	cout << 2*N-i << endl;
}

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


int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A.at(i);
    vector<int> cnt(N+1);
    vector<int64_t> comb(N+1);
    for(int i=0; i<N; i++) cnt.at(A.at(i))++;
    for(int i=0; i<N+1; i++){
        int64_t cnti = cnt.at(i); 
        comb.at(i) = cnti * (cnti - 1);
        if(comb.at(i) != 0) comb.at(i) /= 2;
    }
    int64_t sum = 0;
    for(int i=0; i<N+1; i++) sum += comb.at(i);
    for(int i=0; i<N; i++){
        int64_t Ai = A.at(i);
        int64_t local_sum = sum;
        int64_t cnti = cnt.at(Ai);
        int64_t local_comb = (cnti - 1) * (cnti - 2);
        if(local_comb != 0) local_comb /= 2;
        local_sum = local_sum - comb.at(Ai) + local_comb;

        cout << local_sum << endl;
    }
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  unordered_set<char> odd{'R', 'U', 'D'};
  unordered_set<char> even{'L', 'U', 'D'};
  for (int i = 0; i < S.length(); i++) {
    char c = S[i];
    if ((i + 1) % 2 == 1) {
      if (odd.count(c) == 0) {
        cout << "No";
        return 0;
      }
    } else {
      if (even.count(c) == 0) {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";

  return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(n):
    L = i + A[i]
    if L not in dic:
        dic[L] = 1
    else:
        dic[L] += 1
for j in range(n):
    R = j - A[j]
    if R in dic:
        ans += dic[R]
print(ans)

Measured memory_bytes: 40516
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-19 22:56:34
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int n; cin >> n;

  int64 cnt[10][10];
  fill(cnt[0], cnt[10], 0LL);

  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    char c1 = s[0], c2 = s.back();
    ++cnt[c1 - '0'][c2 - '0'];
  }
  
  int ans = 0;

  for (int i = 1; i < 10; ++i) {
    for (int j = 1; j < 10; ++j) {
      ans += cnt[i][j] * cnt[j][i];
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
    stack<int> num;
    stack<char> ope;
    string s;
    while(cin >> s){
        if(s=="+"){
            int n1, n2;
            n1 = num.top();
            num.pop();
            n2 = num.top();
            num.pop();
            num.push(n1+n2);
        }
        else if(s=="-"){
            int n1, n2;
            n1 = num.top();
            num.pop();
            n2 = num.top();
            num.pop();
            num.push(n2-n1);
        }
        else if(s=="*"){
            int n1, n2;
            n1 = num.top();
            num.pop();
            n2 = num.top();
            num.pop();
            num.push(n1*n2);
        }
        else{
            num.push(stoi(s));
        }
    }
    cout << num.top() << endl;
    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  pr(n*n-m);
}

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


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

int n, a;
double ans;
int main()
{
	cin >> n;
	while (n--) {
		scanf("%d", &a);
		ans += 1.0 / a;
	}
	printf("%.9f", 1 / ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int n,m,c,i,j;
scanf("%d%d%d",&n,&m,&c);
int b[m];
for(i=0; i<m; i++){
scanf("%d",&b[i]);
}

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

int an,count;
count=0;
for(j=0; j<n; j++){
  an=0;
for(i=0; i<m; i++){
an+=a[j][i]*b[i];
}
an+=c;
if(an>0) {count++;}
}

printf("%d",count);

return 0;
}


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int n;
V<int> a;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    cin >> n;
    a = V<int>(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());

    int i = 0, j = 1;
    while (true) {
        if (i == n - 1 || a[i + 1] < j + 1) break;
        i++; j++;
    }
    int u1 = 0, u2 = 0;
    if (a[i] > j) {
        u1 = (a[i] - j) & 1;
    }
    while (i < n - 1 && a[i + 1] == j) {
        i++;
        u2 = 1 - u2;
    }
    if (u1 || u2) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}

Measured memory_bytes: 640
N=int(input())
S=input()
count=0
for i in range(1000):
    p='0'*(3-len(str(i)))+str(i)
    p1=S.find(p[0])
    if p1!=-1:
        p2=S[p1+1:].find(p[1])
        if p2!=-1:
            p3=S[p1+p2+2:].find(p[2])
            if p3!=-1:
                count+=1
print(count)

Measured memory_bytes: 3064
#include<stack>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;
int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c){
	stack<int> S;
	S.push(r);
	color[r] = c;
	while (!S.empty()){
		int u = S.top(); S.pop();
		for (int i = 0; i < G[u].size(); i++){
			int v = G[u][i];
			if (color[v] == NIL){
				color[v] = c;
				S.push(v);
			}
		}
	}
}
void assignColor(){
	int id = 1;
	for (int i = 0; i < n; i++) color[i] = NIL;
	for (int u = 0; u < n; u++){
		if (color[u] == NIL) dfs(u, id++);
	}
}


int main(){
	int s, t, m, q;
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	assignColor();
	cin >> q;

	for (int i = 0; i < q; i++){
		cin >> s >> t;
		if (color[s] == color[t]){
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7060
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int a[];
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int i,n,sum,ans;
		
		while(true){
			sum=0;
			n=sc.nextInt();
			if(n==0) break;
			a=new int[n];
			for(i=0;i<n;i++){
				a[i]=sc.nextInt();
			}
			Arrays.sort(a);
			for(i=1;i<n-1;i++){
				sum+=a[i];
			}
			ans=sum/(n-2);
			System.out.println(ans);
		}

	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    if (n == 1) {
        cout << "Hello World" << endl;
    }
    else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    auto solve = [&](int k) -> ll {
        auto dp = make_v(3, n + 1, 0LL);
        ll ans = 0;
        ll sum = 0;
        int cnt = 0;
        REP(i, 0, n) {
            dp[0][i + 1] += dp[0][i];
            if (s[i] == 'D') {
                dp[0][i + 1]++;
            }
            if (s[i] == 'M') {
                dp[1][i + 1] += dp[0][i + 1];
                dp[2][i + 1]++;
            }
            sum += dp[1][i + 1];
            cnt += dp[2][i + 1];
            if (i - k + 1 >= 0) {
                sum -= dp[1][i - k + 1];
                cnt -= dp[2][i - k + 1];
            }
            //dump(sum, cnt);
            if (s[i] == 'C') {
                int ind = max(0, i - k + 1);
                ans += sum - cnt * dp[0][ind];
            }
        }
        /*
        REP(i, 0, n + 1) {
            REP(j, 0, 3) {
                cout << dp[i][j] << " \n"[j == 2];
            }
        }
        //*/
        return ans;
    };
    int q;
    cin >> q;
    REP(i, 0, q) {
        int k;
        cin >> k;
        cout << solve(k) << endl;
    }

    return 0;
}


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

int		main(void)
{
	int a, b, c, d;

	cin >> a >> b >> c >> d;
	if ((abs(a - b) <= d && abs(b - c) <= d) || (abs(a - c) <= d))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

double L;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> L;
}

int solve(){
    cout << fixed << setprecision(8) <<  (L/3)*(L/3)*(L/3) << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <cstdio>   
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
#define EPS         1e-9
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef long long ll;

vector<vector<double>> datos;
vector<double> a;

int main(){
    ofstream out("output.txt");
    
    int n,d;
    double val;
    cin>>n>>d;
    for(int i = 0; i<n ;i++){
        for(int  j = 0; j<d; j++){
            cin>>val;
            a.pb(val);
        }
        datos.pb(a);
        a.clear();
    }
    vector<double> b;
    double sumas,raiz;
    int minimo = 0;
    for(int i =0; i<n ;i++){
        a = datos[i];
        for(int j=i+1; j<n; j++){
            b = datos[j];
            sumas = 0;
            for(int k = 0; k<d; k++){
                sumas += (abs(b[k]-a[k]) * abs(b[k]-a[k]));
            }

            raiz = sqrt(sumas);
            //cout<<sumas<<" "<<raiz<<" "<<ceil(raiz)<<endl;
            if(raiz == ceil(raiz)){
                minimo++;
            }
        }
    }
    cout<<minimo<<endl;


    return 0;
}
 
 







Measured memory_bytes: 256
#include <iostream>

using namespace std;

int day(int, int, int);

int main() {

	struct P {
		int y, m, d;
	} a, b;

	while(cin >> a.y >> a.m >> a.d >> b.y >> b.m >> b.d) {
		if(a.y<0) {
			break;
		}
		int d1, d2;
		if(a.m<3) {
			a.m+=12;
			a.y--;
		}
		if(b.m<3) {
			b.m+=12;
			b.y--;
		}
		d1=day(a.y, a.m, a.d);
		d2=day(b.y, b.m, b.d);
		cout << d2-d1 << endl;
	}

	return 0;

}


int day(int y, int m, int d) {
	return (365*y+y/4-y/100+y/400+(306*(m+1))/10+d-428);
}

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

int main(){
  int N,T,A;
  cin >> N >> T >> A;
  
  pair<int,int>t[N];
  for(int i=0;i<N;++i){
    int H;
    cin >> H;
    int diff = abs(1000*A-(1000*T-H*6));
    
    t[i] = make_pair(diff,i+1);
  }
  
  sort(t,t+N);
  
  cout << t[0].second << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
int n;
ll ans;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	for(ri i=1;i<=n;++i)
		for(ri j=1;j<=n;++j)
			for(ri k=1;k<=n;++k)
				ans+=__gcd(__gcd(i,j),k);
	print(ans);
	return 0;
}

Measured memory_bytes: 3620
import math

n=int(input())

prev=0
val=26
count=1
while prev+val<n:
    prev=val+prev
    val*=26
    count+=1
   
n=n-prev-1

init=ord('a')
ans=""
while count:
    q,r=divmod(n,26)
    n=q
    ans+=chr(init+r)
    count-=1

print(ans[::-1])

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

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

  string ans = "~";
  for(ll i = 0; i < s.size(); i++){
    string ss = s;
    bool ok = true;
    for(ll j = 0; j < t.size(); j++){
      //cout << ss[j+i] << " " << t[j] << endl;
      if(ss[j+i] == '?' || t[j] == ss[j+i]) ss[j+i] = t[j];
      else ok = false;
    }
    //cout << ok << endl;

    if(ok){
      for(ll j = 0; j < ss.size(); j++){
        if(ss[j] == '?') ss[j] = 'a';
      }
      ans = min(ans, ss);
    }
  }

  if(ans == "~") cout << "UNRESTORABLE" << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256