akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <int MOD = 1000000007>
struct Mint {
    int x;

    Mint() : x(0) {}
    Mint(long long t) {
        x = t % MOD;
        if (x < 0) x += MOD;
    }

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int m = s.size();
    Mint<> dp[n + 1][n + 1];
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dp[i + 1][j + 1] += dp[i][j] * 2;
            dp[i + 1][max(0, j - 1)] += dp[i][j];
        }
    }
    cout << dp[n][m] / Mint<>(2).pow(m) << endl;
    return 0;
}

Measured memory_bytes: 97920
import collections

n = int(input())

d = collections.defaultdict(list)

for _ in range(n - 1):
    u, v = map(int, input().split())
    d[u].append(v)
    d[v].append(u)

bw = collections.defaultdict(str)

bw[1] = 'b'
bw[n] = 'w'

q = collections.deque()
q.append(1)
q.append(n)

fennec = 0
snuke = 0

while True:
    if len(q) == 0:
        break

    t = q.popleft()

    if bw[t] == 'b':
        fennec += 1
    if bw[t] == 'w':
        snuke += 1

    for succ in d[t]:
        if bw[succ] == '':
            bw[succ] = bw[t]
            q.append(succ)

if fennec > snuke:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 39124
block_1_floor_1=[0,0,0,0,0,0,0,0,0,0]
block_1_floor_2=[0,0,0,0,0,0,0,0,0,0]
block_1_floor_3=[0,0,0,0,0,0,0,0,0,0]
block_2_floor_1=[0,0,0,0,0,0,0,0,0,0]
block_2_floor_2=[0,0,0,0,0,0,0,0,0,0]
block_2_floor_3=[0,0,0,0,0,0,0,0,0,0]
block_3_floor_1=[0,0,0,0,0,0,0,0,0,0]
block_3_floor_2=[0,0,0,0,0,0,0,0,0,0]
block_3_floor_3=[0,0,0,0,0,0,0,0,0,0]
block_4_floor_1=[0,0,0,0,0,0,0,0,0,0]
block_4_floor_2=[0,0,0,0,0,0,0,0,0,0]
block_4_floor_3=[0,0,0,0,0,0,0,0,0,0]
for i in range(int(input())):
  b,f,r,v=map(int,input().split())
  if b==1:
    if f==1:
      block_1_floor_1[r-1]+=v
    elif f==2:
      block_1_floor_2[r-1]+=v
    else:
      block_1_floor_3[r-1]+=v
  elif b==2:
    if f==1:
      block_2_floor_1[r-1]+=v
    elif f==2:
      block_2_floor_2[r-1]+=v
    else:
      block_2_floor_3[r-1]+=v
  elif b==3:
    if f==1:
      block_3_floor_1[r-1]+=v
    elif f==2:
      block_3_floor_2[r-1]+=v
    else:
      block_3_floor_3[r-1]+=v
  else:
    if f==1:
      block_4_floor_1[r-1]+=v
    elif f==2:
      block_4_floor_2[r-1]+=v
    else:
      block_4_floor_3[r-1]+=v
print(""," ".join(list(map(str,block_1_floor_1))))
print(""," ".join(list(map(str,block_1_floor_2))))
print(""," ".join(list(map(str,block_1_floor_3))))
print("#"*20)
print(""," ".join(list(map(str,block_2_floor_1))))
print(""," ".join(list(map(str,block_2_floor_2))))
print(""," ".join(list(map(str,block_2_floor_3))))
print("#"*20)
print(""," ".join(list(map(str,block_3_floor_1))))
print(""," ".join(list(map(str,block_3_floor_2))))
print(""," ".join(list(map(str,block_3_floor_3))))
print("#"*20)
print(""," ".join(list(map(str,block_4_floor_1))))
print(""," ".join(list(map(str,block_4_floor_2))))
print(""," ".join(list(map(str,block_4_floor_3))))



