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

#pragma warning(disable : 4996)

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
//#define int long long;

double dist(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
ll idist(ll x1, ll y1, ll x2, ll y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
using namespace std;

signed main() {
  double a, b, c, d;
  cin >> a >> b >> c >> d;
  double x = c / 12.0 + d / 60.0 / 12.0 - d / 60.0;
  x *= 3.14159265358 * 2.0;
  cout << setprecision(15) <<sqrt(a * a + b * b - 2 * a * b * cos(x));
}

Measured memory_bytes: 4052
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

struct group {
    string name;
    vector<string> members;

    group() {}
    ~group() {}
};

vector<group> groups;
set<string> checked;
set<string> employee;

void rec(string name) {
    if (checked.find(name) != end(checked)) {
        return;
    }
    checked.insert(name);
    for (group g : groups) {
        if (name == g.name) {
            for (string s : g.members) {
                rec(s);
            }
            return;
        }
    }
    employee.insert(name);
}

bool solve() {
    int n;
    cin >> n;
    if (n == 0) {
        return false;
    }
    groups.clear();
    checked.clear();
    employee.clear();
    for (int j = 0; j < n; ++j) {
        string data;
        stringstream ss;

        cin >> data;
        replace(begin(data), end(data), ':', ' ');
        replace(begin(data), end(data), ',', ' ');
        replace(begin(data), end(data), '.', ' ');
        ss << data;

        group g;
        ss >> g.name;

        while(!ss.eof()) {
            string member;
            ss >> member;
            if (member == "") {
                continue;
            }

            g.members.push_back(member);
        }

        ss.clear();
        groups.push_back(g);
    }

    rec(groups[0].name);
    cout << employee.size() << endl;
    return true;
}

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

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

int main(){
    long long n,k;
    cin >> n >> k;
    long long a[n];
    long long com=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        com = __gcd(com,a[i]);
        if(a[i]==k){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    sort(a,a+n);
    if(a[n-1]<k){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    if(k%com==0){
        cout <<  "POSSIBLE" << endl;
        return 0;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
}

Measured memory_bytes: 1024
import sys
X = int(input())
if (X <= 6):
    print('1')
    sys.exit()
else:
    n = X // 11
    m = X % 11

if (m == 0):
    print(str(n * 2))
elif (m <= 6):
    print(str(n * 2 + 1))
else:
    print(str(n * 2 + 2))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int a[5];
int main()
{
    scanf("%d%d%d",a+1,a+2,a+3);
    sort(a+1,a+4);
    if(a[1]==a[2]&&a[2]!=a[3]){puts("Yes");}
    else if(a[1]!=a[2]&&a[2]==a[3]){puts("Yes");}
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    A = list(map(int, input().split()))
    tmp = 0
    for j in range(M):
        tmp += A[j] * B[j]
    else:
        tmp += C
        if tmp > 0:
            ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=4999999996000000001;
const int SEG_LEN=1<<20;
ll seg[2*SEG_LEN];


ll get(int ind){
    ind+=SEG_LEN;
    ll res=0;
    res+=seg[ind];
    while(true){
        ind/=2;
        if(ind==0) break;
        res+=seg[ind];
        res%=MOD;
    }
    return res;
}

void update(int l, int r, ll v){
    l+=SEG_LEN; 
    r+=SEG_LEN;
    while(r-l>0){
        if(l%2==1){
            seg[l]+=v;
            seg[l]%=MOD;
            l++;
        }
        l/=2;
        if(r%2==1){
            seg[r-1]+=v;
            seg[r-1]%=MOD;
            r--;
        }
        r/=2;
    }
}


int main(){
    int n,k;
    cin>>n>>k;
    vector<int> l(k), r(k);
    for(int i=0;i<k;i++){
        cin>>l[i]>>r[i];
    }
    seg[SEG_LEN]=1;
    for(int i=0;i<n;i++){
        ll now=get(i);
        for(int j=0;j<k;j++){
            int left=i+l[j];
            int right=i+r[j];
            if(left>=n) continue;
            update(left,min(right+1,n),now);
        }
    }
    cout<<get(n-1)<<endl;
}

Measured memory_bytes: 6308
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>
#include<time.h>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

ll twos = 1;
vector<ll> tate, yoko;
ll utol(int ty, int a, int b, int k, int L, int R) {
	if (ty == 1) {
		if (b <= L || R <= a) {
			return 1e8;
		}
		else if (a <= L && R <= b) {
			return tate[k];
		}

		else {
			return min(utol(ty, a, b, 2 * k + 1, L, (L + R) / 2),
				utol(ty, a, b, 2 * k + 2, (L + R) / 2, R));
		}
	}

	if (ty == 2) {
		if (b <= L || R <= a) {
			return 1e8;
		}

		else if (a <= L && R <= b) {
			return yoko[k];
		}
		else {
			return min(utol(ty, a, b, 2 * k + 1, L, (L + R) / 2),
				utol(ty, a, b, 2 * k + 2, (L + R) / 2, R));
		}
	}

}

void ltou(int ty, int a, ll p) {
	if (ty == 1) {
		while (a != 0) {
			yoko[a] = min(yoko[a], p);
			a = (a - 1) / 2;
		}
		yoko[0] = min(yoko[0], p);
	}
	if (ty == 2) {
		while (a != 0) {
			tate[a] = min(tate[a], p);
			a = (a - 1) / 2;
		}
		tate[0] = min(tate[0], p);
	}
}

int main() {
	ll N, Q; cin >> N >> Q;

	while (twos < N) { twos *= 2; }
	twos *= 2;
	tate = vector<ll>(twos, N - 2), yoko = vector<ll>(twos, N - 2);
	//f**k 
	ll ans = (N - 2) * (N - 2);
	for (int i = 0; i < Q; i++) {
		int ty, x; cin >> ty >> x;
		x -= 2;
		ll temp = utol(ty, x, twos / 2, 0, 0, twos / 2);
		ans -= temp;
		if (temp > 0)ltou(ty, twos / 2 + temp - 2, x);
	}

	cout << ans << endl;
}


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

using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;

int32_t main() {
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall
    oneforall


        
    inl(n);
    if(n == 2){out(1);
        return 0;}
    int tmp  = n;
    int tmp1 = 0;
    for(int i = 2;i*i*1ll<=n;i++){
        if((n-1)%i == 0){
            tmp1++;
            if((n-1)/i!=i)tmp1++;
            }
        else if(n%i == 0){
            while(tmp%i == 0 and tmp!=i){
              tmp/=i;
            }
            if(tmp == 1)tmp1++;
            else{
        tmp-=((tmp/i)*i);
        if(tmp == 1 or tmp == 0)tmp1++;
        tmp = n;
            }
        if(n/i!=i){
            int i1 = n/i;
            while(tmp%i1 == 0 and tmp!=i1){
              tmp/=i1;
            }
            if(tmp == 1)tmp1++;
            else {tmp-=((tmp/i1)*i1);
                if(tmp == 1 or tmp == 0)tmp1++;}
            tmp = n;
        }
        
    }
    }
    out(tmp1+2);
    return 0;
}



Measured memory_bytes: 256
import heapq
import queue
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Info:
    def __init__(self,arg_name,arg_rest_time):
        self.name = arg_name
        self.rest_time = arg_rest_time


N,LIMIT = map(int,input().split())
Q = deque()


for _ in range(N):
    tmp = input().split()
    Q.append(Info(tmp[0],int(tmp[1])))

current_time = 0

while len(Q) > 0:
    info = Q.popleft()
    if info.rest_time > LIMIT:
        info.rest_time -= LIMIT
        current_time += LIMIT
        Q.append(info)
    else:
        current_time += info.rest_time
        print("%s %d"%(info.name,current_time))




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

int main(){
  int d,n,ret = 1;
  cin >> d >> n;
  for(int i = 0; i < d; ++i){
    ret *= 100;
  }
  if( n == 100) n++;
  cout << ret * n << endl;
  return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  map<int,int> a;
  bool can = true;
  rep(i,m){
    int s,c;
    cin >> s >> c;
    if(a.count(s)&&a[s]!=c){
      can = false;
      break;
    }
    else
     a[s]=c;
  }
  
  
  
  if(a.count(1)&&a[1]==0&&n!=1)
      can=false;
  vector<int> ans(n);
  
  if(a.size()>n) can = false;
  if(!can) cout << -1 << endl;
  
  else if(n==1&&can==true&&a[1]==0) cout << 0 << endl;
  
  else if(can==true){
    if(a.count(1))
      ans[0]=a[1];
    
    else ans[0]=1;
    
    rep2(i,1,n){
      if(a.count(i+1))
        ans[i]=a[i+1];
      else ans[i]=0;
    }
     rep(i,n)
      cout << ans[i];
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <queue>
#include <map>
using namespace std;
#define pb          emplace_back
#define fi          first
#define se          second
#define show(...)   fprintf(stderr, __VA_ARGS__ )
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i<(n); ++i)
#define inside(x,y,w,h) ((x)>=0 && (y)>=0 && (x)<(w) && (y)<(h))
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
constexpr int       INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};


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

    int N;
    cin >> N;

    outl(N < 1000 ? "ABC" : "ABD");
}



Measured memory_bytes: 256
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val air = inputs.head.toInt

  println(solve(air))

  def solve(a: Int): String = {
    if(30 <= air) {
      "Yes"
    } else {
      "No"
    }
  }
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++) cin >> l.at(i);
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        int tmp = l.at(i) + l.at(j);
        if (l.at(i) != l.at(j) && l.at(j) != l.at(k) && tmp > l.at(k)) ans++;
      }
    }
  }
  cout << ans;
  return 0;
}


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

