akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>//小数点以下表示
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

int main()
{
  ll n;cin>>n;
  ll keep;
  ll ans=0;
  for(ll i=0;i<n;i++){
    cin>>keep;
    while(keep%2==0){
      keep/=2;
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
let () = Scanf.scanf "%d %d %d %d %d" @@ fun a b c d e ->
  Printf.printf "%d\n" @@
  List.fold_left (fun acc a -> acc + a + 9 - (a + 9) mod 10) 0 [a; b; c; d; e]
  - List.fold_left (fun acc a -> max acc (9 - (a + 9) mod 10)) 0 [a; b; c; d; e]


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

using namespace std;

#define FOR(i,l,r) for( int i = l; i < r; i++ )
#define li long long int
#define vi vector<int>
#define pb push_back

vector<vi> alist;
vector<vi> d;
li mod = 1e9+7;

void addMod( li & a, li b ) {
    a = (a+b)%mod;
}

void mulMod( li & a, li b ) {
    a = (a*b)%mod;
}

li dfs( int u, int col, int p = -1 ) {
    if( d[col][u] != -1 ) return d[col][u];
    li s = 1;
    int c = 0;
    FOR(i,0,alist[u].size()) {
        int v = alist[u][i];
        if( v != p ) {
            c++;
            li ss = 1;
            li a = dfs(v,0,u);
            li b = dfs(v,1,u);
            if( col == 0 ) {
                addMod(a,b);
            } 
            mulMod(s,a);
            // cout<<u<<" "<<col<<" "<<v<<" "<<s<<"\n";
        }
    }
    return d[col][u] = s;
}
 
int main() {
    int n; cin>>n;
    alist.assign(n,vi());
    d.assign(2,vi(n,-1));
    FOR(i,0,n-1) {
        int x, y; cin>>x>>y;
        x--;y--;
        alist[x].pb(y);
        alist[y].pb(x);
    }
    li ans = 0;
    addMod(ans,dfs(0,0));
    addMod(ans,dfs(0,1));
    // FOR(i,0,n) cout<<d[0][i]<<" "<<d[1][i]<<"\n";
    cout<<ans<<"\n";
    return 0;
}

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

#define ll long long
#define ar array
#define endl "\n"

const int MOD = 2019;

int main(){
    //
    //
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    ll ans=0;
    int n= (int) s.size();
    vector <int> mods(MOD);
    int pot = 1, suf=0;
    string sum = "";
    for (int i=n-1; i>=0; --i){
        int digit = s[i]-'0';
        suf = (suf+digit*pot)%MOD;
        if (suf==0){
            ans++;
        }
        pot = 10*pot%MOD;
        ans+= mods[suf];
        mods[suf]++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int m, n, p, q;
  cin >> m >> n;
  p = min(m, n);
  q = max(m, n);
  if(p == 1 && q == 2) cout << 3 << endl;
  else if(p == 1 && q == 3) cout << 2 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const ll INF = ll(1e15)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

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

	rep(i, 20000) {
		int x = i * 0.08;
		int y = i * 0.1;
		if (x == A && y == B) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


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

#define MOD 1000000007;

int main(){
    string s; cin >> s;
    int n = s.length();
    int ans = 0;
    for(int i=0;i<n;i++) for(int j=i;j<n;j++) {
        int l = j-i+1;
        for(int k=i;k<=j;k++) if(s[k]!='A'&&s[k]!='T'&&s[k]!='G'&&s[k]!='C') l=0;
        ans = max(l,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int n;
int x, y;
char s[105];
int main() {
	scanf("%d", &n);
	scanf("%s", s);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'B')x++;
		if (s[i] == 'R')y++;
	}
	if (y > x)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pb push_back

using namespace std;

int price(int a, int b, int c) {
	return 380 * (a / 5 * 5) * 0.8 + 380 * (a % 5) +
			550 * (b / 4 * 4) * 0.85 + 550 * (b % 4) +
			850 * (c / 3 * 3) * 0.88 + 850 * (c % 3);
}

int main() {
	//freopen("0106.inp", "r", stdin);
	int n; cin >> n;
	while (n != 0) {
		int p = 100000;
		loop(c, 0, n / 500 + 1) {
			int p1 = n - 500 * c;
			loop(b, 0, p1 / 300 + 1) {
				int p2 = p1 - 300 * b;
				if ((p2 >= 0) && (p2 % 200 == 0)) {
					int a = p2 / 200;
					p = min(p, price(a, b, c));
					//cout << a << ' ' << b << ' ' << c << endl;
				}
			}
		}
		cout << p << endl;
		cin >> n;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define INF (int)1e9+4
#define INFL (ll)1e18+4
#define md (int)1e9+7
#define mx 10000000  //use fixed<<setprecion 
#define mk make_pair
#define pi pair<int,int>
#define ss second
#define ff first
#define pb emplace_back 
#define onell(x) __builtin_popcountll(x)
#define one(x) __builtin_popcount(x)
#define all(s) s.begin(),s.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, a) for (auto& x: a)
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sz(x) ((long long)x.size())
#define mez(s) memset(s,0,sizeof s)
#define mex(s) memset(s,-1,sizeof s)
#define metr(s) memset(s,true, sizeof s)
typedef vector<int> vi; 
typedef vector<ll>vl;
typedef map<int,int> mp;
typedef queue<int> que;
typedef vector<pi> vp;
void solve(){
int n=0,x=0,y=0,z=0,m=0,k=0;
cin>>n;
vi a(n);
rep(i,0,n)cin>>a[i];
ll ans=0;
rep(i,0,n){
	y=max(y,a[i]);
	ans+=(y-a[i]);
}
cout<<ans;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
 // cin>>t;
  while(t--){
  	solve();
  }
  return 0;
}

Measured memory_bytes: 3984
use std::io::*;
use std::str::FromStr;
use std::cmp;
   
fn read<T: FromStr>() -> T {
	let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
	let s: String = read();
	let t: String = read();

	
	let l: Vec<u32> = s.chars().zip(t.chars()).map(|(si, ti)| if si == ti {return 1} else {return 0}).collect();
	println!("{}", l.iter().fold(0, |x, y| x+y));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// nCr mod を計算する O(n)
const int MAX_N = 1000010;
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll x,y;
    cin>>x>>y;
    if((x+y)%3!=0){
        cout<<0<<endl;
        return 0;
    }

    ll a=(2*y-x)/3;
    ll b=(2*x-y)/3;

    if(a<0 || b<0){
        cout<<0<<endl;
        return 0;
    }

    COMinit();
    cout<<COM(a+b,a)<<endl;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, auto init = 0) {
    return std::accumulate(all(vec), T(init));
}
// -------------------------------------------------------------------

using P = pair<int, int>;

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

    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    vector<int> sabun;
    rep (i, m)
        cin >> x[i];

    sort(all(x), greater<int>());
    int total = x[0] - x[x.size() - 1];
    rep (i, m - 1)
        sabun.push_back(x[i] - x[i + 1]);
    sort(all(sabun), greater<int>());

    rep (i, n - 1) {
        if (i > m - 2) break;
        total -= sabun[i];
    }

    print(total);

    return 0;
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cctype>
#include<cstring>
#include<list>
#include<map>
#include<sstream>
#include<set>
#include<string>
#include<vector>
typedef long long ll;
using namespace std;
#define MN 300005
#define MM 600005
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define RF(i,a,b) for(int i=a;i>=(b);--i)
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
int main()
{
   int n,m;
   cin>>n>>m;
   int a[n];double sum=0;
   F2(i,0,n){
       cin>>a[i];
       sum+=a[i];
   }
   double max = sum/(4.0*m) ;
   int cnt=0;
   F2(i,0,n){
    if((double)a[i]>=max)cnt++;
   }
   if(cnt>=m)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	char a;
	
	cin>>a;
	
	if(a == 'A') cout<<'T'<<endl;
	else if(a == 'T') cout<<'A'<<endl;
	if(a == 'C') cout<<'G'<<endl;
	else if(a == 'G') cout<<'C'<<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;
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<ll>> a(h+1, vector<ll>(w));
  rep(i,w)a[0][i]=0;
  a[0][0]=1;
  rep(i,h){
    rep(bit,1<<(w-1)){
      bool ok=1;
      rep(t,w-2){
        if((bit>>t)&1==1&&(bit>>(t+1))&1==1)ok=0;
      }
      if(ok){
        //cout << ((bit>>0)&1) << endl;
        rep(j,w){
          if(j==0){
            if(((bit>>0)&1)==0)a[i+1][0]+=a[i][0];
            else a[i+1][1]+= a[i][0];
          }else if(j==w-1){
            if(((bit>>w-2)&1)==0)a[i+1][w-1]+=a[i][w-1];
            else a[i+1][w-2] += a[i][w-1];
          }else{
            if(((bit>>j)&1)==1)a[i+1][j+1]+=a[i][j];
            else if(((bit>>(j-1))&1)==1)a[i+1][j-1]+=a[i][j];
            else a[i+1][j]+=a[i][j];
          }
          a[i+1][j]%=1000000007;
        }
      }
    }
  }
  //rep(i,h+1)rep(j,w)cout << a[i][j] << endl;
  cout << a[h][k-1]%1000000007 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAXN 101000
int N, M;
int f[MAXN], dis[MAXN];
void init()
{
	for (int i = 0; i <= N; i++)
	{
		f[i] = i;
	}
}
int find(int x)
{
	if (f[x] == x)
		return x;
	else
	{
		int r = find(f[x]);
		dis[x] = dis[f[x]] + dis[x];
		return f[x] = r;
	}
}
int find_father(int x,int y,int z)
{
	int fx = find(x);
	int fy = find(y);
	if (fx == fy)
	{
		return z == dis[y] - dis[x];
	}
	f[fy] = fx;
	dis[fy] = dis[x] + z - dis[y];
	return 1;
}
int main()
{
	int a = 1;
	scanf("%d %d", &N, &M);
	init();
	for (int i = 1; i <= M; i++)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		if (a)
			a = find_father(x, y, z);
	}
	if (a)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
vector< vector< pair< int, int > > > A;
bool check(int b) {
	rep(i, N) {
		if ((1 << i) & b) {
			rep(j, A[i].size()) {
				int x = A[i][j].first, y = A[i][j].second;
				int tmp = (b >> x) & 1;
				if (tmp != y)
					return false;
			}
		}
	}
	return true;
}
signed main() {
	cin >> N;
	A.resize(N);
	rep(i, N) {
		int a;
		cin >> a;
		A[i].resize(a);
		rep(j, a) {
			cin >> A[i][j].first >> A[i][j].second;
			A[i][j].first--;
		}
	}
	int ans = 0;
	for (int b = 0; b < (1 << N); b++) {
		if (check(b)) {
			int tmp = 0;
			rep(i, N) {
				if ((1 << i) & b)
					tmp++;
			}
			chmax(ans, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int N,max_time;

void func(){

	int candidate_num,ans,min_time = BIG_NUM,min_nanido;

	int tmp,tmp_time;

	for(int i = 1; i <= N; i++){

		scanf("%d",&tmp);

		tmp_time = (max_time/tmp)*tmp;

		if(tmp_time < min_time){
			min_time = tmp_time;
			min_nanido = tmp;
			ans = i;
			candidate_num = 1;
		}else if(tmp_time == min_time){
			if(tmp < min_nanido){
				min_nanido = tmp;
				ans = i;
			}else if(tmp == min_nanido){
				candidate_num++;
			}
		}
	}

	if(candidate_num > 1){
		ans = N;
	}

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

int main(){

	while(true){
		scanf("%d %d",&N,&max_time);
		if(N == 0 && max_time == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 2592
n,y = map(int,input().split())
x1,y1,z1 = -1,-1,-1
for i in range(n+1):
    for j in range(n-i+1):
        if y == 10000*i+5000*j+1000*(n-i-j):
            x1 = i
            y1 = j
            z1 = n-i-j
print(x1,y1,z1)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    
    int N[3], temp, i, j, length;
    
    scanf("%d %d %d", &N[0], &N[1], &N[2]);
    
    length = sizeof(N) / sizeof(N[0]);
    
    for(i = 0; i < length; i++){
        for(j = length - 1; j > i; j--){
            if(N[j] < N[j-1]){
                temp = N[j];
                N[j] = N[j-1];
                N[j-1] = temp;
            }
        }
    }
    
    printf("%d %d %d\n", N[0], N[1], N[2]);
    
    return 0;
    
}

Measured memory_bytes: 596
n = int(input())
a = sorted(list(map(int, [input() for i in range(n)])), reverse=True)
if n % 2 == 0:
  print(2*sum(a[:int(n/2)])-2*sum(a[-int(n/2):])-a[int(n/2-1)]+a[int(n/2)])
else:
  x = 2*sum(a[:int((n-1)/2)])-2*sum(a[-int((n-1)/2):])-a[int((n-1)/2)]+a[int((n-1)/2+1)]
  y = 2*sum(a[:int((n-1)/2)])-2*sum(a[-int((n-1)/2):])+a[int((n-1)/2)]-a[int((n-1)/2-1)]
  if x > y:
    print(x)
  else:
    print(y)

Measured memory_bytes: 14240
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            if (a == 0 & b == 0)
                break;
            if(a >= 1 && a <= 300){
		if(b >= 1 && b <= 300){
            for (int i = 0; i < a; i++) {
                for (int j = 0; j < b; j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
            }
          }
        }
    }
}


Measured memory_bytes: 35080
N = int(input())
X = list(map(int, input().split()))

mod = 10**9+7

kukan_cnt = [0] * (N-1)

orig = 1
for i in range(1,N):
	orig *= i
	orig %= mod

kukan_cnt[0] = orig

tmp = 1

for i in range(1,N-1):
	tmp = pow(i+1,mod-2,mod)
	kukan_cnt[i] = kukan_cnt[i-1] + orig*tmp
	kukan_cnt[i] %= mod
	
ans = 0

for i in range(1,N):
	dist = X[i]-X[i-1]
	dist %= mod

	ans += dist*kukan_cnt[i-1]

	ans %= mod

print(ans)


Measured memory_bytes: 14480
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int n;
    cin>>n;
    map<int,int>mm;
    int sum=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        mm[x]++;
        sum+=x;
    }
    int q;
    cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        int oc=mm[b];
        sum-= (oc*b);
        sum+= (oc*c);
        mm[c]+=mm[b];
        mm[b]=0;
        cout << sum << endl;
    }
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 9520
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

fwd = [A[0]]
for i in range(1, N):
    fwd.append(gcd(fwd[-1], A[i]))

bwd = [A[-1]]
for i in range(N-2, -1, -1):
    bwd.append(gcd(bwd[-1], A[i]))
bwd.reverse()

gmax = max(fwd[-2], bwd[1])
for i in range(1, N-1):
    gmax = max(gmax, gcd(fwd[i-1], bwd[i+1]))

print(gmax)


Measured memory_bytes: 16144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
    int k;

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

    void run() {
        FastReader sc = new FastReader();
        k = sc.nextInt();
        solve();
    }

    void solve() {
        Deque<Pair> deque = new LinkedList<>();
        boolean[] visited = new boolean[k];
        deque.offer(new Pair(1, 1));
        while (!deque.isEmpty()) {
            Pair p = deque.poll();
            if (p.node == 0) {
                System.out.println(p.sumDigits);
                return;
            }
            visited[p.node] = true;
            int add1 = (p.node + 1) % k;
            int multi10 = (p.node * 10) % k;
            if (!visited[add1]) {
                deque.offerLast(new Pair(add1, p.sumDigits + 1));
            }
            if (!visited[multi10]) {
                deque.offerFirst(new Pair(multi10, p.sumDigits));
            }
        }
    }

    class Pair {
        int node;
        int sumDigits;

        Pair(int node, int sumDigits) {
            this.node = node;
            this.sumDigits = sumDigits;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


Measured memory_bytes: 42580
# -*- coding: utf-8 -*-
n = int(input())
s = [0]*n
count = 0
each_count = {}

for i in range(n):
    tmp = list(str(input()))
    tmp.sort()
    s[i] = "".join(tmp)

for si in s:
    if each_count.setdefault(si, 0) == 0:
        each_count[si] = 1
    else:
        count += each_count[si]
        each_count[si] += 1

print(count)


Measured memory_bytes: 19460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 +7;
const ll MAXN = 1e6 + 5;

ll p[10];
ll q[10];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n;cin>>n;
	ll a[n];
	for(int i=0;i<n;++i){
		a[i]=i+1;
	}
	for(int i=0;i<n;++i){
		cin>>p[i];
	}
	for(int i=0;i<n;++i){
		cin>>q[i];
	}
	int x,y,tot=0;
	do{
		tot++;
		int cnt1=0,cnt2=0;
		for(int i=0;i<n;++i){
			if(a[i]==p[i]){
				cnt1++;
			}
			if(a[i]==q[i]){
				cnt2++;
			}
		}
		if(cnt1==n){
			x=tot;
		}
		if(cnt2==n){
			y=tot;
		}
		
	}while(next_permutation(a,a+n));
	cout<<abs(x-y);
	return 0;
}


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		2505

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

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

//
int main(){
	int a;cin>>a;
	string s;cin >> s;

	cout << (a>=3200?s:"red") << endl;;


	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
    char b;
    cin >> b;
    if (b == 'A') putchar('T');
    else if (b == 'T') putchar('A');
    else if (b == 'C') putchar('G');
    else if (b == 'G') putchar('C');

    putchar('\n');
    return 0;
}

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

int main(){ 
 int n;
 cin >> n;
 string s;
 cin >> s;
 int length = s.size();
 string t;
 for(int i=0; i< length ; i++){
     s[i] = s[i]+n;
     if(s[i] > 90)s[i] = 64+ s[i] - 90;
     t += (char)(s[i]);
  }
cout <<  t << endl; 
return 0;
}

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

typedef long long llong;

int main(int argc, const char * argv[]) {
    int N;
    
    cin >> N;
    
    vector<llong> a(N * 3);
    for (llong i = 0; i < N * 3; i++) cin >> a[i];
    
    sort(a.begin(), a.end(), greater<llong>());
    
    llong sum = 0;
    for (llong i = 1; i < 2 * N; i+=2) {
        sum += a[i];
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  map<string, ll> cnt;
  string S;
  rep(i, N){
    cin >> S;

    cnt[S]++;
  }

  ll kind = 0;
  for(auto it = cnt.begin(); it != cnt.end(); it++) kind++;

  cout << kind << endl;
  
  return 0;
}


Measured memory_bytes: 19224
#include<stdio.h>
/*
for any score s,the probality of s larger than K is (1/2)^t, where t is the times of times 2

*/
double p(int s,int k)
{
    double ret = 1;
    while(s < k)
    {
        s*=2;
        ret*=0.5;
    }
    return ret;
}
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    double ans = 0;
    for(int i=1;i<=n;++i)
    {
        ans +=  p(i,k);
    }
    ans /= n;
    printf("%.15f\n",ans);
}

Measured memory_bytes: 128
from collections import Counter
h, w, n = [int(i) for i in input().split()]

vs = []
for i in range(-1, 2):
	for j in range(-1, 2):
		vs.append((i,j))
cnt = []
for _ in range(n):
	a, b = [int(i) for i in input().split()]
	for v in vs:
		aa = a + v[0]
		bb = b + v[1]
		if 2<=aa<=(h-1) and 2<=bb<=(w-1):
			cnt.append(aa*w+bb)

cnt = Counter(cnt)


cnt2 = [0] * 10
cnt2[0] = (h-2)*(w-2)
for k in cnt:
	c = cnt[k]
	cnt2[c] += 1
	cnt2[0] -= 1

for i in cnt2:
	print(i)





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

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int k,x;
int main(){
    ios::sync_with_stdio(false);
    cin>>k>>x;
    for(int i=x-k+1;i<=x+k-1;i++)cout<<i<<' ';
    return 0;
}

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

typedef unsigned uint;
typedef long long INT;
typedef unsigned long long UINT;
const int INF = 1001001001;
const INT INFLL = 1001001001001001001LL;

 int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
INT lin() { INT x; scanf("%lld", &x); return x; }


int main(){
    int a, b, c;
    double fa, fb, fc;
    char sa[128], sb[128], sc[128];

    int K = in();

    INT nTotal = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            for (int k = 1; k <= K; ++k) {
                nTotal += __gcd(i,__gcd(j,k));
            }
        }
    }

    printf("%ld", nTotal);

    return 0;
}







Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
	int a,b;
	cin>>a>>b;
	if (a<=b)  cout<<"un";
	cout<<"safe";
	re 0;
}

Measured memory_bytes: 3636
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    vector<Int> x(3);
    cin >> x[0] >> x[1] >> x[2];
    sort(x.begin(), x.end());

    Int ans = 0;
    while (x[1] != x[2]) {
        x[1]++;
        x[0]++;
        ans++;
    }
    while (x[2] > x[0]) {
        x[0] += 2;
        ans++;
    }

    if (x[2] < x[0]) {
        x[1]++;
        x[2]++;
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using lli = long long;
using pii = pair<lli,lli>;

int n,K;
pii a[200001];
struct seg_tr{
	int tr[200011];
	void upd(int cur) {
		while(cur<=n+1) ++tr[cur], cur+=cur&-cur;
	}
	int sum(int cur) {
		int res=0;
		while(cur) res+=tr[cur], cur-=cur&-cur;
		return res;
	}
}st;

int ccw(pii a, pii b) {
	return 1ll*a.fi*b.se - 1ll*a.se*b.fi > 0;
}
int ccw(pii p,pii a,pii b) {
	return ccw({a.fi-p.fi,a.se-p.se}, {b.fi-p.fi,b.se-p.se});
}

long long getDist(pii p) {
	return p.se - 1ll*K*p.fi;
}
int main() {
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i].se),a[i].fi=i;
	for(int i=1;i<=n;i++) a[i].se += a[i-1].se;

	pii T(1,K);
	stable_sort(a,a+n+1,[](const pii &a,const pii &b) {
		return getDist(a) < getDist(b);
	});

	long long ans=0;
	for(int i=0;i<=n;i++) {
		ans += st.sum(a[i].fi);
		st.upd(a[i].fi+1);
	}
	printf("%lld\n",ans);

	return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int cnt = 0;

    for(int i=0;i<n;i++){
        for(int j=n-1;j>=i+1;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                cnt++;
            }
        }
    }
    cout << a[0];
    for(int i=1;i<n;++i){
        cout <<" "<<a[i];
    }
    cout << endl;
    cout << cnt <<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n, x;
	cin >> n >> x;
	int arr[n];
	int tmp;
	int dif = INT_MAX;
	REP(i, 0, n){
		cin >> tmp;
		arr[i] = abs(x-tmp);
		if(arr[i] > 0 && arr[i] < dif) dif = arr[i];
	}
	
	int ans=arr[0];
	REP(i, 1, n) ans = __gcd(arr[i], ans);
	
	cout << ans;
	
	/*bool f = false;
	while(!f){
		f = true;
		REP(i, 0, n){
			if(arr[i] % dif != 0){
				f=false;
				break;
			}
		}
		if(!f) --dif;
	}
	cout << dif;*/
	

}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";

    int N, A, B;
    void Solve()
    {
        N = cin.Nextint;
        A = cin.Nextint;
        B = cin.Nextint;
        var C = A- B;
        var H = new long[N];
        for (int i = 0; i < N; i++)
        {
            H[i] = cin.Nextlong;
        }
        //Array.Sort(H);

        long l = 0;///ng
        long r = 1000000000;//ok

        while (r - l > 1)
        {
            long mid = (l + r) / 2;
            long c = 0;
            for (int i = 0; i < N; i++)
            {
                long t = H[i] - mid * B;
                if (t <= 0) continue;
                c += t / C;
                if (t % C != 0) c++;
            }
            if (c <= mid)
            {
                r = mid;
            }
            else l = mid;
        }
        WriteLine(r);
    


    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 18000
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

double maxvolume(double s)
{
	double length = s / 3;
	s -= length;

	double breadth = s / 2;
	double height = s - breadth;

	return length * breadth * height;
}

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

	double L;
	cin >> L;

	cout.setf(ios::fixed);
	cout.precision(12);
	cout << maxvolume(L);

	return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val N = readLine.toInt
  var sList = List[Int]()
  for (i <- 1 to N) {
    sList :+= readLine.toInt
  }
  var sum = sList.sum
  if (sum % 10 != 0) {
    println(sum)
  } else {
    var iList = List[Int]()
    try {
      for (i <- sList.sorted) {
        if (i % 10 == 0) iList :+= i
        sum -= i
        if (sum % 10 != 0) {
          if ((sum + iList.sum) % 10 != 0) sum = sum + iList.sum
          throw new RuntimeException("break")
        }
      }
    } catch {
      case _ => 0
    } finally {
      println(sum)
    }
  }
}

Measured memory_bytes: 27340
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;

int inf = (1 << 30);
int mod = 1e9;
long long long_inf = (1 << 60);

int main(){

    int N;
    cin >> N;

    cout << "ABC" << N << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    long d = sc.nextLong();
    long count = 0;
    for(int i = 0;i < num;i++){
      long p = sc.nextLong();
      long q = sc.nextLong();
      long dis = p * p + q * q;
      if(dis <= d * d){
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 59400
#include<iostream>
#include<algorithm>
using namespace std;
long long n,m,a[100005];
int main()
{
    cin>>n>>m;
    for (int i=1;i<=m;i++)
    {
        cin>>a[i];
        n=n-a[i];
    }
    if (n>=0)cout<<n;
    else cout<<"-1";
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
 
#define ll long long
#define loop(a) loopi(i,a)
#define loopi(i,a) for(int i=0; i<(a); i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pow2(x) (1ll<<(x))
 
using namespace std;
 
const int Mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	loop(n) cin >> a[i];
	int ans=0;
	loop(n){
		if(a[i]==ans+1) ans++;
	}
	if(ans!=0) cout << n-ans << "\n";
	else cout << "-1\n";
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  u64 n, x;
  cin >> n >> x;
  u64 bef;
  cin >> bef;
  u64 ret = 0;
  if (bef > x) {
    ret = bef - x;
    bef = x;
  }
  for (u64 i = 1; i < n; ++i) {
    u64 aft;
    cin >> aft;
    if (bef + aft > x) {
      ret += bef + aft - x;
      aft = x - bef;
    }
    bef = aft;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int inf = 1<<30;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

  string ans = "";
  while(N != 0) {
    if(N%2 != 0) {
      N--;
      ans = "1" + ans;
    }
    else {
      ans = "0" + ans;
    }
    N /= -2;
  }
  if(ans == "") ans = "0";

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char s[100005];

int main ()
{
	memset(s,'\0',sizeof(s));
	scanf("%s",s);
	int flag=0;
	if(strlen(s)%2) flag=1;
	else
	{
		for(int i=0;i<strlen(s);i+=2)
		{
			if(s[i]!='h'||s[i+1]!='i')
			{
				flag=1;
				break;
			}
			
		}
		
	}
	if(flag) cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,k,a[21];
int dp[21][1005];
int C[1005][1005];

int main(){
	cin>>n>>k;
	for(int i=1;i<=k;i++) cin>>a[i];
	C[0][0]=1;
	for(int i=1;i<=n;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	dp[0][0]=1;
	for(int i=1;i<=k;i++){
		for(int j=0;j<=n;j++){
			if(!dp[i-1][j]) continue;
			for(int l=0;l<=n-j&&l<=a[i];l++){
				(dp[i][j+l]+=1ll*C[n-j][l]*C[n-l][a[i]-l]%mod*dp[i-1][j]%mod)%=mod;
			}
		}
	}
	printf("%d\n",dp[k][n]);

	return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }

// ll get_pow(ll x, ll y){
//   ll ret=0;
//   ll temp = y;
//   while(true){
//     if(x<=temp) break;
//     ret++;
//     temp *= 2;
//   }
//   return ret;
// }






int main() {
  cout<<fixed<<setprecision(10);

  ll X;cin>>X;
  ll ans = 0;

  while(X>ans*(ans+1)/2){

    ans++;
  }
  // ans--;

  cout<<ans<<endl;

}

















//


Measured memory_bytes: 256
n, d, a = gets.split.map(&:to_i)
monsters = []
n.times { monsters << gets.split.map(&:to_i) }
monsters.sort! { |a, b| a[0] <=> b[0] }
positions = monsters.map { |m| m[0] }
neccesary_attacks = monsters.map { |m| (m[1].to_f / a).ceil }
imos = Array.new(n, 0)
count = 0
positions.each_with_index do |pos, index|
  imos[index] += imos[index - 1]
  tmp_count = [neccesary_attacks[index] - imos[index], 0].max
  count += tmp_count
  imos[index] += tmp_count
  unreachable_index = positions.bsearch_index { |p| p > pos + d * 2 }
  imos[unreachable_index] -= tmp_count if unreachable_index
end
puts count


Measured memory_bytes: 21608
N = int(input())

x = N % 10
hon = [2, 5, 4, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]

result = ""
if x in hon:
  result = "hon"
elif x in pon:
  result = "pon"
else:
  result = "bon"

print(result)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}

int main()
{
  ll X,A,B;
  cin>>X;
  for(ll i=-2500;i<=2500;i++){
      for(ll j=-2500;j<=2500;j++){
          if(i*i*i*i*i-j*j*j*j*j==X){
              A=i;
              B=j;
          }
      }
  }
  cout<<A<<" "<<B<<endl;
}

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

int main() 
{
	long long int n,w;
	cin>>n>>w;
	long long int dp[n+1][w+1];
    long long int wt[n+1],p[n+1];
    wt[0]=0;
    p[0]=0;
    for(long long int i=1;i<=n;i++)
    {
    	cin>>wt[i]>>p[i];
    }
    
    for(long long int i=0;i<=n;i++)
    {
    	for(long long int j=0;j<=w;j++)
    	{
    		if(i==0||j==0)
    		dp[i][j]=0;
    		else if(wt[i]<=j)
    		dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i]]+p[i]);
    		else
    		dp[i][j]=dp[i-1][j];
    		
    	}
    }
    cout<<dp[n][w]<<"\n";
    
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int d = n % 10;
  if(d==3) {
    cout << "bon" << endl;
  } else if(d==0 || d==1 || d== 6 || d== 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main() {

	int m, d;
	int day[12]={31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	char week[][16]={"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};

	while(cin >> m >> d) {
		if(m==0&&d==0)
			break;

		for(int i=0; i<m-1; i++) {
			d+=day[i];
		}
 
		cout << week[d%7] << endl;

	}

	return 0;

}

Measured memory_bytes: 0
n = int(input())
c = list(map(int, input().split()))
c.sort(reverse=True)

MOD = 10**9+7
two = [0]*(n+1)
for i in range(n+1):
    two[i] = pow(2, i, MOD)

cost = 0
for i in range(n):
    current_one_num = two[i]
    left_one_num = 0
    if i != 0:
        left_one_num = two[i-1] * i % MOD
    right_num = two[n-1-i]
    one_num = (current_one_num + left_one_num) * right_num % MOD
    current_cost = one_num * c[i] % MOD
    cost = (cost + current_cost) % MOD

num = two[n]
ans = cost * num % MOD
print(ans)


Measured memory_bytes: 26024