akhauriyash/Code-Regression huggingface dataset:
let rec count ss n =
    let rec loop ss s n =
        match ss with
        | [] -> (n, [])
        | s' :: ss' ->
            if s' = s then loop ss' s (n + 1)
            else (n, ss)
    in
    match ss with
    | [] -> n
    | s' :: ss' ->
        let (n', ss'') = loop ss' s' 1 in
        count ss'' (n + n' * (n' - 1) / 2)

let solve ss =
    let ss' = List.map (List.sort compare) ss |> (List.sort compare) in
    count ss' 0

let rec input n =
    if n = 0 then []
    else let line = read_line () in
        Str.split (Str.regexp "") line :: input (n - 1)

let () =
    let n = read_line () |> int_of_string in
    let ss = input n in
    print_int @@ solve ss;
    print_newline ()


Measured memory_bytes: 79740
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i = 1; i < 10; i++) for(int j = 1; j < 10; ++j) {
        cout << i << 'x' << j << '=' << i*j << '\n';
    }
}


Measured memory_bytes: 3152
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a,b,c;
	cin >> a; cin >> b; cin >> c;
	if(abs(a-b)==0)cout << c << endl;
	else if (abs(b - c) == 0) {
		cout << a << endl;
	}
	else {
		cout << b << endl;
	}
	
}

Measured memory_bytes: 256
import java.util.*;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int a[][] = new int[h][w];
		for(int i=0; i<h; i++) {
			for(int j=0; j<w; j++) {
				a[i][j]=sc.nextInt();
			}
		}

		int s[][] = new int[500*500][4];
		int cnt = 0;
		for(int i=0; i<h-1; i++) {
			for(int j=0; j<w; j++) {
				if(a[i][j] % 2 != 0) {
					a[i][j]--;
					a[i+1][j]++;
					s[cnt][0] = i+1;
					s[cnt][1] = j+1;
					s[cnt][2] = i+2;
					s[cnt][3] = j+1;
					cnt++;
				}
			}
		}
		for(int j=0; j<w-1; j++) {
			if(a[h-1][j] % 2 != 0) {
				a[h-1][j]--;
				a[h-1][j+1]++;
				s[cnt][0] = h;
				s[cnt][1] = j+1;
				s[cnt][2] = h;
				s[cnt][3] = j+2;
				cnt++;
			}
		}

		System.out.println(cnt);
		for(int i=0; i<cnt; i++) {
			System.out.println(s[i][0] + " " + s[i][1] + " " + s[i][2] + " " + s[i][3]);
		}
		sc.close();
	}


}




Measured memory_bytes: 112540
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int n, ww;
    cin >> n >> ww;
    vector<ll> w(n);
    vector<ll> v(n);
    for (int i=0; i<n; i++) cin >> w[i] >> v[i];

    vector<ll> dp(ww+1, 0);
    
    for (int i=0; i<n; i++) {
        for (int j=ww; j>=w[i]; j--)
            dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
    }

    cout << dp[ww] << endl;
}


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

