akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define inf (1ll<<60)
#define tri(x) ((x)*(x)*(x))

using ll = long long;

const int max_N = 55;

int n, m, d, v[max_N], p[max_N], q[max_N];

ll w[max_N], f[tri(max_N)], ans;

struct cmpFunctor{
	bool operator()(const int&a, const int&b){
		return v[a]*w[b] > v[b]*w[a];
	}
};

int main(){
	scanf("%d%d%d", &n, &m, &d);
	for(int i=1;i<=n;++i){
		scanf("%lld", w+i);
		if(i>1) scanf("%d", p+i);
		v[i] = 1, q[i] = i; 
	}
	for(int i=n;i>1;--i){
		w[p[i]] += w[i];
		v[p[i]] += v[i];
	}
	std::sort(q+1, q+1+n, cmpFunctor());
	for(int i=1;i<=tri(n);++i) f[i] = inf;
	f[0] = 0;
	for(int i=1;i<=n;++i){
		int siz_a = i==1 ? n: std::min(n, d);
		while(siz_a --){
			for(int j=tri(n);j>=v[i];--j)
				f[j] = std::min(f[j], f[j-v[i]] + w[i]);
		}
	}
	for(int i=0;i<=tri(n);++i){
		ll siz = m - f[i], sum = i;
		if(siz<0) break;
		for(int j=1;j<=n;++j){
			int siz_b = q[j]==1? m: std::max(d-n, 0);
			int tmp = std::min(siz_b, (int)(siz/w[q[j]]));
			sum += tmp*v[q[j]], siz -= tmp*w[q[j]];
		}
		ans = std::max(ans, sum);
	}
	printf("%lld\n", ans);
	return 0;
} 

Measured memory_bytes: 1280
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N-2):
  for j in range(i+2, N):
    a, b = L[i], L[j]
    right = bisect.bisect_right(L, b-a)
    left = max(right, i+1)
    ans += j - left
print(ans)

Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 2019
ll dmod(ll x){
    return ((x+mod)%mod);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    ll ans=0;
    map <ll,int> mp;
    mp[0]=1;
    ll num=0;
    ll ten=1;
    for(int i=s.length()-1;i>=0;i--){
        num=dmod(num+(s[i]-'0')*ten);
        ans+=mp[num];
        mp[num]++;
        ten=dmod(ten*10);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,d;
  cin>>n>>d;
  int x[n][d];
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>x[i][j];
    }
  }
  int cnt=0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      int sum=0;
      for(int k=0;k<d;k++){
        sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      double dis=sqrt(sum);
      if(dis==(int)dis) cnt++;
    }
  }
  cout<<cnt;
} 

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main(){
  priority_queue<int> mlist;
  int i;
  for(i=0;i<10;i++){
    int dt;
    cin>>dt;
    mlist.push(dt);
  }
  for(i=0;i<3;i++){
    cout <<mlist.top()<<endl;
    mlist.pop();
  }

  return 0;
}

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

int main(){
    int n,a[101];
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n,greater<int>());
    
    int asum = 0,bsum = 0;
    for(int i=0;i<n;i++){
        if(i%2==0) asum+=a[i];
        else bsum+=a[i];
    }
    int sum = asum - bsum;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
using namespace std;

typedef long long ll;
const int mod=1e9+7;
const int INF=1<<30;

int main(){
  string S;
  cin >> S ;
  int cnt=0;
  rep(i,S.length()){
    if(S[i]=='g') cnt++;
  }
  cout << cnt-(S.length()+1)/2 << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 200005

ll inv[N], fac[N], finv[N];

void make()
{
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for(int i = 2; i < N; ++i)
	{
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = MOD - MOD/i * inv[MOD % i] % MOD;
		finv[i] = inv[i] * finv[i - 1] % MOD;
	}
}

ll C(ll n, ll k)
{
	if(n < k || n < 0) return 0;
	return fac[n] * finv[n - k] % MOD* finv[k] % MOD;
}

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

	int n, k;
	string s;
	cin >> n >> k >> s;

	s[k - 1] += 32;

	cout << s << "\n";
	return 0;
}

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

using namespace std;

#define mod 1000000007
#define int unsigned long long int
#define pii pair<int,int>
#define vpii vector<pii>
#define vi vector<int>
#define fi first
#define se second
#define psb push_back
#define ppb pop_back
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define all(x) x.begin(),x.end()

