akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    const int K = 10;
    vector<vector<int>> dp(n+1, vector<int>(K + 1, -1));
    
    dp[0][0] = 0;
    rep(i, n) {
        for(int j = 0; j <= K; j++) {
            if(dp[i][j] == -1) {
                continue;
            }
            for(int k = 1; k <= K && i + k <= n; k++) {
                if(j != k || s.substr(i - j, j) != s.substr(i, k)) {
                    dp[i + k][k] = max(dp[i + k][k], dp[i][j] + 1);
                }
            }
        }
    }

    int ans = 0;
    for(int j = 0; j <= K; j++) {
        ans = max(ans, dp[n][j]);
    }

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

Measured memory_bytes: 17668
# 参考: White_Pie_46
# https://atcoder.jp/contests/abc176/submissions/16168825
from collections import deque


def main():
    height, width = [int(x) for x in input().split()]
    init_h, init_w = [int(x) - 1 for x in input().split()]
    dest_h, dest_w = [int(x) - 1 for x in input().split()]
    grid = [list(input()) for _ in range(height)]

    can_walk = (
        (1, 0),
        (0, 1),
        (-1, 0),
        (0, -1)
    )

    def gen_warp_can_reach():
        for h in range(-2, 3):
            for w in range(-2, 3):
                warping = True
                if h == 0 == w:
                    continue
                if (h, w) in can_walk:
                    warping = False
                yield (h, w, warping)
    warp_can_reach = tuple(gen_warp_can_reach())
    qu = deque()
    qu.append((init_h, init_w, 0))  # 座標とワープ回数を保持

    while qu:
        h, w, warps = qu.popleft()
        if h == dest_h and w == dest_w:
            return warps
        if grid[h][w] == 'R':
            # 同じマスを複数回キューに追加しているかもしれない。
            # 短距離で調査済みなら再調査は不要。
            continue
        grid[h][w] = 'R'  # reached

        for h_delta, w_delta, warping in warp_can_reach:
            new_h, new_w = h + h_delta, w + w_delta
            if 0 <= new_h < height and 0 <= new_w < width:
                if grid[new_h][new_w] == '.':
                    if warping:
                        qu.append((new_h, new_w, warps + 1))
                    else:
                        qu.appendleft((new_h, new_w, warps))
    return -1


