akhauriyash/Code-Regression huggingface dataset:
/*Filename: aoj0003.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

const int a = 0;
const int b = 1;
const int c = 2;

int main() {
	int n = 0;

	while (cin >> n) {
		while (n > 0) {
			int side[3];
			for (int i = 0; i < 3; ++i) {
				cin >> side[i];
			}
			sort(side, side + 3);

			if (side[a] * side[a] + side[b] * side[b] == side[c] * side[c]) {
				cout << "YES" << endl;
			} else {
				cout << "NO" << endl;
			}
			--n;
		}
	}

	return 0;
}

Measured memory_bytes: 1172
#include <iostream>

using namespace std ;

const int N = 100 * 100 + 10 ;
int arr[N] , matrr[N][N] ;
// main memory

int main()
{
    int h, w , n ;

    cin >> h >> w ;
    cin >> n ;

    for(int i = 0 ; i < n ; i++)
        cin >> arr[i] ;

    // vorodi

    int p1 = 0 , p2 = 0 ;

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < arr[i] ; j++)
            if(p1 % 2 == 0){
                matrr[p1][p2] = i + 1 ;
                //cerr << "(" << p1 << " , " << p2 << " )\n" ;
                p2++ ;
                p1 += (p2 / w) ;
                p2 %= w ;
            }

            else{
                matrr[p1][w - (p2 + 1)] = i + 1 ;
                //cerr << "(" << p1 << " , " << w - (p2 + 1) << " )\n" ;
                p2++ ;
                p1 += (p2 / w) ;
                p2 %= w ;
            }
    }

    for(int  i = 0 ; i < h ; i++){
        for(int j = 0 ; j < w ; j++)
            cout << matrr[i][j] << " " ;
        cout << "\n" ;
    }

    cout << endl ;
	return 0 ;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
using namespace std;

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

void Main()
{
	string S;
	cin >> S;

	vector<bool> v(26, false);
	for (auto c : S)
	{
		v[c-'a'] = true;
	}

	char outC = '\0';
	rep(i, v.size())
	{
		if (!v[i])
		{
			outC = static_cast<char>('a' + i);
			break;
		}
	}

	if (outC != '\0') cout << outC << endl;
	else cout << "None" << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define test freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
const int maxn=1e5+5,mod=998244353;
int n;
LL d[maxn],a[maxn];
LL qpow(LL a,LL b)
{
    LL res=1;
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
bool check()
{
    bool flag=false;
    for(int i=0;i<n;++i)
    {
        if(!d[i]) flag=true;
        if(d[i]&&flag) return false;
    }
    return true;
}
int main()
{
    //test
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",a+i),++d[a[i]];
    LL ans=1;
    if(!check()||d[0]!=1||a[1]!=0) {cout<<0;return 0;}
    for(int i=1;i<n;++i)
    {
        ans=(ans*qpow(d[i-1],d[i]))%mod;
    }
    if(ans<0) abort();
    cout<<ans;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

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

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)1e5+11;
ll const LG=(ll)log2(N)+1;


void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n;
        
        vll a(n);
        ll fl=0;
        ll sum=0;
        for(i=0;i<n;i++){
                cin>>a[i];
                if(a[i]<0){
                        fl++;
                }
                sum+=abs(a[i]);
        }
        ll ans=0;
        // cout<<sum<<endl;
        if(fl%2==1){
                for(i=0;i<n;i++){
                        ans=max(ans,sum - 2*abs(a[i]));
                }
        }else{
                ans=sum;
        }
        cout<<ans<<endl;
        
        
        
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


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

int main() {

    string a, b; cin >> a >> b;
    int x = stoi(a + b);

    for (int i = 0; i < 100000000; i++) {
        if (i * i == x) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void) {
    char buffer[2][256], *src, *dest, *tmp;
    int m, i, h, l;
    while (scanf("%255s", buffer[0]) == 1 && strcmp(buffer[0], "-") != 0) {
        src = buffer[0];
        dest = buffer[1];
        l = strlen(src);
        dest[l] = '\0';
        if (scanf("%d", &m) != 1) return 1;
        for (i = 0; i < m; i++) {
            if (scanf("%d", &h) != 1) return 1;
            memcpy(dest + l - h, src, h);
            memcpy(dest, src + h, l - h);
            tmp = src;
            src = dest;
            dest = tmp;
        }
        puts(src);
    }
    return 0;
}


Measured memory_bytes: 2112
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	int a, b;
	cin >> a >> b;
	cout << max(0, a-2*b) << endl;
	return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <map>
#include <algorithm>    
#include <vector>       
#include <set>
#include <utility>  
#include <cstring>
#include <stdio.h>
#include <limits.h>
#include <queue>
#include <algorithm> 
#define MAX_DOUBLE  40000000000.0 
#include <math.h> 
#include <unistd.h>

using namespace std;


int min(int a, int b){
	if( a > b ) return b;
	return a; 
}


int main(){
	int n,k;
	cin>>n>>k;
	
	vector<int> vec(n);
	
	for(int i = 0; i<n; i++){
		
		cin>>vec[i];
		
	}
	
	vector<int> res(n);
	
	res[0] = 0;
		
	for(int i = 1; i < n; i++){
		res[i] = abs(vec[i] - vec[i-1]) + res[i-1];
		for(int j = 2; j <= k; j++){
			if(j > i) break;
			res[i] = min(res[i], abs(vec[i] - vec[i-j]) + res[i-j] );
		}	
	}
	
	cout<<res[n-1];
}


Measured memory_bytes: 1024
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  var n = sc.nextInt()
  val k = sc.nextInt()
  val d = Set.fill(k)(sc.nextInt())

  def ng(n: Int): Boolean = {
    List(1, 10, 100, 1000, 10000).exists(x =>
      x <= n && d.contains((n % (x * 10)) / x)
    )
  }

  while (ng(n)) {
    n += 1
  }
  println(n)
}


Measured memory_bytes: 57488
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n;
int a[maxn], b[maxn];
bool check(int mid)
{
	for(int i = 1; i <= 2 * n - 1; ++i) b[i] = (a[i] > mid);
	for(int j = 1; j <= n - 1; ++j)
	{
		if(b[n - j] == b[n - j + 1]) return b[n - j];
		if(b[n + j] == b[n + j - 1]) return b[n + j];
	}
	if(n & 1) return b[n];
	else return b[n] ^ 1;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= 2 * n - 1; ++i) scanf("%d", &a[i]);
	int l = 1, r = 2 * n - 1;
	while(l <= r)
	{
		int mid = l + r >> 1;
		if(check(mid)) l = mid + 1;
		else r = mid - 1;
	}
	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 5356
#include <cstdio>

typedef long long i64;

const int N = 3000 + 10, MOD = 1000000007;

inline void add(int &lhs, i64 rhs) { lhs = (lhs + rhs) % MOD; }

int n, m, f[N][N][2];

int main() {
  scanf("%d%d", &n, &m);
  f[0][0][1] = 1;
  for (int i = 1; i <= n; ++i) f[0][i][0] = 1;
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j <= n; ++j) {
      for (int k = 0; k < 2; ++k) {
        int cur = f[i][j][k];
        if (!cur) continue;
        if (j) {
          add(f[i + 1][j][k || j == 1], cur);
          add(f[i + 1][j - 1][k || j == 1], cur);
        }
        if (j < n) {
          add(f[i + 1][j][k], cur);
          add(f[i + 1][j + 1][k], cur);
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) add(ans, f[m][i][1]);
  printf("%d\n", (ans + MOD) % MOD);
  return 0;
}


Measured memory_bytes: 70784
#include "bits/stdc++.h"
#define pb push_back
#define mt make_tuple
#define all(a) (a).begin(),(a).end()
#define frep(i,a,n) for(int i=(a);i<(n);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define rrep(i, n) for(int i=n-1;i>=0;--i)
#define debug(x) cout << #x << " : " << x << " ------------ " << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    while (n--) {
        string o;
        cin >> o;
        string m;
        cin >> m;
        
        rrep (i, o.length()) {
            switch (o[i]) {
                case 'A':
                    reverse(all(m));
                    break;
                case 'J':
                    rotate(m.rbegin(), m.rbegin() + 1, m.rend());
                    break;
                case 'C':
                    rotate(m.begin(), m.begin() + 1, m.end());
                    break;
                case 'P': {
                    auto it = m.begin();
                    while (it != m.end()) {
                        if (isdigit(*it) && --(*it) < '0') *it = '9';
                        ++it;
                    }
                    break; }
                case 'M': {
                    auto it = m.begin();
                    while (it != m.end()) {
                        if (isdigit(*it) && ++(*it) > '9') *it = '0';
                        ++it;
                    }
                    break; }
                case 'E': {
                    int len = m.length();
                    string f = m.substr(0, len / 2);
                    char mdl = m.length() % 2 ? m[len / 2] : 0;
                    string b = m.substr((len + 1) / 2);
                    m = b;
                    if (mdl) m += mdl;
                    m += f;
                    break; }
                default:
                    break;
            }
        }
        cout << m << endl;
    }
    return EXIT_SUCCESS;
}

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

int main() {
    int h;
    scanf("%d", &h);
    vector<int> a(h+1);
    for (int i = 1; i <= h; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= h; i++) {
        printf("node %d: ", i);
        printf("key = %d, ", a[i]);
        if (i/2 > 0) printf("parent key = %d, ", a[i/2]);
        if (2*i <= h) printf("left key = %d, ", a[2*i]);
        if (2*i+1 <= h) printf("right key = %d, ", a[2*i+1]);
        printf("\n");
    }
}


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

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

  priority_queue<ll, vector<ll>, greater<ll>> q;
  for (int i=1; i<10; i++) {
    q.push(i);
  }
  ll cnt = 0;
  ll t;
  while (cnt < k) {
    t = q.top(); q.pop();
    ll m = t%10;
    if (m != 0) q.push(10*t+m-1);
    q.push(10*t+m);
    if (m != 9) q.push(10*t+m+1);
    cnt++;
  }
  cout << t << endl;

  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;
typedef long long ll;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N;
    cin>>N;
    vector<pair<ll,ll>> list;
    for(ll i = 1; i*i <= N; ++i){
        if(N%i == 0){
            list.push_back({i,N/i});
            list.push_back({N/i,i});
        }
    }
    int M = list.size();
    ll ans = 1e12;;
    rep(i,M){
        ll x = list[i].first;
        ll y = list[i].second;
        ll d = abs(x-1) + abs(y - 1);
        ans = min(ans, d);
    }
    cout<<ans<<endl;
}

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

int main()
{
  long n;
  cin >> n;
  long sum = 0;
  
  for (int i=1; i<=n; i++) {
	if (i%3!=0 && i%5!=0) sum += i;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n; cin >>n;
  int ans=0;
  for(int i=1; i<=n; i++){
    int a; cin >>a;
    if(i%2&&a%2) ans++;
  }
  cout <<ans;
return 0;}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int n,a,b;
	
	cin>>n>>a>>b;
	if(a*n<b) 
	{
		cout<<a*n<<endl;
		return 0;
	}
	else
	{
		cout<<b<<endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <set>
#include <map>
#include <complex>
#include <iostream>
#include <time.h>
#include <stack>
#include <stdlib.h>
#include <memory.h>
#include <bitset>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <vector>

using namespace std;

const int MaxN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
//  freopen("input.txt", "r", stdin);
  int a, b, c;
  cin >> a >> b >> c;
  long long ans = 8e18;
  if (a & 1) {
    ans = min(ans, 1LL * b * c);
  } else {
    ans = 0;
  }
  if (b & 1) {
    ans = min(ans, 1LL * a * c);
  } else {
    ans = 0;
  }
  if (c & 1) {
    ans = min(ans, 1LL * a * b);
  } else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	string s;
	cin >> s;
	rep(i, s.size())
	{
		cout << 'x';
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
int n, m, d;
char p[5]="RGBY";
int main(){
    int i, j;
    scanf("%d%d%d",&n,&m,&d);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            int c = ((i+j)%(2*d))/d*2 + ((i-j+m)%(2*d))/d;
            printf("%c",p[c]);
        }
        printf("\n");
    }
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll Q, H, S, D;
    ll N;
    ll one, two;
    cin >> Q >> H >> S >> D >> N;
    one = min(min(4 * Q, 2 * H), S);
    two = min(D, 2 * one);
    cout << (N / 2) * two + (N % 2) * one << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct Dice
{
	int North, East, West, South, Top, Bottom;
}Dice;

Dice d;

void SetDice(int t, int s, int e, int w, int n, int b)
{
	d.Top = t;
	d.South = s;
	d.East = e;
	d.West = w;
	d.North = n;
	d.Bottom = b;
}

void checkDice(char str[])
{
	char w = str[0];
	switch(w)
	{
	case 'N':
		SetDice(d.South, d.Bottom, d.East, d.West, d.Top, d.North);
		break;
	case 'E':
		SetDice(d.West, d.South, d.Top, d.Bottom, d.North, d.East);
		break;
	case 'W':
		SetDice(d.East, d.South, d.Bottom, d.Top, d.North, d.West);
		break;
	case 'S':
		SetDice(d.North, d.Top, d.East, d.West, d.Bottom, d.South);
		break;
	case 'R':
		SetDice(d.Top, d.East, d.North, d.South, d.West, d.Bottom);
		break;
	case 'L':
		SetDice(d.Top, d.West, d.South, d.North, d.East, d.Bottom);
		break;
	}
}

int main()
{
	int sum, n, i;
	char ope[7];

	while(1){
		SetDice(1,2,3,4,5,6);
		sum=1;
		scanf("%d", &n);
		if(n==0) return 0;

		for(i=0; i<n; i++){
			scanf("%s",ope);
			checkDice(ope);
			sum += d.Top;
		}
		printf("%d\n", sum);


	}
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
    using namespace std;
    #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define ll  long long
    #define all(v) (v.begin(),v.end())
    #define ff first
    #define ss second
    const ll maxn=2e5+10;
    const ll mod=998244353;
     
     
    int main() {
      	fast;
      	int n,flag=0,d;
      	cin>>n;
      	while(n>0)
      	{
      		d=n%10;
    		  n/=10;
    		  if(d==7)
    		  	flag=1;	
    	}
    	if(flag)
    	cout<<"Yes";
    	else
    	cout<<"No";
      	
    }

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

using namespace std;

int main(){
	int n;
	cin>>n;
	if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9){
		cout<<"hon";
	}
	else if(n%10==0||n%10==1||n%10==6||n%10==8){
		cout<<"pon";
	}
	else cout<<"bon";
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;

int main()
{
    char a;
    scanf("%c",&a);
    getchar();
    if(a=='A')printf("T\n");
    if(a=='T')printf("A\n");
    if(a=='C')printf("G\n");
    if(a=='G')printf("C\n");
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_table(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    N = I()
    A = LI()
    cnt = sum([1 for ai in A if ai < 0])
    B = [abs(ai) for ai in A]
    if cnt % 2 == 0:
        print(sum(B))
    else:
        print(sum(B) - min(B) * 2)


if __name__ == '__main__':
    main()

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

const int N = 100005;

using namespace std;

string s;
int n, l[N], r[N], x[N], root[N], summ[N], sz[N];

int Root(int x)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    if (s.size() == 1)
    {
        cout << "YES";
        return 0;
    }
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> l[i] >> r[i];
        l[i]--, r[i]--;
    }
    if (s.size() % 2 == 1)
    {
        int pos = s.size() / 2;
        for (int i = 0; i < n; i++)
        {
            if (l[i] == pos && r[i] == pos)
            {
                n--;
                swap(l[i], l[n]);
                swap(r[i], r[n]);
                i--;
                continue;
            }
            if (l[i] > pos) l[i]--;
            if (r[i] >= pos) r[i]--;
        }
        string t = "";
        for (int i = 0; i < s.size(); i++) if (i != pos) t += s[i];
        s = t;
    }
    int len = s.size() / 2;
    for (int i = 0; i < n; i++)
    {
        if (l[i] < len && r[i] >= len)
        {
            int p1 = len - l[i], p2 = r[i] - len + 1;
            if (p1 == p2) l[i] = -1, r[i] = -1;
            if (p1 < p2)
            {
                l[i] += 2 * p1;
            }
            if (p1 > p2)
            {
                r[i] -= 2 * p2;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (l[i] >= len)
        {
            int rr = s.size() - 1 - l[i];
            int ll = s.size() - 1 - r[i];
            l[i] = ll, r[i] = rr;
        }
    }
    for (int i = 0; i < len; i++)
    {
        x[i + 1] = (s[s.size() - 1 - i] + 26 - s[i]) % 26;
    }
    for (int i = len + 1; i > 0; i--)
    {
        x[i] = (x[i] - x[i - 1] + 26) % 26;
    }
    for (int i = 0; i < n; i++)
    {
        l[i]++, r[i]++, r[i]++;
    }
    iota(root, root + len + 2, 0);
    fill(sz, sz + len + 2, 1);
    for (int i = 0; i < n; i++)
    {
        int a = Root(l[i]), b = Root(r[i]);
        if (a == b) continue;
        if (sz[a] < sz[b])
        {
            sz[b] += sz[a];
            root[a] = b;
        }
        else
        {
            sz[a] += sz[b];
            root[b] = a;
        }
    }
    for (int i = 1; i < len + 2; i++)
    {
        int j = i;
        while (j != root[j]) j = root[j];
        summ[j] += x[i];
    }
    int t = -1;
    for (int i = 0; i < len + 2; i++)
    {
        if (summ[i] % 26 != 0)
        {
            cout << "NO", exit(0);
        }
    }
    cout << "YES";
}


Measured memory_bytes: 2128
import math

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    M = int(buflist[1])
    max = 1
    for i in get_divisor_list(M):
        # Mがiで割り切れる、かつ割ったときの値がN以上なら可能なはず
        if M % i == 0 and M / i >= N:
            max = i
    print(max)

# 約数のリストを取得
def get_divisor_list(num):
    div_list = [1, num]
    limit = int(math.sqrt(num))
    for i in range(2, limit+1):
        if num % i == 0:
            div_list.append(i)
            div_list.append(int(num / i))
    return sorted(div_list)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*
 * PrintARectangle.cpp
 *
 *  Created on: 2014/07/21
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
using namespace std;

typedef struct {
	int a_H, a_W;
}DataSet;

int main(void) {

	vector<DataSet> vecDataSet;
	while (1) {
		DataSet data;
		int H, W = 0;
		cin >> H >> W;
		if ((0 == H) && (0 == W)) {
			break;
		}
		data.a_H = H;
		data.a_W = W;
		vecDataSet.push_back(data);
	}

	for (unsigned int i = 0; i < vecDataSet.size(); i++) {
		DataSet data = vecDataSet.at(i);
		for (int i = 0; i < data.a_H; i++) {
			for (int j = 0; j < data.a_W; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

alias Seg = Tuple!(int, "l", int, "r");

void main() {
    int n, m;
    scan(n, m);

    auto ft = fenwickTree(m + 1);
    auto sgs = new Seg[](n);

    foreach (i ; 0 .. n) {
        int li, ri;
        scan(li, ri);
        sgs[i] = Seg(li, ri);
    }

    sgs.sort!"a.r - a.l < b.r - b.l"();

    debug {
        writeln(sgs);
    }

    writeln(n);

    foreach (d ; 2 .. m + 1) {
        while (!sgs.empty && sgs[0].r - sgs[0].l + 1 < d) {
            ft.add(sgs[0].l, 1);
            ft.add(sgs[0].r + 1, -1);
            sgs.popFront();
        }

        int ans;

        for (int i = d; i <= m; i += d) {
            ans += ft.psum(i);
        }

        ans += sgs.length.to!int;

        writeln(ans);
    }
}

struct fenwickTree {
    private {
        int N;
        int[] data;
    }

    this (int n) {
        N = n;
        data = new int[](N + 1);
    }

    void add(int i, int x) {
        while (i <= N) {
            data[i] += x;
            i += i & (-i);
        }
    }

    int psum(int r) {
        return r > 0 ? psum(r - (r & (-r))) + data[r] : 0;
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 5884
A,B,Q = map(int,input().split())
INF = 10**18
S = [-INF] + [int(input()) for _ in range(A)] + [INF]

T = [-INF] + [int(input()) for _ in range(B)] + [INF]

X = [int(input()) for _ in range(Q)]

from bisect import bisect_left

for _ in range(Q):
    ans = INF
    x = X[_]
    idxs = bisect_left(S, x)
    idxt = bisect_left(T, x)
    for s in [S[idxs-1], S[idxs]]:
        for t in [T[idxt-1], T[idxt]]:
            d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
            ans = min(ans, d1, d2)
    print(ans)



Measured memory_bytes: 16132
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int N;
  cin>>N;
  bool Flag=0;
  for(int i=0;i<N;i++){
    int s,f;
    cin>>s>>f;
    if((s<=a)&&(a<f)) Flag=1;
    if((s<b)&&(b<=f)) Flag=1;
    if((a<=s)&&(f<=b)) Flag=1;
    if(Flag) break;
  }
  cout<<Flag<<endl;
  return 0;
}



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

class List_of_Top_3_Hills
{
    public static void Main(String[] args)
    {
        List<int> a = new List<int>();
        for (int i = 0; i < 10; i++)
        {
            a.Add(int.Parse(Console.ReadLine()));
        }

        a.Sort();
        a.Reverse();

        for (int i = 0; i < 3; i++)
        {
            Console.WriteLine(a[i]);
        }
    }
}

Measured memory_bytes: 9332
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int N, K;
vector<int> A, F;

bool check(int val) {
    int cnt = 0;
    rep(i, N) {
        int diff = max(0LL, A[i] * F[i] - val);
        cnt += (diff + F[i] - 1) / F[i];
    }
    return cnt <= K;
}

signed main() {
    cin >> N >> K;

    inputVector(A, N);
    inputVector(F, N);

    sort(all(A));
    sort(all(F));
    reverse(all(F));

    int low = -1;
    int high = A.back() * F[0];
    int mid = (low + high + 1) / 2;
    while (high - low > 1) {
        if (check(mid)) {
            high = mid;
        } else {
            low = mid;
        }
        mid = (low + high + 1) / 2;
    }

    cout << mid << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using edge=struct{int to; int cost;};

const int MAXN=100001;
int n;

void bfs(){
  vector<int> ans(n+1,-1);
  vector<vector<edge>> tree(n+1);
  for(int i=0;i<n-1;i++){
    int a,b,c; cin>>a>>b>>c;
    tree[a].push_back(edge{b,c});
    tree[b].push_back(edge{a,c});
  }
  queue<int> que;
  que.push(1);
  ans[1]=0;
  while(!que.empty()){
    int v=que.front(); que.pop();
    for(edge &e:tree[v]){
      int u=e.to,cost=e.cost;
      if(ans[u]!=-1) continue;
      que.push(u);
      if(cost%2==0){
        ans[u]=ans[v];
      }else{
        ans[u]=abs(ans[v]-1);
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout<<ans[i]<<endl;
  }
}

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

Measured memory_bytes: 6784
n = int(input())
a_s = [int(v) for v in input().split()]

a_s.sort()
#max_a = a_s[len(a_s) - 1]
#min_a = a_s[0]
m = a_s[-1] - a_s[0]
for a in a_s[1:-1]:
  m += abs(a)
  
#m = sum(a_s[1:]) - a_s[0]

print(m)

max_a = a_s[-1]
min_a = a_s[0]

for a in a_s[1:-1]:
  if a < 0:
    print("{} {}".format(max_a, a))
    max_a -= a
  else:
    print("{} {}".format(min_a, a))
    min_a -= a
    
print("{} {}".format(max_a, min_a))

Measured memory_bytes: 14264
/*
 * main.c
 *
 *  Created on: 2019/12/29
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;

int main()
{
	int A = 0, B = 0, C = 0, ans = 0;
	scanf("%d %d %d", &A, &B, &C);
	if ((A == B) && (C != A)) {
		ans = 1;
	}
	if ((C == B) && (B != A)) {
		ans = 1;
	}
	if ((A == C) && (B != A)) {
		ans = 1;
	}

	if (ans == 1) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int a = s.nextInt();
    int b = s.nextInt();
    int c = s.nextInt();
    int sum = b/a;

    if(sum > c ){
      System.out.println(c);
    }else{
      System.out.println(sum);
    }

}
}


Measured memory_bytes: 23764
n = int(input())
A = list(map(int,input().split()))
x = dict()
ans = 0

for i in range(n):
    tmp = i + A[i]
    if tmp not in x:
        x[tmp] = 1
    else:
        x[tmp] += 1

for j in range(n):
    l = j - A[j]
    if l in x:
        ans += x[l]

print(ans)

Measured memory_bytes: 40428
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] V = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int[] C = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int tmp = 0;
            for(int i = 0; i < N; i++)
            {
                if(V[i] - C[i] > 0)
                {
                    tmp += V[i] - C[i];
                }
            }
            Console.WriteLine(tmp);
        }
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int n,c,k,cnt = 0;
long long t[100005];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> c >> k;
    for(int i = 0; i < n ; i++){
        cin >> t[i];
    }

    sort(t, t+n);

    int start = 0, i = 0;
    while(i < n){
        int tmp = 0;
        while(i < n && t[i] <= t[start]+k && tmp < c){
            i++; tmp++;
        }
        cnt ++;
        start = i;
    }
    cout << cnt;



    return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int[][] books = new int[n][m + 1];
    for (int i = 0; i < n; i++) {
      books[i][0] = sc.nextInt();
      for (int j = 1; j <= m; j++) {
        books[i][j] = sc.nextInt();
      }
    }
    int answer = -1;
    int[] scores = new int[m];
    for (int sw = 1; sw <= (1 << n); sw++) {
      Arrays.fill(scores, 0);
      int amount = 0;
      for (int index = 0; index < n; index++) {
        if ((1 & (sw >> index)) == 1) {
          for(int i = 0; i < m; i++){
            scores[i] += books[index][i + 1];
          }
          amount += books[index][0];
        }
      }
      boolean isOK = true;
      for(int i = 0; i < scores.length; i++){
        if(scores[i] < x){
          isOK = false;
          break;
        }
      }
      if(isOK){
        if(answer < 0){
          answer = amount;
        } else {
          answer = Math.min(answer, amount);
        }
      }
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 37172
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int res = 0;

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    vector<int> data(1000005, 0);
    sort(A.begin(),A.end());
    for (int x : A)
    {
        if (data[x] != 0)
        {
            data[x] = 2;
            continue;
        }
        for (int i = x; i < 1000005; i+=x)
        {
            data[i]++;
        }
    }
    res = 0;
    for (int x : A)
    {
        if (data[x] == 1)
        {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 7948
import java.util.*;

public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		long attack = 0;
		long[] num = new long[(int) N];
		for(int i = 0;i < N;i++) {
			num[i] = sc.nextInt();
		}
		if(N <= K) {
			System.out.println("0");
		}else {
			Arrays.sort(num);
			for(int j = 1;j <= K;j++) {
				num[(int) (N-j)] = 0;
			}
			for(int k = 0;k < N;k++) {
				attack += num[k];
			}
			System.out.println(attack);
		}
	}
}

Measured memory_bytes: 61896
import fractions
from functools import reduce
N = int(input())
a = [int(ai) for ai in input().split()]

def f(m):
    answer = 0
    for ai in a:
        answer += m % ai
    return answer

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

m = lcm(a) - 1
print(f(m))


Measured memory_bytes: 5716
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  std::string s;

  std::cin >> s;

  bool good = false;

  for (int i = 0, j = 0; i < 10; i ++, j += 111) {
    char buf[256];

    sprintf(buf, "%03d", j);
    
    if (s.find(buf) != std::string::npos)
      good = true;
  }

  std::cout << (good ? "Yes" : "No") << std::endl;

  return 0;
}


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

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

  if(s[0]=='R' && s[1]=='R' && s[2]=='R') cout<<3<<endl;
  else if(s[0]=='R' && s[1]=='R' && s[2]=='S') cout<<2<<endl;
  else if(s[0]=='S' && s[1]=='R' && s[2]=='R') cout<<2<<endl;
  else if(s[0]=='R' || s[1]=='R' || s[2]=='R') cout<<1<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 3624
#include <cstdio>

int main() {
  int n, t, c1 = 1, c2 = 1;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &t);
    if (t%2 == 0) {
      c1 *= 3;
      c2 *= 2;
    } else {
      c1 *= 3;
      c2 *= 1;
    }
  }
  printf("%d",c1 - c2);
}


Measured memory_bytes: 128
n = int(input())
a = list(input() for _ in range(n))
# n = 3
# a = ["cbaa","daacc","acacac"]
s = ""
for c in a[0]:
    f = []
    for i in range(n-1):
        if c not in a[i+1]:
            break
        for d in range(len(a[i+1])):
            if c == a[i+1][d]:
                f.append(d)
                break
    else:
        s += str(c)
        for i in range(n-1):
            a[i+1] = a[i+1][:f[i]] +""+ a[i+1][f[i]+1:]
        
ns = "".join(sorted(s))
print(ns)

Measured memory_bytes: 3064
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(100**3)

def rec(n, dp):
	if n <= 1:
		return n
	if dp[n] < float('inf'):
		return dp[n]
	pow6 = 6
	pow9 = 9
	dp[n] = min(n, dp[n])
	while n >= pow6:
		dp[n] = min(dp[n], rec(n-pow6, dp) + 1)
		pow6 *= 6
	while n >= pow9:
		dp[n] = min(dp[n], rec(n-pow9, dp) + 1)
		pow9 *= 9
	return dp[n]

def resolve():
	n = int(input())
	dp = [float('inf')]*(n+1)
	print(rec(n, dp))
resolve()

Measured memory_bytes: 20592
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;
/*ここから*/
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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()
{ 
    // 前処理
    COMinit();
    LL n;
    cin>>n;
    string S;
    cin>>S;
    int s[n];
    LL r=0;
    LL g=0;
    LL b=0;
    for(int i=0;i<n;i++){
        if(S[i]=='R'){s[i]=0;r++;}
        else if(S[i]=='G'){s[i]=1;g++;}
        else if(S[i]=='B'){s[i]=4;b++;}
    }
    LL ans=r*g*b;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            if(2*j-i<n){
                if(s[i]+s[j]+s[2*j-i]==5){ans--;}
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

class Cube {
   public:
    int f[6];  //サイコロ
    Cube() {}  //コンストラクタ
    void roll_z() { roll(1, 2, 4, 3); }
    void roll_y() { roll(0, 2, 5, 3); }  // to W
    void roll_x() { roll(0, 1, 5, 4); }  // to N
    void roll(int i, int j, int k, int l) {
        int t = f[i];
        f[i]  = f[j];
        f[j]  = f[k];
        f[k]  = f[l];
        f[l]  = t;
    }
    void move(char ch) {
        if (ch == 'E')
            for (int i = 0; i < 3; i++) roll_y();  // Wを３回
        if (ch == 'W') roll_y();
        if (ch == 'N') roll_x();
        if (ch == 'S')
            for (int i = 0; i < 3; i++) roll_x();  // Nを３回
    }
};

int main() {
    Cube   c;    // サイコロ
    string com;  // 命令

    // 入力
    for (int i = 0; i < 6; i++) cin >> c.f[i];  // サイコロの面
    cin >> com;                                 // 命令

    // 処理
    for (int i = 0; i < com.size(); i++) {
        c.move(com[i]);
    }

    // 出力
    cout << c.f[0] << "\n";

    return 0;
}


Measured memory_bytes: 3208
N, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(N - 1):
    S = A[i + 1] + A[i]
    if S > x:
        ans += S - x
        if A[i + 1] > S - x:
            A[i + 1] -= S - x
        else:
            A[i + 1] = 0

print(ans)


Measured memory_bytes: 14252
#include <algorithm>
#include <cstdio>
#include <vector>
template <typename T> constexpr T my_abs(const T &x) { return x < 0 ? -x : x; }
char s[5005], t[5005];
int main()
{
	// freopen("AGC030-E.in", "r", stdin);
	int n;
	scanf("%d%s%s", &n, s, t);
	auto init = [&] (char *str)
	{
		std::vector<int> res;
		for (int i = 1; i < n; i++)
		{
			if (str[i] != str[i - 1])
				res.push_back(i);
		}
		return res;
	};
	auto vec_s = init(s), vec_t = init(t);
	auto get = [&] (std::vector<int> &vec, int idx)
	{
		if (idx < 0)
			return 0;
		if (idx >= vec.size())
			return n;
		return vec[idx];
	};
	int ans = 1e9, a = vec_s.size(), b = vec_t.size();
	for (int off = -a - 1; off <= b + 1; off++)
	{
		if ((off & 1) == (s[0] == t[0]))
			continue;
		int res = 0;
		for (int i = std::min(-off, 0); i < std::max(a, b - off); i++)
			res += my_abs(get(vec_s, i) - get(vec_t, i + off));
		ans = std::min(ans, res);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 384
n = gets.to_i
line = gets.chomp.split(" ").map(&:to_i);

answer = 1

for i in 0 .. (line.length - 1) do
	if line[i] == 0 then
		puts "0"
		exit
	end
end

for i in 0 .. (line.length - 1) do
	answer = answer * line[i]
	if answer > 1000000000000000000 then
		puts "-1"
		exit
	end
end

puts answer

Measured memory_bytes: 23556
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
const int INF=1e7;

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> E, W;
  rep(i,N){
    if(S[i]=='E') E.push_back(i);
    else W.push_back(i);
  }
  int ans=INF;
  rep(L,N){
    int num=0;
    num+=lower_bound(W.begin(),W.end(),L)-W.begin();
    num+=E.size()-(upper_bound(E.begin(),E.end(),L)-E.begin());
    ans=min(ans,num);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2812
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
main(){
	int M,T,P,R,m,t,p,j,ac,time;
	for(;scanf("%d%d%d%d",&M,&T,&P,&R),M;puts("")){
		map<int,pair< //team number
			map<int,int>, //problem, accepted_time
			map<int,int>  //problem, wrong_answer
		> >contest;
		for(;R--;){
			scanf("%d%d%d%d",&m,&t,&p,&j);
			if(j){ //wrong_answer
				contest[t].second[p]+=20;
			}else{
				contest[t].first[p]=m;
			}
		}
		vector<pair<pair<int,int>,int> >contestants;
		for(t=1;t<=T;t++){
			ac=time=0;
			map<int,int>::iterator it=contest[t].first.begin();
			for(;it!=contest[t].first.end();it++){
				ac++;
				time+=it->second+contest[t].second[it->first];
			}
			contestants.push_back(make_pair(make_pair(-ac,time),-t));
		}
		sort(contestants.begin(),contestants.end());
		printf("%d",-contestants[0].second);
		for(t=1;t<T;t++){
			printf(
				contestants[t].first.first==contestants[t-1].first.first &&
				contestants[t].first.second==contestants[t-1].first.second ? "=%d" : ",%d",
				-contestants[t].second
			);
		}
	}
}

Measured memory_bytes: 1100
import math

nk = input().split()
n = int(nk[0])
k = int(nk[1])
res = 0

if k % 2 == 1:
    # a b c equiv 0 mod k
    res = int(math.pow(math.floor(n / k), 3))
else:
    mk0 = 0
    mkk2 = 0
    for i in range(1, n+1):
        if i % k == 0:
            mk0 += 1
        if i % k == (k / 2):
            mkk2 += 1
    res = int(math.pow(mk0, 3) + math.pow(mkk2, 3))

print(res)


Measured memory_bytes: 3064
import math
n, h = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(n)))
m = max(a)
r = 0
for i in sorted(b)[::-1]:
    if h<=0 or i<=m:
        break
    h -= i
    r += 1
print(r + math.ceil(max(h, 0)/m))

Measured memory_bytes: 59096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c=0,d=0;
  for(int i=0;i<4;i++){
    cin >> a;
    c += a;
  }
  for(int i=0;i<4;i++){
    cin >> b;
    d += b;
  }
  if(c>d) cout << c << endl;
  else cout << d << endl;
  return (0);
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	rep(i, s.length()) cout << "x";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
    string s;
    cin>>s;
    ll n=(ll)s.size();
    ll countr=0;
    ll countl=0;
    vector<ll>a(n);
    for(ll i=0;i<n;){
        while(s[i]=='R'&&i<n){
            i++;
            countr++;
        }
        ll x=i-1;
        ll y=i;
        a[x]+=countr-countr/2;
        a[y]+=countr/2;
        while(s[i]=='L'&&i<n){
            i++;
            countl++;
        }
        a[x]+=countl/2;
        a[y]+=countl-countl/2;
        countr=0;
        countl=0;
    }
    cout<<a[0]<<" ";
    for(ll i=1;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
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;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
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 m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		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) % mod;
}

int x;

signed main() {
	cin >> x;
	int a = x / 100;
	if (100 * a <= x && x <= 105 * a)cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,m,c,ans=0,sum=0;
	cin>>n>>m>>c;
	vector<int>b(m),a(m);
	for(int i=0;i<m;i++)cin>>b[i];
	for(int i=0;i<n;i++){
		sum=0;
		for(int j=0;j<m;j++){
			cin>>a[j];
			sum+=a[j]*b[j];
		}
		sum+=c;
		if(sum>0)ans++;


	}
	cout<<ans<<endl;

}


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

int cal(int a, int b){
	if(a <= b) return b-a;
	else return a-b+2;
}

int main(){
	int x, y;
	scanf("%d%d", &x, &y);
	printf("%d\n", min( min(cal(x, y), cal(-x, y)+1), cal(x, -y)+1 ));
}

Measured memory_bytes: 256