Measured memory_bytes: 5636
#include<stdio.h>
int main(void)
{
	int a, b,  c;
	int i, j=0;
	
	scanf("%d %d %d", &a, &b, &c);
	
	for(i=a; i<=b; i++){
		if(c%i==0){
			j++;
		}
	}
	
	printf("%d\n", j);
	
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int T[100010],A[100010];

signed main(){
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>T[i];
	}
	for(int i=1;i<=N;i++){
		cin>>A[i];
	}
	int ans=1;
	for(int i=1;i<=N;i++){
		if((T[i-1]<T[i]&&A[i]<T[i]) || (A[i]>A[i+1]&&A[i]>T[i])){
			ans=0;
		}
		else if(A[i]==A[i+1]&&T[i]==T[i-1]){
			ans*=min(A[i],T[i]);
			ans%=MOD;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double N = sc.nextDouble();
        double K = sc.nextDouble();
        double cnt = K * (Math.pow(K-1.0,N-1.0));
        System.out.println((int)cnt);
    }
}


Measured memory_bytes: 24404
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
using namespace std;
long long accumulate(long long n){return (long long)n*(n+1)/2;}

int main()
{
  long long n;
  int m;
  while(cin >> n >> m,(n||m))
    {
      vector<long long> vec;
      vec.resize(m);
      for(int i=0;i<m;i++)
	cin >> vec[i];

      long long res1,res2;
      res1 = res2 = 0;
      for(int i=1;i<(1<<m);i++)
	{
	  int num = __builtin_popcount(i);
	  long long lcm = 1; 
	  for(int j=0;j<m;j++)
	    {
	      if((i>>j) & 1)
		{
		  lcm = lcm/__gcd(lcm,vec[j])*vec[j]; 
		  if(lcm > n)
		    break;
		}
	    }
	  if(num%2)
	    res1 += n/lcm,res2 += lcm*accumulate(n/lcm);
	  else 
	    res1 -= n/lcm,res2 -= lcm*accumulate(n/lcm);
	}
      res1 = n-res1;
      res2 = accumulate(n) - res2;
      if(res1 == 0)
	cout << "0.0000000000" << endl;
      else 
	cout << setiosflags(ios::fixed) << setprecision(10) << (double)res2/res1 << endl;
     	
    }
  return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int N = 1e5+5;
int n,val[N];
ll ans,abs_sum[N],sum[N];
char op[2];
vector<int> vec;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(val[1]),sum[1]=val[1];
	for(ri i=2;i<=n;++i){
		scanf("%s",op),read(val[i]);
		if(op[0]=='-') vec.push_back(i),sum[i]=sum[i-1]-val[i];
		else sum[i]=sum[i-1]+val[i];
	}
	vec.push_back(n+1);
	for(ri i=1;i<=n;++i) abs_sum[i]=abs_sum[i-1]+val[i];
	if(vec.size()==1) return print(sum[n]),0;
	ans=LLONG_MIN;
	for(ri i=0;i<(int)vec.size()-1;++i){
		int x=vec[i],y=vec[i+1];
		ans=max(ans,sum[x-1]-(abs_sum[y-1]-abs_sum[x-1])+(abs_sum[n]-abs_sum[y-1]));
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 2680
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	float d;
	int e;
	int flag=0;
	for(int i=1;i<=100;i++)
	{

		d=(float)(a*i-c)/b;
	    e=(int)(a*i-c)/b;
	    if(d==e){
	    	flag=1;
	    	break;
		}
	}
	if(flag==0)printf("NO\n");
	else printf("YES\n");
return 0;
}

		



Measured memory_bytes: 256
import java.util.*;

public class Main {

    int INF = 1 << 28;
    boolean[][] map;
    int MAX = 21;
    int dx[] = {-1,0,1,0};
    int dy[] = {0,-1,0,1};

    void run() {
       Scanner sc = new Scanner(System.in);
       for(;;) {
            int n = sc.nextInt();
            if( n==0 ) break;

            map = new boolean[MAX][MAX];
            for(int i=0;i<n;i++) map[sc.nextInt()][sc.nextInt()] = true;

            int m = sc.nextInt();
            int x = 10, y = 10;
            int cnt = 0;
                for(int i=0;i<m;i++) {
               char c = sc.next().charAt(0);
                int l = sc.nextInt();
                int d;
                if( c == 'W' ) d = 0;
                else if( c == 'N' ) d = 3;
                else if( c == 'E' ) d = 2;
                else d = 1;
                for(int j=0;j<l;j++) {
                   x += dx[d];
                   y += dy[d];
                   if( map[x][y] ) {
                        cnt++;
                        map[x][y] = false;
                   }
                }
             }
           System.out.println( (cnt == n? "Yes": "No") );
        }
    }

    public static void main(String[] args) {
       new Main().run();
    }

}

Measured memory_bytes: 42332
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = (double)a / b;
    cout << d << " " << r << " " << fixed << f << endl;
    return 0;
}


Measured memory_bytes: 3288
#

import sys
input=sys.stdin.readline

def main():
    H,W,K=map(int,input().split())
    mas=[list(input().strip("\n")) for i in range(H)]
    bcnt=0
    for i in range(H):
        bcnt+=mas[i].count("#")
    ans=0
    for i in range(2**H):
        for j in range(2**W):
            cnt=bcnt
            for x in range(H):
                for y in range(W):
                    if (i>>x&1 or j>>y&1) and mas[x][y]=="#":
                        cnt-=1
            if cnt==K:
                ans+=1
    print(ans)
    
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 74240
n = gets.to_i
dp = Array.new(n){Array.new(n){Array.new(n){0}}}

mat = []
n.times{|i|
  mat[i] = gets.split.map(&:to_i)
  dp[0][i] = mat[i].dup
}

n.times{|i|
  n.times{|j|
    n.times{|k|
      break if k+i+1 >= n
      dp[i+1][j][k] = dp[i][j][k] + mat[j][k+i+1]
    }
  }
}
max = dp[0][0][0]
n.times{|k|
  n.times{|j|
    next if j + k >= n
    the_max = dp[k][0][j]
    1.upto(n-1){|i|
      x = dp[k][i][j]
      the_max = [x, the_max + x].max
      max = [max, the_max].max
    }
  }
}
puts max

Measured memory_bytes: 17024
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
 
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




string s;
string t;

int sums[210000], sumt[210000];

int main() {
  while (cin >> s >> t) {
	memset(sums, 0, sizeof(sums));
	memset(sumt, 0, sizeof(sumt));

	for (int i = 0; i < s.size(); ++i) {
	  int tmp = 0;
	  if (s[i] == 'A') tmp = 2;
	  else tmp = 1;
	  sums[i+1] = sums[i] + tmp;
	}
	for (int i = 0; i < t.size(); ++i) {
	  int tmp = 0;
	  if (t[i] == 'A') tmp = 2;
	  else tmp = 1;
	  sumt[i+1] = sumt[i] + tmp;
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
	  int a, b, c, d;
	  cin >> a >> b >> c >> d;
	  --a, --c;
	  int ns = sums[b] - sums[a];
	  int nt = sumt[d] - sumt[c];
	  if (abs(ns - nt) % 3 == 0) puts("YES");
	  else puts("NO");
	}
  }
}


Measured memory_bytes: 2688
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        // Arrays.sort(a);
        // Arrays.sort(b);
        
        boolean ok = true;
        int max = 0;
        int[] count = new int[200001];
        for (int i = 0; i < n; i++) {
            count[a[i]]++;
            count[b[i]]++;
        }
        for (int i = 0; i < 200001; i++) {
            max = Math.max(max, count[i]);
        }
        if (max > n) ok = false;
        
        if (!ok) {
            System.out.println("No");
            return;
        }
        
        // offset(0からn-1まで)を全て試す
        int[] ans = new int[n];
        int offset = 0;
        while (true) {
            for (int i = 0; i < n; i++) {
                ans[(i+offset)%n] = b[i];
            }
            
            boolean ok2 = true;
            int ng_length = 0;
            for (int i = 0; i < n; i++) {
                if (ans[i] == a[i]) {
                    ok2 = false;
                    
                    int now = a[i];
                    for (int j = i+1; j < n; j++) {
                        if (a[j] == now) {
                            ng_length++;
                        } else {
                            break;
                        }
                    }
                    break;
                }
            }
            
            if (ok2) {
                break;
            } else {
                offset += 1 + ng_length;
            }
        }
        
        System.out.println("Yes");
        for (int i = 0; i < n; i++) {
            System.out.print(ans[i]);
            if (i != n-1) {
                System.out.print(" ");
            } else {
                System.out.println();
            }
        }
    }
}

