akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

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

  ll ans = (x / 11) * 2;
  ans += (x % 11 == 0 ? 0 : (x % 11 <= 6 ? 1 : 2));

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int month = scanner.nextInt();
        int day = scanner.nextInt();

        if (month<=day){
            System.out.println(month);
        }else {
            System.out.println(month-1);
        }



        scanner.close();
    }
}


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


int main() {
	int N,ansX,ansY,ansH,xt,yt,ht,Ht;
	cin>>N;
	vector<int> x(N),y(N),h(N);
	rep(i,N){
		cin>>x[i]>>y[i]>>h[i];
		if(h[i]!=0){
			xt=x[i],yt=y[i],ht=h[i];
		}
	}
	rep(X,101)rep(Y,101){
		Ht = ht+abs(xt-X)+abs(yt-Y);
		int cnt = 0;
		rep(i,N){
			if(h[i]==max(0,Ht-abs(X-x[i])-abs(Y-y[i]))){
				cnt++;
			}
		}
		if(cnt==N){
		ansX=X,ansY=Y,ansH=Ht;
		break;		
		}
	}
	cout<<ansX<<' '<<ansY<<' '<<ansH<<endl;
}


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

int main(){
  int A, B, C, X;
  int count = 0;
  cin >> A >> B >> C >> X;
  for(int i=0; i<=A; i++){
    for(int j=0; j<=B; j++){
      for(int k=0; k<=C; k++){
        if(10*i+2*j+k==X/50){
          count +=1;
        }
      }
    }
  }
  cout << count;
}

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

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

inline int readInt() {
	int n, c;
	while ((c = getchar()) < '0');
	n = c - '0';
	while ((c = getchar()) >= '0') {
		n = n * 10 + c - '0';
	}
	return n;
}

const int N = 5000;
const int M = 200;

struct Stack {
	short dat[N + 1];
	short sp;

	void push(short v) {
		dat[sp++] = v;
	}

	void pop() {
		sp--;
	}

	short fst() {
		return dat[sp - 1];
	}

	short snd() {
		return dat[sp - 2];
	}
};

int n, m;
Stack mono[M];
int b[N + 1][M];
long long a[N];

struct Tuple {
	long long val, imos;
};
Tuple tup[N + 1];

int main() {
	n = readInt();
	m = readInt();
	for (int i = 1; i < n; i++) {
		a[i] = readInt() + a[i - 1];
		tup[i].val -= a[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			b[i][j] = readInt();
		}
	}
	for (int i = 0; i < m; i++) {
		b[n][i] = 2e9;
		mono[i].push(n);
	}

	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j < m; j++) {
			while (b[mono[j].fst()][j] <= b[i][j]) {
				int l = mono[j].fst();
				int r = mono[j].snd();
				int v = b[l][j];
				mono[j].pop();
				tup[l].imos -= v;
				tup[r].imos += v;
			}
		}
		long long sum = 0;
		for (int j = 0; j < m; j++) {
			tup[mono[j].fst()].imos -= b[i][j];
			mono[j].push(i);
			sum += b[i][j];
		}
		long long u = -1e18;
		for (int j = i; j < n; j++) {
			sum += tup[j].imos;
			tup[j].imos = 0;
			tup[j].val += sum;
			u = max(u, tup[j].val);
		}
		ans = max(ans, u + a[i]);
	}
	cout << ans << endl;
}

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

void solve() {
    int n;
    cin >> n;
    int cnt = n / 2;
    if (n % 2 == 1) ++cnt;
    cout << (double)cnt / n << endl;
}

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

    int t = 1;
    while(t--) {
        solve();
    }
}


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

using namespace std;

typedef long long ll;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(15);
    int N;
    cin >> N;
    if (N == 1) {
        cout << "Hello World\n";
        return 0;
    } else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}


Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmpArray = br.readLine().split(" ");
		int q = Integer.parseInt(tmpArray[0]);
		int h = Integer.parseInt(tmpArray[1]);
		int s = Integer.parseInt(tmpArray[2]);
		int d = Integer.parseInt(tmpArray[3]);
		
		Product[] products = new Product[4];
		
		products[0] = new Product(0.25,q);
		products[1] = new Product(0.5,h);
		products[2] = new Product(1,s);
		products[3] = new Product(2,d);
		
		Arrays.sort(products, new Comparator<Product>() {
			public int compare(Product a, Product b){
				if( a.pricePerLitterD() > b.pricePerLitterD()){
					return 1;
				}
				else if ( a.pricePerLitterD() < b.pricePerLitterD()){
					return -1;
				}
				else {
					return 0;
				}
			}
		});
		
		long result = 0;
		int require = Integer.parseInt(br.readLine());
		for(int i = 0; i < 4; i++){
			if(products[i].amount == 2){
				if(require <= 1){
					continue;
				}
//				result += products[i].pricePerLitter()*(require/2*2);
//				require -= require/2*2;
				result += (long)products[i].price*(require/2);
				require -= require/2*2;
			}
			else {
				result += products[i].pricePerLitter()*require;
				require = 0;
			}
			
			if(require == 0){
				break;
			}
		}
		System.out.println(result);
	}

}