int main() {
    int n; string s; cin >> n >> s;

    /*
     W .. W B .. B とすれば良さそう．all W, all B でも良い
    */
    int ans = count(s.begin(), s.end(), '.'), tmp = ans;
    for (int i = 0; i < n; i++) {
        if (s[i] == '#') tmp++;
        if (s[i] == '.') tmp--;
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

/*
#.##.

#####  2
.####  3
..###  2
...##  3
....#  4
.....  3
*/

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  int high = 0, note = 0, Alice = 0, Bob = 0;
  for (int i = 0; i < N; i += 2) {
    for (int j = 0; j < N; j++) {
      if (a.at(j) > high) {
        high = a.at(j);
        note = j;
      }
    }
    Alice += high;
    a.at(note) = 0;
    high = 0;
    for (int j = 0; j < N; j++) {
      if (a.at(j) > high) {
        high = a.at(j);
        note = j;
      }
    }
    Bob += high;
    a.at(note) = 0;
    high = 0;
  }
  cout << Alice - Bob;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int n, m, q;
int a[55], b[55], c[55], d[55], A[55];
int ans;

void Dfs(int now, int be) {
  if (now == n + 1) {
    int sum = 0;
    for (RI i = 1; i <= q; ++i)
      if (A[b[i]] - A[a[i]] == c[i])
        sum += d[i];
    ans = max(ans, sum);
    return;
  }
  for (RI i = be; i <= m; ++i)
    A[now] = i, Dfs(now + 1, i);
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  read(n), read(m), read(q);
  for (RI i = 1; i <= q; ++i)
    read(a[i]), read(b[i]), read(c[i]), read(d[i]);
  Dfs(1, 1);
  cout << ans << endl;

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
#define int long long int 
#define mp make_pair
#define pb push_back
#define f first
#define s second
 
 
 
int32_t main()
{
     IOS; 
     
     int n,x;
     
     cin>>n>>x;
     
     int a;
     cin>>a;
     int ans=abs(a-x);
     
     for(int i=2;i<=n;i++)
     {
          int a;
          cin>>a;
          ans=__gcd(ans,abs(a-x));
     }
     cout<<ans;
     return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;


const int MAX_V = 210;
const int INF = 1e9;

struct edge {
    int to, cap, rev;
    edge(int to, int cap, int rev): to(to), cap(cap), rev(rev) { }
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap) {
    G[from].push_back(edge(to, cap, G[to].size()));
    G[to].push_back(edge(from, 0, G[from].size() - 1));
}

int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}




int main() {
    int h, w; cin >> h >> w;
    rep(i, h) rep(j, w) {
        char c; cin >> c;
        if (c == 'S') {
            add_edge(200, i, INF);
            add_edge(200, j+100, INF);
            add_edge(i, j+100, 1);
            add_edge(j+100, i, 1);
        } else if (c == 'T') {
            add_edge(i, 201, INF);
            add_edge(j+100, 201, INF);
            add_edge(i, j+100, 1);
            add_edge(j+100, i, 1);
        } else if (c == 'o') {
            add_edge(i, j+100, 1);
            add_edge(j+100, i, 1);
        }
    }

    int min_cost = max_flow(200, 201);
    if (min_cost >= INF) cout << -1 << endl;
    else cout << min_cost << endl;

    return 0;
}

Measured memory_bytes: 896
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int main() {
	int n;
	string s;
	cin>>n>>s;
	int cnt = 0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='R') cnt++;
	}
	int ans = cnt;
	for(int i=0;i<cnt;i++){
		if(s[i]=='R') ans--;
	}
	cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3752
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> m(M);
  vector<vector<int>> n(N + 1);

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    m[i] = {a, b};
    n[a - 1].push_back(b);
  }
  
  map<pair<int, int>, int> nums;
  for (int i = 0; i < N; i++) {
    sort(n[i].begin(), n[i].end());
    for (int j = 0; j < n[i].size(); j++) {
      nums[{i + 1, n[i][j]}] = j + 1;
    }
  }
  
  for (int i = 0; i < M; i++) {
    printf("%06d%06d\n", m[i].first, nums[{m[i].first, m[i].second}]);
  }
  return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, q; cin >> n >> q; n++;
	vector<long long> a(n), sum_odd(n), sum_even(n), sum(n);
	for(int i = 1; i < n; i++){
		int x; cin >> x;
		a[i] = x;
		sum_odd[i] = (i&1)*a[i] + sum_odd[i - 1];
		sum_even[i] = ((i&1)^1)*a[i] + sum_even[i - 1];
		sum[i] = a[i] + sum[i - 1];
	}
	for(int i = 0; i < q; i++){
		int x; cin >> x;
		int l = 1, r = n;
		while(r - l > 1){
			int m = (l + r)/2;
			if(a[n - m] <= x) r = m;
			else if(2*m - 1 > n - 1) r = m;
			else if(a[n - m]-x >= x-a[n-2*m+1]) l = m;
			else r = m;
		}
		long long res = sum[n - 1] - sum[n - l - 1];
		int l1 = n - 2*l - 1;
		if(l1 > 0)
			res += (l1&1)*sum_odd[l1] + ((l1&1)^1)*sum_even[l1];
		cout << res << endl;
	}	
	return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;

int main()
{
	int X, ans;
	cin >> X;

	for (int i = 1; i < 32; i++) {
		for (int j = 2; j < 10; j++) {
			if (pow(i, j) <= X && ans < pow(i, j)) ans = pow(i, j);
		}
	}

	cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	n=sqrt(n);
	cout<<n*n;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main(){
  int N,H,W;
  int ans=0;
  cin>>N>>H>>W;
  int A[N+1],B[N+1];
  for(int in=1;in<N+1;in++)
    cin>>A[in]>>B[in];
  for(int i=1;i<=N;i++){
    if(A[i]>=H && B[i]>=W) ans++;
  }
  cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define mod 1000000007
using namespace std;
#define ll long long int
int main()
{
 		ll n;cin>>n;
  		if(n==1)
  		{
  			cout<<0;
  		}
  		else
  		{
  			cout<<1;
  		}
  	}
		

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
using vc = vector<char>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int n;
  cin >> n;
  vi x(n);
  rep(i,n) cin >> x[i];
  vi y = x;
  sort(all(y));
  int low = y.at(n/2-1);
  int high = y.at(n/2);
  rep(i,n){
    if(x[i] <= low) cout << high << endl;
    else cout << low << endl;
  }
}

Measured memory_bytes: 4840
import java.io.*;
 
public class Main { 
    public static void main(String[] args) throws IOException {             
        BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
        String s = buf.readLine();
        int x = Integer.parseInt(s);
        double i = Math.pow(x, 3);
        int ans = (int)i;
        System.out.println(ans);
    } 
}

Measured memory_bytes: 24192
#pragma warning(disable:4996)
#include "bits/stdc++.h"
using namespace std;

//macro
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,a,b) for(int i=(int)(b) - 1;i>=(int)(a);i--)
#define rrep(i,n) RREP(i,0,n)
#define each(i, ctn) for (auto &&i : (ctn))
#define all(a) (a).begin(),(a).end()
#define mp make_pair
#define INFL 1145148100000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define equals(a,b)(fabs((a)-(b))<EPS)

//alias
using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
using P = pair<ll, ll>;
template<class T> using heap = priority_queue<T>;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H);	rep(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n)os << v[i] << (i == n - 1 ? "\n" : " "); return os; }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template<class T> inline void print(const T &x) { cout << x << '\n'; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	print(min(A*N, B));
	return 0;
}