Measured memory_bytes: 63484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_V = 100000;

int V, E, r;
int s, t, d;

vector<pair<int, int>> G[MAX_V];
int dist[MAX_V];

int main() {
    cin >> V >> E >> r;
    REP(i, E) {
        cin >> s >> t >> d;
        G[s].PB(MP(d, t));
    }

    REP(i, V) dist[i] = MOD;
    
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;

    dist[r] = 0;
    Q.push(MP(0, r));

    while (Q.size()) {
        pair<int, int> p = Q.top(); Q.pop();
        int pos = p.second;
        if (dist[pos] < p.first) continue;
        REP(i, G[pos].size()) {
            pair<int, int> edge = G[pos][i];
            int to = edge.second;
            if (dist[pos] + edge.first >= dist[to]) continue;
            dist[to] = dist[pos] + edge.first;
            Q.push(edge);
        }
    }

    REP(i, V) {
        int di = dist[i];
        if (di == MOD) PRINT("INF");
        else PRINT(di);
    }
    
    return 0;
}


Measured memory_bytes: 16180
#include <bits/stdc++.h>
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();
    ll a, b; cin >> a >> b;
    for(ll x = 0; x < max(b,a); ++x){
        if(abs(b - x) == abs(a - x)) return cout << x << '\n', 0;
    }
    cout << "IMPOSSIBLE\n";
    return 0;
}

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