if __name__ == '__main__':
    print(main())


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


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

    for(int i = x; i < 1000003; i++){
        bool f = true;
        for(int j = 2; j <= i / 2; j++){
            if(i % j == 0) f = false;
        }
        if(f){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

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

ll mod_pow(ll a, int n, int m) {
    if (n == 0)
        return 1;
    else if (n % 2 == 1)
        return (a * mod_pow((a * a) % m, n >> 1, m)) % m;
    else
        return mod_pow((a * a) % m, n >> 1, m);
}

ll inv(ll a, int m) { return mod_pow(a, m - 2, m); }

ll dp[200005];
ll factorial(ll N, int m) {
    if (dp[N] != -1) return dp[N];
    ll ret = 1;
    rep(i, N + 1) if (i) {
        ret *= i;
        ret %= m;
    }
    return dp[N] = ret;
}

int f(int N, int M) {
    if (N == 0 or M == 0) return 1;
    ll a = factorial(N + M, MOD);
    ll b = factorial(N, MOD);
    ll c = factorial(M, MOD);

    ll ret = inv((b * c) % MOD, MOD);
    ret *= a;
    ret %= MOD;
    ret += MOD;
    ret %= MOD;

    return ret;
}

int H, W, A, B;
ll f2(int N, int M) {
    ll a = f(N - 1, M - 1);
    ll b = f(H - N - 1, W - M);
    // printf("(%d, %d): %lld %lld\n", N, M, a, b);
    return (a * b) % MOD;
}

int main() {
    dp[0] = 1;
    rep(i, 200005) if (i) dp[i] = (i * dp[i - 1]) % MOD;
    cin >> H >> W >> A >> B;
    ll ans = 0;
    for (int x = B + 1; x <= W; x++) {
        ll c = f2(H - A, x);
        ans += c;
        // printf("%d: %lld\n", x, c);
        ans %= MOD;

    }

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


Measured memory_bytes: 1792
#include <stdio.h>
#define n 8
char a[n+2][n+2], player, opponent;

void search(int i, int j, int* maxcnt, int* besti, int* bestj)
{
    int k, l, cnt=0;
    for(k=-1;k<2;++k) for(l=-1;l<2;++l) {
        int ii=i+k, jj=j+l, c=0;
        if (k==0&&l==0) continue;
        if (a[ii][jj]!=opponent) continue;
        while (ii>=1 && jj>=1 && ii<=n && jj<=n && a[ii][jj]==opponent) {
            ii+=k;
            jj+=l;
            ++c;
        }
        if (a[ii][jj]==player) cnt+=c;
    }
    if (*maxcnt<cnt) { *maxcnt=cnt; *besti=i; *bestj=j; }
}
void flip(int i, int j)
{
    int k, l;
    for(k=-1;k<2;++k) for(l=-1;l<2;++l) {
        int ii=i+k, jj=j+l, c=0;
        if (k==0&&l==0) continue;
        if (a[ii][jj]!=opponent) continue;
        while (ii>=1 && jj>=1 && ii<=n && jj<=n && a[ii][jj]==opponent) {
            ii+=k;
            jj+=l;
        }
        if (a[ii][jj]==player) {
            while (ii!=i || jj!=j) {
                a[ii][jj]=player;
                ii-=k;
                jj-=l;
            }
            a[ii][jj]=player;
        }
    }
}

int main(void)
{
    int i, j, pass;
    for(i=1;i<=n;++i)
        scanf("%s", a[i]+1);
    pass=0;
    player='o', opponent='x';
    while (pass<2) {
        int besti=-1, bestj=-1, maxcnt=0;
        if (player=='o') {
            for(i=1;i<=n;++i) for(j=1;j<=n;++j) if (a[i][j]=='.')
                search(i, j, &maxcnt, &besti, &bestj);
        }
        else {
            for(i=n;i>0;--i) for(j=n;j>0;--j) if (a[i][j]=='.')
                search(i, j, &maxcnt, &besti, &bestj);
        }
        if (maxcnt) {
            flip(besti, bestj);
            pass=0;
        }
        else {
            pass++;
        }
        { char t=player; player=opponent; opponent=t; }
    }
    for(i=1;i<=n;++i) {
        for(j=1;j<=n;++j) putchar(a[i][j]);
        puts("");
    }
    return 0;
}

Measured memory_bytes: 524
def comb2(n)
  return 0 if n < 2
  return n*(n-1)/2
end

n = gets.to_i
a = gets.split.map(&:to_i)

sum = 0
bs = Hash.new(0)
a.each{|an| bs[an] += 1}
bs.each do |k,v|
  sum += comb2(v) if v >= 2
end

for i in 0..(n-1)
  if bs[a[i]] >= 2
    puts sum - comb2(bs[a[i]]) + comb2(bs[a[i]]-1)
  else
    puts sum
  end
end

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

void Main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);

  double c = a[n - 1] / 2.0;

  double min_diff = a[n - 1];
  double aj = 0;
  for (int i = 0; i < n - 1; i++) {
    if (abs(c - a[i]) < min_diff) {
      min_diff = abs(c - a[i]);
      aj = a[i];
    }
  }
  cout << a[n - 1] << " " << int(aj) << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 640
#include<stdio.h>
int main(void){
  int i, j, tmp;
  char a[100], b[100];
  scanf("%s %s", a, b);
  //printf("%s %s\n", a, b);
  //printf("%d\n", strcmp(a, b));
  //printf("%d\n", strlen(a));
  //printf("%d\n", a[0] - b[0]);
  for( i = 0; i < strlen(a); i++){
    for( j = i + 1 ; j < strlen(a); j++){
      if( a[i] > a[j]){
        tmp = a[j];
        a[j] = a[i];
        a[i] = tmp;
      }
    }
  }
  //printf("%s\n", a);
  for( i = 0; i < strlen(b); i++){
    for( j = i + 1 ; j < strlen(b); j++){
      if( b[i] < b[j]){
        tmp = b[j];
        b[j] = b[i];
        b[i] = tmp;
      }
    }
  }
  //printf("%s\n", b);
  //printf("%d\n", strcmp(a, b));
  if( strcmp( a, b) < 0 ){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int ans = INF;
  int maxa = max(A, max(B, C));
  FOR(i, maxa, maxa+1000){
    int diff = 3 * i - A - B - C;
    if(diff % 2) continue;
    ans = min(ans, diff/2);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
	
    int qtdPedras;
	int salto;
	int alt;
	int altura;
	int pulo;
	int last;

    scanf("%d", &qtdPedras);
    scanf("%d", &salto);  
	
	int v[qtdPedras];
	int high[qtdPedras]; 

    for(int i = 0; i <= qtdPedras; i++){
        if(i < qtdPedras){
            scanf("%d", &altura); 
            *(high + i) = altura;
        } else {
            printf("%d\n", *(v + (qtdPedras-1)));
        }
        
        if(i == 0){
            alt = altura; 
        } else if(i == 1){
            *(v + 1) = abs(alt - altura);
        }else {
            pulo = min(salto, min(qtdPedras, i));
            
            *(v + i) = 2000000000; //INT_MAX;
            
            for(int j = 0; j < pulo; j++){
                if(j == i-1){
                    *(v + i) = min(*(v + i), abs(alt - altura));
                } else {
                    last = abs(altura - *(high + (i-j-1)));
                    *(v + i) = min(*(v + i), last + *(v + (i-j-1))); 
                }
            }
        }
    }
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)
    x = x->left;
  return x;

}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  return x;
  
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)
    return u;
  if(k < u->key)
    return treeSearch(u->left,k);
  else
    return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  if(x->right != NIL)
    return treeMinimum(x->right);

  Node y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);

  if(y->left != NIL)
    x = y->left;
  else
    x = y->right;

  if(x != NIL)
    x->parent = y->parent;

  if(y->parent == NIL)
    root = x;
  else if(y == y->parent->left)
    y->parent->left = x;
  else
    y->parent->right = x;
  
  z->parent = y;
  
  if(y != z)
    z->key = y->key;


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL ){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }


  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20432
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    string s; cin >> s;
    rep(i, 3) {
        cout << s[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3604
import numpy as np

n, m, c = map(int, input().split())
bbb = np.fromiter(map(int, input().split()), dtype=np.int64)
ans = 0
for _ in range(n):
    aaa = np.fromiter(map(int, input().split()), dtype=np.int64)
    if sum(aaa * bbb) + c > 0:
        ans += 1
print(ans)


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=500005;
const int mod=998244353;
int n,m,ans;
int fac[maxn],ifac[maxn],pw_n[maxn],pw_m[maxn];
int C(int a,int b){
	if(a<b||a<0||b<0)return 0;
	return 1LL*fac[a]*ifac[b]%mod*ifac[a-b]%mod;
}

int main(){
	scanf("%d%d",&n,&m);
	int s=max(n,m);
	fac[0]=ifac[0]=fac[1]=ifac[1]=1;
	for(int i=2;i<=s;i++){
		fac[i]=1LL*fac[i-1]*i%mod;
		ifac[i]=1LL*ifac[mod%i]*(mod-mod/i)%mod;
	}
	REP(i,s)ifac[i]=1LL*ifac[i-1]*ifac[i]%mod;
	pw_n[0]=1;
	REP(i,m)pw_n[i]=1LL*pw_n[i-1]*(n+1)%mod;
	pw_m[0]=1;
	REP(i,n)pw_m[i]=1LL*pw_m[i-1]*(m+1)%mod;
	rep(i,min(n,m)+1){
		ans+=1LL*C(n,i)*C(m,i)%mod*fac[i]%mod*pw_n[m-i]%mod*pw_m[n-i]%mod*(i&1?(mod-1):1)%mod;
		if(ans>=mod)ans-=mod; 
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;

	int ss = s.size();
	int ts = t.size();

	int ans = 1000;
	for (int i = 0; i < ss - ts + 1; ++i) {
		int cnt = ts;
		for (int j = 0; j < ts; ++j) {
			if (s[i + j] == t[j]) {
				--cnt;
			}
		}
		ans = min(ans, cnt);
	}

	cout << ans << '\n';

	return 0;
}


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


using namespace std;





int main()
{
    int x,y;
    string s[111],t[111];
    int c1=0,c2=-666;
    cin>>x;
    for(int i=0;i<x;i++)
    cin>>s[i];
    cin>>y;
    for(int i=0;i<y;i++)
    cin>>t[i];
    for(int i=0;i<x;i++)
    {for(int j=0;j<x;j++)
    if(s[i]==s[j])
    c1++;
    for(int j=0;j<y;j++)
    if(s[i]==t[j])
    c1--;
    c2=max(c1,c2);
    c1=0;
    }
    if(c2<0)
    c2=0;
    cout<<c2; 
 
    return 0;
}     

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

struct UnionFind
{
	int n;
	std::vector<int> par,size;
	UnionFind(int sz) : n(sz), par(sz,0), size(sz,1) {
		std::iota(par.begin(),par.end(),0);
	}
	int find(int x) {
		if(par[x]==x) return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x=find(x);y=find(y);
		if(x==y) return;
		if(size[x]<size[y]) std::swap(x,y);
		size[x]+=size[y];
		par[y]=x;
	}
};


int main() {
	int n,m;
	std::cin >> n >> m;
	UnionFind uf(n);
	rep(i,m) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		uf.unite(a,b);
	}
	// get max size;
	int max=0;
	rep(i,n) max=std::max(max,uf.size[uf.find(i)]);
	print(max);
}


Measured memory_bytes: 4776
#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

typedef struct { int parent; int sibling; int depth, height; int k; int c[2]; } TREE;
TREE tree[30];

void calc_depth(int node, int d)
{
	int i;
	tree[node].depth = d;
	for (i = 0; i < tree[node].k; i++) calc_depth(tree[node].c[i], d+1);
}

int calc_height(int node)
{
	int i, h, t;

	h = 0;
	for (i = 0; i < tree[node].k; i++) {
		if ((t = calc_height(tree[node].c[i])+1) > h) h = t;
	}
	tree[node].height = h;
	return h;
}

int main()
{
	int n, i, id;
	int root, left, right;

	n = in();
	for (i = 0; i < n; i++) {
		id = in(), left = in(), right = in();
		if (left < 0 && right < 0) tree[id].k = 0;
		else if (left >= 0 && right >= 0) {
			tree[id].k = 2;
			tree[id].c[0] = left, tree[id].c[1] = right;
			tree[left].parent = id+1;
			tree[left].sibling = right+1;
			tree[right].parent = id+1;
			tree[right].sibling = left+1;
		} else {
			if (left < 0) left = right;
			tree[id].k = 1;
			tree[id].c[0] = left;
			tree[left].parent = id+1;

		}
	}
	for (root = 0; root < n; root++) {
		if (tree[root].parent == 0) break;
	}
	calc_depth(root, 0);
	calc_height(root);

	for (i = 0; i < n; i++) {
		printf("node %d:", i);
		printf(" parent = %d,", tree[i].parent-1);
		printf(" sibling = %d,", tree[i].sibling-1);
		printf(" degree = %d,", tree[i].k);
		printf(" depth = %d,", tree[i].depth);
		printf(" height = %d,", tree[i].height);
		if (i == root)          printf(" root");
		else if (tree[i].k == 0) printf(" leaf");
		else                    printf(" internal node");
		putchar('\n');
	}
	return 0;
}




Measured memory_bytes: 1988
N = int(input())

counter = {}
max_count = 0
for _ in range(N):
    s = input()
    n = counter.get(s, 0) + 1
    max_count = max(max_count, n)
    counter[s] = n

most_common = (k for k, v in counter.items() if v == max_count)
for s in sorted(most_common):
    print(s)


Measured memory_bytes: 32156
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


  int main()
  {


    // ifstream fin(".in");
    // ofstream fout(".in");
int s;
cin>>s;
double x=s/3.0;


printf("%.6f",x*x*x);



    return 0;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge{
	int f,t,nxt;
};
edge e[100100];
int head[100100],vis[100100][3],dis[100100][3];
int cnt;
void add_edge(int f,int t){
	e[cnt]=(edge){f,t,head[f]};
	head[f]=cnt;
	cnt++;
	return;
}
queue<int> q,qq;
void bfs(int s){
	q.push(s);
	dis[s][0]=0;
	vis[s][0]=1;
	qq.push(0);
	while(!q.empty()){
		int u=q.front(),v=qq.front();
		q.pop();qq.pop();
		for(int i=head[u];i;i=e[i].nxt){
			int x=e[i].t;
			if(!vis[x][(v+1)%3]){
				vis[x][(v+1)%3]=1;
				dis[x][(v+1)%3]=dis[u][v]+1;
				q.push(x);
				qq.push((v+1)%3);
			}
		}
	}
	return;
}
int main(){
	cnt=1;
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		add_edge(f,t);
	}
	int s,t;
	scanf("%d%d",&s,&t);
	bfs(s);
	if(vis[t][0]){
		printf("%d\n",dis[t][0]/3);
	}
	else{
		printf("-1\n");
	}
	return 0;
}


Measured memory_bytes: 4096
H, W = map(int, input().split())
s = [input() for i in range(H)]
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
ans = "Yes"
for i in range(H):
        for j in range(W):
                if s[i][j] == "#":
                        flag = 1 
                        for k in range(4):
                                y = i + dy[k]
                                x = j + dx[k]
                                if 0 <= x < W and 0 <= y < H:
                                        if s[y][x] == "#":
                                                flag = 0 
                        if flag:
                                ans = "No"
                                break
        else:
                continue
        break
print(ans)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) throws IOException {
        List<String> lines = readLines();
        int X = Integer.parseInt(lines.get(0).split(" ")[1]);
        List<Integer> Ls = Arrays.stream(lines.get(1).split(" "))
                .map((l) -> Integer.parseInt(l))
                .collect(Collectors.toList());

        int tSum = 0;
        int boundCount = 1;
        for (int l : Ls) {
            tSum += l;
            if (tSum > X) {
                break;
            }
            boundCount += 1;
        }
        System.out.println(String.format("%d", boundCount));
    }

    public static List<String> readLines() throws IOException {
        InputStream in = System.in;
        InputStreamReader reader = new InputStreamReader(in, "utf-8");
        BufferedReader br = new BufferedReader(reader);

        List<String> retList = new ArrayList<>();
        String line = br.readLine();
        while (line != null && !line.isEmpty()) {
            retList.add(line);
            line = br.readLine();
        }

        reader.close();
        br.close();
        return retList;
    }
}