Measured memory_bytes: 256
#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++)
typedef long long ll;
typedef pair<int,int> pii;

int main(){
   int x,y,z;
   cin>>x>>y>>z;
   cout<<z<<" "<<x<<" "<<y<<endl; 
   return 0;
}

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

int main(void){
	
	int n,Min=0;
	int  a[10];
	int tmp;
		
	
			
		Min=0;
	cin>>n;
	while(n--){
		cin >> tmp;
		if(tmp < 400) a[1] = 1;
		else if(tmp < 800) a[2] = 1;
		else if(tmp < 1200) a[3] = 1;
		else if(tmp < 1600) a[4] = 1;
		else if(tmp < 2000) a[5] = 1;
		else if(tmp < 2400) a[6] = 1;
		else if(tmp < 2800) a[7] = 1;
		else if(tmp < 3200) a[8] = 1;
		else a[9]++;
	}	
		for(int i=1;i<9;i++){
			if(a[i]==1)
					Min++;	
			
	}
					
	

	
		
	cout<<max(1,Min)<<" "<<Min+a[9]<<endl;	



				return 0;			
			
			
}	

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define int long long
signed main(){
        int a,b,c,d,e;
        while( scanf("%lld %lld %lld %lld %lld", &a, &b, &c, &d, &e) != EOF ){
                vector<int> data{a,b,c,d,e};
                sort(data.begin(), data.end());
                printf("%lld %lld %lld %lld %lld\n", data[4], data[3], data[2], data[1], data[0]);
        }
        return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int ans = 0;
    if (N % 2 == 1) {
        ans = B[N/2] - A[N/2] + 1;
    } else {
        int m = (N - 1) / 2;
        ans = B[m + 1] + B[m] - A[m + 1] - A[m] + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4792
program double_fractorial
    implicit none
    integer(8):: n, md, ans, i,div
    read*, n

    if (mod(n,2) /= 0) then
        print*, 0
        stop
    end if

    div = 10
    ans = 0
    do while(div <= n)
        ans = ans + n/div
        div = div*5
    end do
    print*, ans
end program double_fractorial

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

int main(int argc, char const *argv[]) {

  int sx,sy,tx,ty;
  std::cin >>  sx >> sy >> tx >> ty;
  int dx=tx-sx,dy=ty-sy;

  std::cout << string(dy,'U') << string(dx,'R');
  std::cout << string(dy,'D') << string(dx,'L');
  std::cout << "L" << string(dy+1,'U') << string(dx+1,'R') << 'D';
  std::cout << "R" << string(dy+1,'D') << string(dx+1,'L') << 'U';

  return 0;
}


Measured memory_bytes: 256
right_str = "yuiophjklnm"

while True:
    msg = input()
    if msg == "#": break

    change_count = 0
    # type_right = False

    # 最初の1回は右手のフラグの初期化
    first = msg[0]
    if first in right_str:
        type_right = True
    else:
        type_right = False

    for char in msg[1:]:
        if char in right_str:
            if not type_right:
                change_count += 1
            type_right = True
        else:
            if type_right:
                change_count += 1
            type_right = False

    print(change_count)

Measured memory_bytes: 6728
# 解答例
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret

print(dfs(0, 'TTT'))

Measured memory_bytes: 3872
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define mod 1e9+7
#define debug(x) cout<<x<<endl;
#define fi first
#define se second
int main(){
	ll n; cin>>n;
	vector<pair<int,int>> v(n);
	for(int i=0;i<n;i++) cin>>v[i].se>>v[i].fi;
	sort(v.begin(),v.end());
	ll cd=0;
	bool ans=1;
	for(ll i=0;i<n;i++){
		ll ft=cd+v[i].se;
		if(ft>v[i].fi){
			ans=0;
			break;
		}else{
			cd=cd+v[i].se;
		}
	}
	if(ans) cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 4820
// AOJ 0142: Nature of Prime Numbers
// 2017.8.16 bal4u@uu
// 2018.5.4

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

char ob[20]; int w;
void out(int n)
{
	int i;
	w = 0;
	if (!n) ob[w++] = '0';
	else while (n) ob[w++] = n%10 + '0', n /= 10;
	i = w; while (i--) pc(ob[i]); 
}

#define MAX  10000
#define HALF 5000
int  sqr[HALF+5];
int  a[HALF+5];
int  d[HALF+5];
char f[MAX+5];

char prime[MAX+5];
int tbl[24] = {
  3,  5,  7, 11, 13, 17, 19, 23, 29, 31,
 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
 79, 83, 89, 97 };
int sqp[24] = {
  9,25,49,121,169,289,361,529,841,961,
1369,1681,1849,2209,2809,3481,3721,4489,5041,
5329,6241,6889,7921,9409 };

void init()
{
	int i, j, k;

	for (i = 0; i < 24; i++) {
		k = tbl[i];
		for (j = sqp[i]; j < MAX; j += k) prime[j] = 1;
	}
	for (sqr[1] = 1, j = 3, i = 2; i <= 5000; i++, j+=2) sqr[i] = sqr[i-1]+j; // sqr[i] = i^2
}

int main()
{
	int n, i, j, k, b, m;

	init();
	while (n = in()) {
		k = n >> 1;
		// 4m+3の素数
		if (!prime[n] && (n & 3) == 3) {
			out(k-1), pc('\n');
			while(--k) {
				i = w; while (i--) pc(ob[i]); pc('\n');
			}
			continue;
		}

		// 他の奇数についてはまじめに計算
		memset(d, 0, sizeof(d));
		memset(f, 0, sizeof(f));
		m = 0;
		for (i = 1; i <= k; i++) {
			b = sqr[i] % n;
			if (!f[b]) f[b] = 1, a[m++] = b;
		}
		for (i = 0; i < m; i++) {
			for (j = 0; j < i; j++) {
				if (b = a[i] - a[j]) {
					if (b < 0) b += n;
					if (b > k) b = n - b;
					d[b]++;
				}
			}
		}
		for (i = 1; i <= k; i++) out(d[i]<<1), pc('\n');
	}
	return 0;
}



Measured memory_bytes: 2072
#include<stdio.h>
#include<stdlib.h>
#define TABLESIZE 3 //おまけでテーブルの可変化を実装
#define BUFFSIZE TABLESIZE*(TABLESIZE+2)

int main() {
	//変数宣言。tblでマップフィールドを表現
	int i, j;
	int tbl[TABLESIZE][TABLESIZE];
	char buff[BUFFSIZE];

	//データ入力受付
	for (i = 0; i < TABLESIZE; i++) {
		fgets(buff, BUFFSIZE, stdin);
		sscanf(buff, "%d %d %d", &tbl[i][0], &tbl[i][1], &tbl[i][2]);
	}

	//一致の条件は(a(i)+b(j))-(a(i+1)+b(j))と
	//(a(i)+b(j+1))-(a(i+1)+b(j+1))を比較すれば求められるから以下の通りになる
	for (i = 0; i < TABLESIZE - 1; i++) {
		for (j = 0; j < TABLESIZE - 1; j++) {
			//条件を満たせなければ失敗とみなして終了する
			if (tbl[i][j] - tbl[i + 1][j] != tbl[i][j + 1] - tbl[i + 1][j + 1]) {
				printf("No\n");
				goto EndFanction;
			}
		}
	}
	printf("Yes\n");

EndFanction:
	return 0;
}

Measured memory_bytes: 256
var
	n,i,j,x,y,ans:Longint;
	by:array[1..200]of Longint;
	ax:array[1..200]of Longint;
begin
	read(n);
	for i:=1 to n do begin
		read(x,y);
		ax[y+1]:=x+1;
	end;
	for i:=1 to n do begin
		read(x,y);
		by[x+1]:=y+1;
	end;
	for i:=1 to 2*n do begin
		if by[i]=0 then continue;
		for j:=by[i]-1 downto 1 do begin
			if(ax[j]>0)and(ax[j]<i)then begin
				inc(ans);
				ax[j]:=0;
				break;
			end;
		end;
	end;
	writeln(ans);
end.

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
	int a, b, c, d;
	
	scanf("%d %d %d %d", &a, &b, &c, &d);
	
	printf("%d", min(a,b) + min(c,d));
	
	return 0;
}

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

void fnInput(int& rnLimit, vector<llong>& rvnCostA, vector<llong>& rvnCostB)
{
  int nCostASiz, nCostBSiz;
  cin >> nCostASiz >> nCostBSiz >> rnLimit;
  rvnCostA.resize(nCostASiz + 1);
  rvnCostB.resize(nCostBSiz + 1);

  for (int i = 1; i < rvnCostA.size(); i++)
  {
    int nOneCost;
    cin >> nOneCost;
    rvnCostA[i] = rvnCostA[i - 1] + nOneCost;
  }

  for (int i = 1; i < rvnCostB.size(); i++)
  {
    int nOneCost;
    cin >> nOneCost;
    rvnCostB[i] = rvnCostB[i - 1] + nOneCost;
  }
}

int fnMaxSelCnt(int nLimit, const vector<llong>& cnrvnCostA, 
                            const vector<llong>& cnrvnCostB)
{
  int nMaxSelCnt = 0;
  int nBgnB = cnrvnCostB.size() - 1;
  int nCntA = 0;

  while (nCntA < cnrvnCostA.size()  &&
         cnrvnCostA[nCntA] <= nLimit   )
  {
    int nCntB = nBgnB;

    while (cnrvnCostB[nCntB] > nLimit - cnrvnCostA[nCntA])
      nCntB--;

    nMaxSelCnt = max(nMaxSelCnt, nCntA + nCntB);
    nBgnB = nCntB;

    nCntA++;
  }
  return nMaxSelCnt;
}
 
int main()
{
  int nLimit;
  vector<llong> vnCostA, vnCostB;

  fnInput(nLimit, vnCostA, vnCostB);
  cout << fnMaxSelCnt(nLimit, vnCostA, vnCostB) << endl;

  return 0;
}

Measured memory_bytes: 6428
# 難易度 484
# 800~
# 解法805,pi~pjの合計が最大となる区間を求める
# Kの区間が固定されているので0~K-1 -> N-K~N-1を足していイケば良い
# 2~10^5こしかNがないので，せいぜいO(N)で終わるので十分
# 期待値の計算をいちいちしていたら，計算量がもタンクなるかも？最初から計算しておくか
# なぜTLEが起こるのかがよくわからない

N, K = map(int,input().split())
P = list(map(int,input().split()))
P_MAX = 10**3
E = [0]*(P_MAX+1)
for i in range(1,P_MAX+1):
    E[i] = sum([1/i * j for j in range(1,i+1)])

ans = 0
for i in range(0,N-K+1):
    if i == 0:
        old = sum([E[l] for l in P[0:0+K]])
        ans = old
        continue
    new = old - E[P[i-1]] + E[P[i+K-1]]
    ans = max(ans,new)
    old = new
print(ans)




Measured memory_bytes: 25604
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){  
	int x;
	int a;
	int b;
	cin >> x >> a >> b;
	if(fabs(x - a) > fabs(x - b)){
		cout << "B" << endl;
	}else{
		cout << "A" << endl;
	}
	return 0;
}

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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int mod = 998244353;
inline int mul(int x,int y){return 1ll*x*y%mod;}
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
inline int sq(int x){return 1ll*x*x%mod;}
int mpow(int a,int b){return b == 0 ? 1 : ( b&1 ? mul(a,sq(mpow(a,b/2))) : sq(mpow(a,b/2)));}

const int N = 18400;
int fac[N+10],invfac[N+10];

int C(int n,int m){
	if(n<0 || m<0 || m>n)return 0;
	return mul(fac[n],mul(invfac[m],invfac[n-m]));
}

int n,m,dp[303][8080],coef[N],co2;

struct poly{
	int wroot = 3;
	int n,l,rev[N],mrt[N],invn,MXLNTT = 14,MXNTT = 1<<MXLNTT;
	int uptopow(int x){
		while(x!=(x&(-x)))x+=x&(-x);
		return x;
	}
	void ori(){
		int stepv = mpow(wroot,(mod-1)/MXNTT);
		mrt[0] = 1;	for(int i=1;i<=MXNTT;i++)mrt[i] = mul(mrt[i-1],stepv);
		rev[0] = 0;	for(int i=1;i<=MXNTT;i++)rev[i] = (rev[i>>1]>>1)|(i&1?(1<<(MXLNTT-1)):0);
	}
	void dft(int a[],int sz,int typ){
		static int cc1[N],us[N];
		int mn = MXLNTT-__builtin_ctz(sz);
		for(int i=0;i<sz;i++)cc1[i] = a[rev[i]>>mn];
		for(int l=2;l<=sz;l*=2){
			int m = l>>1,step = MXNTT/l;
			if(typ == 0) for(int i=0,j = 0;i<=m;i++,j+=step)us[i] = mrt[j];
			else for(int i=0,j=MXNTT;i<=m;i++,j-=step)us[i] = mrt[j];
			for(int i = 0;i!=sz;i+=l){
				for(int j=0;j<m;j++){
					int t = mul(cc1[i+j+m],us[j]);
					cc1[i+j+m] = sub(cc1[i+j],t);
					cc1[i+j] = add(cc1[i+j],t);
				}
			}
		}
		if(typ){
			int invn = mpow(sz,mod-2);
			for(int i=0;i<sz;i++)a[i] = mul(cc1[i],invn);
		}else{
			memcpy(a,cc1,sz*sizeof(int));
		}
	}
}NTT;

int main() {
	fac[0] = 1;
	for(int i=1;i<=N;i++)fac[i] = mul(fac[i-1],i);
	invfac[N] = mpow(fac[N],mod-2);
	for(int i=N-1;i>=0;i--) invfac[i] = mul(invfac[i+1],i+1);
	NTT.ori();
	read(n);read(m);
	for(int i=0;i<=n;i++) dp[1][i] = 1;
	for(int i=1;i<=n;i++) coef[i] = invfac[i+2];
	int sz = NTT.uptopow((n+1)*2);
	NTT.dft(coef,sz,0);
	int pdp[N];
	int inv2 = (mod+1)/2;
	for(int ech=2;ech<=m;ech++){
		memset(pdp,0,sizeof(pdp));
		for(int i=0;i<=n;i++)pdp[i] = mul(dp[ech-1][i],invfac[i]);
		NTT.dft(pdp,sz,0);
		for(int i=0;i<sz;i++)pdp[i]=mul(pdp[i],coef[i]);
		NTT.dft(pdp,sz,1);
		for(int i=0;i<=n;i++){
			dp[ech][i] = add(mul(pdp[i],fac[i+2]),mul(dp[ech-1][i],i*(i+1)/2+1));
		}
	}
	int ans = 0;
	for(int i=0;i<=n;i++)ans = add(ans,mul(C(n,i),dp[m][i]));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8704
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       String s=sc.next();
       if(s.substring(0,n/2).equals(s.substring(n/2,n)) && n%2==0) System.out.println("Yes");
       else System.out.println("No");

    }
}