inline int f(int x)
{
	return x*(x+1)/2;
}
int32_t main()
{
	int  n;
	cin>>n;
	int n2=n,ans=0;
	for(int i=2;i*i<=n2;i++)
	{
		if(n%i)
			continue;
		int cnt=0,x=0;
		while(n%i==0)
		{
			n/=i;
			cnt++;
			if(f(x+1)<=cnt)
				x++;
		}
		ans+=x;
	}
	if(n>1)
		ans++;
	cout<<ans<<endl;
}

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

int main()
{
  ll a, b, x;
  a = b = x = 0;
  cin >> a >> b >> x;

  if (a == 0)
  {
    cout << (b / x) + 1 << endl;
  }
  else
  {
    cout << (b / x) - ((a - 1) / x) << endl;
  }
}


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

int main(){
  int A,B,K,i,num=0;
  cin >> A >> B >> K;
  for(i=100;i>=0;i--){
    if(A%i==0&&B%i==0){
      num++;
      if(num==K){
        cout<<i;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
	char c[4];
	scanf ("%s", c);
	for (int i=0; i<3; i++) {
		if (c[i] == '1')
			c[i] = '9';
		else if (c[i] == '9')
			c[i] = '1';
	}
	printf ("%s\n", c);
	return 0;
}

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


int main(){
    int H,N;
    cin >> H >> N;
    vector<int>A(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
    }
    int sum=0;
    for(int i=0; i<N; i++){
        sum+=A.at(i);
    }
    if(H<=sum){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}
	

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main()
{
	long long x;
	long long a = 100,b = 0;

	cin >> x;

	while (a < x) {
		a = a * 1.01;
		b++;

	}

	cout << b;
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
long long dp[100005][5];
int main()
{
     int n,x,y,z,p,q,i;
     cin>>n;
     cin>>dp[1][1]>>dp[1][2]>>dp[1][3];
     for(i=2; i<=n; i++)
     {
            cin>>x>>y>>z;
            dp[i][1]=x+max(dp[i-1][2],dp[i-1][3]);
            dp[i][2]=y+max(dp[i-1][1],dp[i-1][3]);
            dp[i][3]=z+max(dp[i-1][2],dp[i-1][1]);
     }
       cout<< max(max(dp[n][1],dp[n][2]),dp[n][3])<<endl;
       return 0;
}


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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(auto& x : s)
        cin >> x;

    vector<vector<i64>> f(h);
    vector<vector<i64>> g(w);
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(s[i][j] == '.')
                continue;
            f[i].emplace_back(j);
            g[j].emplace_back(i);
        }
    }
    for(auto& x : f){
        x.emplace_back(-1);
        x.emplace_back(w);
        sort(x.begin(), x.end());
    }
    for(auto& x : g){
        x.emplace_back(-1);
        x.emplace_back(h);
        sort(x.begin(), x.end());
    }

    i64 ans = 0;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(s[i][j] == '#')
                continue;
            auto it = lower_bound(f[i].begin(), f[i].end(), j);
            auto it2 = lower_bound(g[j].begin(), g[j].end(), i);
            ans = max(ans, (*it - *prev(it) - 1) + (*it2 - *prev(it2) - 1) - 1);
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
	long long int n, l, psum = 0, idx, curr, prev;
    cin >> n >> l >> prev;
    for (int i = 1; i < n; ++i) {
        cin >> curr;
        if (curr + prev > psum) {
            psum = curr + prev;
            idx = i;
        }
        prev = curr;
    }
    if (psum >= l) {
        cout << "Possible" << endl;
        for (int i = 1; i < idx; ++i) {
            cout << i << endl;
        }
        for (int i = n-1; i > idx; --i) {
            cout << i << endl;
        }
        cout << idx << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
	return 0;
}


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

#define INF 1001001001
#define MAX (1e9+5)

int main() {
  int n;
  cin >> n;
  int maxa[2] = {-INF,-INF},mina[2] = {INF,INF};
  rep(i,n) {
    int x, y;
    cin >> x >> y;
    maxa[0] = max(maxa[0], x-y);
    mina[0] = min(mina[0], x-y);
    maxa[1] = max(maxa[1], x+y);
    mina[1] = min(mina[1], x+y);
  }
  cout << max(maxa[0]-mina[0],maxa[1]-mina[1]) << endl;

  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL MOD=1e9+7;
LL memo[100005][2];
vector<int> adj[100005];
LL solve(int u, bool c, int par)
{
	if(memo[u][c]!=-1) return memo[u][c];
	LL ret=1;
	if(c==1)
	{
		bool check=0;
		for(int z=0;z<adj[u].size();z++)
		{
			int v=adj[u][z];
			if(v==par) continue;
			check=1;
			ret*=(solve(v, 0, u)+solve(v, 1, u));
			ret%=MOD;
		}
	}
	else
	for(int z=0;z<adj[u].size();z++)
	{
		int v=adj[u][z];
		if(v==par) continue;
		ret*=solve(v, 1, u);
		ret%=MOD;
	}
	return memo[u][c]=ret;
}

int main()
{
	int n;
	scanf("%d", &n);
	for(int a=1;a<n;a++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		adj[l].pb(r);
		adj[r].pb(l);
	}
	memset(memo, -1, sizeof(memo));
	printf("%lld\n", (solve(1, 0, -1)+solve(1, 1, -1))%MOD);
	return 0;
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define debug(x) if(MODE==x)
#define MODE 0
using namespace std;

struct info
{
    int a;
    int b;
};

int chart[1007][1007];
bool ok[1007][1007];

stack<int>stk[1007];

int main()
{
    int i,j;
    int N;

    scanf("%d",&N);
    for( i=1; i<=N; i++)
    {
        for( j=1; j<=N-1; j++)
        {
            scanf("%d",&chart[i][j]);
        }
    }

    queue<info>que;
    for( i=1; i<=N; i++)
    {
        for( j=N-1; j>=1; j--)
        {
            stk[i].push(chart[i][j]);
        }
        ok[i][ stk[i].top() ] = 1;
        if(ok[i][stk[i].top()] && ok[stk[i].top()][i])
        {
            debug(2) printf("YEE\n");
            que.push({i,stk[i].top()});
            ok[i][ stk[i].top() ] = 0;
            ok[stk[i].top()][i] = 0;
        }
    }

    debug(1)
    {
        printf(">>>check\n");
        for( i=1; i<=N; i++)
        {
            for( j=1; j<=N; j++)
                printf("%d ",ok[i][j]);
            printf("\n");
        }
        printf("\n");
    }

    int step = 0;
    while(!que.empty())
    {
        int goal = que.size();
        while(goal--)
        {
            int a = que.front().a;
            int b = que.front().b;
            debug(1) printf("{%d,%d}\n",a,b);

            que.pop();
            stk[a].pop();
            stk[b].pop();
            if(!stk[a].empty())
                ok[a][ stk[a].top() ] = 1;
            if(!stk[b].empty())
                ok[b][ stk[b].top() ] = 1;
            if(!stk[a].empty() && ok[a][stk[a].top()] && ok[stk[a].top()][a])
            {
                que.push({a,stk[a].top()});
                ok[a][ stk[a].top() ] = 0;
                ok[stk[a].top()][a] = 0;
            }
            if(!stk[b].empty() && ok[b][stk[b].top()] && ok[stk[b].top()][b])
            {
                que.push({b,stk[b].top()});
                ok[b][ stk[b].top() ] = 0;
                ok[stk[b].top()][b] = 0;
            }
            debug(1)
            {
                printf(">>>check\n");
                for( i=1; i<=N; i++)
                {
                    for( j=1; j<=N; j++)
                        printf("%d ",ok[i][j]);
                    printf("\n");
                }
                printf("\n");
            }
        }
        step++;
    }

    bool flag = 0;
    for( i=1; i<=N; i++)
    {
        if(!stk[i].empty())
            flag = 1;
    }

    if(flag)
        printf("-1\n");
    else
        printf("%d\n",step);



    return 0;
}


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

int main(){
	int h;
	int w;
	int a;
	int b;
	while(true) {
		cin >> h >> w;
		if ( h==0 && w==0 ) break;
		b=h;
		while ( b>0 ) {
			a=w;
			while ( a>0 ) {
				if ( b==1 || b==h || a==1 || a==w ) {
					cout << "#";
				}else {
					cout << ".";
				}
				a--;
			}
			cout << endl;
			b--;
		}
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 1152
n , k = gets.split(" ").map!{|i| i.to_i}
group = Array.new(n+1,0)
data = gets.split(" ").map!{|i| i.to_i}
alter = 0

n.times do |i|
  group[data[i]] = group[data[i]]+1
end
group.sort!
(n+1-k).times do |i|
  alter = alter + group[i]
end
puts alter

Measured memory_bytes: 16768
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
vvpi g;vi vis,c;
void dfs(ll i,ll s){
	vis[i]=1;c[i]=s%2;
	for(auto j:g[i]) if(!vis[j.fs]) dfs(j.fs,s+j.se);
}
int main(){
	ll n,i,u,v,w;cin>>n;g.resize(n+1),vis.resize(n+1,0),c.resize(n+1,0);
	for(i=1;i<n;i++) cin>>u>>v>>w,g[u].eb(v,w),g[v].eb(u,w);
	dfs(1,0);
	for(i=1;i<=n;i++) cout<<c[i]<<endl;
}


Measured memory_bytes: 9984
X = int(input())
if X <= 599:
    print(8)
elif X <= 799:
    print(7)
elif X <= 999:
    print(6)
elif X <= 1199:
    print(5)
elif X <= 1399:
    print(4)
elif X <= 1599:
    print(3)
elif X <= 1799:
    print(2)
else:
    print(1)


Measured memory_bytes: 61612
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define in(x) (read(x))
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ld eps = 1e-9;
const int inf = mod;
template<typename T>
inline int sign(const T&a){if(a<0)return -1;if(a>0)return 1;return 0;}


template<typename T> inline void read(T &x){
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
    while (isdigit(ch))  {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

int main(){
	ll a,b,c;cin>>a>>b>>c;
	if(a%2==0 || b%2 == 0 || c%2==0){
		cout<<0;return 0;
	}
	ll ans = min(a*b,a*c); ans = min(ans,b*c);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ii pair <int, int>
#define x first
#define y second
#define db(x) cerr << #x << " = " << x << endl;

using namespace std;

inline void read(int &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void read(long long &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void writeln(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar('\n');}
inline void write(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar(' ');}

int dem;
long long a, b, x;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	read(a); read(b);
	x = a;
	while (a <= b){
		dem++;
		a *= 2;
	}
	writeln(dem);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 205;
vector<int> G[MAX_N];
bool visited[MAX_N][MAX_N];
int col[MAX_N];
int d[MAX_N][MAX_N];

void init()
{
	rep(i,MAX_N)
	{
		rep(j,MAX_N)
		{
			if (i == j) d[i][j] = 0;
			else d[i][j] = 300;
		}
	}
}

bool dfs(int n, int c)
{
	/*
	cout << "visiting:" << n << endl;
	if (num[n] != -1 && num[n] != c) return false;
	num[n] = c;
	bool res = true;
	rep(i,G[n].size())
	{
		if (visited[n][G[n][i]]) continue;
		visited[n][G[n][i]] = true;
		visited[G[n][i]][n] = true;
		if (!dfs(G[n][i],c+1)) res = false;
	}
	return res;
	*/
	col[n] = c;
	rep(i,G[n].size())
	{
		if (col[G[n][i]] == c) return false;
		if (col[G[n][i]] == 0 && !dfs(G[n][i],-c)) return false;
	}
	return true;
}

int main()
{
	init();
	int N;
	cin >> N;
	rep(i,N)
	{
		string S;
		cin >> S;
		rep(j,N)
		{
			if (S[j] == '1')
			{
				G[i].push_back(j);
				d[i][j] = 1;
				d[j][i] = 1;
			}
		}
	}

	int ans = 0;
	if (!dfs(0,1))
	{
		cout << -1 << endl;
		return 0;
	}
	for (int k = 0; k < N; ++k)
	{
		for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j < N; ++j)
			{
				d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	rep(i,N)
	{
		rep(j,N)
		{
			ans = max(ans,d[i][j]);
		}
	}
	cout << ans+1 << endl;
	return 0;
}

Measured memory_bytes: 3932
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
c = 0
for i in range(N):
  for j in range(i + 1, N):
    d = math.sqrt(sum(map(lambda y, z: (y - z) ** 2, X[i], X[j])))
    if d == int(d):
      c += 1
print(c)

Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

signed main(){
    lint N, K;
    cin>>N>>K;
    long double res = 0;
    for(int i=1; i<=N; i++){
        long double t = log2l(1.0*K/i);
        lint s = ceil(t);
        long double tmp = 1.0/N;
        REP(i, s){
           tmp *= 0.5;
        }
        res += tmp;
    }
    cout << fixed << setprecision(14) << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
int findMin(int k, int i){
  for (int l = 0; l<=19; l++){
    if (pow(2.0, double(l))>=double(k)/double(i))
      return l;
  }
}


int main () {
  int n, k;
  cin >> n >> k;
  int j;
  double prob=0.0;
  for (int i=1; i<=n; i++){
    j=findMin(k, i);
    prob+=1.0/(double(n)*pow(2.0, double(j)));
  }
  cout << fixed << setprecision(10) << prob;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
const int INF = 0;
 
int main(){
    int H,W,K; cin>>H>>W>>K;
    int field[H][W],copy[H][W];
    rep(i,H){
      string a; cin>>a;
      rep(j,W){
        field[i][j]=a[j]-'0';
        copy[i][j]=field[i][j];
      }
    }
  
int rec=0;
rep(a,H) rep(b,W){
    rep(i,H) rep(j,W) field[i][j]=copy[i][j];
    field[a][b]=INF;
 
rep(k,30){
        for(int i=0;i<H-1;i++){
            rep(j,W){
                if(field[i+1][j]==INF){
                    field[i+1][j]=field[i][j];
                    field[i][j]=INF;
                }
            }
        }
    }
 
 
 int ans=0; 
 int two=1;
 rep(l,30){
   
    int point=0;
    rep(i,H){
 
        int count=1;
        for(int j=1;j<W;j++){
            if(field[i][j]==field[i][j-1]) count++;
            else{
                if(count<K) count=1;
                else{
                    point+=field[i][j-1]*count;
                    rep(k,count) field[i][j-1-k]=INF;
                    count=1;
                }   
            }
            if(j==W-1){
                    if(count>=K){
                        point+=field[i][j-1]*count;
                        rep(k,count) field[i][j-k]=INF;
                    }
            }
        }
    }
    rep(k,30){
        for(int i=0;i<H-1;i++){
            rep(j,W){
                if(field[i+1][j]==INF){
                    field[i+1][j]=field[i][j];
                    field[i][j]=INF;
                }
            }
        }
    }
 
    
   ans+=point*two;
   two*=2;
 }
 rec=max(ans,rec);
}
 
cout<<rec<<endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int D,n,m,d[100010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>D && D){
		cin>>n>>m;
		d[0]=0;
		rep(i,n-1){
			cin>>d[i];
		}
		sort(d,d+n);
		d[n++]=D;
		ll ans=0;
		int k;
		rep(i,m){
			cin>>k;
			int lb=lower_bound(d,d+n,k)-d;
			ans+=lb?min(d[lb]-k,k-d[lb-1]):0;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1600
n, k = map(int, input().split())
card = {x : i for x, i in zip (("s", "p", "r") , map(int, input().split()))}
t = input()
ans = [0]*k

for i in range(k):
    chk = 0
    for j in range(i, n, k):
        if j < k:
            tmp, chk = card[t[j]], 1
        elif t[j] != t[j-k]:
            tmp, chk = card[t[j]], 1
        elif chk == 0 and t[j] == t[j-k]:
            tmp, chk = card[t[j]], 1
        else:
            tmp, chk = 0, 0
        ans[i] += tmp
print(sum(ans))



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

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	int next_btn_pos = 1;
	int push_cnt = 0;
	for (int i = 0; i < n; i++) {
		next_btn_pos = a[next_btn_pos];
		if (next_btn_pos == 2) {
			push_cnt = i + 1;
			break;
		}
	}

	if (push_cnt == 0) {
		push_cnt = -1;
	}

	cout << push_cnt << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>
using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = (int)(n-1); i >= 0; i--)
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    int cnt = 0;
    rep(i, N) {
        if (p[i] !=i+1)cnt++;
    }
    if (cnt <= 2)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

using namespace std;

bool dp[5001][5001];
long N, K;
long a[5000];
bool judge(int c){
    if(a[c] >= K) return false;
    for(int i = 0; i <= N; i++){
        memset(dp[i], false, K+1);
        dp[i][0] = true;
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= K; j++){
            dp[i+1][j] = dp[i][j];
        }
        if(i != c){
            for(int j = 0; j <= K; j++){
                if(dp[i][j]){
                    if(j+a[i] < K-a[c]) dp[i+1][j+a[i]] = true;
                    else if(j+a[i] < K) return false;
                }
            }
        }
    }
    return true;
}

int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a, a+N);
    int l = 0, r = N-1;
    if(!judge(l)){
        cout << 0 << endl;
        return 0;
    }
    if(judge(r)){
        cout << N << endl;
        return 0;
    }
    int c;
    while(r-l > 1){
        c = (r+l)/2;
        if(judge(c)) l = c;
        else r = c;
    }
    cout << l+1 << endl;
}

Measured memory_bytes: 24704
#pragma GCC optimize("O3")
            #pragma comment(linker, "/stack:200000000")
            #pragma GCC optimize("unroll-loops")
             
            #include <algorithm>
            #include <bitset>
            #include <cassert>
            #include <chrono>
            #include <cmath>
            #include <complex>
            #include <cstdio>
            #include <cstdlib>
            #include <cstring>
            #include <ctime>
            #include <deque>
            #include <functional>
            #include <iomanip>
            #include <iostream>
            #include <iterator>
            #include <limits>
            #include <climits>
            #include <list>
            #include <map>
            #include <numeric>
            #include <queue>
            #include <random>
            #include <ratio>
            #include <set>
            #include <sstream>
            #include <stack>
            #include <string>
            #include <unordered_map>
            #include <unordered_set>
            #include <utility>
            #include <vector>
            using namespace std;
             
            typedef long long ll;
            typedef long double LD;
            #define int ll
            #define double LD
            #define pb push_back
            #define mp make_pair
            #define REP(i,n) for (int i = 0; i < n; i++)
            #define loop(i,n) for (int i = 0; i < n; i++)
            #define FOR(i,a,b) for (int i = a; i < b; i++)
            #define REPD(i,n) for (int i = n-1; i >= 0; i--)
            #define FORD(i,a,b) for (int i = a; i >= b; i--)
            #define remax(a,b) a = max(a,b)
            #define remin(a,b) a = min(a,b)
            #define mem(a, b) memset(a, b, sizeof a)
            #define append push_back
            #define all(v) v.begin(),v.end()
            #define F first
            #define S second
            #define print(x) cout << (x) << endl
            #define PRECISION(x) cout << fixed << setprecision(x)
            #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
            #define N 505
            #define pb push_back
            const double PI=acos(-1);
            const int MOD = 1000000007;
            const int FMOD = 998244353;
            const double eps = 1e-9;
             
            mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 

           signed main()
           {
    ll n,k;
    cin>>n>>k;
    ll ans = 0;
    for(ll i=k;i<n+2;i++){
        ll mn = i*(i-1)/2;
        ll mx = n*(n+1)/2 - (n-i)*(n-i+1)/2;
        ll val = mx-mn+1;
        val = val%MOD;
        ans = (ans+val)%MOD;
    }
    cout<<ans;
	return 0;
		   }

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
vector<int> V[MC];

P2 dfs(int p , int q){
	int r = 0 , s = 0 , t = 0 , c = 0;
	for(auto u : V[q]){
		if(u == p) continue;
		P2 z = dfs(q,u);
		r += z.first;
		if(z.first==0) ++s;
		else if(z.second>0) ++t;
		else ++c;
	}
	if(s>0) r += s-1;
	return MP(r,s>0||(t+c==1&&t>0)?1:0);
}

int main(){
	cin >> N;
	repp(i,1,N){
		int a,b;
		cin >> a >> b;
		V[a].PB(b);
		V[b].PB(a);
	}
	int r = 0;
	while((int)V[r].size()>1) ++r;
	P2 ans = dfs(-1,r);
	cout << ans.first + ans.second << endl;
	return 0;
}


Measured memory_bytes: 13568
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int64 x,y;
  cin>>x>>y;
  int64 result=0;
  for(int i=1;i<=3;i++){
    if(x==i){
      result+=(4-i)*100000;

    }
    if(y==i){
      result+=(4-i)*100000;

    }
  }
  if(x==1&&y==1){

    result+=400000;
  }
  cout<<result<<endl;



  return 0;
}

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

typedef long long gg;

gg solve(){
    gg n;cin>>n;
    if(n%2) return 0;
    n/=2;
    gg d=5,a=0;
    while(d<=n){
        a+=n/d;
        if(d>n/5) break;
        d*=5;
    }
    return a;
}

int main(){
    cout<<solve()<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;
template <typename... Args> void dbg(Args &&... args) {
  using expander = int[];
  (void)expander{
      0,
      (static_cast<void>(void(cout << std::forward<Args>(args) << " ")), 0)...};
  cout << endl;
}
void gen() {
  exit(0);
}

ll k, a, b;

void input() {
  scanf("%llu %llu %llu", &k, &a, &b);
}

void solve() {
  ll d = b - a;
  ll t = 1 + k;

  if (d <= 2) {
    printf("%llu\n", t);
    return;
  } else if (k - a + 1 < 2) {
    printf("%llu\n", t);
    return;
  }

  k = k - a + 1;
  ll q = (d * (k / 2));
  ll ans = a + q + (k % 2);
  printf("%llu\n", ans);
}

void clean() {
  scanf(" ");
}

int main() {
#ifdef DEBUG
  freopen("input", "r", stdin);
  freopen("output", "w", stdout);
  // gen();
  while (!feof(stdin)) {
#endif
    input();
    solve();
#ifdef DEBUG
    clean();
  }
#endif
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    vector<int> O(N);
    for (int i = 0; i < N; i++) {
        O[i] = i;
    }

    double ans = 0;
    int cnt = 0;
    do {
        double t = 0;
        for (int i = 1; i < N; i++) {
            t += sqrt((x[O[i]] - x[O[i - 1]]) * (x[O[i]] - x[O[i - 1]]) + (y[O[i]] - y[O[i - 1]]) * (y[O[i]] - y[O[i - 1]]));
        }
        ans += t;
        cnt++;
    } while (next_permutation(O.begin(), O.end()));
    cout << setprecision(10) << ans / cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    int a, b;
    char op;

    while(1){
        cin >> a;
        cin >> op;
        cin >> b;

        if(op=='+'){
            cout << a + b << endl;
        }else if(op=='-'){
            cout << a - b << endl;
        }else if(op=='*'){
            cout << a * b << endl;
        }else if(op=='/'){
            cout << a / b << endl;
        }else{
            break;
        }
        
    }

}



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

ll ans, a = 2, n, l, i;

void upd(ll x, ll y) {
  if ((i = __gcd(x,y) > 1 ? 0 : inv_mod(a*x,y)) > 0)
    ans = min({ans, i * x * a - 1, (y-i) * x * a});
}

int main() {
  cin >> n; ans = n + (n % 2 == 0);
  while (n % 2 == 0)
    a *= 2, n /= 2;
  for (ll d = 1; d * d <= n; d++)
    if (n % d == 0)
      upd(d, n / d), upd(n / d, d);
  cout << ans << "\n";
}

Measured memory_bytes: 3660
// D - Not Divisible
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int N; cin>>N;
	vi A(N);
	vi l(1000000+1, 0);
	vi c(1000000+1, 0);
	// int mn = 0;
	int mx = 0;
	rep(i, N){
		int a; cin>>a;
		A[i] = a;
		// mn = min(mn, a);
		mx = max(mx, a);
		c[a]++;
	}

	for(int a:A){
		for(int i=a*2; i<=mx; i+=a) l[i] = 1;
	}

	int ans = 0;
	for(int a:A){
		if(!l[a] && c[a] <= 1) ans++;
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 11896
N = int(input())
A = list(map(int, input().split()))
A = list(reversed(sorted(A)))
new_A = []
for i in range(1, N//2+1):
    new_A.append(A[i])
    new_A.append(A[i])

new_A = [0] + [A[0]] + new_A

print(sum(new_A[:N]))

Measured memory_bytes: 31696
import math
def stddd(alist) :

    adv = sum(alist) / len(alist)
    std = 0.0
    for dd in alist:
        std = std + (dd - adv)**2.0

    std = std/len(alist)
    return math.sqrt(std)


dlist = []
while True:
    n_data = int(input())
    if n_data == 0:
        [print(dd) for dd in dlist]
        break
    dataarr =  map (float, input().split())
    alist = []
    [alist.append(dd) for dd in dataarr]
    dlist.append(stddd(alist))



Measured memory_bytes: 5720
s = str(input())
ans = 0
n = len(s)
for i in range(n):
    if s[i]=="a":
        ans +=1
    
    if s[i]=="b":
        ans +=2
    if s[i]=="c":
        ans +=3
if ans==6:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
from functools import reduce
import operator

N = int(input())
Ss = list(map(int, input().split()))
Ts = list(map(int, input().split()))
Us = list(map(int, input().split()))
Vs = list(map(int, input().split()))
mat = [[0] * N for _ in range(N)]
counts_r = [[0] * 64 for _ in range(N)]
counts_c = [[0] * 64 for _ in range(N)]


class NotOK(Exception):
    pass


try:
    for i in range(N):
        for j in range(N):
            x = 0
            if not Ss[i]:
                x |= Us[i]
            if not Ts[j]:
                x |= Vs[j]
            if Ss[i] and (~Us[i] & x):
                raise NotOK
            if Ts[j] and (~Vs[j] & x):
                raise NotOK
            if Ss[i] and Ts[j]:
                x |= Us[i] & Vs[j]
            mat[i][j] = x
            for k in range(64):
                if (x >> k) & 1:
                    counts_r[i][k] += 1
                    counts_c[j][k] += 1

    def corr(x, vals, ors, counts):
        for k in range(64):
            if (x >> k) & 1 == 0:
                continue
            for j in range(N):
                if ors[j]:
                    continue
                if counts[j][k] >= N - 1:
                    continue
                counts[j][k] += 1
                vals[j] += 1 << k
                x -= 1 << k
                if not x:
                    return x
                break
        return x

    for i in range(N):
        vals = mat[i]
        if Ss[i]:
            x = reduce(operator.or_, vals)
            if corr(Us[i] & ~x, vals, Ts, counts_c):
                raise NotOK
        else:
            x = reduce(operator.and_, vals)
            if x != Us[i]:
                raise NotOK
        vals = []
        for j in range(N):
            vals.append(mat[j][i])
        if Ts[i]:
            x = reduce(operator.or_, vals)
            if corr(Vs[i] & ~x, vals, Ss, counts_r):
                raise NotOK
            for j in range(N):
                mat[j][i] = vals[j]
        else:
            x = reduce(operator.and_, vals)
            if x != Vs[i]:
                raise NotOK
    for i in range(N):
        print(*mat[i])
except NotOK:
    print(-1)


Measured memory_bytes: 106632
#include<iostream>
#include<cmath>
#include<iomanip>
#define ll long long
using namespace std;
int main() {
	ll num=0;
	string s;
	cin>>s;
	int len=s.size();
	for(int i=0; i<len; i++) {
		num+=s[i]-'0';
	}
	if(num%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}
// }}} End Header

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

    VAR(i64, N);
    VAR(string, s);
    VAR(int, Q);

    while (Q--) {
        VAR(int, K);
        i64 ans = 0;
        i64 cntD = 0;
        i64 cntM = 0;
        i64 DM = 0;

        rep(i, 0, K) {
            if (s[i] == 'D') {
                ++cntD;
            } else if (s[i] == 'M') {
                ++cntM;
                DM += cntD;
            } else if (s[i] == 'C') {
                ans += DM;
            }
        }

        rep(i, K, N) {
            {
                const char ch = s[i - K];
                if (ch == 'D') {
                    --cntD;
                    DM -= cntM;
                } else if (ch == 'M') {
                    --cntM;
                }
            }
            {
                const char ch = s[i];
                if (ch == 'D') {
                    ++cntD;
                } else if (ch == 'M') {
                    ++cntM;
                    DM += cntD;
                } else if (ch == 'C') {
                    ans += DM;
                }
            }
        }

        print(ans);
    }

    return 0;
}


Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int a, b;
  cin >> a >> b;

  int aAmari = a % 500;
  if (aAmari <= b) {
     cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int cups[15];
int n, m;
const int A = 0, B = 1, C = 2;
int pow(int x, int y) {
    int ret = 1;
    while (y--) {
        ret *= x;
    }
    return ret;
}
int calculate(int from) {
    int ret = 0;
    for (int i=0; i<n; ++i) {
        if (cups[i] == from) {
            // ignore
        } else if (cups[i] == B) {
            ret += pow(3, n-1-i);
            from = (from == A) ? C : A;
        } else {
            ret += 2 * pow(3, n-1-i);
        }
    }
    return ret;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (cin >> n >> m, n|m) {
        for (int i=0; i<3; ++i) {
            int l; cin >> l;
            for (int j=0; j<l; ++j) {
                int cup; cin >> cup;
                cups[cup-1] = i;
            }
        }

        int ret = min(calculate(A), calculate(C));
        if (ret > m) {
            ret = -1;
        }
        cout << ret << "\n";
    }

    return 0;
}

Measured memory_bytes: 1196
n = int(input())

adj = [[]] * n
for i in range(n):
    x = list(map(int, input().split()))
    adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])]

import heapq

def dijkstra():
    PQ = [(0, 0)]
    isVisited = [False] * n
    distance = [999900001] * n

    distance[0] = 0
    
    while PQ:
        uc, u = heapq.heappop(PQ)

        if uc > distance[u]:
            continue

        isVisited[u] = True
        
        for vc, v in adj[u]:
            if isVisited[v] == True:
                continue
            
            t_cost = distance[u] + vc
            if t_cost < distance[v]:
                distance[v] = t_cost
                heapq.heappush(PQ, (t_cost, v))

    for v, d in enumerate(distance):
        print(v, d)


dijkstra()

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

int main(){
    int n, k, i, count;
    vector<int> h(100000);
    cin >> n >> k;
    for(i = 0;i < n;i++){
        cin >> h.at(i);
    }

    count = 0;
    for(i = 0;i < n;i++){
        if(h.at(i) >= k) count++;
    }
    cout << count << endl;
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INF = 2147483647;
const long long LINF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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 main(void){
    ll N,K; cin >> N >> K;
    ll x = N%K;
    cout << min(x, K-x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    int D, T, S; cin >> D >> T >> S;
    if(D<=S*T) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=998244353;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}
long modInverse(long a) {return powmod(a, mod-2);}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int l;
    cin>>l;
    cout.precision(9);
    double ans=double(l)/double(3);
    double res=ans*ans*ans;
    cout<<res<<endl;
    return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n; cin >> n;
  vector<int> b(n-1);
  REP(i,n-1) cin >> b[i];

  int ans = b[0]+b[n-2];
  for(int i = 1; i < n-1; i++) {
    ans+= min(b[i-1],b[i]);
  }

  COUT(ans);
  return 0;
}

Measured memory_bytes: 256