Measured memory_bytes: 26324
#include<iostream>
#include<cstdio>

using namespace std;
int N[50];
int main(){
  int n,p,p1;
 
  int i=0;
  while(true){
    cin>>n>>p;
    //ishi
    p1=p;
    if(n==0&&p==0)break;
    i=0;
    while(true){
      if(i==n)i=0;
      if(p1==0){
	p1=N[i];
	N[i]=0;
      }
      else {
	p1--;
	N[i]++;
	if(N[i]==p)break;
      }
     i++;
    }
    cout<<i<<endl; 
    N[i]=0;
    /*
    for(int i=0;i<n;i++){
      cout<<"person"<<i<<" "<<N[i]<<endl;
      }*/
  }
  return 0;
  
}

Measured memory_bytes: 1160
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;
    string st;
    char ch;
    while(cin>>a>>ch>>b)
    {
        if(ch=='+')cout<<a+b<<en;
        else cout<<a-b<<en;
    }
}



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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using namespace std;

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

    int a_array[] = {1, 3, 5, 7, 8, 10, 120};
    int b_array[] = {4, 6, 9, 11};
    int c_array[] = {2};

    int a, b; cin >> a >> b;
    int af, bf; af = bf = 0;

    REPI(i, sizeof(a_array) / sizeof(a_array[0])){
        if(a_array[i] == a) af = 1;
        if(a_array[i] == b) bf = 1;
    }
    REPI(i, sizeof(b_array) / sizeof(b_array[0])){
        if(b_array[i] == a) af = 2;
        if(b_array[i] == b) bf = 2;
    }
    af == bf ? cout << "Yes" : cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	
	int cost=0;
	while(1){
		bool ok=true;
		for(int i=0;i<n;i++){
			if(h[i]>0)ok=false;
		}
		
		if(ok){
			cout << cost << endl;
			return 0;
		}
		
		bool cnt_now=false;
		for(int i=0;i<n;i++){
			if(cnt_now>0 && h[i]<=0){
				break;
			}
			if(h[i]>0){
				h[i]--;
				cnt_now=true;
			}
		}
		if(cnt_now)cost++;
	}
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var a = ReadLine();
            var b = new int[4];
            var Re = "No";

            for (int i = 0; i < a.Length; i++) {
                b[i] = int.Parse(a[i].ToString());
            }

            if(b[0] == b[1] && a[1] == a[2]) {
                Re = "Yes";
            }else if(a[1] == a[2] && a[2] == a[3]) {
                Re = "Yes";
            }


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

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

