akhauriyash/Code-Regression huggingface dataset:
//It’s never too late to become what you might have been....
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 100001
ll cnt[maxn];
int main()
{
	boost1;boost2;
	ll i,j,n,x,d=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		d=max(x,d);
		cnt[x]++;
	}	
	if(d%2)
	{
		for(i=d;i>d/2+1;i--)
		{
			if(cnt[i]<2)
			{
				cout<<"Impossible";
				return 0;
			}
		}
		if(cnt[d/2+1]!=2)
		{
			cout<<"Impossible";
				return 0;
		}
		cout<<"Possible";
	}
	else
	{
		for(i=d;i>d/2;i--)
		{
			if(cnt[i]<2)
			{
				cout<<"Impossible";
				return 0;
			}
		}
		if(cnt[d/2]!=1)
		{
			cout<<"Impossible";
				return 0;
		}
		cout<<"Possible";
	}
	

	return 0;
}


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

int main(){
  int n,count,i,j,ans;

  while(1){
    count=0;
    cin >> n;
    if(n == 0)break;

    while(n != 1){
      if(n%2 == 0){
	n=n/2;
	count++;
      }
      else{
	n=(n*3)+1;
	count++;
      }
    }
    cout << count << endl;

  }




}

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

using namespace std;

int main()
{
    int N=0;
    cin >> N;
    vector<int> d_vec = vector<int>();
    for(int i = 0; i < N; i++){
        int d = 0;
        cin >> d;
        d_vec.push_back(d);
    }
    sort(d_vec.begin(), d_vec.end());

    int med = (d_vec.size() / 2);  // `0 1 2 2 3 4` とかだと大きい方の2を取る
    int med_d = d_vec[med];
    // printf("med = %d, med_d = %d\n", med, med_d);
    int pre_med_d = d_vec[med - 1];
    int k = 0;
    if(pre_med_d < med_d){
        k = med_d - pre_med_d;
    }
    printf("%d\n", k);
    return 0;
}

Measured memory_bytes: 1020
#include<stdio.h>

typedef long long hyper;

hyper W[100000];
int n, k;

int value(hyper P)
{
    hyper sum = 0;
    int v = 0, t = 1; // v: baggages, t: tracks.

    while(1){
        sum = sum + W[v];
        if(sum > P){
            sum = 0; t++;   // to the next track.
        }else{ v++; }       // to the new baggage.
        if(v == n || t > k) break;
    };

    return v;   // return possible ...
}

hyper solve()
{
    hyper left, right, mid;
    left = 0;
    right = 100000 * 10000;

    while(right - left > 1){

        mid = (left + right) / 2;

        if(value(mid) < n){ left = mid; }
        else{ right = mid; }
    };

    return right;
}

int main()
{
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++) scanf("%d", &W[i]);

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

    return 0;
}

Measured memory_bytes: 1808
A,B,C,X,Y = map(int,input().split())

if A + B <= C*2:
    answer = X*A + Y*B
else:
    if X >= Y:
        if A <= 2*C:
            answer = min(X,Y)*C*2 + abs(X-Y)*A
        else:
            answer = min(X,Y)*C*2 + abs(X-Y)*2*C
    else:
        if B <= 2*C:
            answer = min(X,Y)*C*2 + abs(X-Y)*B
        else:
            answer = min(X,Y)*C*2 + abs(X-Y)*2*C

print(answer)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
	int a,b[100],c;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>b[i];
	}
	for(int i=a-1;i>=0;i--){
		cout<<b[i];
		if(i==0)break;
		cout<<" ";
	}
	cout<<endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> h(N);
  for(int i=0; i<N; i++)  cin >> h.at(i);
  
  vector<long long> dp(N);
  dp.at(0) = 0;
  dp.at(1) = abs(h.at(0) - h.at(1));
  
  for(int i=2; i<N; i++){
    dp.at(i) = min(dp.at(i-1)+abs(h.at(i)-h.at(i-1)), dp.at(i-2)+abs(h.at(i)-h.at(i-2)));
  }
    
  cout << dp.at(N-1) << endl;
}

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


def main():
    """Function."""
    n, m = map(int, input().split())

    counter = [0 for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        counter[a-1] += 1
        counter[b-1] += 1

    for cit in counter:
        print(cit)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_A
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a > b){
    cout << "a > b" << endl;
  }
  else{
    if(a == b){
      cout << "a == b" << endl;
    }else{
      cout << "a < b" << endl;
      }
  }
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

