akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  cin >> s;
  int n = sz(s);
  s.push_back('_');
  int ans = 0;
  rep(i,n){
    int j = i;
    while(s[j] == 'A'|| s[j] == 'C' || s[j] == 'G' || s[j] == 'T')j++;
    maxs(ans,j-i);
  }
  print(ans);
  return 0;
}

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

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);

int K;
vi a;

signed main(){
    fast_io();
    cin >> K;
    a.resize(K);
    for(int &A : a) cin >> A;
    reverse(a.begin(), a.end());
    int mi = 2, ma = 2;
    for(int A : a){
        if(mi % A == 0) mi -= A;
        mi -= mi % A;
        mi += A;
        if(mi > ma) {
            //cout << mi << " " << ma << endl;
            cout << -1 << endl;
            return 0;
        }
        ma /= A;
        ma ++;
        ma *= A;
        ma --;
    }
    cout << mi << " " << ma << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int h[] = new int[N];
		int k[] = new int[N];
		boolean b[] = new boolean[N];
		int count = 0;
		for(int i = 0;i < N;i++) {
			k[i] = sc.nextInt();
		}
		int oc = 0;
		while(true) {
			int e = oc;
			for(int i = oc;i < N;i++) {
				for(int q = oc;q < N;q++) {
					oc=q;
					if(h[q] != k[q])break;
				}
				if(h[i] != k[i]) {
					e++;
				}
				if(h[i] == k[i]) {
					break;
				}
			}
			boolean w = false;
			for(int j = oc;j < e;j++) {
				if(h[j] != k[j]) {
					w = true;
					h[j]++;
				}
			}
			if(w)count++;

			//---
			boolean f = true;
			for(int i = 0;i < N;i++) {
				if(h[i] != k[i])f=false;
			}
			if(f)break;
		}

		System.out.println(count);
	}
}

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