Measured memory_bytes: 23636
#include <algorithm>
#include <bitset>
#include <chrono>
#include <complex>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = int64_t;
using vll = vector<ll>;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, x;
        in >> n >> x;
        vll a(n);
        for (int i = 0; i < n; i++) {
            in >> a[i];
        }
        vll b(a);
        ll ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (a[i] + a[i + 1] > x) {
                if (a[i] > x) {
                    ans += a[i] + a[i + 1] - x;
                    a[i] = x;
                    a[i + 1] = 0;
                }
                else {
                    ans += a[i] + a[i + 1] - x;
                    a[i + 1] -= a[i] + a[i + 1] - x;
                }
            }
        }
        out << ans << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;
typedef pair<plint, lint> query;

template< typename T >
struct BinaryIndexedTree {
	vector< T > data;

	BinaryIndexedTree(int sz) {
		data.assign(++sz, 0);
	}

	T sum(int k) {
		T ret = 0;
		for (++k; k > 0; k -= k & -k) ret += data[k];
		return (ret);
	}

	void add(int k, T x) {
		for (++k; k < data.size(); k += k & -k) data[k] += x;
	}
};

lint N, Q, L, R;
lint arr[500000];
vector<query> queries;
vector<plint> sec;
lint last[500000];
lint ans[500000];