Measured memory_bytes: 11092
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    D, T, S = map(int, readline().split())
    if D-T*S>0:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9216
#include <cstdio>
#include <string>
#include <queue>
#include <iostream>

using namespace std;

int main(){
    string s;

    priority_queue<int> PQ;

    while(1){

        cin>>s;
        
        if(s=="end")break;
        else if(s=="insert"){
            int num;
            cin>>num;
            PQ.push(num);
        }else if(s=="extract"){
            cout<<PQ.top()<<endl;
            PQ.pop();

        }
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<string> S(100009);
  for(int i=0;i<N;i++){cin >> S[i];}
  long long m=0,a=0,r=0,c=0,h=0;
  for(int i=0;i<N;i++){
    if(S[i][0]=='M'){m++;}
    if(S[i][0]=='A'){a++;}
    if(S[i][0]=='R'){r++;}
    if(S[i][0]=='C'){c++;}
    if(S[i][0]=='H'){h++;}
  }
  long long ans=m*a*(r+c+h)+m*r*(c+h)+m*c*h+a*r*(c+h)+a*c*h+r*c*h;
  cout << ans << endl;
}

Measured memory_bytes: 6144
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

#define PI 3.141592653589793238
#define INF 1050000000

using namespace std;



//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	int x, y;

	cin >> x >> y;

	vector<int> A = { 1,3,5,7,8,10,12 }, B = { 4,6,9,11 }, C = { 2 };

	int opx = 0, opy = 0;

	for (int i = 0; i < 4; i++) {
		if (x == B[i]) {
			opx = 1;
		}
		if (y == B[i]) {
			opy = 1;
		}
	}

	if (x == 2||y==2) {
		cout << "No" << endl;
	}
	else if (opx == opy) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int length = S.length();
        int g1 = 0;
        int g2 = 0;
        int gcnt = 0;
        char now = 'L';
        int rInd = 0;
        int V[] = new int[length];
        for(int i = 0; i < length; i++){
            V[i] = 0;
        }
        for(int i = 0; i < length; i++){
            char c = S.charAt(i);
            if(now != c){
                if(c == 'L'){
                    rInd = i - 1;
                    if(gcnt % 2 == 0){
                        V[i] = g1;
                        V[i - 1] = g2;
                    }else{
                        V[i] = g2;
                        V[i - 1] = g1;
                    }
                }
                now = c;
                g1 = 0;
                g2 = 0;
                gcnt = 0;
            }
            gcnt++;
            if(c == 'R'){
                if(gcnt % 2 != 0){
                    g1++;
                }else{
                    g2++;
                }
            }else{
                if(gcnt % 2 != 0){
                    V[rInd + 1]++;
                }else{
                    V[rInd]++;
                }
            }
        }
        for(int i = 0; i < length; i++){
            System.out.print(V[i] + " ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 43892
list_ = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = input()

print(list_[int(k) - 1])

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(void){
    int n, t;
    vector<int> a;
    map<int, int> p;
    cin >> n >> t;
    a.assign(n, 0);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int mn = a[0];
    for(int i=1;i<n;i++){
        p[a[i]-mn]++;
        mn = min(mn, a[i]);
    }
    auto itr = p.end();
    itr--;
    cout << (itr->second) << endl;
}


Measured memory_bytes: 5376
package main

import "fmt"

func main() {
	var S string
	var ans int
	fmt.Scan(&S)
	switch S {
	case "SUN":
		ans = 7
	case "MON":
		ans = 6
	case "TUE":
		ans = 5
	case "WED":
		ans = 4
	case "THU":
		ans = 3
	case "FRI":
		ans = 2
	case "SAT":
		ans = 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
   int n,k;
   cin>>n>>k;
   int ans=0;
   for(int i=0;i<n;i++){
       int x;
       cin>>x;
       int y=k>x?k-x:x-k;
       ans+=min(x,y)*2;
   }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>

long long MOD=1000000007;
long long MOD2=998244353;

int main(){
  long long N;
  std::cin>>N;
  if(N%2){
    std::cout<<"0\n";
    return 0;
  }
  long long ans=0, tmp=10;
  while(tmp<=N){
    ans+=N/tmp;
    tmp*=5;
  }
  std::cout<<ans<<std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){
	int A,B,C,Soma1,Soma2,Soma3;
	scanf("%d %d %d",&A,&B,&C);
	

		
		Soma1= A + B;
		Soma2= B + C;
		Soma3 = C+A;
		
		if(Soma1< Soma2 && Soma1 < Soma3)
		{
			printf("%d\n",Soma1);
		}
		else
		{
			if(Soma2 < Soma3){
				printf("%d\n",Soma2);
			}
			else{
				printf("%d\n",Soma3);
			}
		}
	
	return 0;
}

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


/*
    Breadth First Search (BFS) on a grid
    return distance from start
*/

template <typename T> vector<vector<int>> grid_bfs(const vector<T> &S, int sh, int sw) {
    const int delta_h[4] = {0, 1, 0, -1}, delta_w[4] = {1, 0, -1, 0};
    const char wall = '#'; // change yourself
    int H = S.size(), W = S.at(0).size();
    vector<vector<int>> dist(H, vector<int>(W, -1)); dist[sh][sw] = 0;
    vector<vector<bool>> seen(H, vector<bool>(W, false));
    queue<pair<int, int>> que; que.emplace(sh, sw);
    while (!que.empty()) {
        int h, w; tie(h, w) = que.front(); que.pop();
        if (seen[h][w]) { continue; }
        int d = dist[h][w] + 1; seen[h][w] = true;
        for (int i = 0; i < 4; i++) {
            int nh = h + delta_h[i], nw = w + delta_w[i];
            if (nh < 0 || H <= nh || nw < 0 || W <= nw) continue;
            if (S[nh][nw] == wall || seen[nh][nw]) continue;
            dist[nh][nw] = d; que.emplace(nh, nw);
        }
    }
    return dist;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) cin >> S[i];
    
    auto longest_path = [=] (vector<vector<int>> G) {
        int longest = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (G[i][j] > longest) longest = G[i][j];
            }
        }
        return longest;
    };
    
    int ans = 0;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        if (S[i][j] == '#') continue;
        int res = longest_path(grid_bfs(S, i, j));
        if (ans < res) { ans = res; }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define testcase int t;cin>>t;while(t--)
#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define P pair<int,int>
/*bool isprime(lli n)
{
    if(n==1) return 0;
    for(lli i=2;i<=n/2;i++)
    {
        if(n%i==0) return 0;
    }
    return 1;
}
bool issemiprime(lli n)
{
    for(int i=2;i<n;i++)
    {
        if(isprime(i)&&isprime(n/i)&&n%i==0&&i!=n/i){
            return 1;
        }
    }
    return 0;
}
lli extendedgcd(lli q,lli r1,lli r2,lli r,lli s1,lli s2,lli s,lli t1,lli t2,lli t)
{
if(r2==0) return r1;
	r1=r2;
        r2=r;
        s1=s2;
        s2=s;
        t1=t2;
        t2=t;
        q=r1/r2;
        r=r1%r2;
        s=s1-(s2*q);
        t=t1-(t2*q);
return extendedgcd(q,r1,r2,r,s1,s2,s,t1,t2,t);
}
lli gcd(lli a,lli b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
void SOE()
{
    for(lli i=2;i<=100000;i++)
    {
        if(sieve[i]) continue;
        for(lli x=i;x<=100000;x+=i)
        {
            sieve[x]+=1;
        }
    }
}*/
/*bool func(pair<int,int> a,pair<int,int> b)
{
    return a.first<b.first;
}*/
int n,a[1000000];
int dp[1000000];
int f(int i)
{
    if(i==(n-1)) return 0;
    if(i>=n) return INT_MAX;
    if(dp[i]!=-1) return dp[i];
    int left=abs(a[i]-a[i+1])+f(i+1);
    int right=INT_MAX;
    if(i+2<n){
    right=abs(a[i]-a[i+2])+f(i+2);
    }
    return dp[i]=min(left,right);
}
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<f(0);
}
int main()
{
    fast_io;
    solve();
}


Measured memory_bytes: 12556
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

signed main(){
    fastio
    int n;
    cin>>n;
    for(int i=0;i<3;i++){
        if(n%10==7){
            cout<<"Yes\n";
            return 0;
        }
        n/=10;
    }
    cout<<"No\n";
    return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    map <int, int> mp;
    long long ans = 0;
    int pw = 1, pf = 0;
    mp[0] = 1;
    for (int i = (int)s.size() - 1; i >= 0; i--) {
        pf = (pf + pw * (s[i] - '0')) % 2019;
        ans += mp[pf];
        mp[pf]++;
        pw = (pw * 10) % 2019;
    }
    cout << ans << endl;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n;
ll d, a;
ll x[200005], h[200005];
ll sum[200005];
void solve() {
    cin >> n >> d >> a;
    rep(i, n) cin >> x[i] >> h[i];

    vector<pair<ll, ll>> p(n);
    rep(i, n) { p[i].first = x[i]; p[i].second = h[i]; }
    all(sort, p);
    rep(i, n) { x[i] = p[i].first; h[i] = p[i].second; }

    ll ans = 0;
    rep(i, n) {
        if (i != 0) sum[i] += sum[i - 1];
        h[i] -= sum[i];

        ll cnt = (h[i] < 0 ? 0 : (h[i] + a - 1) / a);
        auto pos = distance(x, upper_bound(x + i, x + n, x[i] + 2 * d));
        ans += cnt;

        sum[i] += a * cnt;
        sum[pos] -= a * cnt;
    }

    cout << ans << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int k;
    cin >> k;
    cout << (k/2)*(k/2+k%2) << "\n";
    
    return 0;
}



Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
s = []
for _ in range(n):
    s.append(input())

inc = []
zeros = []
dec = []

for i, j in enumerate(s):
    minimum = 0
    now = 0
    for k in j:
        if k == "(":
            now += 1
        else:
            now -= 1
        minimum = min(minimum, now)
    if now > 0:
        inc.append([minimum, i])
    elif now < 0:
        dec.append([minimum - now, i])
    else:
        zeros.append([minimum, i])

inc.sort(reverse=True)
dec.sort()

now = 0

for i, j in inc:
    for k in s[j]:
        if k == "(":
            now += 1
        else:
            now -= 1
        if now < 0:
            print("No")
            sys.exit()
for i, j in zeros:
    for k in s[j]:
        if k == "(":
            now += 1
        else:
            now -= 1
        if now < 0:
            print("No")
            sys.exit()
for i, j in dec:
    for k in s[j]:
        if k == "(":
            now += 1
        else:
            now -= 1
        if now < 0:
            print("No")
            sys.exit()
ans = "Yes" if now == 0 else "No"
print(ans)


Measured memory_bytes: 242060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n,x;
    cin >> n >> x;
    vi a(n);
    rep(i,n) cin >> a[i];
    bool ok = true;
    ll ans = 0;
    rep(i,n-1){
        if(a[i+1] + a[i] > x){
            int t = (a[i+1] + a[i]) - x;
            if(a[i+1] - t >= 0 ){
                a[i+1] -= t;
            }else{
                a[i+1] = 0;
            }
            ans += t;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
use std::io;
use std::collections::HashMap;


fn main() {
    let (n, p) = {
        let i = read::<u64>();
        (i[0], i[1])
    };

    let mut hm = HashMap::new();
    let mut x = p;
    while let Some(f) = divide(x) {
        x /= f;
        *hm.entry(f).or_insert(0) += 1;
    }
    *hm.entry(x).or_insert(0) += 1;

    let mut ans: u64 = 1;

    for (k, v) in hm.iter() {
        if v >= &n {
            ans *= k.pow((v / n) as u32);
        }
    }

    println!("{}", ans);
}


fn divide(n: u64) -> Option<u64> {
    for i in 2..(n as f64).sqrt().ceil() as u64 + 2 {
        if n % i == 0 {
            return Some(i);
        }
    } 
    return None;
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	string s;
	cin >> s;

	int ans1 = 0, ans0 = 0, l = s.length();
	for(int i = 0; i < l; i++){
		if(i&1){
			if(s[i] == '0') ans0++;
			else ans1++;
		} 
		else{
			if(s[i] == '0') ans1++;
			else ans0++;
		}
	}
	cout << min(ans0, ans1);
}	

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

vector<vector<ii>> adj;
vector<ll> dist;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	adj.resize(n);
	dist.resize(n,-1);
	for (int i=0; i<n-1; i++) {
		int u,v,w; cin>>u>>v>>w; u--; v--;
		adj[u].push_back({v,w%2});
		adj[v].push_back({u,w%2});
	}
	queue<int> q; q.push(0); dist[0]=0;
	while(!q.empty()) {
		int cur=q.front(); q.pop();
		for (ii nxt : adj[cur]) {
			if(dist[nxt.first]!=-1) continue;
			dist[nxt.first]=(dist[cur]+nxt.second)%2;
			q.push(nxt.first);
		}
	}
	for (int i=0; i<n; i++)
		cout<<dist[i]<<"\n";
	return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;

#define FORN(i, j, k) for(int i=j;i<k;i++)
#define FORR(i, j, k) for(int i=j;i>=k;i--)
#define REP(i, n) FORN(i, 0, n)
#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

const int MODO = 1e+9 + 7;
int H, W;

void solve(){
	char a[H][W];
	REP(i, H){
		REP(j, W){
			cin >> a[i][j];
		}
	}
	int dp[H+1][W+1];
	memset(dp, 0,  sizeof(dp));
	FORN(i, 1, H+1){
		FORN(j, 1, W+1){
			if(i==1 && j==1){
				dp[i][j] = 1;
			}
			else{
				if(a[i-1][j-1] == '#'){
					dp[i][j] = 0;
				}
				else{
					dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MODO;
				}
			}
		}
	}
	cout << dp[H][W] << endl;
	return;
}

int32_t main(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cin >> H >> W;
		solve();
		return 0;
}



Measured memory_bytes: 12444
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n-1; i++){
		cout << a[i] << " ";
	}
	cout << a[n-1];
	cout << endl;

	for(int i = 1; i < n; i++){
		int v = a[i];
		int j = i-1;
		while(j >= 0 && a[j] > v){
			int tmp = 0;
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;

		for(int i = 0; i < n-1; i++){
			cout << a[i] << " ";
		}
		cout << a[n-1];
		cout << endl;
	}

}



Measured memory_bytes: 3076
using System;

namespace ITP1_8_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string p = Console.ReadLine();
            string Ans = "No";

            s = s + s;

            for (int i = 0; i < (s.Length - p.Length); ++i)
            {
                for(int j =0; j<p.Length;++j)
                {
                    if (s[i + j] != p[j])
                        break;
                    else if (j == p.Length - 1)
                        Ans = "Yes";
                }
            }

            Console.WriteLine("{0}", Ans);


        }
    }
}

Measured memory_bytes: 5356