akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

void solve(int h,int w){
	int in;
	int ans=0;
	vvb vv(h+2,(vb(w+2,false)));
	rep(i,h){
		rep(j,w){
			cin>>in;
			vv[i+1][j+1]=(in==1);
		}
	}
	rep(i,h){
		rep(j,w){
			if(vv[i+1][j+1]){
				stack<pll> stk;
				stk.push(pll(i+1,j+1));
				while(!stk.empty()){
					int x,y;
					tie(x,y)=stk.top();stk.pop();
					vv[x][y]=false;
					rep(k,8){
						if(vv[x+dx[k]][y+dy[k]])stk.push(pll(x+dx[k],y+dy[k]));
					}
				}
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w,h;
	while(cin>>h>>w,h){
		solve(w,h);
	}
}



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

using namespace std;

#define pb push_back

typedef long long ll;

int n, i, j;
int m;
vector<int> adj[100002];
int dp[100002];

int dfs(int v){
    int &ans = dp[v];
    if(ans == -1){
        ans = 0;
        for(int x : adj[v])
            ans = max(ans, 1+dfs(x));
    }
    return ans;
}

int main(){
    memset(dp, -1, sizeof dp);
    scanf("%d %d",&n, &m);
    for(i=0;i<m;++i){
        int a, b;
        scanf("%d %d", &a ,&b);
        adj[a].pb(b);
    }
    int ans = 0;
    for(i=1;i<=n;++i){
        ans = max(ans, dfs(i));
    }
    printf("%d\n", ans);
    return 0;
}







Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, m; cin >> n >> m;
    VI s(n), t(m); cin >> s >> t;

    auto dp = vec<ll>(n + 1, m + 1);
    eFOR(i, 0, n)dp[i][0] = 1;
    eFOR(j, 0, m)dp[0][j] = 1;

    FOR(i, 0, n)FOR(j, 0, m) {
        if (s[i] == t[j])(dp[i + 1][j + 1] += dp[i][j]) %= mod;
        (dp[i + 1][j + 1] += dp[i + 1][j]) %= mod;
        (dp[i + 1][j + 1] += dp[i][j + 1]) %= mod;
        (dp[i + 1][j + 1] -= dp[i][j] - mod) %= mod;
    }
    cout << dp[n][m] << "\n";
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
#define v(T) vector<T>
#define vv(T) vector<v(T)>
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main()
{
    int n;
    cin >> n;
    ll d= 1e9;
    vll a(n);
    vvll c(20, vll(20, 0));
    rep(i, n){
        long double x;
        cin >> x;
        a[i] = x*d + 0.5;
    }
    for (auto x : a){
        int i = 0, j = 0;
        while (x%2 == 0 && i < 19){
            i++;
            x /= 2;
        }
        while (x%5 == 0 && j < 19){
            j++;
            x/=5;
        }
        c[i][j]++;
    }
    ll ans = 0;
    rep(i, 20) rep(j, 20){
        rep(k, 20) rep(l, 20){
            if (i+k < 18 or j + l < 18) continue;
            ans += c[i][j]*c[k][l];
            if (i==k and j==l) ans -= c[i][j];
        }
    }
    ans /= 2;
    cout << ans << endl;
}

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

int main(){
    std::vector< std::vector< int > > A(3, std::vector< int >(3));
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            std::cin >> A[i][j];
        }
    }
    int N;
    std::cin >> N;
    std::vector< int > B(N);
    for(int i=0; i<N; i++){
        std::cin >> B[i];
    }
    
    std::vector< std::vector< bool > > exist(3, std::vector< bool >(3));
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            exist[i][j] = false;
        }
    }
    
    for(int bc=0; bc<N; bc++){
        for(int aic=0; aic<3; aic++){
            for(int ajc=0; ajc<3; ajc++){
                if(B[bc] == A[aic][ajc]){ exist[aic][ajc] = true; }
            }
        }
    }
    
    bool bingo = false;
    for(int i=0; i<3; i++){
        if(exist[i][0] && exist[i][1] && exist[i][2]){ bingo = true; }
        if(exist[0][i] && exist[1][i] && exist[2][i]){ bingo = true; }
    }
    if(exist[0][0] && exist[1][1] && exist[2][2]){ bingo = true; }
    if(exist[2][0] && exist[1][1] && exist[0][2]){ bingo = true; }

    if(bingo){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{

  int count=0,i;
  char a[1200];
  while(1)
  {
    scanf("%c",&a[count]);
    if(a[count]=='\n') break;
    count++;
  }
  for(i=0;i<count;i++)
  {
    if('a'<=a[i]&&a[i]<='z') a[i]=a[i]-32;
    else if('A'<=a[i]&&a[i]<='Z') a[i]+=32;
    printf("%c",a[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i+=2)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
 string s;
  ll n,m,k,x=LLONG_MAX,y=0,c=0,q,ans=0;
  cin>>n;

  ll a[5];
for(ll j=0;j<5;j++)
{
  cin>>a[j];
}
for (ll i = 0; i < 5; ++i)
{
 x = min(x,a[i]);
}
y = (n+x-1)/x;
c = 5LL + (y-1);
c(c);
}

signed main(){
  
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


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

using namespace std;

string x;
int main() {
  cin >> x;
  int s_c = 0;
  int t_c = 0;
  for(int i = 0; i < x.length(); i++) {
    if(s_c > t_c && x[i] == 'T')t_c++;
    if(x[i] == 'S')s_c++;
  }
  cout << x.length() - min(s_c,t_c) * 2 <<endl;
}
    
  


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P& p) const {
        return b < p.b;
    }
    int a, b;
};

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

    int n, m;
    cin >> n >> m;

    vector<P> p(m);
    for (int i = 0; i < m; i++) {
        cin >> p[i].a >> p[i].b;
    }

    sort(p.begin(), p.end());

    int r = 0, c = -1;
    for (int i = 0; i < m; i++) {
        if (p[i].a >= c) {
            r++;
            c = p[i].b;
        }
    }

    cout << r << endl;

    return 0;
}

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

using namespace std;

int N, A, B;

int main() {
    cin >> N >> A >> B;
    
    long long ans = (long long)N - 2;
    ans = ans * (B - A) + 1;
    if(ans < 0) ans = 0;
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#define mp make_pair
#define fi first
#define se second
using namespace std;
pair <long long, int> a[1000006];
pair <int, int> edge[1000006];
int sze[1000006];
int main(){
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++ i){
		scanf("%lld", &a[i].fi);
		a[i].se = i;
	}
	sort(a + 1, a + 1 + n);
	int m = 0;
	long long sum = 0;
	for (int i = n; i >= 2; -- i){
		sum += ++ sze[i];
		long long d = a[i].fi - n + 2 * sze[i];
		int index = lower_bound(a + 1, a + 1 + n, mp(d, 0)) - a;
		if (a[index].fi != d || index >= i){
			cout << -1 << endl;
			return 0;
		}
		edge[++ m] = mp(a[index].se, a[i].se);
		sze[index] += sze[i];
	}
	if (a[1].fi != sum){
		cout << -1 << endl;
		return 0;
	}
	for (int i = 1; i <= m; ++ i)
		printf("%d %d\n", edge[i].fi, edge[i].se);
	return 0;
}
/*
7
9
14
12
17
10
13
18
*/


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

int main(){
  int N; cin >> N;
  vi a(N);
  rep(i,N) cin >> a[i];
  int count = 0;
  int cur = 1;
  
  rep(i,N){
    if(a[i]==1) break;
    if (i == N-1) { cout << -1 << endl; return 0;}
  }
  
  rep2(i,0,N){
    if(a[i] == cur){cur++; continue;}
    else count++;
  }
  
  cout << count <<endl;
  return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N;
  cin >> N;
  int ans = 0;
  FOR(n,1,N+1) {
    if(n<10 || (n >= 100 && n < 1000) || (n >= 10000 && n < 100000)) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
def kton(S):
    r = 0
    m = 0
    for s in S:
        r += 1 if s == '(' else -1
        m = min(m, r)
    return r, m
        
def main():
    N = int(input())
    RM = [kton(input()) for _ in range(N)]
    pos = 0
    negp = []
    negn = []
    posn = []
    for r, m in RM:
        if m < 0:
            if r >= 0:
                negp.append((-m, r))
            else:
                negn.append((-(r-m), -r, m))
        else:
            pos += r
 
    negp.sort()
    for m, r in negp:
        if pos - m < 0:
            return False
        pos += r
    negn.sort()
    for _, r, m in negn:
        if pos + m < 0:
            return False
        pos -= r
    return pos == 0
 
print('Yes' if main() else 'No')

Measured memory_bytes: 116136
# frozen_string_literal: true

N = gets.chomp.to_i
PATTERN = 26
ALPHABET = ('a'..'z').to_a

def fuga(digit)
  return 0 if digit.zero?

  PATTERN**digit + fuga(digit - 1)
end

def count_digit
  num = 1
  loop do
    break if N - fuga(num) <= 0

    num += 1
  end
  num
end

num = N - fuga(count_digit - 1) - 1

ans = count_digit.times.map do
  r = num % 26
  num /= 26
  ALPHABET[r]
end

puts ans.reverse.join


Measured memory_bytes: 14316
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

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

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod  100000007
#define pii pair<int, int>
#define PI 2*acos(0.0)
#define forn(i, n) for(int i = 0; i < n; i++)

const ll INF = 1e12;

int main()
{
    io;
    int n, w;
    cin>>n>>w;
    int val[n], wgt[n];
    ll sum = 0;
    for(int i = 0; i<n ;i++)
    {
        cin>>wgt[i] >> val[i];
        sum += val[i];
    }
    vll dp(sum+5, INF);
    dp[0] = 0;
    for(int i = 0; i< n;i++)
    {
        for(int j = sum- val[i]; j>= 0; j--)
            dp[j+val[i]] = min(dp[j+val[i]] , dp[j]+wgt[i]);
    }
    int ans = 0;
    for(int i = 0; i <= sum; i++)
    {
        if(dp[i] <= w)
            ans = max(ans,i);
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 1024
import sys
import heapq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10**20
N, M = map(int, input().split())
G = [[]for i in range(N)]
for i in range(1, N):
    G[i].append([i-1, 0])

for i in range(M):
    L, R, C = map(int, input().split())
    G[L-1].append([R-1, C])

S = 0

def dijkstra(N, S):
    d = [INF for i in range(N)]

    que = []
    d[S] = 0
    heapq.heappush(que, [0, S])

    while not(len(que) == 0):
        q = heapq.heappop(que)
        ver = q[1] # ノード
        dis = q[0] # 過去に更新された最短距離

        # vまで2番目に短い距離（最新）　＜　過去最短距離　の時、
        # キューから取り出した過去のものを無視する
        if d[ver] < dis:
            continue

        # 隣接リストに対してループ
        for i in range(len(G[ver])):
            e = G[ver][i]
            if d[e[0]] > d[ver] + e[1]:
                d[e[0]] = d[ver] + e[1]
                heapq.heappush(que, [d[e[0]], e[0]])

    return d[N-1]

ans = dijkstra(N, S)
if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 91568
#include <stdio.h>
#include <stdint.h>

#ifdef DEBUG
#define DEBUG_LOG(fmt, ...)   printf(fmt, ##__VA_ARGS__)
#else
#define DEBUG_LOG(fmt, ...)
#endif

using namespace std;
int main()
{
    uint32_t N, X, Nd;
    scanf(" %u", &N);
    X = N / 1.08;
    Nd = X * 1.08;
    do {
        if (Nd == N) {
            printf("%d\n", X);
            return 0;
        }
        X++;
        Nd = X * 1.08;
    } while (Nd <= N);
    printf(":(\n");
    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) v[i] = i+1;
    for (int i = 0; i < n; i++) {
        cout << v[i];
        if (i==n-1) cout <<endl;
        else cout << " ";
    }
    while (next_permutation(v.begin(), v.end())) {
        for (int i = 0; i < n; i++) {
            cout << v[i];
            if (i!=n-1) cout << " ";
            else cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <map>
#include <complex>
using namespace std;
typedef complex<double> P;

int col[1000] , row[1000] , val[1000][1000];

typedef unsigned int uint;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}

int main(){
	int H,W;
	cin >> H >> W;
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){	
			int t = in();
			col[i] += t;
			row[j] += t;
			val[i][j] = t;
		}	
	}
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			printf("%d%c",(col[i]+row[j]+val[i][j]+1)%2,(char)(j == W-1 ? 10 : 32 ));
		}
	}
}

Measured memory_bytes: 4784
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

    public class Program
    {
        public static void Main(string[] args)
        {
            new A().test();
        }
    }

	public class A
	{
		public void test()
		{
			// 普通の文字列
			var intList = CommonRead.ReadIntL();

			Console.WriteLine(intList[0] * intList[1]);
		}
	}


static class CommonRead
{
    public static string ReadStr()
    {
        return Console.ReadLine();
    }
    public static string[] ReadStrA()
    {
        return ReadStr().Split(' ');
    }
    public static List<string> ReadStrL()
    {
        return ReadStrA().ToList();
    }
    public static int ReadInt()
    {
        return Convert.ToInt32(ReadStr());
    }
    public static int[] ReadIntA()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray();
    }
    public static List<int> ReadIntL()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToList();
    }
    public static long ReadLong()
    {
        return Convert.ToInt64(ReadStr());
    }
    public static long[] ReadLongA()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray();
    }
    public static List<long> ReadLongL()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToList();
    }

    public static decimal ReadDecimal()
    {
        return Convert.ToDecimal(ReadStr());
    }
    public static decimal[] ReadDecimalA()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray();
    }
    public static List<decimal> ReadDecimalL()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList();
    }

    public static double ReadDouble()
    {
        return Convert.ToDouble(ReadStr());
    }
    public static double[] ReadDoubleA()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray();
    }
    public static List<double> ReadDoubleL()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToList();
    }

}


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