int main() {
	cin >> N >> Q;
	REP(i, N) last[i] = -1;
	REP(i, N) {
		cin >> arr[i]; arr[i]--;
		if (last[arr[i]] != -1) sec.push_back({ last[arr[i]], i });
		last[arr[i]] = i;
	}
	REP(i, Q) {
		cin >> L >> R; L--; R--;
		queries.push_back({ { L, R }, i });
	}
	sort(ALL(queries), greater<query>());
	sort(ALL(sec), greater<plint>());
	BinaryIndexedTree<int> bit(N);
	lint sec_idx = 0;
	REP(i, Q) {
		while (sec_idx < SZ(sec) && queries[i].first.first <= sec[sec_idx].first) {
			bit.add(sec[sec_idx].second, 1);
			sec_idx++;
		}
		lint l = queries[i].first.first, r = queries[i].first.second;
		ans[queries[i].second] = (r - l + 1) - (bit.sum(r));
	}
	REP(i, Q) {
		cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 40480
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int N;
  cin >> N;
  cout << N * (N + 1) / 2 << endl;
}

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

int main() {
  	string s,t;
  	cin >> s >> t;
  	int n = s.size();
  	int q = 0;
  	for(long i = 0; i<n; i++){
      if(s[i]==t[i]){
        q++;
    }
    else{
      cout << "No" << endl;
      break;
    }
    }
  if(q==n){
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
    using namespace std;
     
     
    int main() {
    	int n,m; cin>>n>>m;
    	set<int> s;
    	while(m--){
    		int d; cin>>d;
    		while(d--){
    		int x; cin>>x;
    		s.insert(x);
    		}
    	}
    	cout<<n-s.size()<<endl;
    }

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
#include <bitset>
#include <queue>

using namespace std;

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

    if(s.size() == 3){
        cout << s[2];
        cout << s[1];
        cout << s[0] << endl;
        return 0;
    }

    cout << s << endl;


    return 0;
}

Measured memory_bytes: 256
import * as fs from 'fs';

const readString = (() => {
  const input = fs.readFileSync(0).toString();
  const words = input.split(/[ \n]/);
  let i = 0;
  return () => words[i++] || '';
})();
const readInt = () => parseInt(readString(), 10);
const readBigInt = () => BigInt(readString());

const gcd = (a: bigint, b: bigint) => {
  const _gcd = (a: bigint, b: bigint): bigint => {
    const q = a % b;
    return q === 0n ? b : _gcd(b, q);
  };
  return a > b ? _gcd(a, b) : _gcd(b, a);
};

const MOD = 1000000007;
const MOD_BIGINT = BigInt(MOD);
class ModBigInt {
  constructor(public v: bigint) { }

  static of(n: number | bigint) {
    return new ModBigInt(ModBigInt.toBigInt(n));
  }

  static toBigInt(other: number | bigint | ModBigInt) {
    if (typeof other === 'bigint') return other;
    if (typeof other === 'number') return BigInt(other);
    return other.v;
  }

  clone = () => new ModBigInt(this.v);
  plus = (other: number | bigint | ModBigInt) => {
    this.v = (this.v + ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  }
  minus = (other: number | bigint | ModBigInt) => {
    this.v = (this.v + MOD_BIGINT - ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  }
  multiply = (other: number | bigint | ModBigInt) => {
    this.v = (this.v * ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  }
  pow = (other: number) => {
    let v = mod(1);
    for (let i = 0; i < other; i++) v.multiply(this.v);
    return v;
  }
}

const mod = ModBigInt.of;

const abs = (a: bigint) => a > 0n ? a : -a;

(function main() {
  const N = readInt();

  let zero: number = 0;
  const groups: { [k: string]: [number, number] } = {};
  Array.from({ length: N }, () => {
    let A = readBigInt();
    let B = readBigInt();
    if (A === 0n && B === 0n) {
      zero++;
    } else if (A === 0n) {
      groups['0:1'] = groups['0:1'] || [0, 0];
      groups['0:1'][0]++;
    } else if (B === 0n) {
      groups['0:1'] = groups['0:1'] || [0, 0];
      groups['0:1'][1]++;
    } else {
      const n = gcd(abs(A), abs(B));
      A /= n;
      B /= n;
      if (A < 0) {
        A *= -1n;
        B *= -1n;
      }

      if (B > 0) {
        const k = `${A}:${B}`;
        groups[k] = groups[k] || [0, 0];
        groups[k][0]++;
      } else {
        const k = `${-B}:${A}`;
        groups[k] = groups[k] || [0, 0];
        groups[k][1]++;
      }
    }
  });

  let result = mod(1);
  for (const k of Object.keys(groups)) {
    const [xn, yn] = groups[k];

    let tmp = mod(0);
    if (xn) {
      tmp.plus(mod(2).pow(xn).minus(1));
    }

    if (yn) {
      tmp.plus(mod(2).pow(yn).minus(1));
    }

    tmp.plus(1);

    result.multiply(tmp);
  }

  result.plus(zero).minus(1);

  console.log(result.v.toString());
})();


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

int main(int argc, char const *argv[])
{
  string s;
  cin >> s;
  int cnt = 0;
  for(int i = 0; i < s.length() / 2; ++i){
    if(s[i] != s[s.length() - i - 1]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define lint long long
#define pb(a) push_back(a)

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;

using namespace std;

int ans;
string s;

int main(){
  cin >> s;
  char k=s[0];
  REP(i,s.size()){
    if(s[i]!=k){
      ans ++;
      k = s[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

string s;
int dp[200005];
int from[256];
queue<int> allLocs[256];
void solve() {
  cin >> s;
  s = "!" + s;
  dp[s.size()] = 1;
  for(int i = 'a'; i <= 'z'; i++) from[i] = s.size()+1;
  for(int i = s.size()-1; i >= 0; i--) {
    from[s[i]] = i;
    dp[i] = 1e9;
    for(int a = 'a'; a <= 'z'; a++) {
      dp[i] = min(dp[i], dp[from[a]+1] + 1);
    }
  }
  for(int i = 0; i < s.size(); i++) allLocs[s[i]].push(i);
  int currIdx = 0;
  while(true) {
    bool printed = false;
    for(int a = 'a'; a <= 'z'; a++) {
      while(allLocs[a].size() && allLocs[a].front() < currIdx) allLocs[a].pop();
      if(allLocs[a].empty()) {
        cout << (char)a;
        return;
      }
      int nextIdx = allLocs[a].front() + 1;
      if(dp[nextIdx] == dp[currIdx] - 1) {
        cout << (char)a;
        printed = true;
        currIdx = nextIdx;
        break;
      }
    }
    assert(printed);
  }
  cout << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 2256