class Product {
	double amount;
	int price;
	
	public Product(double amount, int price){
		this.amount = amount;
		this.price = price;
	}
	
	public long pricePerLitter(){
	//	return (long)(price/amount);
		if(amount == 0.25){
			return (long)price*4;
		}
		else if(amount == 0.5){
			return (long)price*2;
		}
		else if(amount == 1){
			return price;
		}
		else {
			return price/2;
		}
	}
	
	public double pricePerLitterD(){
		//	return (long)(price/amount);
			if(amount == 0.25){
				return price*4;
			}
			else if(amount == 0.5){
				return price*2;
			}
			else if(amount == 1){
				return price;
			}
			else {
				return (double)price/2;
			}
		}
}


Measured memory_bytes: 23380
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int x;
    string s;
    cin>>x>>s;
    if(x%2==0&&s.substr(0,x/2)==s.substr(x/2))
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846
 
typedef long long ll;
typedef pair< int, int > P;   
typedef pair< ll, P > PP;

//-----------------------------------------------------------------------------

int n;
ll a;
ll imos[200010];
map<ll, ll> mp;

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

	cin >> n;
	REP(i, n) {
		cin >> a;
		imos[i + 1] = imos[i] + a;
	}
	REP(i, n + 1) {
		mp[imos[i]]++;
	}
	ll ans = 0;
	for (auto x: mp) {
		if (x.se >= 2) {
			ans += x.se * (x.se - 1) / 2;
		}
	}
	cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 14336
/* Author	: Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define jehian using
#define mau namespace
#define libur std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(NULL);}

jehian mau libur;
/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n");
#define sp printf(" ");

/* MACROS FOR FUNCTION */
#define pb push_back
#define mp make_pair
#define eb emplace_back

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