using namespace std;

typedef long long ll;

const int mod = 1000000007;
const int maxn = 200010;
 
ll fact[maxn], invfact[maxn], inv[maxn];
int h, w, a, b;

ll modpow(ll a, ll b)
{
	ll x = 1, y = a;
	while(b){
		if(b&1)
			x = (x*y)%mod;
		y = (y*y)%mod;
		b >>= 1;
	}
	return x;
}

int main()
{	
	int i, j;
	inv[1] = 1;
	for(i=2; i<maxn; i++)
		inv[i] = mod - ((mod/i)*inv[mod%i])%mod;
	fact[0] = invfact[0] = 1;
	for(i=1; i<maxn; i++){
		fact[i] = (fact[i-1]*i)%mod;
		invfact[i] = (invfact[i-1]*inv[i])%mod;
	}
	scanf("%d%d%d%d", &h, &w, &a, &b);
	ll ans = 0;	
	for(i=1; i<=h-a; i++){
		ll ways1 = ((fact[b+i-2]*invfact[b-1])%mod * invfact[i-1])%mod;
		ll ways2 = ((fact[w+h-i-b-1]*invfact[h-i])%mod * invfact[w-b-1])%mod;
		ans = (ans + (ways1*ways2)%mod)%mod;	
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4864
x,y= list(map(int, input().split()))
s=input()
anslis=[0]*x
ans=0
for k in range(1,x):
    if s[k-1:k+1]=="AC":
        ans+=1
    anslis[k]+=ans

for k in  range(y):
    i,j= list(map(int, input().split()))
    i-=1
    j-=1
    print(anslis[j]-anslis[i])

Measured memory_bytes: 7748
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  map<char,char> mp;
  string s,t;
  cin>>s>>t;
  int n=s.size();
  vector<int> tbl(26,-1);
  rep(i,n) {
    int code = s[i]-'a';
    if(tbl[code]==-1) {
      tbl[code]=t[i]-'a';
    } else {
      char c = 'a'+tbl[code];
      if(c!=t[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  set<char> x;
  rep(i,26) {
    if(tbl[i]==-1) continue;
    char c = tbl[i]+'a';
    if(x.find(c)!=x.end()) {
      cout << "No" << endl;
      return 0;
    }
    x.insert(c);
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main()
{
	int s;
	cin >> s;
	if (s == 1)
	{
		s += 3;
	}
	else if (s == 2)
	{
		s += 2;
	}
	int i = s;
	int cnt = 1;
	while (i > 1)
	{
		if (i % 2 == 0)
			i /= 2;
		else 
			i = (i*3)+1;
		cnt++;
	}
	cout << cnt+1 << endl;
	return (0);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    int n,d,x,sum=0;
    cin>>n>>d>>x;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        sum+=((d-1)/a[i]+1);
    }
    cout<<sum+x;
    return 0;
}


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

int main(){
  int n, K, x, y, sum;
  cin >> n >> K >>  x >> y;
  if(n <= K){
    sum = n*x;
    cout << sum << endl;
  }
  else{
     sum = K*x + (n-K)*y;
    cout << sum << endl;
  }
}

  
  
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,ans;cin>>s;ans="Yes";
  for(int i=1;i<s.length()+1;++i){
    if(i%2==0){
      if((s[i-1]!='L') and (s[i-1]!='U') and (s[i-1]!='D')){
        ans="No";
        break;
      }  
    }else{
      if((s[i-1]!='R') and (s[i-1]!='U') and (s[i-1]!='D')){
        ans="No";
        break;
      }
    }
  }
  cout<<ans<<endl;
}   

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

string O, E;

signed main()
{
	cin >> O >> E;
	for (int i = 0; i < E.size(); i++)
	{
		printf("%c%c", O[i], E[i]);
	}
	if (O.size() > E.size()) printf("%c", O.back());
	puts("");
	return 0;
}

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

using namespace std;

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

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n;
	
	cin >> n;
	
	cout << n + n * n + n * n * n << endl;
	
	return 0;
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
    map<string, int>mp;
    int n;
    cin >> n;
    vector<string>p;
    rep(i, 0, n){
        string s;
        cin >> s;
        p.push_back(s);
        mp[s]++;
    }
    for(auto i:mp){
        if(i.second>1){
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i, 1, n){
        if(p[i][0]!=p[i-1][p[i-1].size()-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <functional>
#include <bitset>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using string_view = boost::string_ref;

#include <boost/function_output_iterator.hpp>


using namespace std;

template<class T, size_t N, class F>
struct compare_n
{
    F f;
    bool operator() (const T& t1, const T& t2)
    {
        return f(get<N>(t1), get<N>(t2));
    }
};
 
template<size_t N, class T>
auto make_less_n(const T&)
{
    using t = typename T::value_type;
    using less = std::less<typename tuple_element<N, t>::type>;
    return compare_n<t, N, less>();
}

template<class T>
T digit(T x)
{
    return static_cast<T>(floor(log10(x)+1));
}

int64_t ipow(int64_t x, int64_t y)
{
    return static_cast<int64_t>(pow(x, y));
}

struct edge_t {
    int a,b;
};

vector<int> neighbour(const vector<edge_t>& edges, int k)
{
    vector<int> neighbour_k;
    neighbour_k.reserve(edges.size());
    
    for(const auto& e : edges)
    {
        if(e.a == k) neighbour_k.push_back(e.b);
        else if(e.b == k) neighbour_k.push_back(e.a);
    }
    
    sort(begin(neighbour_k), end(neighbour_k));
    
    return neighbour_k;
}

int mul(int x, int y)
{
    return static_cast<int>((static_cast<int64_t>(x) * y) % 1000000007);
}

int add(int x, int y)
{
    return static_cast<int>((static_cast<int64_t>(x) + y) % 1000000007);
}

int addeq(int& x, int y)
{
    return x = add(x, y);
}


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

    int h,w,k;
    cin >> h >> w >> k;
    
    if(w == 1)
    {
        cout << "1\n";
        return 0;
    }

    vector<vector<int>> table(h+1, vector<int>(w+2, 0));
    
    for(int& x : table[0]) x = 0;
    table[0][1] = 1;
    for(int y = 1; y <= h; ++y)
    {
        table[y][0] = table[y][w+1] = 0;
        for(int x = 1; x <= w; ++x)
        {
            for(int p = 0; p < (1 << (w-1)); ++p)
            {
                if(p & (p << 1)) continue;
                bitset<8> bits(p);
                if(x == 1)
                {
                    if(!bits[x-1])
                        addeq(table[y][x], table[y-1][x]);
                    else
                        addeq(table[y][x], table[y-1][x+1]);
                }
                else if(x == w)
                {
                    if(bits[x-2])
                        addeq(table[y][x], table[y-1][x-1]);
                    else
                        addeq(table[y][x], table[y-1][x]);
                }
                else
                {
                    if(bits[x-2])
                        addeq(table[y][x], table[y-1][x-1]);
                    else if(bits[x-1])
                        addeq(table[y][x], table[y-1][x+1]);
                    else
                        addeq(table[y][x], table[y-1][x]);
                }
            }
        }
    }
    cout << table[h][k] << '\n';
    
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>	
#include<string>
#include<math.h>
#include <vector>
using namespace std;
int main() {
	string S;
	string a;
	string fire[1000];
	int ans = 0;
	

	cin >> S >> a;
	for (int i = 0; i < 3; i++) {
		if (S[i] == a[i]) {
			ans++;
		}
	}

	cout << ans << endl;
}



Measured memory_bytes: 256
S = input()
len_now = 0
len_max = 0
list_s = ["A","C","G","T"]

for i in range(len(S)):
    if S[i] in list_s:
        len_now += 1
        if len_now > len_max:
            len_max = len_now
    else:
        len_now = 0
print(len_max)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  string str;
  cin >> str;
  bool a=0,b=0;
  for(int i=0;i<3;i++)if(str[i]=='A')a=1;
  for(int i=0;i<3;i++)if(str[i]=='B')b=1;
  if(a and b)cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
"""
A - Beginning
"""
#入力処理
def simple_input():
    temp_input = input().rstrip().split(' ')
    if len(temp_input) > 1:
        return temp_input
    return temp_input[0]

#メイン処理
if __name__ == '__main__':
    #入力
    n1,n2,n3,n4 = simple_input()
    n1 = int(n1)
    n2 = int(n2)
    n3 = int(n3)
    n4 = int(n4)   

    result = "NO"

    l = [0,0,0,0,0,0,0,0,0,0]

    l[n1] = 1
    l[n2] = 1
    l[n3] = 1
    l[n4] = 1

    if(l[1]==1 and l[9]==1 and l[7] == 1 and l[4] == 1):
        result = "YES"

    #出力
    print(result)


Measured memory_bytes: 3064
/*
 * Problem Description: Binary Trees
 * Category: Tree
 * Author: Khan
 * Date: 23th October, 2017
 */

#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node
{
    int parent, left, right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d)
{
    if(u == NIL)
        return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u)
{
    int h1 = 0, h2 = 0;
    if(T[u].left != NIL)
        h1 = setHeight(T[u].left) + 1;
    if(T[u].right != NIL)
        h2 = setHeight(T[u].right) + 1;
    return H[u] = ((h1 > h2) ? h1 : h2);
}

int getSibling(int u)
{
    if(T[u].parent == NIL)
        return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u)
{
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if(T[u].left != NIL)
        deg++;
    if(T[u].right != NIL)
        deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if(T[u].parent == NIL)
        printf("root\n");
    else if(T[u].left == NIL && T[u].right == NIL)
        printf("leaf\n");
    else
        printf("internal node\n");
}

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    int v, l, r, root = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        T[i].parent = NIL;
    for (int i = 0; i < n; ++i)
    {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if(l != NIL)
            T[l].parent = v;
        if(r != NIL)
            T[r].parent = v;
    }

    for (int i = 0; i < n; ++i)
    {
        if(T[i].parent == NIL)
            root = i;
    }

    setDepth(root, 0);
    setHeight(root);

    for (int i = 0; i < n; ++i)
        print(i);
    return 0;
}

Measured memory_bytes: 2748
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n,m;
vector<string> z;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> m;
  z.resize(n);
  R(i,n)cin >> z[i];
  vector<vector<int>> res(n, vector<int>(m, 1e9));
  res[0][0] = (z[0][0] == '#') + (z[n-1][m-1] == '#');
  R(i,n)R(j,m){
    if(i){
      mini(res[i][j], res[i-1][j] + (z[i][j] != z[i-1][j]));
    }
    if(j){
      mini(res[i][j], res[i][j-1] + (z[i][j] != z[i][j-1]));
    }
  }
  cout << res[n-1][m-1] / 2 << "\n";
  
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define N 100100
#define ll long long
const ll mod=1e9+7;

char s[N];
ll a[26],ans=1;
int n;

int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	for (int i=0;i<n;i++) a[s[i]-'a']++;
	for (int i=0;i<26;i++) ans=ans*(a[i]+1)%mod;
	printf("%lld\n",(ans-1+mod)%mod);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<string>

using namespace std;

typedef struct {
    string name;
    int spend;
} Task;

int main(int argc, char const *argv[])
{
    queue<Task> taskQueue;
    int nums, timeslice;
    cin >> nums >> timeslice;
    for (int i=0; i<nums; i++) { 
        string name;
        int spend;
        cin >> name >> spend;
        Task task = {name, spend};
        taskQueue.push(task);
    }

    int timestamp = 0;
    while(!taskQueue.empty()) {
        Task current = taskQueue.front();
        if (current.spend > timeslice) {
            current.spend -= timeslice;
            taskQueue.pop();
            taskQueue.push(current);
            timestamp += timeslice;
        } else {
            taskQueue.pop();
            timestamp += current.spend;
            cout << current.name << " " << timestamp << endl;
        }
    }
    
    return 0;
}



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

using namespace std;
typedef long long int ll;
typedef pair<string,int> psi;
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, m;
    cin>>n>>m;
    if(n==m)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int 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++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;
    int ans=0;
    FOR(i,1,n+1){
        int t=i;
        int sum=0;
        while(t){
            sum+=t%10;
            t/=10;
        }
        if(a<=sum&&sum<=b){
            ans+=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;

ll const MAX = 100005;
ll a[MAX];

int main() {
	ll n, m;
	cin >> n >> m;
	REP(i, 1, n) {
		cin >> a[i];
	}
	ll min_a = a[1];
	ll max_dif = -1;
	REP(i, 2, n) {
		ll t = a[i] - min_a;
		max_dif = max(t, max_dif);
		min_a = min(min_a, a[i]);
	}
	ll buy = 1;
	ll ans = 0;
	REP(i, 2, n) {
		if (a[i] < a[buy]) {
			buy = i;
		}
		if (a[i] - a[buy] == max_dif) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

bool p[1000000];
int main()
{
	for (int i = 2; i < 1000000; ++i)
	{
		if (!p[i])
		{
			for (int j = 2*i; j < 1000000; j += i)
				p[j] = true;
		}
	}

	int n;
	while (scanf("%d", &n), n)
	{
		int ans = 0;
		for (int i = 3; i <= n/2; i += 2)
			if (!p[i] && !p[n-i])
				++ans;
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-

def main():
    import sys
    import math

    N = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))

    money = 1000

    for i in range(1,len(A_list)):
        if A_list[i] > A_list[i-1]:
            stock = money // A_list[i-1]
            money -= (stock * A_list[i-1])

            money += (stock * A_list[i])
    
    
    print(money)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
n = gets.to_i

c = Array.new(4){Array.new(3){Array.new(10, 0)}}

n.times do
  a, b, f, d = gets.split(" ").map(&:to_i)
  c[a-1][b-1][f-1] += d
end

4.times do |i|
  3.times do |j|
    10.times do |k|
      print " #{c[i][j][k]}"
    end
    puts
  end
  puts "#" * 20 if i != 3
end



Measured memory_bytes: 6888
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int a, b, n;
  while (cin >> a >> b >> n) {
    a %= b;
    int s = 0;
    rep(i, n) {
      a *= 10;
      s += a / b % 10;
      a %= b;
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 3044
program main
implicit none
character(1) :: a,b
logical      :: t
  read(*,*) a,b
  t = a=='H'
  if(t)then
    t = b=='H'
  else
    t = .not.b=='H'
  endif
  if(t)then
    print*,'H'
  else
    print*,'D'
  endif
end program main


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <cstdlib>
using namespace std;

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
stack<int> s;
int main() {
	char str[8];
	while(1) {
		if(scanf("%s", str) == EOF) break;
		if(!strcmp(str,"*")) {
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			s.push(a * b);
		} else if(!strcmp(str,"+")) {
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			s.push(a + b);
		} else if(!strcmp(str,"-")) {
			int a = s.top();
			s.pop();
			int b = s.top();
			s.pop();
			s.push(b - a);
		} else {
			s.push(atoi(str));
		}
	}
	cout << s.top() << endl;
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}



signed main(){
	ll n,x; cin>>n>>x;
	ll ans = 0;
	VL a(n);
	rep(i,n){
		int b; cin>>b;
		if(b>x){
			ans += b-x; a[i]=x;
		}else{
			a[i]=b;
		}
	}
	reps(i,n-1){
		if(a[i-1]+a[i]>=x){
			ll loss = a[i-1]+a[i]-x;
			ans += loss; a[i] -= loss;
		}
	}
	cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll f(ll b, ll n)
{
    if(b == 1) return -1;
    if(n < b) return n;
    else
    {
        return f(b, n/b) + n % b;
    }
}
int main()
{
    ll N, s;
    cin >> N >> s;
    if(N == s)
    {
        cout << N + 1 << endl;
        return 0;
    }

    for(ll i = 2; i * i <= N; i++)
    {
        if(f(i, N) == s)
        {
            cout << i << endl;
            return 0;
        }
    }
    for(ll i = sqrt(N) + 1; i >= 1; i--)
    {
        ll b = (N - s) / i + 1;
        if(b >= sqrt(N) && f(b, N) == s)
        {
          cout << b << endl;
          return 0;
        }
    }
    cout << -1 << endl;
}



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

ll movx[] = {0,1,0,-1},movy[] = {1,0,-1,0}; 

int main()
{
	ll h,w;
	cin >> h >> w;
	vector<string> s(h);
	for(ll i = 0;i<h;i++)
	{
		cin >> s[i];
	}
	vector<vector<ll>> COL(h,vector<ll>(w));
	queue<pair<ll,ll>> Q;
	ll nowC = 1;
	ll cntB = 0,cntW = 0;
	ll ans = 0;
	for(ll i = 0;i<h;i++)
	{
		for(ll j = 0;j<w;j++)
		{
			if(COL[i][j]==0&&s[i][j]=='#')
			{
				COL[i][j] = 1;
				Q.push(make_pair(i,j));
				cntB =1;
				cntW = 0;
				while(!Q.empty())
				{
					pair<ll,ll> now = Q.front();
					Q.pop();
					for(ll ii = 0;ii< 4;++ii)
					{
						ll nx = now.first+movx[ii];
						ll ny = now.second+movy[ii];
						if(0<=nx&&nx<h&&0<=ny&&ny<w)
						{
							if(s[now.first][now.second]!=s[nx][ny]&&COL[nx][ny]==0)
							{
								Q.push(make_pair(nx,ny));
								if(s[nx][ny]=='#')cntB++;
								else cntW++;
								COL[nx][ny] = 1;
							}
						}
					}
				}
				ans += cntW*cntB;
			}

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

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

typedef long long ll;

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

    if(S[2]==S[3] && S[4]==S[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

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

int main(){
	int q;
	while ( cin >> q && q != -1 ){
		double x = static_cast< double >( q ) / 2;
		while ( ( ( x * x * x - q ) > 0 ? ( x * x * x - q ) : -( x * x * x - q ) ) >= 0.00001 * q ){
			x -= ( x * x * x - q ) / ( 3 * x * x );
		}

		cout << setprecision( 6 ) << setiosflags( ios::fixed );
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s;
  u64 k;
  cin >> s >> k;
  u64 size = s.size();
  for (u64 i = 0; i < size; ++i) {
    if (s[i]=='a') continue;
    if (26-(s[i]-'a') <= k) {
      k -= 26-(s[i]-'a');
      s[i] = 'a';
    }
  }
  s[size-1]+=k%26;
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 592
def main(n,a,b,c):
    cnt=0
    for i in range(n):
        if a[i]==b[i]==c[i]:
            pass
        elif a[i]!=b[i] and b[i]!=c[i] and a[i]!=c[i]:
            cnt+=2
        else:
            cnt+=1
    return cnt
print(main(int(input()),[i for i in input()],[i for i in input()],[i for i in input()]))

Measured memory_bytes: 3060
function main() {
  const num = parseInt(input[0], 10);
  console.log(num * num * num);
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});


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

using namespace std;

int main () {
    long long n; cin >> n;
    long long s = 0;
    for (long long i = 1; 1; i++) {
        s += i;
        if (s >= n) {
            cout << i;
            return 0;
        }
    }
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vll a(x), b(y), c(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    vll ab;
    rep(i, x) rep(j, y) ab.pb(a[i] + b[j]);
    RSORT(ab);
    vll abc;
    rep(i, min(k, sz(ab))) rep(j, z) abc.pb(ab[i] + c[j]);
    RSORT(abc);
    rep(i, k) cout << abc[i] << endl;
    return 0;
}


Measured memory_bytes: 43368