int main() {
    long long l, r; cin >> l >> r;
    if(r-l>=2018){
        cout << 0 << endl;
        return 0;
    }
    long long ans=2018;
    for(long long  i=l; i<r; i++){
        for(long long j=i+1; j<=r; j++){
            ans=min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[10],t[10],u[10];
    scanf("%s %s",s,t);
    int a,b;
    scanf("%d %d",&a,&b);
    scanf("%s",u);
    if(strcmp(u,s)==0)
        a--;
    else if(strcmp(u,t)==0)
        b--;
    printf("%d %d",a,b);
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N, D;
    cin >> N >> D;
    int c = 0;
    for(int i = 0; i < N; ++i) {
        long double x, y;
        cin >> x >> y;
        if(sqrt(x * x + y * y) <= D) ++c;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3784
n = int(input())
l = list(map(int, input().split()))
l.sort()
#print(n,l)

x = 0#半分の境目のindex
y = 0#判定用
if n%2 == 0:
  x = n//2 - 1
else:
  y = 1
#print(x,y)

ans = 0
if y == 0:
  ans = l[x+1] - l[x]
print(ans)

Measured memory_bytes: 14396
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int r;
    cin >> r;
    cout << 3*r*r;
}

Measured memory_bytes: 256
x = gets.to_i

a_max = (x ** 0.25).to_i + 1

begin
  (1..a_max).each do |a|
    (-a..a).each do |b|
      if a**5 - b**5 == x
        puts [a, b] * ' '
        raise
      end
    end
  end
rescue
  :OK
end

load __FILE__ unless $stdin.eof?


Measured memory_bytes: 14788
import sys
from collections import defaultdict
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, C = in_nn()
    D = [list(map(int, readline().split())) for _ in range(C)]
    c = [list(map(int, readline().split())) for _ in range(N)]

    grid = [defaultdict(int) for _ in range(3)]

    for y in range(N):
        for x in range(N):
            d = grid[(x + y + 2) % 3]
            d[c[y][x]] += 1

    comb = itertools.permutations(range(1, C + 1), 3)

    ans = 10**9 + 7
    for com in comb:
        iwa = 0
        for i in range(3):
            n_c = com[i]
            for k, v in grid[i].items():
                iwa += D[k - 1][n_c - 1] * v
        ans = min(ans, iwa)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11692
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
const ll mn=1e5+4;
pair<ll,ll> a[mn];
int main() {
	ios_base::sync_with_stdio(false);
	ll n; scanf("%lld",&n);
	for (ll i=0;i<n;i++) {
		ll x;scanf("%lld",&x);
		a[i]=MP(x,i);
	}
	sort(a,a+n);
	ll need=0;
	for (ll i=0;i<n;i++) {
		if ((a[i].second-i)%2) {
			need++;
		}
	}
	ll ans=need/2;
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792
from collections import deque

n = int(input())
e_list = [list(map(int, input().split())) for _ in range(n-1)]

edges = [[]for _ in range(n)]
for x, y in e_list:
    edges[x-1].append(y-1)
    edges[y-1].append(x-1)

# bfsの準備
q = deque([])
visited = [False]*n
visited[0] = True
color_list = [0]*n
q.append(0)
eColor_dic = {}
max_color = 0
# bfs
while q:
    here = q.popleft()
    color = 1
    for i in edges[here]:
        if visited[i]:
            continue
        q.append(i)
        visited[i] = True
        if color_list[here] == color:
            color += 1
        eColor_dic[(here, i)] = color
        color_list[i] = color
        max_color = max(max_color, color)
        color += 1

print(max_color)
for x, y in e_list:
    print(eColor_dic[(x-1, y-1)])

Measured memory_bytes: 99032
#include <bits/stdc++.h>
using namespace std;
int main(){
  int m,d;
  cin >>m>>d;
  int ans=0;
  for(int i=0;i<m;i++){
    for(int j=0;j<d;j++){
      if(j>8){
        int a=(j+1)/10;
        int b=(j+1)%10;
        
        if(i+1==a*b&&a>1&&b>1){
          ans++;

        }
      }
    }
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 256
use std::io;
use std::io::BufRead;

fn main() {
    let mut sc = Scanner::new(std::io::stdin());
    let n: usize = sc.next().unwrap();

    let mut a: Vec<i64> = vec![0; 1 << n];
    for i in 0..(1<<n) {
        a[i] = sc.next().unwrap();
    }
    let neg = 0usize.wrapping_sub(1);
    let mut dp: Vec<(usize, usize)> = vec![(neg, neg); 1<<n];
    dp[0] = (0, neg); // first, second
    for i in 1..(1<<n) {
        dp[i].0 = i;
        for j in 0..n {
            if (i & (1<<j)) > 0 {
                let i2 = i ^ (1<<j);
                for j in vec![dp[i2].0, dp[i2].1] {
                    if j == dp[i].0 || j == dp[i].1 || j == neg {
                        continue;
                    }
                    if a[j] > a[dp[i].0] {
                        dp[i].1 = dp[i].0;
                        dp[i].0 = j;
                    } else if dp[i].1 == neg || a[j] > a[dp[i].1] {
                        dp[i].1 = j;
                    }
                }
            }
        }
    }
    for k in 1..(1<<n) {
        let mut res = a[dp[k].0] + a[dp[k].1];
        for i in (0..n).rev() {
            let i2 = 1 << i;
            if k & i2 > 0 {
                let i3 = (k & (((1<<n) - 1) ^ (i2 - 1))) - 1;
                if i3 == 0 {
                    continue;
                }
                let v = a[dp[i3].0] + a[dp[i3].1];
                res = std::cmp::max(res, v);
            }
        }
        println!("{}", res);
    }
}

/// Scanner
///
/// # Example
/// ```
/// use contest::io::scanner;
/// let mut sc = scanner::Scanner::new("1 2 \n\n \r\t \n 3.5".as_bytes());
/// assert_eq!("1".to_string(), sc.next::<String>().unwrap());
/// assert_eq!(2, sc.next());
/// assert_eq!(3.5, sc.next());
/// assert_eq!(None, sc.next::<i32>());
/// ```

pub struct Scanner<R: io::Read> {
    br: io::BufReader<R>,
    // Read tokens are stored in reversed order per line.
    buf: Vec<String>,
}

impl<R: io::Read> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner {
            br: io::BufReader::new(r),
            buf: vec![],
        }
    }
    #[inline]
    pub fn next<T>(&mut self) -> Option<T>
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        self.next_string().map(|s| s.parse::<T>().expect("Parse failed: "))
    }
    fn next_string(&mut self) -> Option<String> {
        self.buf.pop().or_else(|| match self.update() {
            true => self.next_string(),
            false => None,
        })
    }
    #[inline]
    fn update(&mut self) -> bool {
        let mut s = String::new();
        let res = self.br.read_line(&mut s);
        match res.expect("I/O error.") {
            0 => false,
            _ => {
                self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();
                true
            }
        }
    }
}


Measured memory_bytes: 20924
#include <iostream>

using namespace std;

int main() {
int n;
int k;
string s;
cin>>n;
cin>>k;
cin>>s;
char c;
int d=s[k-1];
if(d>=65&&d<=67)
{c=d+32;
s[k-1]=c;}
cout<<s;
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    l,r=map(int,input().split())
    ans=2019
    for i in range(l,r):
        for j in range(i+1,r+1):
            ans=min(ans,i*j%2019)
            if ans==0:
                print(0)
                sys.exit()
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define MOD 1000000007

ll ppow(ll a,ll b){
	a %= MOD;
	ll res = 1;
	while(b){
		if(b & 1) res = (res * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

vector<ll> prime_enum(ll n){
    vector<ll> res;
    vector<bool> is_prime(n, true);
    is_prime[0] = false; is_prime[1] = false;
    for(ll i = 2; i < n; i++){
        if(!is_prime[i]) continue;
        res.push_back(i);
        for(ll j = 2; i * j < n; j++){
            is_prime[i*j] = false;
        }
    }
    return res;
}

map<ll,int> prime_factor(ll n, vector<ll> primes){
	map<ll, int> res;
	for(ll p: primes){
        if(p * p > n) break;
		while(n % p == 0){
			res[p]++;
			n /= p;
		}
	}
	if(n != 1) res[n]++;
	return res;
}

int main(void){
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i,n) cin >> A[i];

    vector<ll> primes = prime_enum(1e6);
    
    map<ll, int> lcm;
    rep(i,n){
        auto fac = prime_factor(A[i], primes);
        for(auto p: fac){
            lcm[p.first] = max(lcm[p.first], p.second);
        }
    }
    ll L = 1;
    for(auto p:lcm){
        L = (L * ppow(p.first, p.second)) % MOD;
    }
    ll ans = 0;
    for(ll a:A){
        ans = (ans + L * ppow(a, MOD-2)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

ll keta[40][2000005];

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	rep(i,n){
		ll b = a[i];
		rep(j,40){
			if(a[i] >> j & 1){
				if(i == 0){
					keta[j][1]++;
					keta[j][n]--;
				} else if (i == n-1){
					keta[j][0]++;
					keta[j][n-1]--;
				} else{
					keta[j][0]++;
					keta[j][i]--;
					keta[j][i+1]++;
					keta[j][n]--;
				}
			}
		}
	}
	rep(j, 40){
		rep(k,n+1){
			if(k > 0){
				keta[j][k] += keta[j][k-1];
			}
		}
	}
	rep(i,n){
		ll ans = 0;
		rep(j,40){
			ll two = 1;
			rep(k,j){
				two *= 2;
			}
			if(keta[j][i] % 2 == 1){
				ans += two;
			}
		}
		cout << ans << endl;
	}
    return 0;
}

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

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

    ll zero = 0;
    ll neg = 0;
    ll sum = 0;
    ll mn = 1e18;
    rep(i, 0, N){
        ll a;
        cin >> a;
        sum += abs(a);
        mn = min(mn, abs(a));
        if(a < 0) neg++;
        if(a == 0) zero++;
    }

    if(neg % 2 == 1 && zero == 0){
        cout << sum - 2*mn << endl;
    }else{
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        boolean result=true;

        if(s.length()<=26||s.length()>=2){
            for(int i=0;i<s.length();i++){
                for(int j=i+1;j<s.length();j++){
                    char a=s.charAt(i);
                    char b=s.charAt(j);
                    if(a==b){
                        result=false;
                    }
                }
            }
        }

        if(result){
            System.out.println("yes");
        }else{
            System.out.println("no");
        }
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int m = 1e9 + 7;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	int s = 0;
	for(int i = 1; i < n; i++) (s += a[i]) %= m;
	int res = 0;
	for(int i = 0; i < n - 1; i++) {
		(res += 1LL * s * a[i] % m) %= m;
		(s += m - a[i + 1]) %= m;
	}
	cout << res << '\n';
}


Measured memory_bytes: 3968
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define X first
#define Y second
int main(){
  vector<pair<double,double> > pin;
  bool f[100];
  int n;
  while(cin >>n,n){
    pin.clear();
    for(int i=0; i<n; i++) f[i] = true;
    for(int i=0; i<n; i++){
      double a,b;
      scanf("%lf,%lf",&a,&b);
      pin.push_back(make_pair(a,b));
    }
    sort(pin.begin(),pin.end());
    int now = 0,next,ans = 0;
    for(;;){
      for(int i=0; i<n; i++){
	if(i == now || !f[i]) continue;
	next = i;
	double ax = pin[i].X-pin[now].X;
	double ay = pin[i].Y-pin[now].Y;
	for(int j=0; j<n; j++){
	  if(!f[j] || i == j) continue;
	  double bx = pin[j].X-pin[now].X;
	  double by = pin[j].Y-pin[now].Y;
	  if(ax*by-ay*bx<0){next = -1;break;}
	}
	if(next == i) break;
      }
      now = next;
      f[now] = false;
      if(now == 0) break;
    }
    for(int i=0; i<n; i++) if(f[i]) ans++;
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int ba=b-a;
	int cb=c-b;
	if(ba==cb)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, P: "List[int]", Q: "List[int]"):
    if P == Q:
        print(0)
        return 
    all = list(itertools.permutations(list(range(1,N+1)))) 
    a = None
    b = None
    P = tuple(P)
    Q = tuple(Q)
    for i in range(len(all)):
        if all[i] == P:
            a = i
        elif all[i] == Q:
            b = i
    
    print(abs(a-b))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    Q = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P, Q)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int K;cin>>K;
	vector<long> dp[16];
	int cnt = 9;
	rep(i,1,10) dp[1].push_back(i);
	if(cnt >= K){
		cout<<dp[1][K - 1]<<endl;
		return 0;
	}
	rep(i,2,16){
		for(long t:dp[i-1]){
			int r = t % 10;
			if(r == 0){
				dp[i].push_back(10 * t);
				dp[i].push_back(10 * t + 1);
				cnt += 2;
			}else if(r < 9){
				dp[i].push_back(10 * t + r - 1);
				dp[i].push_back(10 * t + r);
				dp[i].push_back(10 * t + r + 1);
				cnt += 3;
			}else{
				dp[i].push_back(10 * t + 8);
				dp[i].push_back(10 * t + 9);
				cnt += 2;
			}
		}
		if(cnt >= K){
			cout<<dp[i][dp[i].size() - 1 - (cnt - K)]<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1976
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];

    vector<vector<ll>> dp(N + 10, vector<ll>(2 * W + 10, 0));

    rep(j, W) dp[0][j + w[0]] = v[0];

    rep(i, N) rep1(j, W){
        ll nextw = w[i + 1], nextv = v[i + 1];
        
        if(j - nextw < 0) dp[i + 1][j] = dp[i][j];
        else dp[i + 1][j] = max({dp[i][j], dp[i + 1][j], dp[i][j - nextw] + nextv});
    }

    print(dp[N - 1][W]);

    return 0;
}

Measured memory_bytes: 173824
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) ll((a).size())
#define all(a) (a).begin(), (a).end()
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
const ll MOD = 1E9+7;
const ll INF = 1E18;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s >> i & 1;}
template<class T> void flipbit(T& s, int i) {s ^= (1LL << i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll n,a,b;
	cin>>n>>a>>b;
	if(a+b-1>n||a*b<n) exit(puts("-1\n")*0);
	int cur=n;
	Ford(i,b,1){
		if(cur-a>=i-1){
			For(j,cur-a+1,cur) cout<<j<<' ';
			cur-=a;
		}
		else{
			For(j,i,cur) cout<<j<<' ';
			cur=i-1;
		}
	}
	cout<<'\n';
}



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

int  main() {
  string n;
  cin>>n;
  for(int i=0;i<3;i++) {
    if(n.at(i)=='1') {
      n.at(i)='9';
    }
    else if(n.at(i)=='9') {
      n.at(i)='1';
    }
  }
  cout<<n<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF (9223372036854775807LL)
#define EPS (1e-10)
#define endl ('\n')
#define MOD 1000000007LL
//#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

int main(){
    lint a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    lint p=a*60+b;
    lint q=c*60+d;
    cout<<q-p-e<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	double res = 0;
	rep(i, n){
		int a; cin >> a;
		res += 1.0 / a;
	}
	printf("%.20f\n", 1 / res);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long

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

	int A, B, C;
	cin >> A >> B >> C;

	if (A == B)cout << C << endl;
	if (A == C)cout << B << endl;
	if (C == B)cout << A << endl;

	return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  
  for (int i = 0; i < n - k; i++) {
    if (v.at(i + k) > v.at(i))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    int n;cin>>n;
    vector<double> p(n);
    rep(i,0,n)cin>>p[i];
    vector<vector<double>> dp(3000,vector<double>(3010,0));
    dp[0][0]=1;
    rep(i,0,n)rep(j,0,n){
        dp[i+1][j]+=(dp[i][j]*(1-p[i]));
        dp[i+1][j+1]+=(dp[i][j]*p[i]);
    }
    double ans = 0;
    rep(i,n/2+1,n+1){
        ans+=dp[n][i];
    }
    printf("%.9f", ans);
}


Measured memory_bytes: 70912
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define MAX 100
class Tree{
    public:
    string L;
    double value;
    int P, A, B, C, D, E, F, S, M;
    Tree(){}

    void setValue(){
	int t = A + B + C + (D+E)*M;
	int v = F*S*M - P;
	value = 1.0*v/t;
    }

    bool operator < ( const Tree &t ) const{
	if ( fabs(value - t.value) < 0.000000001 ) return L < t.L;
	return value > t.value;
    }
};

main(){
    Tree T[MAX];
    int n;
    while(1){
	cin >> n;
	if ( n == 0 ) break;
	for ( int i = 0; i < n; i++ ){
	    cin >> T[i].L >> T[i].P >> T[i].A >> T[i].B;
	    cin >> T[i].C >> T[i].D >> T[i].E >> T[i].F;
	    cin >> T[i].S >> T[i].M;
	    T[i].setValue();
	}
	sort(T, T+n);
	for ( int i = 0; i < n; i++ ) cout << T[i].L << endl;
	cout << "#" << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ff first
#define ss second
const ll mod = 1e9 + 7 ;
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
///////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////
void solve( ){
    ll h , a ;
    cin >> h >> a ;
    cout << (ll)ceil((1.0*h)/a) ;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test_case=1 ;
    //cin >> test_case ;
    for( int i = 1 ; i <= test_case ; i++){
        solve( );
    }
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int N, M;
vector<int> D, T;
int main() {
    cin >> N;
    D.resize(N);
    rep(i, N) cin >> D[i];
    cin >> M;
    T.resize(M);
    rep(i, M) cin >> T[i];
    map<int, int> m;
    rep(i, N) m[D[i]]++;
    rep(i, M) {
        if (m.count(T[i]) == 0) {
            cout << "NO" << endl;
            return 0;
        }
        if (m[T[i]] == 0) {
            cout << "NO" << endl;
            return 0;
        }
        m[T[i]]--;
    }
    cout << "YES" << endl;

    return 0;
}


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

int main ( ) {
    int N, l, r;
	int results = 0;

    cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> l >> r;

		results += r - l +1;
	}

	cout << results << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, w, i, j, wt;
    cin >> n >> w;
    long long dp[w+1] = {0}, v;
    for(i = 0; i < n; ++i) {
        cin >> wt >> v;
        for(j = w; j >= wt; --j) 
			dp[j] = max(dp[j], dp[j-wt] + v);
    }
    cout << dp[w];
    return 0;
}


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

int main(){
	string s;
	cin>>s;
	vector<int> cnt[26];
	for(int i=0;i<s.size();i++){
		cnt[s[i]-'a'].push_back(i);
	}
	for(int i=0;i<26;i++){
		if(cnt[i].size()<2)continue;
		for(int j=0;j<s.size();j++){
			int k=j+1;
			while(k-j<=2&&k<s.size()){
				if(s[j]==s[k]){
					cout<<j+1<<" "<<k+1<<endl;
					return 0;
				}
				k++;
			}
		}
	}
	cout<<"-1 -1"<<endl;
	return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin>>S;
  
  if(S=="SUN") cout<<7<<endl;
  else if(S=="MON") cout<<6<<endl;
  else if(S=="TUE")  cout<<5<<endl;
  else if(S=="WED") cout<<4<<endl;
  else if(S=="THU") cout<<3<<endl;
  else if(S=="FRI") cout<<2<<endl;
  else if(S=="SAT") cout<<1<<endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;
    vector<ll> x(N);
    REP(i, N) cin >> x[i];
    vector<pll> P(N);
    REP(i, N) P[i].first = x[i], P[i].second = i+1;

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

    vector<ll> res(N*N, -1);
    vector<ll> te(N*N, -1);
    queue<ll> qu;

    REP(i, N){
    	res[P[i].first-1] = P[i].second;
    	te[P[i].first-1] = P[i].second;

    	REP(j, P[i].second-1){
    		qu.push(P[i].second);
    	}
    }

    REP(i, N*N){
    	if(res[i]==-1){
    		if(qu.empty()){
    			cout << "No" << endl;
    			return 0;
    		}else{
    			ll tmp = qu.front();
    			qu.pop();
    			res[i] = tmp;
    		}
    	}else{
    		REP(j, N-res[i]){
    			qu.push(res[i]);
    		}
    	}
    }
    
    bool ok = true;
    vector<ll> cnt(N+1, 0);
    REP(i, N*N){
    	cnt[res[i]]++;
    	if(te[i]>0){
    		if(te[i] != cnt[res[i]]) ok = false;
    	}
    }

    if(ok){
    	cout << "Yes" << endl;
    	cout << res << endl;
    }else{
    	cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 8704
A, B, C = map(int, input().split())

import math

Asmall = math.floor(A/2)
Abig = A- Asmall
Bsmall = math.floor(B/2)
Bbig = B- Bsmall
Csmall = math.floor(C/2)
Cbig = C- Csmall

print(min((Cbig-Csmall)*A*B, (Abig-Asmall)*C*B, (Bbig-Bsmall)*A*C))

Measured memory_bytes: 3060
#include <bits/stdc++.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 pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=998244353;
ll dp[3001][3001];
int n,s;
int a[3001];
int main(){
    cin>>n>>s;
    rep(i,n) cin>>a[i];
    ll ans=0;
    rep(i,n){
        rep(j,s){
            if(j+a[i]<=s){
                dp[i+1][j+a[i]]+=dp[i][j];
                if(j==0) dp[i+1][j+a[i]]+=i+1;
                dp[i+1][j+a[i]]%=mod;
                if(j+a[i]==s){
                    ans+=dp[i+1][j+a[i]]*(n-i);
                    ans%=mod;
                }
            }
            dp[i+1][j]+=dp[i][j];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>

using namespace std;

int main()
{
     int X,c,b,a;
     cin>>X;
     if(X<500)
     {
         c=X/5;
         cout<<c*5;
     }
     else{

            a=X/500;
            b=X%500;
            c=b/5;
            cout<<a*1000+c*5;
        }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  string S;
  cin >> S;

  int a = 0,b = 0,c = 0;
  REP(i,S.size()){
    if(S.at(i)=='a'){
      a++;
    }else if(S.at(i) == 'b'){
      b++;
    }else{
      c++;
    }
  }

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

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    while (true)
    {
        int fl = true;
        for (int i = 2; i * i <= x; ++i)
        {
            if (x % i == 0)
            {
                fl = false;
                break;
            }
        }
        if (fl && x > 1)
        {
            cout << x << endl;
            return 0;
        }
        ++x;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define jam(t) cout<<"Case #"<<t<<": "
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007ll
#define sz 400005
#define bitcnt(x) __builtin_popcountll(x)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}



void solve(){
    ll an = 0;
    ll n;
    cin >> n;
    for(ll i=1;i<=n;i++){
        if(i%3!=0 && i%5!= 0)
            an+=i;
    }
    g(an);
    
}
int main()
{
#ifndef ONLINE_JUDGE
input_from_file
#endif
 
    FASTIO
    cin.tie(NULL);
    fflush(stdout);
    ll t = 1;
  //  cin >> t;
    for(ll tcase = 1;tcase <= t;tcase++){
        solve();
        
    }
return 0;
}

Measured memory_bytes: 3656
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 500 + 5;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int n, id[N * N], num[N][N], dist[N][N];
bool mark[N][N];

bool is_valid(int x, int y) {
	return ~x && ~y && x < n && y < n;
}

void dfs(int x, int y) {
	for (int i = 0; i < 4; i++) {
		int u = x + dx[i], v = y + dy[i];
		if (is_valid(u, v) && dist[u][v] > dist[x][y] + !mark[u][v])
			dist[u][v] = dist[x][y] + !mark[u][v], dfs(u, v);
	}
}

void read_input() {
	cin >> n;
	for (int i = 0; i < n * n; i++) {
		int x;
		cin >> x;
		id[i] = --x;
		num[x / n][x % n] = i;
	}
}

void solve() {
	int ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			dist[i][j] = min(min(i, j) + 1, n - max(i, j));
	for (int i = 0; i < n * n; i++) {
		int x = id[i] / n, y = id[i] % n, mn = dist[x][y];
		for (int j = 0; j < 4; j++) {
			int u = x + dx[j], v = y + dy[j];
			mn = min(mn, is_valid(u, v)? dist[u][v]: 0);
		}
		mark[x][y] = true, ans += dist[x][y] = mn, dfs(x, y);
	}
	cout << ans;
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input(), solve();
	return 0;
}


Measured memory_bytes: 26124
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,x;
    cin >> n >> x;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    LL diff = max(0, a[0] - x);
    LL ans = diff;
    a[0] -= diff;
    REP(i,1,n) {
        int diff = max(0, (a[i] + a[i-1]) - x);
        ans += diff;
        a[i] -= diff;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 640
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static class Point {
		int x, y;
		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}

	static int INF = Integer.MAX_VALUE;
	static int h, w;
	static String[][] s;
	static Point start, goal;
	static String barrior = "#";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		h = Integer.parseInt(sc.next());
		w = Integer.parseInt(sc.next());
		s = new String[h][w];
		int count = 0;
		for (int i = 0; i < h; i++) {
			s[i] = sc.next().split("");
			for (int j = 0; j < w; j++)
				if(s[i][j].equals("."))
					count++;
		}
		start = new Point(0, 0);
		goal = new Point(h - 1, w - 1);
		int ans = bfs();
		if (ans != -1)
			ans = count - ans;
		System.out.println(ans);
	}

	public static int bfs() {
		int[] dx = {0, 0, 1, -1};
		int[] dy = {1, -1, 0, 0};
		int[][] d = new int[h][w];
		for (int i = 0; i < h; i++)
			Arrays.fill(d[i], INF);
		d[start.x][start.y] = 1;
		Deque<Point> p = new ArrayDeque<Point>();
		p.add(start);
		while(!p.isEmpty()) {
			Point q = p.pop();
			int x = q.x, y = q.y;
			for (int i = 0; i < 4; i++) {
				int nx = x + dx[i], ny = y + dy[i];
				if (nx < 0 || nx >= h || ny < 0 || ny >= w || s[nx][ny].equals(barrior) || d[nx][ny] != INF)
					continue;
				d[nx][ny] = d[x][y] + 1;
				if (nx == goal.x && ny == goal.y)
					return d[nx][ny];
				p.add(new Point(nx, ny));
			}
		}
		return -1;
	}
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; i ++){
        int d;
        cin >> d;
        mp[d]++;
    }
    cout << mp.size() << endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    for(int i = 0; i<3; i++){
        cin >> s[i];
    }
    int count = 0;
    for(int i = 0; i<3; i++){
        if(s[i] == 'o') count++;
        else ;
    }
    cout << 700 + 100*count << endl;
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  # a〜z
  l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

  _l=[0]*26

  n=I()

  al=[]
  for _ in range(n):
    s=S()
    bl=_l[::]
    for x in s:
      bl[l.index(x)]+=1

    al.append(bl)

  s=''
  for i in range(len(l)):
    cnt=inf
    for j in range(len(al)):
      cnt=min(cnt,al[j][i])
    s+=l[i]*cnt

  return s

print(main())


Measured memory_bytes: 5524
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll r=0;
    ll g=0;
    ll b=0;
    rep(i,n){
        if(s[i]=='R')r++;
        if(s[i]=='G')g++;
        if(s[i]=='B')b++;
    }
    ll ans = r*g*b;
    rep(i,n)rep(j,n){
        if(i>=j)continue;
        if(2*j-i>=n)continue;
        if(s[i]!=s[j]&&s[j]!=s[2*j-i]&&s[i]!=s[2*j-i])ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
class Dice
  def initialize(string)
    @dice_value = string.split.map(&:to_i)
  end

  def roll(operates)
    operate_ary = operates.chomp.split('')

    while operate = operate_ary.shift
      case operate
      when "N"
        tmp = @dice_value[0]
        @dice_value[0] = @dice_value[1]
        @dice_value[1] = @dice_value[5]
        @dice_value[5] = @dice_value[4]
        @dice_value[4] = tmp
      when "S"
        tmp = @dice_value[0]
        @dice_value[0] = @dice_value[4]
        @dice_value[4] = @dice_value[5]
        @dice_value[5] = @dice_value[1]
        @dice_value[1] = tmp
      when "W"
        tmp = @dice_value[0]
        @dice_value[0] = @dice_value[2]
        @dice_value[2] = @dice_value[5]
        @dice_value[5] = @dice_value[3]
        @dice_value[3] = tmp
      when "E"
        tmp = @dice_value[0]
        @dice_value[0] = @dice_value[3]
        @dice_value[3] = @dice_value[5]
        @dice_value[5] = @dice_value[2]
        @dice_value[2] = tmp
      end
    end

    print_result
  end

  def print_result
    puts @dice_value[0]
  end
end

dice = Dice.new(gets.chomp)
dice.roll(gets)

Measured memory_bytes: 8632
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int W ,a ,b;
  cin >> W >> a >> b;

  if(b >= a){
    int ans = b - a - W;
    if(ans <0){
      cout << 0 << endl;
      return 0;
    }else{
      cout << ans << endl;
      return 0;
    }
  }
  if(a > b){
    int ans = a - b - W;
    if(ans <0){
      cout << 0 << endl;
      return 0;
    }else{
      cout << ans << endl;
      return 0;
    }

  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MAXN 100010

using namespace std;

int a[MAXN];
long long gong = 1;

bool isprime(int x) {
	int j = 2;
	bool f = true;
	while (j <= sqrt(x) && f) {
		if (x % j == 0) return false;
		else j++;
	}
	if (f) return 1;
}

long long qiu(int x) {
	int g = gong;
//	if (isprime(x)) {
//		if (g % x == 0) return g;
//		else return g * x;
//	}
	while (1) {
		if (gong % x == 0) return gong;
		else gong += g;	
	}
}

int main() {
	int n, m;
	scanf("%d", &n);
	cin >> a[1];
	gong = a[1];
	for (int i = 2; i <= n; i++) {
		scanf("%d", &a[i]);
//		gong = qiu(a[i]);
	}
	ll zi = gong;
	double fen = 0;
	for (int i = 1; i <= n; i++) {
		fen += 1.0 / a[i];
	}
	printf("%.7lf\n", 1.0 / fen);
	return 0;
}

Measured memory_bytes: 256