vll data;
int main(){
	ll N;
	cin >> N;
	for (ll i = 0; i < N; ++i){
		ll temp;
		cin >> temp;
		data.pb(temp);
	}
	ll cnt = 0;
	for (ll i = 0; i < N - 1; ++i){
		if (data[i] == i+1){
			swap(data[i], data[i+1]);
			++cnt;
		}
	}
	if (data[N-1] == N){
		swap(data[N-1],data[N-2]);
		++cnt;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d", &n);
	int res = 0;
	for (int i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		if (x & 1) res++;
	}
	printf(res & 1 ? "NO\n" : "YES\n");
	return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <ll> a(N);
	vector <ll> idx(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> a[ii];
		idx[a[ii]-1] = ii;
	}

	ll ans = 0;
	set<ll> s;
	s.insert(-1);
	s.insert(N);
	for (int ii = 0; ii < N; ++ii){
		ll val = ii + 1;
		//idx[ii]を基準にlidxを求める
		auto itr = s.upper_bound(idx[ii]);
		ll ridx = *itr - 1;
		itr--;
		ll lidx = *itr + 1;
		s.insert(idx[ii]);

		//ansに追加
		ans += val * (idx[ii] - lidx + 1) * (ridx - idx[ii] + 1);
	}

	cout << ans << endl;

	return 0;
}


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

const unsigned long mod = 998244353;
long n;
long f;
long g[10000001];
long p[10000001];

long power(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return power(b, e - 1) * b % mod;
  long t = power(b, e / 2);
  return t * t % mod;
}

long inv(long n) {
  return power(n, mod - 2);
}

void pre() {
  p[0] = 1;
  for (int i = 1; i <= n; ++i) {
    p[i] = p[i - 1] * 2;
    if (p[i] >= mod) p[i] -= mod;
  }
  f = 1;
  for (int i = 1; i <= n; ++i) {
    f = f * i % mod;
  }
  g[n] = inv(f);
  for (int i = n; i >= 1; --i) {
    g[i - 1] = g[i] * i % mod;
  }
}

long sub(long k) {
  return p[n - k] * g[k] % mod * g[n - k] % mod;
}

int main() {
  cin >> n;
  pre();
  long sum = 0;
  for (int k = n; 2 * k > n; --k) {
    sum += sub(k);
    if (sum >= mod) sum -= mod;
  }
  cout << (power(3, n) - 2 * f * sum % mod + mod) % mod << endl;
}

Measured memory_bytes: 156544
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long int ll;
 ll  p=1e9+7; 

 int  main() {
        ff;
       
       ll a,b,n;
       cin>>a>>b>>n;
       
       ll x=min(b-1,n);
       
       ll ans=(a*x)/b-a*(x/b);
       cout<<ans<<endl;
       
       
    
       
      
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define check system("pause")
#define all(x) (x).begin(),(x).end()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 0x3f3f3f3f
const ll mod = 1e9+7;
const int N = 1e6+20;
#define dep(i,a,b) for(int i=(a);i>=(b);i--)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define mes(p,b) memset(p,b,sizeof(p))
#define sz(x) int(x.size())

int main()
{
  	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll x;
	cin>>x;
	ll t=100;
	rep(i,1,10000000){
		t*=1.01;
		if(t>=x){
			cout<<i;return 0;
		}
	}
  	return 0;
}



Measured memory_bytes: 3648
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

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

    std::cout << (s == "AAA" || s == "BBB" ? "No" : "Yes") << std::endl;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  vector<int> nishi(N+1);
  vector<int> higashi(N+1);
  for( int i = 0; i < N+1; i++ ){
    if( i == 0 ){
      nishi.at(0) = 0;
      higashi.at(0) = 0;
    }else{
      if( S.at(i-1) == 'W' ){
        nishi.at(i) = nishi.at(i-1) + 1;
        higashi.at(i) = higashi.at(i-1);
      }else if( S.at(i-1) == 'E' ){
        higashi.at(i) = higashi.at(i-1) + 1;
        nishi.at(i) = nishi.at(i-1);
      }
    }
  }
  
  int ans = N;
  for( int i = 0; i < N; i++ ){
    if( ans > nishi.at(i) + ( higashi.at(N) - higashi.at(i+1) ) ){
      ans = nishi.at(i) + ( higashi.at(N) - higashi.at(i+1) );
    }
  }
  cout << ans << endl;
    
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
vector<int> A [301];
int L [300],X [300];
struct P{
	int r,g,b;
};
int dp [301] [301] [301];
const int MOD = 1e9 + 7;

int main()
{
	scanf("%d%d",&N,&M);
	FOR(i,0,M){
		int l,r,x;
		scanf("%d%d%d",&l,&r,&x);
		A [r].push_back(i);
		L [i] = l;
		X [i] = x;
	}
	queue<P> q;
	q.push(P{0,0,0});
	dp [0] [0] [0] = 1;
	FOR(i,1,N) FOR(j,0,i) FOR(k,0,i){
		q.push(P{i,j,k});
		q.push(P{j,k,i});
		q.push(P{k,i,j});
		while(q.empty() == false){
			int r = q.front().r,g = q.front().g,b = q.front().b;
			q.pop();
			int nxt = max({r,g,b}) + 1;
			{
				int nr = nxt,ng = g,nb = b;
				bool ok = true;
				for(const auto& it : A [nxt]){
					ok &= (nr >= L [it]) + (ng >= L [it]) + (nb >= L [it]) == X [it];
				}
				if(ok){
					(dp [nr] [ng] [nb] += dp [r] [g] [b]) %= MOD;
				}
			}
			{
				int nr = r,ng = nxt,nb = b;
				bool ok = true;
				for(const auto& it : A [nxt]){
					ok &= (nr >= L [it]) + (ng >= L [it]) + (nb >= L [it]) == X [it];
				}
				if(ok){
					(dp [nr] [ng] [nb] += dp [r] [g] [b]) %= MOD;
				}
			}
			{
				int nr = r,ng = g,nb = nxt;
				bool ok = true;
				for(const auto& it : A [nxt]){
					ok &= (nr >= L [it]) + (ng >= L [it]) + (nb >= L [it]) == X [it];
				}
				if(ok){
					(dp [nr] [ng] [nb] += dp [r] [g] [b]) %= MOD;
				}
			}
		}
	}

	int ans = 0;
	FOR(i,0,N) FOR(j,0,N){
		(ans += dp [N] [i] [j]) %= MOD;
		(ans += dp [j] [N] [i]) %= MOD;
		(ans += dp [i] [j] [N]) %= MOD;
	}
	printf("%d\n",ans);

	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

int c[maxn] , id , ans[maxn] ;

vector <int> g[maxn] ;

void dfs(int u , int par)
{
    ans[u] = c[id--] ;

    for(auto v: g[u])
    {
        if(v==par) continue ;
        dfs(v,u) ;
    }
    return ;
}

int main()
{
    int n ;
    scanf("%d",&n) ;

    for(int i=1 ; i<n ; i++)
    {
        int u , v ;
        scanf("%d %d",&u,&v) ;
        g[u].pb(v)  ; g[v].pb(u) ;
    }

    for(int i=1 ; i<=n ; i++) scanf("%d",&c[i]) ;
    sort(c+1,c+n+1) ;

    id = n ;

    dfs(1,0) ;

    int ret = 0;
    for(int i=1 ; i<n ; i++) ret += c[i] ;

    printf("%d\n",ret) ;
    for(int i=1 ; i<=n ; i++) printf("%d ",ans[i]) ;
    printf("\n") ;

    return 0 ;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define fp(i,l,r) for(register int i=(l);i<=(r);++i)
#define fd(i,l,r) for(register int i=(l);i>=(r);--i)
using namespace std;
int main(){
	int n,a;
	scanf("%d%d",&n,&a);
	printf("%d\n",n*n-a);
	return 0;
}

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

int main(){
    string S; cin >> S;
    if(S.at(0)!='A'){
        cout << "WA" << endl; return 0;
    }
    int cnt=0;
    for(int i=2;i<S.size()-1; i++){
        if(S.at(i)=='C') {cnt++; S.at(i)='c';}
    }
    if(cnt!=1) {cout << "WA" << endl; return 0;}
    for(int i=1; i<S.size(); i++){
        if( (S.at(i) -'a') >25  || (S.at(i)-'a') <0){
            cout <<"WA" << endl; return 0;
        }
    }
    cout << "AC" << endl;
}

Measured memory_bytes: 256
def main():
  n, l = map(int, input().split())
  u = l + n - 1
  v = (l + u) * n // 2

  if u * l <= 0:
    print(v)
  elif u > 0:
    print(v - l)
  else:
    print(v - u)


if __name__ == '__main__':
  main()


Measured memory_bytes: 38384
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define ll long long

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

const ll INF = 1LL << 60;
const ll MAX = 100100;
const ll MAX_N = 100100;
const ll MAX_M = 100100;

int main() {
    int N;
    cin >> N;
    for(int i = 1; i < 10; i++) {
        for(int j = 1; j < 10; j++) {
            if(i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import math
n,d = map(int,input().split())
x = []
for i in range(n):
    temp = list(map(int,input().split()))
    x.append(temp)

ans = 0
for i in range(n):
    for k in range(i+1,n):
        dist = 0
        for j in range(d):
            dist += (x[i][j]-x[k][j])**2
        if dist == (math.floor(dist**0.5))**2:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main(void)
{
     int i,j,k,n,m,s=0;
     scanf("%d",&n);
     for(i=0;i<n;i++)
     {
          scanf("%d%d",&j,&k);
          s+=k-j+1;
     }
     printf("%d\n",s);
     return 0;
}


Measured memory_bytes: 256
def solve(n, m, x)
  return 0 if n >= m

  x.map!(&:to_i).sort!
  total = x[-1] - x[0]
  return total if n == 1

  d = (0...(m - 1))
        .map {|i| x[i + 1] - x[i] }
        .sort! {|a, b| b <=> a }
        .take(n - 1)
        .reduce{|a,e| a + e}
  total - d
end

stdin = STDIN.gets
nm = stdin.split(/\s/)
n = nm[0].to_i
m = nm[1].to_i
stdin = STDIN.gets
x = stdin.split(/\s/)

puts(solve(n, m, x))


Measured memory_bytes: 9500
#include<stdio.h>
int main()
{
	int n,k,p[1000],i,j,a=0,c=0,b=0;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
		b+=p[i];
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(p[i]<p[j]){
				a=p[j];
				p[j]=p[i];
				p[i]=a;
			}
		}
	}
	for(i=0;i<n-k;i++){
		b-=p[i];
	}
	printf("%d\n",b);
	return 0;
}


Measured memory_bytes: 1720
#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

height = list(map(float,open(0).read().split()))
print(max(height) - min(height))


Measured memory_bytes: 8928
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int main(){
    
multimap<int,int>d;

int N;
cin >> N;
int x;
for(int i=0;i<N;i++){
    cin >> x;
    d.insert(make_pair(x,i));
}
int count=0;
int ans;
for(auto i=d.begin();i!=d.end();i++){
count++;
if(count==N/2){
    ans=i->first;
    i++;
    ans=((i->first)-ans);
    break;
}

}

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

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main() {
    
    int n;
    cin>>n;
    vector<int>arr(n);
    for(int i=0;i<n;i++)
    cin>>arr[i];
    string ans="APPROVED";
    for(int i=0;i<n;i++)
    if(arr[i]%2==0)
    {
        if(arr[i]%3==0 || arr[i]%5==0)
        continue;
        else 
        {
            ans="DENIED";
            break;
        }
    }
    cout<<ans;
//     int a,b,c;
//     cin>>a>>b>>c;
//     if(a==b && a==c || a!=b && b!=c && a!=c)
//     cout<<"No";
//     else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

func Solve() {
  var N int
  NextInt(&N)
  var A []int
  NextIntVec(&A)
  DP := make([][]int, N)
  DP2 := make([][]int, N)
  for i := range DP {
    DP[i] = make([]int, 16)
    DP2[i] = make([]int, 16)
    for j := range DP[i] {
      DP[i][j] = j
      DP2[i][j] = j
    }
  }
  for i := N - 2; 0 <= i; i-- {
    k := 0
    for a := A[i + 1]; a < A[i]; a *= 4 { k++ }
    for a := A[i]; 4 * a <= A[i + 1]; a *= 4 { k-- }
    for j := range DP[i] {
      DP[i][j] += DP[i + 1][MaxInt(MinInt(j + k, 15), 0)]
      DP[i][j] += (N - 1 - i) * MaxInt(j + k - 15, 0)
    }
  }
  for i := 1; i < N; i++ {
    k := 0
    for a := A[i - 1]; a < A[i]; a *= 4 { k++ }
    for a := A[i]; 4 * a <= A[i - 1]; a *= 4 { k-- }
    for j := range DP2[i] {
      DP2[i][j] += DP2[i - 1][MaxInt(MinInt(j + k, 15), 0)]
      DP2[i][j] += i * MaxInt(j + k - 15, 0)
    }
  }
  C := make([]int, N + 1)
  for i := range C {
    C[i] = i
  }
  for i := range DP {
    C[i] += 2 * DP[i][0]
    C[i + 1] += 2 * DP2[i][0]
  }
  Write(MinInt(C...))
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 66944
import time
import random
import math

def dfs(i, s):
    if (i == 4):
        if (eval(s) == 7): return s
        else: return ""
    
    b = dfs(i + 1, s + "+" + str(a[i]))
    c = dfs(i + 1, s + "-" + str(a[i]))
    if (b != ""): return b
    else: return c

a = input()
print(dfs(1, str(a[0])) + "=7")




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

h=[int(x) for x in input().split()]


flag = True

if n==1:
    print('Yes')
else:
    for i in range(n-1):
        l=h[i]
        r=h[i+1]
        if l < r:
            h[i+1]-=1
        else:
            h[i+1]=l
        if l > r:
            flag=False

    if flag:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 14228
#include<iostream>
#include<vector>
// #include<climits>
#include<algorithm>
// #include<string>
// #include<stack>
// #include<queue>

using namespace std;

// long long int pe(long long int n, long long int k) 
// { 
//     long long int P[n + 1][k + 1]; 
//     for (long long int i = 0; i <= n; i++) 
//     { 
//         for (long long int j = 0; j <= min(i, k); j++) 
//         { 
//             if (j == 0) 
//                 P[i][j] = 1; 
//             else
//                 P[i][j] = P[i - 1][j] +  
//                           (j * P[i - 1][j - 1]); 
//             P[i][j + 1] = 0; 
//         } 
//     } 
//     long long int ans = 0;
//     // cout<<P[5][2]<<endl;
//     for(long long int i=1;i<=n;i++) {
//         ans += i%P[n][i];
//         // cout<<"this "<<P[n][i]<<endl;
//         cout<<i%P[n][i]<<endl;
//     }
//     return ans;
// } 

int main(){
    unsigned long long int n;
    cin>>n;
    unsigned long long int a, b;
    if(n%2==0){
        a = n/2;
        b = n-1;
    }
    else{
        a = (n-1)/2;
        b=n;
    }
        
    cout<<a*b<<endl;
}

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

const long long inf = 1e15 + 7;

long long get_sum(vector<long long> &prefix, int left, int right)
{
	if(left != 0)
		return prefix[right] - prefix[left-1];
	else
		return prefix[right];
}

void Slimes(vector<long long> &a)
{
	int n = a.size();
	vector<long long> prefix = a;
	
	for(int i = 1; i < n; i++)
		prefix[i] += prefix[i-1];

	vector<vector<long long>> dp(n, vector<long long>(n, inf));

	/* dp[i][j] represents the min cost to compress arr[i...j] to 
	 * a single element
	 */

	for(int i = n - 1; i >= 0; i--)
	{
		for(int j = i; j < n; j++)
		{
			if(i == j)
			{
				dp[i][j] = 0;
				continue;
			}

			for(int k = i; k < j; k++)
			{
				auto current_cost = get_sum(prefix, i, j);
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + current_cost);
			}
		}
	}

	cout << dp[0][n-1] << endl;
}

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

	vector<long long> a(n);
	for(auto &ele : a)
		cin >> ele;

	Slimes(a);
	return 0;
}



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

int main(){
	int N; cin>>N;
	int r = 0, n = 0;
	vector<int> A(N);
	rep(i, N){ cin>>A[i]; n = max(n, A[i]); }
	rep(i, N) if(abs(n/2 - r) > abs(n/2 - A[i])) r = A[i];
	cout<< n <<" "<< r <<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
 
using namespace std;
 
#define MAX 10000
#define INFTY (1 << 29)
 
class DisjointSet{
    public:
        vector<int> rank, p;
 
        DisjointSet(){}
        DisjointSet(int size){
            rank.resize(size,0);
            p.resize(size,0);
            for(int i=0;i < size;i++) makeSet(i);
        }
 
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
 
        bool same(int x, int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }
 
        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }
 
        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};
 
class Edge{
public:
    int source, target, cost;
    Edge(int source = 0, int target = 0, int cost = 0):
    source(source), target(target), cost(cost){}
    bool operator < (const Edge &e) const{
        return cost < e.cost;
    }
};
 
int kruskal(int N, vector<Edge> edges){
    int totalCost = 0;
    sort(edges.begin(), edges.end());
 
    DisjointSet dset = DisjointSet(N + 1);
 
    for(int i = 0; i < N; i++) dset.makeSet(i);
 
    int source, target;
    for(int i = 0; i < edges.size(); i++){
        Edge e = edges[i];
        if(!dset.same(e.source, e.target)){
 
            totalCost += e.cost;
            dset.unite(e.source, e.target);
        }
    }
    return totalCost;
}
 
 
int main(){
    int N, M, cost;
    int source, target;
 
    cin >> N >> M;
 
    vector<Edge> edges;
    for(int i = 0; i < M; i++){
        cin >> source >> target >> cost;
        edges.push_back(Edge(source, target, cost));
    }
 
    cout << kruskal(N, edges) << endl;
 
    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> a(N), b(N);
	for (int i = 1, p; i <= N;i++) {
		cin >> p;
		a[p - 1] = i;
		b[p - 1] = i;
	}
	for (int i = 1; i < N;i++) {
		a[i] = a[i - 1] + a[i];
		b[N - i - 1] = b[N - i] + b[N - i - 1];
	}
	cout << a[0];
	for (int i = 1; i < N;i++) {
		cout << ' ' << a[i];
	}
	cout << endl;
	cout << b[0];
	for (int i = 1; i < N; i++) {
		cout << ' ' << b[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main() {
    fastIO
    long long int  n,sum=0;
    cin >> n;
    for(int i=1; i<=n; i++){
        if(i%3==0 || i%5==0){
            continue;
        }
        sum += i;
    }
    cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        String a = sc.next();
        sc.close();
        int ans = 1;
        String s[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

        for (int i = 0; i < 7; i++) {
            if (s[i].equals(a)) {
                ans = 7 - i;
                break;
            }
        }
        // 出力
        System.out.println(Integer.toString(ans));
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	int n;
	cin>>n;
	int ans=0;
	if(n%1000==0){
	    ans=0;
	}
	else{
	    int x=(n/1000)+1;
	    ans=(x*1000)-n;
	    
	}
	cout<<ans<<endl;
	    
	    
	    
	    
	  return 0; 
	}
	


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

//ll a[220000];
int main(){
    ll n,k,a,b,ans=0;
    cin>>k;
    ll c=100,cnt=0;
    while(c<k){
        c*=1.01;
        cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 3640
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line1 = sc.nextLine().split(" ");
        Integer N = Integer.parseInt(line1[0]);
        Integer K = Integer.parseInt(line1[1]);
        List<Integer> values = Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt)
                .collect(Collectors.toList());
        Integer[] valArray = values.toArray(new Integer[values.size()]);
        sc.close();

        // 期待値の計算
        Map<Integer, Double> valMap = new HashMap<>();
        for (int i = 0; i < N; i++) {
            Double val = ((double) (1 + valArray[i]) / (double) 2);
            if (Objects.isNull(valMap.get(valArray[i]))) {
                valMap.put(valArray[i], val);
            }
        }

        // 累積和の計算
        Double[] S = new Double[N + 1];
        S[0] = (double) 0;
        for (int i = 0; i < N; i++) {
            int a = valArray[i];
            Double val = S[i] + valMap.get(a);
            S[i + 1] = val;
        }

        // 各隣接分の値を計算
        Double max = (double) 0;
        for (int i = 0; i <= N - K; i++) {
            Double val = S[i + K] - S[i];
            if (val > max) {
                max = val;
            }
        }

        System.out.println(max);
    }

}


Measured memory_bytes: 62688
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n; string s;
vector<pair<string, string>>le, ri;
signed main() {
	cin >> n >> s;
	rep(i, 1 << n) {
		string p = "", q = "", r = "", u = "";
		rep(j, n) {
			if (i >> j & 1) {
				p += s[j]; r += s[n + j];
			}
			else {
				q += s[j]; u += s[n + j];
			}
		}
		le.push_back({ p,q });
		ri.push_back({ r,u });
	}
	sort(all(ri));
	int ans = 0;
	for (auto p : le) {
		string red = p.first, blue = p.second;
		reverse(all(red)); reverse(all(blue));
		int index = upper_bound(all(ri), mkp(blue, red)) - lower_bound(all(ri), mkp(blue, red));
		ans += index;
	}
	cout << ans << endl;
}


Measured memory_bytes: 67288
def dijkstra(v, G):
    import heapq

    ret = [10 ** 20] * len(G)
    ret[v] = 0
    q = [(ret[i], i) for i in range(len(G))]
    heapq.heapify(q)

    while len(q):
        tmpr, u = heapq.heappop(q)
        if tmpr == ret[u]:
            for w, l in G[u]:
                if ret[w] > ret[u] + l:
                    ret[w] = ret[u] + l
                    heapq.heappush(q, (ret[w], w))
    return ret


N, M, S = map(int, input().split())
UVAB = [tuple(map(int, input().split())) for _ in range(M)]
CD = [tuple(map(int, input().split())) for _ in range(N)]

maxA = max([a for u, v, a, b in UVAB])
Q = maxA * (N - 1) + 1
G = [[] for _ in range(Q * N)]

for u, v, a, b in UVAB:
    for q in range(Q):
        if q >= a:
            G[Q * (u - 1) + q].append((Q * (v - 1) + q - a, b))
            G[Q * (v - 1) + q].append((Q * (u - 1) + q - a, b))

for n, (c, d) in enumerate(CD):
    for q in range(Q):
        G[Q * n + q].append((Q * n + min(Q - 1, c + q), d))

ans = dijkstra(min(S, Q - 1), G)
for n in range(1, N):
    print(min(ans[Q * n:Q * (n + 1)]))


Measured memory_bytes: 126344
#include <cstdio>
#include <algorithm>
#include <map>
#include <iostream> 
#include <queue>
#include <cstring>
#define INF 0x3f3f3f3f

const int MAXN = 1e5 + 1, MAXM = 2e5 + 1;

int n, m;

struct Edge { int ver, nxt, val; } edge[MAXM << 3];
int head[MAXN << 3], tot = 0;
inline void Ins(int x, int y, int z) { edge[++tot].ver = y, edge[tot].val = z, edge[tot].nxt = head[x], head[x] = tot; }

std :: map<std :: pair<int, int>, int> ex;
int cnt;
#define mp std :: make_pair
inline int id(int x, int num) { return ex[mp(x, num)] ? ex[mp(x, num)] : ex[mp(x, num)] = ++cnt; }

std :: deque<int> q; int d[MAXN << 3];
void BFS() {
    memset(d, 0x3f, sizeof d);
    d[1] = 0; q.push_front(1);
    while (q.size()) {
        int x = q.front(); q.pop_front();
        for (int i = head[x]; i; i = edge[i].nxt) {
            int y = edge[i].ver, z = edge[i].val;
            if (d[y] > d[x] + z) {
                d[y] = d[x] + z;
                !z ? q.push_front(y) : q.push_back(y);
            }
        }
    }
}

int main() {
    scanf("%d%d", &n, &m); cnt = n;
    for (int i = 1; i <= m; ++i) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        int p = id(u, w), q = id(v, w);
        Ins(u, p, 1), Ins(q, v, 1), Ins(p, q, 0);
        Ins(p, u, 1), Ins(v, q, 1), Ins(q, p, 0);
    }
    BFS();
    printf("%d\n", d[n] == INF ? -1 : d[n] >> 1);
    return 0;
}

Measured memory_bytes: 46208
#include <cstdio>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

ll solve(VL &as, ll x) {
  ll ans = 0;
  if(as[0] > x) {
    ans += as[0] - x;
    as[0] = x;
  }
  REP(i,0,as.size()-1) {
    ll s = as[i] + as[i+1];
    if(s > x) {
      ans += s - x;
      as[i+1] -= s - x;
      assert(as[i+1] >= 0);
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  int N;
  ll x;
  cin >> N >> x;
  VL as(N);
  FOR(a,as) {
    cin >> a;
  }
  // ll a1 = solve(as, x);
  // reverse(as.begin(), as.end());
  // ll a2 = solve(as, x);
  cout << solve(as,x) << endl;
  return 0;
}


Measured memory_bytes: 1024
import itertools
import math

N = int(input())
nums = [i for i in range(N)]
town = []
distance = {}
d_sum = 0

for _ in range(N):
    town.append(list(map(int, input().split())))
    
for i in range(N):
    for j in range(i + 1, N):
        key = str(i) + "_" + str(j)
        distance[key] = (math.sqrt((town[i][0] - town[j][0]) ** 2 + (town[i][1] - town[j][1]) ** 2 ))

for v in itertools.permutations(nums, N):
    for i in range(N -1):
        if v[i] > v[i + 1]:
            key = str(v[i + 1]) + "_" + str(v[i])
        else:
             key = str(v[i]) + "_" + str(v[i + 1])
        d_sum += distance[key]

print(d_sum / math.factorial(N))

Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  ll w,h; cin>>w>>h;
  vector<PII> v;
  int x;
  rep(i,w) cin>>x, v.PB({x,0});
  rep(i,h) cin>>x, v.PB({x,1});
  sort(ALL(v));
  ll ans = 0;
  w++; h++;
  for(auto& r:v){
    if(r.second) ans+=w*r.first, h--;
    else ans+=h*r.first, w--;
  }
  cout << ans << endl;
  return 0;
}


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

void sayYes(){
  cout << "Yes" << "\n";
}

int solver() {
  int c[3][3];

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

  int n;
  cin >> n;
  bool nums[101];
  for (int i = 0; i < 101; i++) {
    nums[i] = false;
  }

  for (int i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    nums[tmp] = true;
  }

  for (int i = 0; i < 3; i++) {
    int cnt = 0;
    for (int j = 0; j < 3; j++) {
      if (nums[c[i][j]]) cnt++;
    }
    if (cnt == 3) {
      sayYes();
      return 0;
    }
  }

  for (int i = 0; i < 3; i++) {
    int cnt = 0;
    for (int j = 0; j < 3; j++) {
      if (nums[c[j][i]]) cnt++;
    }
    if (cnt == 3) {
      sayYes();
      return 0;
    }
  }

  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (nums[c[i][i]]) cnt++;
  }
  if (cnt == 3) {
    sayYes();
    return 0;
  }

  cnt = 0;
  for (int i = 0; i < 3; i++) {
    if(nums[c[2-i][i]]) cnt++;
  }
  if (cnt == 3) {
    sayYes();
    return 0;
  }

  cout << "No" << "\n";
  return 0;
}

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


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

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

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

ll lcm(ll a,ll b){
    return b/gcd(a,b)*a;
}

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

    ll N;
    ll T;
    ll ans;

    cin >> N;
    cin >> ans;
    for (int i = 1;i < N;i++){
        cin >> T;
        ans = lcm(ans,T);
    }

    cout << ans << endl;

    return 0;

}

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

int main(){ 
  int n;
  cin >> n;
  vector<pair<string,int>> mp;
  for (int i = 0; i < n; i++) {
    string s;
    int t;
    cin >> s >> t;
    mp.emplace_back(make_pair(s,t));
  }
  string x;
  cin >> x;
  int res = 0;
  bool ok = false;
  for (auto e : mp) {
    if (ok) res += e.second;
    if (e.first == x) ok = true;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
//InTheNameOfGod
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn =20;
int n;
ll re;
string s;
map<pair<string,string>,int> mp;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    cin>>s;
    rep(i,0,(1<<n))
    {
        string l="",r="";
        rep(j,0,n)
        {
            if(i&(1<<j))l.pb(s[j]);
            else r.pb(s[j]);
        }
        reverse(r.begin(),r.end());
        mp[{l,r}]++;
        //cout<<l<<' '<<r<<endl;
    }
    rep(i,0,(1<<n))
    {
        string l="",r="";
        rep(j,0,n)
        {
            if(i&(1<<j))l.pb(s[j+n]);
            else r.pb(s[j+n]);
        }
        reverse(r.begin(),r.end());
        re+=mp[{r,l}];
    }
    cout<<re;
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int f;
string s,t;

main() {
    cin >> s >> t;
    for(int i=s.size()-t.size();i>=0;i--) {
        repo(j,i,t.size()+i) if (s[j]!=t[j-i] && s[j]!='?') goto hoge;
        repo(j,i,t.size()+i) s[j] = t[j-i];
        f++;
        break;
        hoge:;
    }
    rep(i,s.size()) if (s[i]=='?') s[i] = 'a';
    if (!f) ct("UNRESTORABLE")
    else ct(s)

}



Measured memory_bytes: 384