signed main() {
	int k, x;
	cin >> k >> x;
	if (500 * k >= x) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
/* Life is all about calculated risks.
    But man am I bad at math. */

#include <bits/stdc++.h> 
#define ll long long int
#define INF (ll)1e12
#define MOD 1000000007

#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;

using namespace std;

ll f(ll n,ll w);

ll N,W;
ll value[110], weight[110];

vector<vector<ll>> dp(110, vector<ll>(100010,-1));

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>N>>W;
    for(ll i=1; i<=N; i++)
    {
        cin>>weight[i]>>value[i];
    }

    cout<<f(N,W)<<endl;

    return 0;
}

ll f(ll n,ll w)
{
    if(dp[n][w] != -1)
    {
        return dp[n][w];
    }
    if(n == 0)
    {
        return 0;
    }
    if(weight[n] > w)
    {
        return dp[n][w] = f(n-1,w);
    }

    return dp[n][w] = max( f(n-1,w) , value[n]+f(n-1,w-weight[n]) );
}

Measured memory_bytes: 87296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for(int i = (l); i < (r); ++i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
//-------
const int N = 202020;
int n;
int a[N];
int p[21][N];
int main() {
	scanf("%d", &n);
	rep(i, 0, n) scanf("%d", a + i);
	rep(i, 0, n) {
		rep(j, 0, 20) {
			p[j][i + 1] = p[j][i] + (a[i] >> j & 1);
		}
	}
	rep(i, 0, 20) p[i][n + 2] = N;
	ll ans = 0;
	rep(l, 1, n + 1) {
		int r = n + 1;
		rep(i, 0, 20) {
			r = min(1ll * r, 1ll * (upper_bound(p[i], p[i] + n + 1, p[i][l] + !(a[l - 1] >> i & 1)) - p[i]));
		}
		//de(r);
		ans += r - l;
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 17408
import java.util.Scanner;

class Main{
	
	public static void main(String args[]){
      
	  Scanner scanner = new Scanner(System.in);
      String input = scanner.nextLine();
      
	  String nums[] = input.split(" ");
	  
	  // double eight = 8 / 100;
	  // double ten = 10 / 100;
	  
	  // long A = Long.parseLong(nums[0]);
	  // long B = Long.parseLong(nums[1]);
	  // long sum = Long.parseLong(nums[2]);
	  // int A = Integer.parseInt(nums[0]);
	  // int B = Integer.parseInt(nums[1]);

	  long A = Long.parseLong(nums[0]);
	  long Aplus = A + 1;
	  long B = Long.parseLong(nums[1]);
	  long Bplus = B + 1;

	  
	  long ansA = (A * 100) / 8;
	  if((A * 100) % 8 > 0){
	  	ansA++;
	  }
	  long ansAplus = (Aplus * 100) / 8;
	  if((Aplus * 100) % 8 > 0){
	  	ansAplus++;
	  }
	  
	  
	  long ansB = B * 10;
	  long ansBplus = Bplus * 10;
	  
	  if(ansA > ansB){
	    if(ansA >= ansBplus){
		  System.out.println(-1);
		}else{
	      System.out.println(ansA);
		}
	  }else{
	    if(ansB >= ansAplus){
		  System.out.println(-1);
		}else{
	      System.out.println(ansB);
		}
	  }
	  
	}
}


Measured memory_bytes: 21972
def calcurate(x):
  for a in range(1000):
    a5 = a**5
    for b in range(-1000, 1000):
      b5 = b**5
      if a5 - b5 == X:
        return a, b
      
if __name__ == "__main__":
  X = int(input())
  A, B = calcurate(X)
  print(A, B)


Measured memory_bytes: 9124
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

M = 0

for i in range(N):
    if A[i] <= B[i]:
        m = B[i] - A[i]
        M += A[i]
        if A[i+1] <= m:
            M += A[i+1]
            A[i+1] = 0
        else:
            M += m
            A[i+1] -= m

    else:
        M += B[i]

print(M)

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

#define int LL
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int32_t main() {
  ios_base::sync_with_stdio(0); cin.tie(0);

  int n; cin >> n;
  vec<int, 1> a(n + 1), l(n + 1), r(n + 1);
  for (int i = 0; i <= n; ++i) {
    cin >> a[i];
    l[i] = a[i];
  }
  l[0] = 1;
  r[0] = 1; r[n] = a[n];
  for (int i = n; i; --i) {
    r[i - 1] = a[i - 1] + r[i];
  }

  if (1 < a[0]) {
    cout << "-1\n";
    return 0;
  }

  int ans = 1;
  for (int i = 1, prvB = 1; i <= n; ++i) {
    int curB = min(r[i], (prvB - a[i - 1]) << 1);
    if (curB < l[i]) {
      cout << "-1\n";
      return 0;
    }
    if (curB < prvB - a[i - 1]) {
      cout << "-1\n";
      return 0;
    }
    ans += (prvB = curB);
  }

  cout << ans << '\n';

  return 0;
}

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

int main() {
    ll n,k;
    std::cin >> n>>k;
    
    ll cnt = 1;
    while(n/k>0){
        cnt++;
        n/=k;
    }
    std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
A, B = list(map(int, input().split(" ")))
p_array = np.asarray(sorted(list(map(int, input().split(" ")))))

type_1 = (p_array <= A)
type_3 = (p_array >= B+1)
type_2 = (~type_1) * (~type_3)

out = min([sum(type_1), sum(type_2), sum(type_3)])

print(out)

Measured memory_bytes: 21636
#include<stdio.h>
#include<limits.h>

int f(int n,int *w,int p,int k)//最大積載量を仮定した時に必要な台数を返す
{
	int i,cnt=0,sum=0;
	for(i=0;i<n;i++){
		if(cnt==k||w[i]>p) return i;//台数が上限または最大積載量以上の荷物ありなら終了
		if(w[i]<=p-sum) sum+=w[i];
		else{
			cnt++;
			sum=0;
			i--;
		}
	}
	return n;
}

int main(void)
{
	int i,n,k,w[1000000];
	int right=INT_MAX,left=0,mid,result;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++) scanf("%d",&w[i]);
	
	while(right-left>1){//二分探索 right,left,midは最大積載量
		mid=(right+left)/2;
		result=f(n,w,mid,k);
		if(result>=n) right=mid;
		else left=mid;
	}
	
	printf("%d\n",right);
	return 0;
}


Measured memory_bytes: 2236
import numpy as np
w,h,n = map(int, input().split())
area = np.array([[1]*w]*h)

for _ in range(n):
  x,y,a = map(int, input().split())
  if a == 1:
    area[:,:x]=0
  elif a == 2:
    area[:,x:]=0
  elif a == 3:
    area[:y,:]=0
  elif a == 4:
    area[y:,:]=0
print(area.sum())

Measured memory_bytes: 27240
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {
    input! {
        r: i64,
    }
    let r = r as f64;
    println!("{}", r * 2. * std::f64::consts::PI);
}


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

 
// Driver code to test above functions
int32_t main()
{
 
    int n, ans = 0;
    cin >> n;
    map<int, int> mp;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin >> x;
 
        ans += mp[i-x];
 
        mp[i+x]++;
    }
 
    cout << ans;
 
    return 0;
 
} 


Measured memory_bytes: 26196
import java.util.Scanner;

public class Main {

    private static int taskOne(int n, int k) {
        return 0;
    }

    private static int taskTwo(long n, int k) {
        int cnt = 0;

        while (n > 0) {
            n /= k;
            cnt += 1;
        }

        return cnt > 0 ? cnt : 1;
    }

    private static int taskThree() {
        return 0;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        System.out.println(taskTwo(n, k));
    }
}

Measured memory_bytes: 22612
from itertools import product

D, G = map(int, input().split())
G //= 100
prob = []

for i in range(1, D+1):
  p, c = map(int, input().split())
  prob.append((i, p, c//100))

ans = 1000
for comp in product((0, 1), repeat=D):
  cnt, score = 0, 0
  for i, c in enumerate(comp):
    if c:
      cnt += prob[i][1]
      score += prob[i][0]*prob[i][1] + prob[i][2]
  j = D-1
  while score < G and j >= 0:
    if comp[j] == 0:
      if score + prob[j][0]*prob[j][1] <= G:
        cnt += prob[j][1]
        score += prob[j][0]*prob[j][1]
      else:
        temp = -(-(G - score)//prob[j][0])
        cnt += temp
        score += prob[j][0]*temp
    j -= 1
  ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 9148
n = int(input())

def dot(a,b):
    return a[0] * b[0] + a[1] * b[1]
def s(a):
    return a[0]**2 + a[1]**2

for i in range(n):
    points = [int(j) for j in input().split()]
    p0 = points[:2]
    p1 = points[2:4]
    p2 = points[4:6]
    p3 = points[6:8]
    a = [p0[0]-p1[0],p0[1]-p1[1]]
    b = [p2[0]-p3[0],p2[1]-p3[1]]
    c = dot(a,b)**2/(s(a) * s(b))
    if c == 0: print(1)
    elif c == 1: print(2)
    else: print(0)

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

int main() {
  long N; cin >> N;
  int sqrtN = sqrt(N);
  long minAns = 1000000000000;
  for (int i =1; i<=sqrtN; i++) {
    if(N % i == 0) {
      long cand = i + N / i;
      minAns = min(cand,minAns);
    }
  }
  minAns -= 2;
  cout << minAns << endl;
}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int solve(long long n) {
    long long val = 100;
    int ans = 0;
    while (val < n) {
        val += val / 100;
        ans++;
    }
    return ans;
}

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


Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
typedef pair<int, int> P;

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    P p[100010];
    rep(i, n) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p, p + n);
    int ans = 0;
    int i = 0;
    while(m > 0) {
        int c = min(m, p[i].second);
        m -= c;
        ans += p[i].first * c;
        i++;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
  static Long T[];
  static Long A[];
  static Long TA[];
  static Long TT[];
  static int  N;
  static Long ans=0L;

  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    T = new Long[N];
    TT = new Long[N];
    TA = new Long[N];
    A = new Long[N];
    for(int i=0;i<N;i++){
      T[i] = sc.nextLong();
      A[i] = sc.nextLong();
    }
    TT[0] = T[0];
    TA[0] = A[0];
    ans += T[0]+A[0];
    for(int i=0;i<N-1;i++){
      update(i);
    }
    System.out.println(ans);
  }


  static void update(int m){
    Long k = Math.max((TT[m] + T[m+1] - 1) / T[m+1], (TA[m] + A[m+1] - 1) / A[m+1]);
    ans += T[m+1]*k-TT[m]-TA[m]+A[m+1]*k;
    TT[m+1] = T[m+1]*k;
    TA[m+1] = A[m+1]*k;
  }
}


Measured memory_bytes: 25940
#include <stdio.h>
typedef long long ll;
const ll M = 1000000007;
ll fact[200001]={1,};
ll powmod(ll a, ll n){
    ll ret = 1;
    for(int i=0;i<31;i++){
        if(n&(1<<i)){
            ret = (ret*a)%M;
        }
        a = (a*a)%M;
    }
    return ret;
}
ll inverse(ll x){
    return powmod(x,M-2);
}
ll comb(int n, int x){
    ll ret = 1;
    for(int i=0;i<x;i++){
        ret = (ret*(n-i))%M;
    }
    ret = (ret*inverse(fact[x]))%M;
    return ret;
}
int main(){
    for(int i=1;i<=200000;i++){
        fact[i] = (fact[i-1]*i)%M;
    }
    int N,A,B;
    scanf("%d %d %d",&N,&A,&B);
    printf("%lld",(powmod(2,N)-1+M-comb(N,A)+M-comb(N,B))%M);
}


Measured memory_bytes: 1664
/*
 * atcoder/abc163/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * N = 2の時
 * 必ず、1 0
 * N = 3の時
 * 1
 * 1 1 0 or 2 0 0
 */
const int MAX = 200010;
int N;
vector<int> A;
int counter[MAX] = {0};

void solve() {
  cin >> N;
  int a;
  loop(n,2,N+1) {
    cin >> a;
    counter[--a]++;
  }
  loop(n, 0, N) {
    cout << counter[n] << endl;
  }
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


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

int main(){
    int A,B,C;
    cin >> A >> B >> C;

    vector<int> Ai(B);
    for(int i=1; i<=B; i++){
        Ai[i-1] = A*i;
    }

    vector<int> modBAi(B);
    for(int i=0; i<B; i++){
        modBAi[i] = Ai[i] % B;
    }
    int ok = 0;
    for(int i=0; i<B; i++){
        if(modBAi[i] == C){
            ok++;
        }
    }

    if(ok == 0){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }
}


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


int main() {
  int n;
  cin>>n;
  vector<double> p(n);
  for (int i=0;i<n;i++) cin>>p[i];
  vector<vector<double>> dp(n+1,vector<double>(n+1,0));
  
  dp[1][0] = 1-p[0];
  dp[1][1] = p[0];
  for (int i=2;i<=n;i++) {
    dp[i][0] = dp[i-1][0] * (1-p[i-1]);
    for (int j=1;j<=i;j++) {
      dp[i][j] = dp[i-1][j-1]*p[i-1] + dp[i-1][j]*(1-p[i-1]);
    }
  }
  double result = 0;
  for (int j=n;j>n/2;j--) result += dp[n][j];
  cout<<setprecision(10)<<result;
  
  return 0;
}
	

Measured memory_bytes: 73720
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		long ans = 0;

		long b = a / 15;
		long c = a % 15;

		ans += ((b * (b + 1)) * 60 - 60 * b);

		long x =  b * 15;

		if(c == 0) {
			ans += 0;
		} else if(c == 1) {
			ans += x + 1;
		} else if(c == 2 || c == 3) {
			ans += x + 1 + x + 2;
		} else if(c == 4 || c == 5 || c == 6) {
			ans += x + 1 + x + 2 + x + 4;
		} else if(c == 7) {
			ans += x + 1 + x + 2 + x + 4 + x + 7;
		} else if(c == 8 || c == 9 || c == 10) {
			ans += x + 1 + x + 2 + x + 4 + x + 7 + x + 8;
		} else if(c == 11 || c == 12) {
			ans += x + 1 + x + 2 + x + 4 + x + 7 + x + 8 + x + 11;
		} else if(c == 13) {
			ans += x + 1 + x + 2 + x + 4 + x + 7 + x + 8 + x + 11 + x + 13;
		} else if(c == 14) {
			ans += (120*(b+1) - 60);
		}

		System.out.println(ans);

		sc.close();
	}

}

Measured memory_bytes: 35772
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
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;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vpii red,blue;
    rep(i,0,n){
        int x,y;
        cin>>x>>y;
        pii e;
        e.first=x;
        e.second=y;
        red.push_back(e);
    }
    rep(i,0,n){
        int x,y;
        cin>>x>>y;
        pii e;
        e.first=y;
        e.second=x;
        blue.push_back(e);
    }
    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());
    bool fixed[n];
    fill(fixed,fixed+n,false);
    ll ans=0;
    rep(bi,0,n){
        int bx=blue[bi].second,by=blue[bi].first;
        int alt=-1;
        rep(ri,0,n){
            if(fixed[ri])continue;
            int rx=red[ri].first,ry=red[ri].second;
            if(bx>rx&&by>ry)alt=ri;
        }
        if(alt!=-1)fixed[alt]=true,ans++;
    }
    cout<<ans<<endl;
    return 0;
}




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