using namespace std;


#ifdef CLION

ifstream ifs("/home/kyuridenamida/CLionProjects/untitled4/input.txt");
#define cin ifs
#define scanf DONT_USE_SCANF
#endif

typedef long long ll;

int AB = 0;
int AC = 1;
int BC = 2;
bool dp[3][8001];

void build(string a, string b, int dpk) {
    for (int i = -4000; i <= 4000; i++) {
        bool ok = true;
        for (int j = 0; j < b.size(); j++) {
            if (i + j < 0 || i + j >= a.size() || (b[j] == '?' || a[i + j] == '?') || b[j] == a[i + j]) {

            } else {
                ok = false;
            }
        }
        dp[dpk][i + 4000] = ok;
    }
}

int main() {

    string a;
    string b;
    string c;
    cin >> a >> b >> c;
    build(a, b, AB);
    build(a, c, AC);
    build(b, c, BC);

    int ll = a.size() + b.size() + c.size();
    for (int i = -4000; i <= 4000; i++) {
        for (int j = -4000; j <= 4000; j++) {
            if (abs(i - j) <= 4000 && dp[AB][i + 4000] && dp[AC][j + 4000] && dp[BC][j - i + 4000]) {
                int s = max<int>({(int) a.size(), i + (int) b.size(), j + (int) c.size()}) -
                        min<int>({0, i, j});
                ll = min(ll, s);
            }
        }
    }
    cout << ll << endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;
using Edges = vector<pair<int, int>>;
using Graph = vector<Edges>;
const long long INF = (1LL << 60);

bool warshall_floyd(vector<vector<LL>> &dist) {
    int n = dist.size();
    rep(k, n) rep(i, n) if (dist[i][k] != INF) {
        rep(j, n) if (dist[k][j] != INF) {
            dist[i][j]= min(dist[i][j] , dist[i][k] + dist[k][j]);
            if (j == k and dist[j][k] < 0) return false;
        }
    }
    return true;
}


int main() {
    int n, m; cin >> n >> m;

    vector<int> a(m, 0), b(m, 0), c(m, 0);
    vector<vector<LL>> dist(n, vector<LL>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dist[i][j] = INF;
        }
        dist[i][i] = 0; // ここがポイント
    }
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        --a[i]; --b[i];
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];

    }

    warshall_floyd(dist);

    int ans = 0;
    for (int i = 0; i < m; i++) {
        bool ok = false;
        for (int p = 0; p < n; p++) {
            for (int q = 0; q < n; q++) {
                if (dist[p][q] == dist[p][a[i]] + c[i] + dist[b[i]][q]) {
                    ok = true;
                }
            }
        }
        if (!ok) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll n, m;
    cin >> n >> m;

    ll p[m];
    string s[m];
    rep(i, m) { cin >> p[i] >> s[i]; }

    map<ll, ll> m_num;
    map<ll, bool> m_bool;

    rep(i, m) {
        if (m_bool.find(p[i]) == m_bool.end()) {
            if (s[i] == "AC") {
                m_bool.insert(make_pair(p[i], true));
                m_num.insert(make_pair(p[i], 0));
            } else {
                m_bool.insert(make_pair(p[i], false));
                m_num.insert(make_pair(p[i], 1));
            }
        } else {
            if (s[i] == "AC") {
                m_bool[p[i]] = true;
            } else {
                if (!m_bool[p[i]]) {
                    m_num[p[i]]++;
                }
            }
        }
    }

    ll ac = 0, pe = 0;
    for (auto iter = m_bool.begin(); iter != m_bool.end(); iter++) {
        ll num = iter->first;
        if (m_bool[num]) {
            ac++;
            pe += m_num[num];
        }
    }
    cout << ac << " " << pe << endl;

    return 0;
}