int main() {
  int turn = 0;
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (A > 0 && C > 0) {
    if (turn == 0) {
      C = C - B;
      turn = turn + 1;
    } else {
      A = A - D;
      turn = turn - 1;
    }
  }
  if (A <= 0) {
    cout << "No" << endl;
  } else if (C <= 0) {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;
  sort(ALL(a));
  ll c = 0;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    if (c >= m) break;
    if (c + a[i].second <= m) {
      ans += a[i].first * a[i].second;
    } else {
      ans += a[i].first * (m - c);
    }
    c += a[i].second;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 4820
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> inline void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> inline void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

int main() {
    ll n;
    cin >> n;
    map<ll, ll> a;
    ll sum = 0;
    rep(i,n) {
        ll t;
        cin >> t;
        sum += t;
        ll temp = 0;
        auto it = a.find(t);
        if (it!=a.end()) {
            temp = it->second;
        }
        a.erase(t);
        a.insert(make_pair(t, 1 + temp));
    }
    ll q; cin >> q;
    rep(i, q) {
        ll b,c;
        cin >> b >> c;
        auto it = a.find(b);
        if (it!=a.end()) {
            sum -= it->second * b;
            sum += it->second * c;
            auto it2 = a.find(c);
            if(it2 != a.end()) {
                ll temp2 = it2->second + it->second;
                a.erase(c);
                a.insert(make_pair(c, temp2));
            } else {
                a.insert(make_pair(c,it->second));
            }
            a.erase(b);
        }

        print(sum);
    }

    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

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

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

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

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

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

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

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

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

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

Measured memory_bytes: 19364
N,K = map(int,input().split())
h = list(map(int,input().split()))

def aa (n,k,ll):
  dp = [0] * n
  for i in range(1,n):
    s = max(i-k,0)
    mn = float('inf')
    for a,b in zip(dp[s:i],ll[s:i]):
      cur = a + abs(ll[i]-b)
      if cur < mn:
        mn = cur
  
    dp[i] = mn
  print(dp[-1])

aa(N,K,h)

Measured memory_bytes: 13980
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void solve() {
		int n=s.nextInt();
		int[] arr = new int[n];
		int mod = (int)1e9+7;
		for(int i=0;i<n;i++) {
			arr[i]=s.nextInt();
		}
		int[] count = new int[n+1];
		count[0]=3;
		long ans = 1;
		for(int i =0;i<n;i++) {
			int current= arr[i];
			int last = arr[i]-1;
			int vc = count[current+1];
			int vl = count[last+1];
			ans = (ans*(vl-vc))%mod;
			count[current+1]++;
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}


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

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<vector<int>> card(K, vector<int>(N/2));
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < N/2; j++) {
            cin >> card[i][j];
            card[i][j]--;
        }
    }
    
    random_device rd;
    mt19937 mt(rd());
    bool finished = 0;
    while (!finished) {
        finished = 1;
        
        vector<int> seq(N);
        for (int i = 0; i < N; i++) {
            seq[i] = mt() % 2;
        }
        
        for (int i = 0; i < K; i++) {
            int sum = 0;
            for (int j = 0; j < N/2; j++) {
                sum += seq[card[i][j]];
            }
            if (sum < N/8 || sum > 3*N/8) {
                finished = 0;
                break;
            }
        }

        if (finished) {
            for (int i = 0; i < N; i++) {
                cout << seq[i];
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3876
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(), v.end()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };


int n;
int v[100005];
map<int, int> mp[2];
vector <PII> vec[2];

int main() {

	cin >> n;
	rep(i, n)cin >> v[i];

	rep(i, n) {
		if (i % 2 == 0) {
			mp[0][v[i]]++;
		}
		else {
			mp[1][v[i]]++;
		}
	}

	rep(i, 2) {
		for (const auto& x : mp[i]) {
			vec[i].push_back(dmp(x.se, x.fi));
		}
	}

	rep(i, 2) {
		if (vec[i].size() == 1)vec[i].push_back(dmp(0, -5));
		sort(all(vec[i]));
		reverse(all(vec[i]));
	}

	if (vec[0][0].se != vec[1][0].se)cout << n - (vec[0][0].first + vec[1][0].first) << endl;
	else cout << min(n - (vec[0][1].first + vec[1][0].first), n - (vec[0][0].first + vec[1][1].first)) << endl;

	return 0;
}


Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
long double dp[3000][3000];
int main() {
    ios::sync_with_stdio(false);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n;
    cin>>n;
    long double coins[3000];
    for(int i=0; i<n;i++){
        cin>>coins[i];
    }
    dp[0][0] = (1-coins[0]);
    dp[0][1] = coins[0];
    for(int i=1; i< n;i++){
        for(int j = 0; j<= i+1; j++){
            dp[i][j] = dp[i-1][j] * (1-coins[i]);
            if(j!=0) dp[i][j] += dp[i-1][j-1] * coins[i]; 
        }
    }
    long double ans = 0;
    for(int i = 0; i<= n; i++){
        if(n-i < i) ans += dp[n-1][i];
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 139008
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <map>
#include <set>
#include <algorithm>
#include <stack>

using namespace std;

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vll> vvl;
typedef pair<ll, ll> pll;
typedef pair<string, ll> psl;
typedef vector<psl> vpsl;
typedef vector<pll> vpl;
typedef unordered_set<ll> usl;
typedef set<ll> sl;
typedef unordered_map<ll, ll> uml;
typedef map<ll, ll> ml;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

#define all(v) v.begin() , v.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll inf = 1e9 + 7;
const double pie = 3.14159265358979323846;
const char nl = '\n';

template<typename Type>
istream &operator>>(istream &in, vector<Type> &v)
{
    ll n = v.size();
    for (int i = 0; i < n; i++)
        in >> v[i];
    return in;
}

template<typename Type>
ostream &operator<<(ostream &out, vector<Type> &v)
{
    for (auto value : v)
        out << value << " ";
    out << endl;
    return out;
}

void solve()
{
    string s;
    cin >> s;
    ll sum = 0;
    for (char c : s)
        sum += (c - '0');
    if (sum % 9 == 0)
        cout << "Yes" << nl;
    else
        cout << "No" << nl;
}

int main()
{
    IOS
    ll t;
    t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3780
N = int(input())
list_d = [0] * N

for i in range(N):
  list_d[i] = int(input())

list_d.sort()

result_cnt = 1
for i in range(N - 1):
  if list_d[i] != list_d[i + 1]:
    result_cnt += 1

print(result_cnt)

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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

int main() {
	int n, k;
	int num;
	cin >> n >> k;
	vector<int> inp;
	for(int i=0;i<n;i++) {
		cin >> num;
		inp.push_back(num);
	}
	sort(inp.begin(), inp.end());
	int ans = 0;
	for(int i=0;i<k;i++) {
		ans += inp[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#define MAX 100
#define INFTY 2001

int main(){
  int n, i, j, e, sum;
  int M[MAX][MAX];
  int u, v;
  int minv;
  int d[MAX];
  int p[MAX];
  int vis[MAX];

  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      if(e == -1) M[i][j] = INFTY;
      else M[i][j] = e;
    }
  }

  for ( i = 0; i < n; i++ ) {
    d[i] = INFTY;
    p[i] = -1;
    vis[i] = 0;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for ( i = 0; i < n; i++ ){
      if ( minv > d[i] && !vis[i] ){
        u = i;
        minv = d[i];
      }
    }
    if ( u == -1 ) break;
    vis[u] = 1;
    for ( v = 0; v < n; v++ ){
      if ( !vis[v] && M[u][v] != INFTY ){
        if ( d[v] > M[u][v] ){
          d[v] =  M[u][v];
          p[v] = u;
        }
      }
    }
  }

  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }

  printf("%d\n", sum);

  return 0;
}



Measured memory_bytes: 2056
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
struct UnionFind{
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	bool unionSet(int x,int y){
		x=root(x);y=root(y);
		if(x==y)return 0;
		if(data[y]<data[x])swap(x,y);
		data[x]+=data[y],data[y]=x;
		return 1;
	}
	bool findSet(int x,int y){
		return root(x)==root(y);
	}
	int root(int x){
		return data[x]<0 ? x : data[x]=root(data[x]);
	}
	int size(int x){
		return -data[root(x)];
	}
};
int main(){
	int n,q,c,x,y;
	scanf("%d%d",&n,&q);
	UnionFind uf(n);
	for(;q--;c?printf("%d\n",uf.findSet(x,y)):uf.unionSet(x,y))scanf("%d%d%d",&c,&x,&y);
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll n;
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	if(n & 1) cout << 0 << endl;
	else{
		ll ans = 0;
		ll k = 10;
		while(k <= n){
			ans += n / k;
			k *= 5;
		}
		cout << ans << endl;
	}
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

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

int main() {
	string s;
	string t="ATCG";
	cin>>s;
	
	int ans=0;
	int now=0;
	
	for(int i=0;i<s.size();i++){
		bool ok=false;
		for(int j=0;j<t.size();j++){
			if(s[i]==t[j])ok=true;
		}
		if(ok){
			now++;
			ans=max(ans,now);
		}
		else{
			now=0;
		}
	}
	
	cout<<ans<<endl;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

class date {
public:
	int year, month, day;
	bool operator<(const date&d);
	string gengoh();
	int year_wareki();
};
const date meiji_ganzitsu{ 1868,9,8 }, taisho_ganzitsu{ 1912,7,30 }, showa_ganzitsu{ 1926,12,25 }, heisei_ganzitsu{ 1989,1,8 };
bool date::operator<(const date&d)
{
	return year < d.year || year == d.year && (month < d.month || month == d.month && day < d.day);
}
string date::gengoh() {
	return
		*this < meiji_ganzitsu ? "pre-meiji" :
		*this < taisho_ganzitsu ? "meiji" :
		*this < showa_ganzitsu ? "taisho" :
		*this < heisei_ganzitsu ? "showa" : "heisei";
}
int date::year_wareki()
{
	return year - (
		gengoh() == "meiji" ? meiji_ganzitsu.year :
		gengoh() == "taisho" ? taisho_ganzitsu.year :
		gengoh() == "showa" ? showa_ganzitsu.year : heisei_ganzitsu.year
		) + 1;
}

signed main()
{
	int year, month, day;
	while (cin >> year >> month >> day) {
		date d{ year, month, day };
		cout << d.gengoh();
		if (d.gengoh() != "pre-meiji")cout << ' ' << d.year_wareki() << ' ' << d.month << ' ' << d.day;
		cout << endl;
	}
}


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include <cmath>
#include<vector>
#include<algorithm>
#include<stdio.h>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define ll long long


int main()
{
    ll N;
    cin >> N;
    
    for(ll i = N; i > 0; i--)
    {
        ll x = sqrt(i);
        if(x*x == i) 
        {
            cout << i << endl;
            return 0;
        }
    }
}

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

int main()
{
  int N ;
  cin>>N ;
  int A[N] ;
  for(int i=0;i<N;i++) cin>>A[i] ;
  
  int max=0 ;
  int min=1e10 ;
  for(int i=0;i<N;i++){
    if(A[i]>max) max=A[i] ;
    if(A[i]<min) min=A[i] ;
  }
  cout<<max-min<<endl ;
  
  return 0 ;
}

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

int main() {
  int S, W;
  cin >> S >> W;
  bool bl;
  bl = (S > W);
  if (bl) cout << "safe" << '\n';
  else cout << "unsafe" << '\n';
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#pragma warning (disable: 4996)
using namespace std;

int N, M, L[1 << 18], R[1 << 18];
int A[1 << 18];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> L[i] >> R[i];
		A[L[i]]++;
		A[R[i] + 1]--;
	}
	for (int i = 1; i <= N; i++) A[i] += A[i - 1];

	int cnt = 0;
	for (int i = 1; i <= N; i++) {
		if (A[i] == M) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;


int main() {
	int n;
	string s;
	cin >> n >> s;
	bool flag;
	int last;
	int search,index;
	int cnt = 0;
	vector<int> v[10];
	for (int i = 0;i < s.length();i++) {
		v[atoi(s.substr(i, 1).c_str())].push_back(i);
	}
	for (int i = 0;i < 1000;i++) {
		last = -1;
		flag = true;
		for (int j = 0;j < 3;j++) {
			search = (i / (int)pow(10, j)) % 10;
			index = upper_bound(v[search].begin(), v[search].end(), last) - v[search].begin();
			if (index >= v[search].size()) {
				flag = false;
				break;
			}
			else {
				last = v[search][index];
			}
		}
		if (flag)cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 512
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)	

int max(int a, int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


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

	ll sum = 100;
	ll cnt = 0;
	while (sum < x) {
		sum += sum * 0.01;
		cnt++;
	}

	cout << cnt << endl;
} 

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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define REREP(i,n) for(int i=int(n-1); i>=0; i--)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define Cout(str) cout << str << endl

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

	if(S[0] != 'A'){
		Cout("WA");
		return 0;
	}
	if('A' <= S[1] && S[1] <= 'Z'){
		Cout("WA");
		return 0;
	}
	sum = 0;
	FOR(i, 2, S.length()-1){
		if('a' <= S[i] &&  S[i] <= 'z') sum += 1;
		else if(S[i] == 'C') sum += 100;
		else sum += 1000;
	}
	if(sum/100 == 1 && 'a' <= S[S.length()-1] && S[S.length()-1] <= 'z') Cout("AC");
	else Cout("WA");

	return 0;
} 

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

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; }

using pll = pair<long long, long long>;
int N, Q;
vector<long long> A;
vector<long long> sum, evensum;

vector<long long> ths, vals;

int main() {
    while (cin >> N >> Q) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        reverse(A.begin(), A.end());
        
        sum.assign(N+1, 0); evensum.assign(N+1, 0);
        for (int i = 0; i < N; ++i) {
            sum[i+1] = sum[i] + A[i];
            evensum[i+1] = evensum[i] + (i % 2 == 0 ? A[i] : 0);
        }
        
        ths.clear(); vals.clear();
        for (int i = 0; i < (N-1)/2; ++i) {
            long long th = (A[i+1] + A[i*2+2])/2 + 1;
            long long val = (sum[i+1] - sum[0]) + (evensum[N] - evensum[i*2+2]);
            ths.push_back(th); vals.push_back(val);
        }
        reverse(ths.begin(), ths.end());
        reverse(vals.begin(), vals.end());
        for (int _ = 0; _ < Q; ++_) {
            long long x; cin >> x;
            int it = upper_bound(ths.begin(), ths.end(), x) - ths.begin();
            if (it == 0) cout << sum[(N+1)/2] - sum[0] << endl;
            else cout << vals[it-1] << endl;
        }
    }
}















Measured memory_bytes: 5108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T>
inline bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

int main(){
    string s;
    cin >> s;
    int n = s.size();
    string t=s;
    reverse(t.begin(), t.end());
    if (s!=t){
        cout << "No" << endl;
        return 0;
    }
    string a = s.substr(0, (n - 1) / 2);
    string b =a;
    reverse(b.begin(), b.end());
    if (a!=b){
        cout << "No" << endl;
        return 0;
    }
    string c = s.substr((n + 3) / 2 - 1);
    string d = c;
    reverse(d.begin(), d.end());
    if (c!=d){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <cstring>
using namespace std;
int main(){
  char S[200];
  cin>>S;
  int len=strlen(S);
  while(1){
    for(int i=0;i<len/2;i++){
      if(i==len/2-1){printf("%d\n",len-2);return 0;}
      if(S[i]!=S[len/2-1+i]){len=len-2;break;}
    }
  }
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        JSushi solver = new JSushi();
        solver.solve(1, in, out);
        out.close();
    }

    static class JSushi {
        int BASE;

        private int digit(int dim) {
            if (dim == 1) {
                return 1;
            }
            if (dim == 2) {
                return BASE;
            }
            if (dim == 3) {
                return BASE * BASE;
            }
            throw new RuntimeException("bad dim");
        }

        private int inc(int state, int dim) {
            return state + digit(dim);
        }

        private int dec(int state, int dim) {
            return state - digit(dim);
        }

        private int prev(int state, int dim) {
            if (get(state, dim) == 0) {
                return 0;
            }
            state = dec(state, dim);
            if (dim > 1) {
                state = inc(state, dim - 1);
            }
            return state;
        }

        private int get(int state, int dim) {
            int shifted = state / digit(dim);
            return shifted % BASE;
        }

        private int sum(int state) {
            return get(state, 1) + get(state, 2) + get(state, 3);
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            BASE = N + 1;
            int target = 0;
            for (int i = 0; i < N; i++) {
                int a = in.nextInt();
                target = inc(target, a);
            }
            double[] E = new double[BASE * BASE * BASE];
            E[0] = 0;
            for (int state = 1; state <= target; state++) {
                E[state] = N;
                for (int dim = 1; dim <= 3; dim++) {
                    E[state] += get(state, dim) * E[prev(state, dim)];
                }
                E[state] /= sum(state);
            }
            out.println(E[target]);
        }

    }
}



Measured memory_bytes: 239188
using System;
using System.Linq;

namespace AtcoderProblem
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int len = S.Length - 1;
            string last = S.Substring(len);
            string answer;
            if (last == "s") answer = S + "es";
            else answer = S + "s";

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 25876
n = gets.to_i
a = gets.split.map(&:to_i).sort
b = gets.split.map(&:to_i).sort
c = gets.split.map(&:to_i).sort
ans = 0

b.each do |be|
  a_tmp = a.bsearch_index {|ae| be <= ae }
  c_tmp = c.bsearch_index {|ce| be < ce }
  a_tmp = n if a_tmp.nil?

  if !c_tmp.nil?
    ans += a_tmp * (n - c_tmp)
  end
end

puts ans

Measured memory_bytes: 24680
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [list(input().split()) for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    from math import gcd
    from functools import reduce
    k=int(input())
    res=0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                res+=reduce(gcd,[i,j,l])
    print(res)


if __name__ == '__main__':
    main()



Measured memory_bytes: 69156
from collections import defaultdict
n,m,x = map(int, input().split()) 
# b = list(map(int, input().split()))
# n = int(input())
# a = [int(input()) for _ in range(n)]
ca =[]
for i in range(n):
    ca.append(list(map(int, input().split())))


ans = 10**9
for i in range(1 << n):
    abil = [0]*m
    val = 0
    for j in range(n):
        if ((i >> j) & 1):
            val += ca[j][0]
            for k in range(m):
                abil[k] += ca[j][k+1]
    if min(abil) >=  x:
        if val < ans:
            ans = val
if ans == 10**9:
    print(-1)
else:
    print(ans)
 

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

void solve() {

}

bool bad(vector<ll> &vec) {
  if( vec[(int)vec.size()-1] == 0 ) return true;
  if( vec[0] != 0 ) return true;
  return false;
}

bool debug = 0;

ll solve(int n, vector<ll> &A) {
  vector<ll> pow2;
  pow2.pb(1);
  rep(_,51) {
    pow2.pb(pow2.back()*2LL);
  }

  vector<ll> build(n);
  for(int i=n-1;i>=0;--i) {
    if( i == n-1 ) {
      build[i] = A[i];
    } else {
      build[i] = build[i+1] + A[i];
    }
  }
  vector<ll> tsui(n);
  rep(i,n) {
    tsui[i] = build[i] - A[i];
  }
  
  
  ll ans = 1;
  ll yoyu = 2;
  REP(i,1,n) {
    if( debug ) {
      cout << "* " << i << "-th: A[" << i << "] = " << A[i] << endl;
    }
    yoyu -= A[i];
    if( yoyu < 0 ) return -1LL;
    ans += A[i];
    ll cost = min(tsui[i],yoyu);
    ans += cost;
    yoyu = yoyu * 2LL;
    if( yoyu >= pow2.back() ) yoyu = pow2.back();
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  
  ++n;
  vector<ll> vec(n);
  rep(i,n) cin >> vec[i];
  if( n == 1 ) {
    if( vec[0] == 1LL ) {
      puts("1");
    } else {
      puts("-1");
    }
    return 0;
  }

  
  if( bad(vec) ) {
    puts("-1");
    return 0;
  }
  ll ans = solve(n,vec);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5636
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
        t: String,
    }
    if let None = s.find('?') {
        if s.contains(&t) {
            println!("{}", s);
        } else {
            println!("UNRESTORABLE");
        }
        return;
    }
    let s = s.chars().collect::<Vec<_>>();
    let t = t.chars().collect::<Vec<_>>();
    let n = s.len();
    let m = t.len();
    if m > n {
        println!("UNRESTORABLE");
        return;
    }
    'outer: for i in (0..n - m + 1).rev() {
        for j in 0..m {
            if s[i + j] != '?' && s[i + j] != t[j] {
                continue 'outer;
            }
        }
        for k in 0..n {
            if i <= k && k < i + m {
                print!("{}", t[k - i]);
            } else if s[k] == '?' {
                print!("a");
            } else {
                print!("{}", s[k]);
            }
        }
        println!("");
        return;
    }
    println!("UNRESTORABLE");
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double n,x,t;
	cin>>n>>x>>t;
	cout<<fixed<<setprecision(0)<<ceil(n/x)*t<<endl;
	return 0;
}


Measured memory_bytes: 3760
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double d;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    vector<int>v{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<v[k-1];
    return 0;
}


Measured memory_bytes: 256
use std::fmt::Debug;
use std::io::{self, Read};
use std::str;
use std::str::FromStr;

fn main() {
    let mut sc = StdinScanner::new();
    let n = sc.next();
    println!("{}", solve(sc.vec(n)));
}


fn solve(s: Vec<u32>) -> u32 {
    let sum = s.iter().sum::<u32>();
    let min_multiple_of_10 = s.iter().filter(|&n| n % 10 != 0).map(|&n| n).min();
    if sum % 10 == 0 {
        if let Some(min_multiple_of_10) = min_multiple_of_10 {
            sum - min_multiple_of_10
        } else {
            0
        }
    } else {
        sum
    }
}


#[test]
fn test1() {
    assert_eq!(25, solve(vec![5, 10, 15]));
    assert_eq!(0, solve(vec![10, 20, 30]));
}


struct StdinScanner {
    buf: Vec<u8>,
}

impl StdinScanner {
    fn new() -> Self {
        StdinScanner { buf: Vec::with_capacity(256) }
    }

    fn next<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let stdin = io::stdin();
        let mut stdin = stdin.lock().bytes();
        let mut c = stdin.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = stdin.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = stdin.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.next()).collect()
    }
}


Measured memory_bytes: 4352
n, x = map(int, input().split())

a = list(map(int, input().split()))


state = 0

ans = 0

for i in range(n-1):
    if a[i] + a[i+1] > x:
        if a[i] > x:
            ans += a[i] - x
            a[i] = x
        ans += a[i] + a[i+1] - x
        a[i+1] = x - a[i]

print(ans)


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

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define _shv(v) for (auto _t1 : v) cerr << _t1 << " "; cerr << endl;
#define dg(x) cerr << #x << ": " << (x) << endl;
#define dgv(v) cerr << #v << ": "; _shv(v);
#define dgm(m) cerr << #m << ":" << endl; for (auto _t2 : m) { _shv(_t2); }

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

template<typename T> inline void pt(T x) { cout << x << endl; }
template<typename T> inline void inv(T& v) { for (auto& t : v) cin >> t; }
template<typename T> inline int siz(T& x) { return x.size(); }
template<typename T> inline ll pow2(T n) { return 1ll << n; }
template<typename T, typename U> inline int bit(T x, U n) { return x >> n & 1; }
template<typename T, typename U>
inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }


int calc(vvi& dp, vvi& g, int b, int e) {
    if (dp[b][e] != -2) return dp[b][e];
    int v = siz(g);
    vi t;
    rep(i, v) if (!bit(b, i)) t.pb(i);
    if (siz(t) == 1) {
        if (e == 0) return dp[b][e] = 0;
        else return dp[b][e] = -1;
    } else if (siz(t) < v) {
        if (e == 0) return dp[b][e] = -1;
    }
    dp[b][e] = INF;
    for (auto t1 : t) {
        if (t1 == e) continue;
        if (calc(dp, g, b | ((e != 0) << e), t1) >= 0 && g[t1][e] >= 0)
            umin(dp[b][e], calc(dp, g, b | ((e != 0) << e), t1) + g[t1][e]);
    }
    if (dp[b][e] == INF) dp[b][e] = -1;
    return dp[b][e];
}

int main() {
    int v, e; cin >> v >> e;
    vvi g(v, vi(v, -1));
    rep(i, e) {
        int s, t, d;
        cin >> s >> t >> d;
        g[s][t] = d;
    }
    vvi dp(pow2(v), vi(v, -2));

    pt(calc(dp, g, 0, 0));

    return 0;
}



Measured memory_bytes: 6288
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
using ll = long long;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
int a[3][3];
int b[20];
bool c[3][3];

int main(void) {
  rep(i,3)rep(j,3){
    cin >> a[i][j];
    c[i][j] = false;
  }
  int n;
  cin >> n;
  rep(i,n) cin >> b[i];
  rep(i,3){
    rep(j,3){
      rep(k,n){
        if(a[i][j] == b[k]) c[i][j] = true;
      }
    }
  }
  bool res = false;
  rep(i,3){
    if(c[i][0] && c[i][1] && c[i][2]) res = true;
    if(c[0][i] && c[1][i] && c[2][i]) res = true;
  }
  if(c[0][0] && c[1][1] && c[2][2]) res = true;
  if(c[0][2] && c[1][1] && c[2][0]) res = true;
  if(res) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main() {

    int a,b,c;

    cin >> a >> b >> c;

    for(int i=1; i<=max(b,c); i++){
        if((a*i)%b == c){
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>

#define LOWBIT( _x) ( (_x) & (-_x) )

using namespace std;

typedef pair<int ,int > pii;
typedef pair<int ,pii > pipii;
typedef vector<pipii > :: iterator vpipiii;
vector<pipii> L;
vector<int> U;

const int maxn = 100000 + 5;

int n;
int bit[ maxn << 1 ];
int l[ maxn ] , r[ maxn ] , f[ maxn ];

void insert(int p, int v)
{
	for (; p <= U.size() ; p += LOWBIT( p ) )
		bit[p] = max(bit[p] , v);
}

int query(int p)
{
	int ret = 0;
	for (; p ; p-= LOWBIT( p ) )
		ret = max(ret , bit[p]);
	return ret;
}

int main()
{
	int t1 , t2;
	scanf("%d",&n);
	for (int i = 0 ; i < n ; i++)
		scanf("%d%d%d%d", &t1, &t2, &l[i], &r[i]),
		L.push_back( pipii( t1 , pii( 0 , i ) ) ),
		L.push_back( pipii( t2 , pii( 1 , i ) ) ),
		U.push_back( l[i] ),
		U.push_back( r[i] );
	sort( U.begin() , U.end() );
	sort( L.begin() , L.end() );
	for (int i = 0 ; i < U.size() ; i++)
	{
		int id = L[i].second.second , flag = L[i].second.first;
		if ( flag )
		{
			insert( lower_bound( U.begin() , U.end() , r[id] ) - U.begin() + 1 , f[id]);
		}else
			f[id] = query( lower_bound( U.begin() , U.end() , l[id] ) - U.begin() + 1 ) + 1;
	}
	printf("%d\n", *max_element(&f[0] , &f[n]) );
	return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(20);
  int k,a,b;
  cin >> k >> a >> b;
  bool flag = false;
  for(int i=a;i<=b;i++) {
    if(i%k==0)
    {
        flag = true;
        break;
    }
  }
  if(flag)
    cout << "OK\n";
  else
    cout << "NG\n";
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;

  if (e - a > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256