int main() {
    string S, T;
    cin >> S >> T;
    string tmp1 = S;
    string tmp2 = S;
    rep(i, S.size()) {
        tmp1 = tmp2[S.size() - 1];
        tmp1 += tmp2.substr(0, S.size() - 1);
        if (tmp1 == T) {
            cout << "Yes" << endl;
            return 0;
        }
        tmp2 = tmp1;
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

void Main() {
    vector<vector<int> > c(3, vector<int>(3, 0));
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> c[i][j];
        }
    }

    for (int a1 = -100; a1 <= 100; ++a1) {
        for (int a2 = -100; a2 <= 100; ++a2) {
            for (int a3 = -100; a3 <= 100; ++a3) {
                bool ok = true;
                int b1 = c[0][0] - a1;
                int b2 = c[1][1] - a2;
                int b3 = c[2][2] - a3;
                if (c[1][0] == a2 + b1 && c[2][0] == a3 + b1
                    && c[0][1] == a1 + b2 && c[2][1] == a3 + b2
                    && c[0][2] == a1 + b3 && c[1][2] == a2 + b3) {
                    cout << "Yes" << endl;
                    return;
                }
            }
        }
    }
    cout << "No" << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main()
{
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> accepts(N, K-Q);
    int Ai;
    for(int i=0;i<Q;i++){
        cin >> Ai;
        accepts[Ai-1]++;
    }
    for(auto v : accepts){
        if(v>0) cout<<"Yes"<<endl;
        else    cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define N	 100
int a, b,c, d;
void solve(){
	cin>>a>>b>>c;
	if(a+b>=c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N = INT()

print(2**int(log2(N)))

Measured memory_bytes: 5156
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pi 3.1415926535897932384
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18 ;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    ll i,a,b,c,r,k,n,s1=0;
    cin>>s;
    n=s.size()+1;
    ll arr[n];
    c=0;
    memset(arr,-1,sizeof(arr));
    for(i=n-2;i>=0;i--)
    {
        if(s[i]=='<')
        {
            c=0;
            continue;
        }
        else
        {
            if(c==0)
                arr[i+1]=0,c++;
            arr[i]=c;
            c++;
        }
    }
    c=0;
   for(i=0;i<=n-2;i++)
   {
       if(s[i]=='>')
       {
           c=0;
           continue;
       }
       else
       {
           if(c==0)
            arr[i]=max(c,arr[i]),c++;
           arr[i+1]=max(arr[i+1],c);
           c++;
       }
   }
   for(i=0;i<n;i++)
   {
       s1=s1+arr[i];
   }
  // cout<<s1<<endl;;
    cout<<accumulate(arr,arr+n,0LL)<<endl;
}


Measured memory_bytes: 4764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s;   cin >> s;
    int r = 0;
    rep(i, 3)   if(s[i] == 'R') r++;
    if(r == 2){
        if(s[1] == 'S') r = 1;
    }
    cout << r << endl;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		int max = 0;
		Integer[] ii = new Integer[N];
		for(int i = 0; i < N; i++){
			ii[i] = Integer.parseInt(br.readLine());
			max += ii[i];
		}

		//合計
		if (max % 10 > 0) { System.out.println(max); return; }

		//配列のソート
		Arrays.sort(ii);
		
		for(int i = 0; i < N; i++){
			if( (max-ii[i])%10>0 ) { System.out.println(max-ii[i]); return; }
		}

		System.out.println(0);
		return;
	}


}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


// nC2を求める関数
ll pair_conb(ll n) {
    return n*(n-1)/2;
}


double getTime(chrono::system_clock::time_point st,chrono::system_clock::time_point ed) {
    return static_cast<double>(chrono::duration_cast<chrono::microseconds>(ed - st).count() / 1000.0);
}

void solve() {
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];

    sort(ALL(A));
    // binary search (K番目の値である様なxを探す)
    // お気持ち的に NC2ループの二個目のforを二分探索にしてNlogNに計算量を落としおいる。
    ll left = -2e18, right = 2e18;
    while (right - left > 1) {
        // cnt はx(mid)よりも小さい数のカウンタ
        ll mid = (left+right)/2, cnt = 0;

        REP(i,N) {
            // 普通に書いたらO(N^2)だが、xを決め打ちするのと、Aの単調性を利用することでO(NlogN)に落とす。
            // 片方をA[i]と決定して,iより先にある値mで、A[i]*A[m] < x 以下である様な最大のmを二分探索で求める
            ll l = i, r = N;
            while ( r - l > 1) {
                ll m = (l+r)/2;
                if (A[i] >= 0) (A[i] * A[m] < mid) ? l = m : r = m;
                else (A[i] * A[m] < mid) ? r = m : l = m;

            }
            // l を足す(m) -> (r-l) == 0なら r = lなので自明
            // (r-l) == 1 なら m = (l+r)/2;から切り捨てられるので結局 (l+l)/2と同じなので l を使用する
            cnt += (A[i] >= 0) ? l - i : N - r;

        }
        // cnt が小さい -> xが小さい
        ( cnt < K) ? left = mid : right = mid;
    }
    cout << left << endl;
}
int main() {
    auto st = chrono::system_clock::now();
    solve();
    auto ed = chrono::system_clock::now();
    cerr << "end with: " << getTime(st,ed) << "ms" << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    int n, a, b, c;
    while(cin>>a>>b>>c){
        ll ans=0;
        ans=b+min(c, a+b+1);
        cout<<ans<<endl;
    }
  return 0;
}




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

#define MOD 1000000007LL
#define ll long long

using namespace std;

ll popcntandmod(ll n){
    ll nn = n;
    ll m = 0;
    while(n > 0){
        if((n & 1) == 1) m++;
        n >>= 1;
    }
    return nn % m;
}

int main(void){
    int N;
    cin >> N;
    string X;
    cin >> X;
    ll pX = 0;
    for(int i = 0; i < N; i++) pX += (X[i] == '1' ? 1 : 0);
    vector<ll> m_plus(N), m_minus(N);
    
    ll b;
    b = 1;
    ll pM_plus = 0;
    if(pX < N){
        for(int i = 0; i < N; i++){
            m_plus[i]  = b % (pX + 1);
            if(X[N - i - 1] == '1'){
                pM_plus += m_plus[i];
                pM_plus %= pX + 1;
            }
            b <<= 1;
            b %= pX + 1;
        }
    }
    b = 1;
    ll pM_minus = 0;
    if(1 < pX){
        for(int i = 0; i < N; i++){
            m_minus[i] = b % (pX - 1);
            if(X[N - i - 1] == '1'){
                pM_minus += m_minus[i];
                pM_minus %= pX - 1;
            }
            b <<= 1;
            b %= pX - 1;
        }
    }

    // for(int i = 0; i < N; i++) cout << m_plus[i] << " " << m_minus[i] << endl;

    for(int i = 0; i < N; i++){
        if(X[i] == '0'){
            ll X = pM_plus + m_plus[N - i - 1];
            X %= pX + 1;
            ll ans = 1;
            while(X != 0){
                // cout << "\t" << X << endl;
                ans++;
                X = popcntandmod(X);
            }
            cout << ans << endl;
        }else{
            ll X = pM_minus - m_minus[N - i - 1] + pX - 1;
            if(pX - 1 == 0){
                cout << 0 << endl;
                continue;
            }
            X %= pX - 1;
            ll ans = 1;
            while(X != 0){
                // cout << "\t" << X << endl;
                ans++;
                X = popcntandmod(X);
            }
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6824
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int f;
  int cnt=0;
  while(cin>>s){
    f=0;
    for(int i=0;i<s.size();i++){
      if(s[i] != s[s.size()-1-i]){
	f=1;
      }
    }
    if(f==0) cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 1184
#include <stdio.h>

int main(){
    int array[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;

    scanf("%d", &k);

    printf("%d", array[k-1]);

    return 0;
}

Measured memory_bytes: 128
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{
  vll a(3);
  rep(i,3) cin >> a[i];

  vsort(a);

  ll ans = a[0] * a[1];

  if((a[0] * a[1] * a[2]) % 2 == 0)
  {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        x: u64,
        y: u64,
        z:u64,
    }

    println!("{} {} {}", z, x, y);
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
		// 出力
      if(a+b == c){
		System.out.println("Yes");
      }else if(a+c == b){
        System.out.println("Yes");
      }else if(b+c == a){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
	}
}

Measured memory_bytes: 35680
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    string s;

    cin >> s;

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
        cout << "Bad" <<endl;
    } else {
        cout << "Good" << endl;
    }

    return 0;
}

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

using namespace std;
using ll=long long;
using vl=vector<ll>;


#define all(a) a.begin(),a.end()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<n;i++)
#define LINF ((ll)1ll<<60)

int main(){
    string g;
    while(cin>>g, g!="#"){
        int y,m,d;
        cin>>y>>m>>d;
        if(y>31 or (y==31 and m>4)){
            cout<<'?'<<' '<<y-30<<' '<<m<<' '<<d<<endl;
        }else{
            cout<<g<<' '<<y<<' '<<m<<' '<<d<<endl;
        }
    }
}


Measured memory_bytes: 3164
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	int n, x;
	cin >> n >> x;

	vi vec(n);
	REP(i, n) {
		cin >> vec[i];
	}

	LL cnt = 0;
	FOR(i, 1, n) {
		if (vec[i - 1] + vec[i] <= x) continue;

		if (x <= vec[i - 1]) {
			cnt += vec[i];
			vec[i] = 0;

			cnt += vec[i - 1] - x;
			vec[i - 1] -= vec[i - 1] - x;
		} else {
			cnt += vec[i] - (x - vec[i - 1]);
			vec[i] = x - vec[i - 1];
		}
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

int main(){
  char buf[1024];
  int N,M;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d", &N, &M);

  if(N<M){
    printf("%d\n", 0);
  }
  else{
    printf("%d\n", 10);
  }

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
ll N,P;
ll ans=1;
ll prime_factor(ll n){
    map<ll, ll> res;
    for (ll i=2; i*i<=n; i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
        ans*=pow(i,res[i]/N);
    }
    if (n!=1) ans*=pow(n,1/N);
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>> N>>P;
    cout << prime_factor(P)<<"\n";
}


Measured memory_bytes: 26240
#include <stdio.h>
int main(){
  int i,j,n,flag=1,hozon,cnt=0;
  scanf("%d",&n);
  int hai[n];
  for(i=0;i<n;i++)
    scanf("%d",&hai[i]);
  
  while(flag){
    flag=0;
    for(j=n-1;j>0;j--){
      if(hai[j]<hai[j-1]){
	hozon=hai[j-1];
	hai[j-1]=hai[j];
	hai[j]=hozon;
	flag=1;
	cnt+=1;
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d",hai[i]);
    if(i==n-1) printf("\n");
    else printf(" ");
  }
  printf("%d\n",cnt);

  return 0;
}

Measured memory_bytes: 604
n, m = gets.split.map(&:to_i)
l, r = m.times.map{gets.split.map(&:to_i)}.transpose
min = 1
max = n
for i in 0..(m-1)
  min = l[i] if min < l[i]
  max = r[i] if max > r[i]
end
if max >= min
  puts max - min + 1
else
  puts 0
end

Measured memory_bytes: 11132
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1005

int N;
int H,W;
int table[NUM][NUM];

int main(){

	H = NUM-1;
	W = NUM-1;

	for(int row = 0; row <= H; row++){
		for(int col = 0; col <= W; col++){
			table[row][col] = 0;
		}
	}

	scanf("%d",&N);

	int x1,y1,x2,y2;

	for(int loop = 0; loop < N; loop++){

		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
		table[y1][x1]++;
		table[y1][x2]--;
		table[y2][x1]--;
		table[y2][x2]++;
	}

	int ans = 0;

	//左→右に足す
	for(int row = 0; row < H; row++){
		for(int col = 1; col < W; col++){
			table[row][col] += table[row][col-1];
		}
	}

	//上→下に足す
	for(int col = 0; col < W; col++){
		for(int row = 1; row < H; row++){
			table[row][col] += table[row-1][col];
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			ans = max(ans,table[row][col]);
		}
	}

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

	return 0;
}



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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,p,f[200020];
void solve(){
    string s;
    cin>>n>>p>>s;

    ll ans=0;

    if(p==2 or p==5)
    {
    	for(int i=0;i<n;i++)
			if((s[i]-'0')%p==0) ans+=i+1;
		printf("%lld",ans);
    	return;
    }

    f[0]=1;
    int cur=1,mod=0;
    for(int i=sz(s)-1;i>=0;i--){
        mod=(mod+cur*(s[i]-'0'))%p;
        cur=cur*10%p;
        ans+=f[mod];
        f[mod]++;
    }
    cout<<ans<<endl;
}

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

Measured memory_bytes: 3840
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for (int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EB emplace_back
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, n) (s.find(n) != s.end())

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;
#define int LL
signed main(void) {
    int N; cin >> N;
    VI a(N);
    LL ans = 0;
    VI id(N);
    //id[num] = num id in array
    REP(i, N) {
        scanf("%d", &a[i]);
        id[a[i] - 1] = i;
    }
    set <int> se;
    se.insert(-1);
    se.insert(N);
    REP(_, N) {
        int i = id[_];
        int l = *se.lower_bound(i) + 1;
        int r = *(--se.upper_bound(i)) - 1;
        se.insert(i);
        ans += a[i] * ((i - l + 1) * (r - i + 1));
    }
    cout << ans << endl;
}


Measured memory_bytes: 12800
//39
#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

short gg[5001][5001];

int main(){
  int n,m;
  cin>>n>>m;
  short (*g)[5001]=gg;//(short(*)[5001])malloc(sizeof(short)*5001*5001);
  fill(g[0],g[5000],-1);
  while(m--){
    int a,b,x;
    cin>>a>>b>>x;
    g[a-1][b-1]=x;
  }
  int a=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<=i;j++){
      a+=g[i][j]>=0;
      g[i+1][j]=max<short>(g[i+1][j],g[i][j]-1);
      g[i+1][j+1]=max<short>(g[i+1][j+1],g[i][j]-1);
    }
  }
  cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 50008
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
    int n,k;
    cin >>n >>k;

    if(k == 1 || n == k){
        printf("0\n");
    }else{
        printf("%d\n", n-k);
    }
    return 0;
}

Measured memory_bytes: 256