Measured memory_bytes: 18944
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
     
      	int a[] = new int[N];
      
      	for(int i=0; i<N; i++){
      		a[i] = sc.nextInt();
      	}
       
      	Arrays.sort(a);
      
      	for(int j=0; j<N-1; j++){
      	if(a[j]==a[j+1]){
           System.out.println("NO");
        	return;
      	}
      	}
      	   System.out.println("YES");
    }
}

Measured memory_bytes: 64648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y))

int main(void)
{
	double v;
	while(scanf("%lf",&v) != EOF)
	{
		printf("%d\n",(int)(v*v/98.0)+2);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int a, b, k;

  cin >> a >> b >> k;
  int i;
  for (i = a; i < min(a + k, b + 1); ++i) {
    cout << i << endl;
  }
  for (i = max(b - k + 1, i); i <= b; ++i) {
    cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
map<string,int>f;

int dr[4]={1,1,1,0};
int dc[4]={-1,0,1,1};

string cmp(string s){
   string ans(20,'0');
   int cnt=0;
   for(int i=0;i<20;i++){
      while(i<20 && s[i]=='0')i++;
      if(i<20)ans[cnt++]=s[i];
   }
   return ans;
}
int solve(string s){
   if(f.count(s)!=0) return f[s];
   int ans=-1;
   int cnt=0;
   bool fnd=false;
   for(int i=0;i<5;i++){
      for(int j=0;j<4;j++){
         if(s[i*4+j]=='0')break;
         cnt++;
         for(int x=0;x<4;x++){
            int nr=i+dr[x];
            int nc=j+dc[x];
            if(0<=nr && nr<5)
            if(0<=nc && nc<4)
            if(s[i*4+j]==s[nr*4+nc]){
               fnd=true;
               string t=s;
               t[i*4+j]='0';               
               t[nr*4+nc]='0';
               int bet=solve(cmp(t));
               if(ans==-1 || bet<ans)
                  ans=bet;
            }
         }
      }
   }
   if(fnd)f[s]=ans;
   else f[s]=cnt;
   
   return f[s];
}
int main(){
//   freopen("data.in","r",stdin);
   int t,v;
   scanf("%d",&t);
   while(t--){
      string s;
      for(int i=0;i<5;i++){
         for(int j=0;j<4;j++){
            scanf("%d",&v);
            s+=string(1,'0'+v);
         }
      }
      int ans=solve(s);
      printf("%d\n",ans);
   }
   return 0;
}

Measured memory_bytes: 1656
W, H, N = map(int,input().split())
points = [list(map(int,input().split())) for _ in range(N)]
width = list(range(1, W + 2))
height = list(range(1, H + 2))

a = len(width)
b = len(height)

for i in range(N):
    if points[i][2] == 1:
        for j in range(a):
            if width[j] < points[i][0] + 1:
                width[j] = 0
    if points[i][2] == 2:
        for j in range(a):
            if width[j] > points[i][0] + 1:
                width[j] = 0
    if points[i][2] == 3:
        for j in range(b):
            if height[j] < points[i][1] + 1:
                height[j] = 0
    if points[i][2] == 4:
        for j in range(b):
            if height[j] > points[i][1] + 1:
                height[j] = 0

c = width.count(0)
d = height.count(0)

for i in range(c):
    width.remove(0)
for i in range(d):
    height.remove(0)
if width != []:
    s = max(width)
    t = min(width)
else:
    s, t = 0, 0
if height != []:
    x = max(height)
    y = min(height)
else:
    x, y = 0, 0
ans = (s-t) * (x-y)
print(ans)

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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(iii,n){cout<<x[iii]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

typedef pair<li, li> PI;


li a[101010];

int main() {
	li n, l;
	cin >> n >> l;
	rin{cin >> a[i];}

	rep(i, n - 1) {
		if (a[i] + a[i + 1] >= l) {
			puts("Possible");
			li now = i + 1;
			rep(j, now - 1)cout << j + 1 << endl;
			for (li j = n - 1; j > now; j--)cout << j << endl;
			cout << now << endl;
			return 0;
		}
	}
	puts("Impossible");


	return 0;
}

Measured memory_bytes: 1536
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

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

	cin >> N >> M;
	while (N) {
		vector<int>v(M + 1);
		for (int i = 0; i < N; i++) {
			cin >> L >> R;
			v[L] = max(v[L], (int)R);
		}
		cout << accumulate(v.begin(), v.end(),0) << endl;
		cin >> N >> M;
	}
	return 0;
}


Measured memory_bytes: 3104
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto x = lread();
    long ans;
    foreach (p; 2 .. 11)
    {
        foreach (b; 1 .. 1001)
        {
            if (b ^^ p <= x)
            {
                ans = max(ans, b ^^ p);
            }
        }
    }
    writeln(ans);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int a,b;
    string s;
    cin >> a >> b >> s;
    bool ok=true;
    rep(i,s.size()){
        if(s[a]!='-')ok=false;
        if(i!=a and !(s[i]>='0' and s[i]<='9'))ok=false;
    }
    
    cout << (ok?"Yes":"No");
    
	return 0;
}

Measured memory_bytes: 3628
import java.util.*;
public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int x = sc.nextInt();
	int[] l = new int[n+1];

	for(int i = 0; i < n; i++) {
	    l[i] = sc.nextInt();
	}

	int d1 = 0;
	int di = d1;
	
	
	for(int i = 1; i <= n+1; i++) {
	    if(di > x) {
		System.out.println(i-1);
		break;
	    }
	    if(i == n+1){
		System.out.println(i);
		break;
	    }
	    di += l[i-1];
	    
	}
	


    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

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

    if((b-a)==(c-b)){
        cout<<"YES"<<endl;
    }else{
    cout<<"NO"<<endl;
    }

    return 0;
}


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

#define lli long long int
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define INF 1000000007
#define endl "\n"

lli nn,a,dp[100005],k;
vector<lli> v;

lli dfs(int n){
	lli minn;
	if(dp[n]!=-1){
		return dp[n];
	}
	if(n==nn-1){
		return 0;
	}
	for(int i=1;i<=k;i++){
		if(n+i<nn)
			minn=min(abs(v[n]-v[n+i]) + dfs(n+i),minn);
	}
	return dp[n] = minn;
}

int main(){
	memset(dp,-1,sizeof(dp));
	cin>>nn>>k;
	for (int i = 0; i < nn; i++)
	{
		cin>>a;
		v.pb(a);
	}
	cout<<dfs(0);
	//system("pause");
}

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

int main() {
	int N;
	double x,r=0;
	string u;
	cin >> N;

	rep(i,N) {
		cin >> x >> u;
		if(u == "JPY")
			r += x;
		else
			r += x * 380000;
	}

	cout << r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

struct Tag {
    int pos, used, cost;

    Tag() {}
    Tag(int p, int u, int c) : pos(p), used(u), cost(c) {}

    bool operator < (const Tag &other) const {
        if(cost != other.cost) return cost > other.cost;
        return used > other.used;
    }
};


int main() {
    ios::sync_with_stdio(0);
    while(true) {
        int N, M, C;
        cin >> N >> M >> C;
        if(!N && !M && !C) break;

        vector<vector<pair<int,int> > > v(N);
        for(int i = 0; i < M; ++i) {
            int f, t, c;
            cin >> f >> t >> c;
            --f; --t;
            v[f].push_back(make_pair(t, c));
        }

        int ans = INT_MAX;
        vector<vector<int> > dp(N, vector<int>(N+1, INT_MAX));
        priority_queue<Tag> q;
        q.push(Tag(0, 0, 0));
        while(!q.empty()) {
            Tag t = q.top();
            q.pop();

            if(t.pos == N-1 && t.cost <= C) {
                ans = min(ans, t.used);
                continue;
            }
            if(dp[t.pos][t.used] <= t.cost) continue;
            dp[t.pos][t.used] = t.cost;

            for(int i = 0; i < v[t.pos].size(); ++i) {
                const pair<int,int> &p = v[t.pos][i];
                if(t.cost+p.second < dp[p.first][t.used]) {
                    q.push(Tag(p.first, t.used, t.cost+p.second));
                }
                if(t.used+1 <= N && t.cost < dp[p.first][t.used+1]) {
                    q.push(Tag(p.first, t.used+1, t.cost));
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  int H, W, N;
  char c;
  int sum[1005][1005][3] = {0};
  cin >> H >> W >> N;
  for(int i = 1; i <= H; i++) {
    for(int j = 1; j <= W; j++) {
      scanf(" %c",&c);
      if(c == 'J') sum[i][j][0]++;
      else if(c == 'O') sum[i][j][1]++;
      else sum[i][j][2]++;
      Rep(k,3) {
	sum[i][j][k] += sum[i - 1][j][k] + sum[i][j - 1][k] - sum[i - 1][j - 1][k];
      }
    }
  }

  int A, B, C, D;
  while(N--) {
    cin >> A >> B >> C >> D;
    Rep(i,3) {
      cout << sum[C][D][i] - sum[A - 1][D][i] - sum[C][B - 1][i] + sum[A - 1][B - 1][i];
      if(i == 2)cout << endl;
      else cout << " ";
    }
  }
  return 0;
}

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

int main()
{
	int n,m,x;
	cin >> n>>m>>x;
	vector<vector<int>> lib;
	for (int i = 0; i < n; i++)
	{
		vector<int> book;
		for (int i = 0; i < m+1; i++)
		{
			int a;
			cin >> a;
			book.push_back(a);
		}
		lib.push_back(book);
	}
	long min_cost = 100000*12+1;
	for (int i = 1; i < (1<<(n+1)); i++)
	{
		int cost = 0;
		vector<int> skills;
		for (int t = 0; t < m+1; t++)
		{
			skills.push_back(0);
		}
		for (int j = 0; j < n; j++)
		{
			if (i&(1<<j))
			{
				cost += lib[j][0];
				for (int r=1; r<m+1; r++)
				{
					skills[r] += lib[j][r];
				}
			}
		}
		int count = 0;
		for (int s = 1; s < m+1; s++)
		{
			if (skills[s]>=x)
			{
				count += 1;
			}
		}
		if (count==m and cost<min_cost)
		{
			min_cost = cost;
		}
	}
	cout << ((min_cost== 100000 * 12 + 1)?-1:min_cost);
	return 0;
}



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

int main() {
  string s;
  cin >> s;
  int x = 0;
  
  for(int i=0; i<s.size(); i++) {
    if(s.at(i) == '1') {
      x++;
    }
  }
  cout << x << endl;
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        int sum = 0;
        rep(j, s.size()) sum += s[j] - '0';
        if (sum >= a && sum <= b) ans += i;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
int main() {
  string s;
  cin>>s;
  for(int i=0;i<3;i++)s[i]=(s[i]=='1'?'9':'1');
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  ll n,x;
  cin >> n >> x;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  
  ll ans = 0LL;
  for(int i = 1;i<n;i++){
    if(a[i]+a[i-1] > x){ //現在位置と左側を足すとxを上回る場合
      if((a[i]+a[i-1])-x <= a[i]){ //a[i]に収まる場合
        ans +=(a[i]+a[i-1])-x;
        a[i] -=(a[i]+a[i-1])-x;
      }else{
        ans +=(a[i]+a[i-1])-x;
        a[i] = 0LL; //a[i]で収まらない場合は0にする。
      }
    }
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = []
for i in range(n):
    s.append(input())
#s = list(map(int, input().split()))
a =0
b=0
c=0
d=0
for i in range(n):
    if s[i] == "AC":
        a += 1
    elif s[i] == "WA":
        b += 1
    elif s[i] == "TLE":
        c += 1
    elif s[i] == "RE":
        d += 1

print("AC x", a)
print("WA x", b)
print("TLE x", c)
print("RE x", d)



Measured memory_bytes: 16340
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

/*******************************************************/

int main() {
  ll x, y; cin >> x >> y;
  ll cnt = 0;
  while (x <= y) {
    x *= 2;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
function main(arg) {
  var a = arg.split(/\r\n|\r|\n/)

  var n = parseInt(a[0])
  var result = ''
  for (var i = 0; i < a[1].length; i++) {
    var charCode = a[1][i].charCodeAt() + n
    if (charCode > 90) {
      charCode = charCode - 26
    }

    result += String.fromCharCode(charCode)
  }

  console.log(result)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 12360
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mo 1000000007
#define mems(a,x) memset(a,x,sizeof(a))
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
vector<ll>v[100005];
vector<ll>s(100005,0);
void dfs(ll u)
{
	s[u]=1;
	for(auto i: v[u])
	{
		if(s[i]==1)
			continue;
		dfs(i);
	}
}


int main() {
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		ll a,b,c;
		cin>>a>>b>>c;
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]==0)
		{
			dfs(i);
			++ans;
		}
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 9600
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n, m;
  cin >> n >> m;
  long long tot = 0;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    tot += a;
  }
  if (tot > n) {
    cout << -1 << endl;
  } else {
    cout << n - tot << endl;
  }
  return 0;
}

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

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int gcd(int a,int b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

int kaizyou(int N){
  int num=1;
  for(int i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

signed main() {
  int k,n;
  cin >> k>>n;
  vector<int> a(n);
  rep(i,n){
    cin >>a[i];
  }
  int num=0;
  rep(i,n-1){
    num=max(a[i+1]-a[i],num);
  }
  num=max(num,k-a[a.size()-1]+a[0]);
  cout << k-num << endl;
    
}

  
  
  

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

int main() {
	int X, A, B; cin >> X >> A >> B;
	if (B <= A) {
		cout << "delicious";
	}
	else if (B > A && (B - A) <= X) {
		cout << "safe";
	}
	else if (B > A && (B - A) > X) {
		cout << "dangerous";
	}
}

Measured memory_bytes: 256
# cook your dish here
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[i]+l[k]>l[j] and l[i]<l[j] and l[j]<l[k]:
                ans+=1
print(ans)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
        #define ll long long
        #define f   first
        #define s   second
        #define pb          push_back
        #define mod        1000000007
        #define mod1       1000000009
        #define hell        998244353
        #define inf         1000000000000000000LL
        #define pi          3.14159265358979323
        #define N           1000005
        using namespace std;
        ll n,k,sum,q,res,m,val,ans;
        ll x,y;
        ll xx[]={1,0,-1,0};
        ll yy[]={0,1,0,-1};
        void solve()    
        {   ll a,b;
            cin>>n;
            if(n%1000==0) {cout<<"0";}
            else cout<<1000-(n%1000);


        }
        int main()
        {   ios_base::sync_with_stdio(false);
            cin.tie(0);cout.tie(0);
            ll t=1;
            //cin>>t;
            while(t--)
                solve();
            

        }            

Measured memory_bytes: 3648
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define hcf __gcd

bool is_prime(ll n){
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3;i*i<=n;i+=2){
        if(n%i==0)
            return false;
    }
    return true;
}

int main(void){
     ios::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen ("C:\\Users\\Animesh\\Desktop\\i.txt", "r", stdin);
    //freopen ("C:\\Users\\Animesh\\Desktop\\o.txt", "w", stdout);
#endif
    int n; cin>>n;
    int l; cin>>l;
    vector<string> s(n); for(auto& it:s) cin>>it;
    sort(s.begin(),s.end());
    for(auto it:s)
        cout<<it;

return 0;
/* check for bounds before submitting */
}


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

int gcd(int a,int b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}

int main(){
    int K,a,b,c;
    long sum = 0;
    cin >> K;
    for(a=1;a<=K;a++){
        for(b=1;b<=K;b++){
            for(c=1;c<=K;c++){
                sum += gcd(gcd(a,b),c);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3596