akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
char a[105];
int stra;
int main()
{
//	freopen("replace.in","r",stdin);
//	freopen("replece.out","w",stdout);
	scanf(" %s",a);
	stra=strlen(a);
	printf("%c%d%c\n",a[0],stra-2,a[stra-1]);
	return 0;
}

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



struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}

	double x,y;
};

typedef Point Vector;

struct Line{
	Line(){

	}
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	Point p[2];
};

struct Circle{
	Point center;
	double r;
};


int N;
Circle C[105];


Point calc_minus(Point a,Point b){
    Point ret;

    ret.x = a.x-b.x;
    ret.y = a.y-b.y;

    return ret;
}

double calc_len(Vector a){
    return sqrt(a.x*a.x+a.y*a.y);
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}

//線分ではなく直線と点の距離
double getDistanceLP(Line l,Point p){
    return fabs(cross(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0]))/calc_len(calc_minus(l.p[1],l.p[0])));
}

//点と線分の距離
double getDistanceSP(Line l,Point p){
	if(dot(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0])) < 0.0)return calc_len(calc_minus(p,l.p[0]));
	if(dot(calc_minus(l.p[0],l.p[1]),calc_minus(p,l.p[1])) < 0.0)return calc_len(calc_minus(p,l.p[1]));
	return getDistanceLP(l,p);
}



double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}

void func(){

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

		scanf("%lf %lf %lf",&C[i].center.x,&C[i].center.y,&C[i].r);
	}

	int num_query;
	scanf("%d",&num_query);

	Line line;
	bool FLG;

	double mini = BIG_NUM;

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

		scanf("%lf %lf %lf %lf",&line.p[0].x,&line.p[0].y,&line.p[1].x,&line.p[1].y);
		FLG = false;

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

			mini = min(mini,getDistanceSP(line,C[i].center)-C[i].r);

			//両方中ならSKIP
			if(calc_dist(line.p[0],C[i].center) <= C[i].r && calc_dist(line.p[1],C[i].center) <= C[i].r)continue;

			if(getDistanceSP(line,C[i].center) <= C[i].r){
				FLG = true;
				break;
			}
		}

		if(!FLG){

			printf("Danger\n");

		}else{

			printf("Safe\n");
		}
	}
}

int main(){

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

		func();
	}

	return 0;
}



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

using namespace std;

char s[200005];

int main() {
	scanf("%s", s);
	
	int sum = 0;
	int l = strlen(s);
	
	for (int i = 0; i < l; i++) {
		sum = (sum + s[i] - '0') % 9;
	}
	
	if (sum == 0) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 3912
#include <stdio.h>

void merge_sort(int x[], int temp[], int start, int end);

int main(void)
{
  int i;
  int height[10];
  int temp[10];
  
  for (i=0;i<10;i++)
    {
      scanf ("%d", &height[i]);
    }

  merge_sort(height,temp,0,i);

  for (i=9;i>6;i--)
    {
      printf("%d\n", height[i]);
    }
  
  return 0;
  
}

void merge_sort(int x[], int temp[], int start, int end)
{
  int middle;
  int i, j, k;

  if (end <= start)
    {
      return ;
    }
  middle = (end+start)/2;
  merge_sort(x,temp,start,middle);
  merge_sort(x,temp,middle+1,end);

  for (i=start;i<=middle;i++)
    {
      temp[i] = x[i];
    }

  j = end;
  for (i=middle+1;i<=end;i++)
    {
      temp[i] = x[j];
      j--;
    }

  i = start;
  j = end;
  
  for (k=start;k<=end;k++)
    {
      if (temp[i] <= temp[j])
	{
	  x[k] = temp[i];
	  i++;
	}
      else
	{
	  x[k] = temp[j];
	  j--;
	}
    }
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) {
    const T inf = numeric_limits<T>::max();
    using P     = pair<T, int>;
    int n       = G.size();
    vector<T> d(n, inf);
    priority_queue<P, vector<P>, greater<P>> q;
    d[s] = 0;
    q.emplace(d[s], s);
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        for (auto &e : G[v]) {
            int u = e.first;
            T c   = e.second;
            if (d[u] > d[v] + c) {
                d[u] = d[v] + c;
                q.emplace(d[u], u);
            }
        }
    }
    return d;
}

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m, s;
    cin >> n >> m >> s;

    vector<vector<pair<int, lint>>> edges(3000 * n); // 3000: max de iihazu
    for (int i = 0; i < m; ++i) {
        int u, v;
        lint a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        for (int j = 0; j < 3000; ++j) {
            if (j - a >= 0) {
                edges[n * j + u].emplace_back(n * (j - a) + v, b);
                edges[n * j + v].emplace_back(n * (j - a) + u, b);
            }
        }
    }
    vector<lint> c(n), d(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i] >> d[i];
        for (int j = 0; j < 3000; ++j) {
            edges[n * j + i].emplace_back(n * (min(2999LL, j + c[i])) + i, d[i]);
        }
    }
    auto dist = dijkstra<lint>(n * min(2999LL, s), edges);
    for (int i = 1; i < n; ++i) {
        lint ret = inf;
        for (int j = 0; j < 3000; ++j) {
            chmin(ret, dist[j * n + i]);
        }
        cout << ret << "\n";
    }
    return 0;
}

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

int main(){
  int n;
  long long max,min;
  long long total=0;
  cin >> n;
  int a[n];
  for(int i=0; i < n; i++){
    scanf("%d",&a[i]);
    if(i==0){
      max = a[i];
      min = a[i];
    }else if(max < a[i]){
      max = a[i];
    }else if(min > a[i]){
      min = a[i];
    }
    total += a[i];
  }
  printf("%lld %lld %lld\n", min, max, total);

}

Measured memory_bytes: 3196
S = list(input())
from collections import defaultdict
def zarts(L):
    #d = defaultdict(int)
    order = 0
    count = 1
    s = L[0]
    z = []
    for i in range(1,len(L)):
        if L[i]==s:
            count += 1
            continue
        else:
            #d[s] = order
            s = L[i]
            #z.append([order,count])
            z.append(count)
            order += 1
            count = 1
    z.append(count)
    return z
def ceil(n): # ceiling関数
    if n > int(n):
        return(int(n)+1)
    else:
        return(int(n))

Z = zarts(S)
ans = [0]*len(S)
now = 0
for i in range(0,len(Z),2):
    b = now+Z[i]-1
    ans[b] += ceil(Z[i]/2) + Z[i+1]//2
    ans[b+1] += ceil(Z[i+1]/2) + Z[i]//2
    now = b+Z[i+1]+1
print(*ans)

Measured memory_bytes: 8200
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
using namespace std;


int main(){
int a,b;
cin >> a >> b;
int h = b - a;
int H = 0;
for(int i = 1; i < h; i++){
     H += i;
}
cout << H - a << endl;
}

Measured memory_bytes: 256
import math
N, D = map(int, input().split())
X = [[int(x) for x in input().split()] for i in range(N)]
count = 0
for i in range(N):
    for j in range(i+1, N):
        sum = 0
        for d in range(D):
            sum += pow(X[i][d]-X[j][d], 2)
        if math.sqrt(sum)%1==0:
            count += 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i, start, end) for(ll i=(ll)start; i<(ll)end; i++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(i,0,len) cout << a[i] << " ";

int main(){
  ll n, d, a, b;
  cin >> n;
  priority_queue<ll> q;
  rep(i, 0, n){
    cin >> d;
    q.push(d);
  }
  rep(i, 0, n/2){
    a = q.top();
    q.pop();
  }
  b = q.top();
  print(a-b);
  
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;

signed main(){
  int n;cin>>n;
  vector<vector<int>> a(n,vector<int>(n,0));
  rep(i,n){
      rep(j,n){
          cin>>a[i][j];
      }
  }
  int num=(1ll<<n);
  vector<int> dp(num,0);
  rep(i,num){
      int buf=0;
      rep(j,n){
          if(i&(1ll<<j)){
              rep(k,n){
                  if(i&(1ll<<k)){
                      buf+=a[k][j];
                  }
              }
          }
      }
      dp[i]=buf/2;
  }
  rep(i,num){
      //printf("dp[%lld] = %lld\n",i,dp[i]);
  }
  rep(i,num){
      for(int j=i;j>0;--j){
          j=j&i;
          int buf=dp[j]+dp[i-j];
          dp[i]=max(dp[i],buf);
      }
  }
  cout<<dp[(1ll<<n)-1]<<"\n";
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
vector<bool>visited;
vector<vector<int>>l;
vector<int>deg;
int isprime(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
            return 0;
    }
    return 1;

}
int isperfectsq(ll n)
{


    long double x;
    x=(long double)(sqrt((long double )(n)));
    ll y=sqrt(n);
    if(x==y)
        return 1;
        else
            return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);



    ll i,t;
    ll n;
    cin>>n;
    vector<ll>a(n,0);
    ll sum=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum^a[i];
    }
    //cout<<sum<<endl;
    for(i=0;i<n;i++)
    {
        cout<<(sum^a[i])<<" ";
    }



   }










Measured memory_bytes: 4748
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

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

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

    if(x >= 30) {
        cout << "Yes"
             << "\n";
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628
num = input()
num_WHxyr = num.split()
W = int(num_WHxyr[0])
H = int(num_WHxyr[1])
x = int(num_WHxyr[2])
y = int(num_WHxyr[3])
r = int(num_WHxyr[4])
if x-r < 0:
    print('No')
elif x+r > W:
    print('No')
elif y-r < 0:
    print('No')
elif y+r > H:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 7676
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

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

int N;
double xs[1002];
double ys[1002];
double rs[1002];
double ds[1002][1002];
double dist[1002];
int main() {
	cin >> xs[0] >> ys[0] >> xs[1] >> ys[1];
	cin >> N;
	N+=2;
	for(int i=2;i<N;i++){
		cin >> xs[i] >> ys[i] >> rs[i];
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			auto f=[](double x,double y){
				return sqrt(x*x+y*y);
			};
			double d=f(xs[i]-xs[j],ys[i]-ys[j]);
			ds[i][j]=max(0.0,d-rs[i]-rs[j]);
		}
	}
	for(int i=1;i<N;i++){
		dist[i]=1e30;
	}
	priority_queue<P,vector<P>,greater<P> > pq;
	pq.push(P(0,0));
	while(pq.size()){
		double d=pq.top().first;
		int p=pq.top().second;
		pq.pop();
		if(dist[p]<d)continue;
		for(int i=0;i<N;i++){
			double d2=d+ds[p][i];
			if(d2<dist[i]){
				dist[i]=d2;
				pq.push(P(d2,i));
			}
		}
	}
	cout.precision(18);
	cout << dist[1] << endl;


	return 0;
}



Measured memory_bytes: 14192
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    static int n;
    static int[] idGroup;
    static ArrayList<ArrayList<Integer>> G;
    public static void main(String[] arsg) {
        Scanner input = new Scanner(System.in);
        n = input.nextInt();
        int m = input.nextInt();
        G = new ArrayList<ArrayList<Integer>>();
        for(int i = 0; i < n; i++) {
            G.add(new ArrayList<Integer>());
        }
        for(int i = 0; i < m; i++) {
            int s = input.nextInt();
            int t = input.nextInt();
            G.get(s).add(t);
            G.get(t).add(s);
        }

        assignId();

        int q = input.nextInt();
        for(int i = 0; i < q; i++) {
            int s = input.nextInt();
            int t = input.nextInt();
            if(idGroup[s] == idGroup[t]) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }

    static void assignId() {
        int id = 1;
        idGroup = new int[n];
        for(int i = 0; i < n; i++) {
            idGroup[i] = -1;
        }
        for(int u = 0; u < n; u++) {
            if(idGroup[u] == -1) {
                dfs(u, id++);
            }
        }
    }

    static void dfs(int r, int id){
        Stack<Integer> S = new Stack<Integer>();
        S.push(r);
        idGroup[r] = id;
        while(!S.isEmpty()) {
            int u = S.pop();
            for(int i = 0; i < G.get(u).size(); i++) {
                int v = G.get(u).get(i);
                if(idGroup[v] == -1) {
                    idGroup[v] = id;
                    S.push(v);
                }
            }
        }
    }
}



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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

bool check_max(int n, vector<ll> a){
	ll ma = -1;
	for(int i=0; i<n; i++){
		ma = max(ma, a[i]);
	}
	if(ma <= n-1) return false;
	else return true;
}

ll solve(int n, vector<ll> a){
	ll ans = 0;
	while(check_max(n, a)){
		ll ma = -1;
		int id = -1;
		for(int i=0; i<n; i++){
			if(ma < a[i]){
				ma = a[i];
				id = i;
			}
		}
		a[id] -= a.size();

		for(int i=0; i<n; i++){
			if(i != id){
				a[i]++;
			}
			//printf("%d ", a[i]);
		}
		//puts("");
		ans++;
	}
	return ans;
}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	ll k;
	cin >> k;

	vector<ll> a;
	int n = 50;
	for(int i=0; i<50;i++){
		a.pb((k/50) + i);
	}
	for(int i=0; i<(k%50); i++){
		a[i] += n;
		for(int j=0; j<50; j++){
			if(i == j) continue;
			a[j]--;
		}
	}

	cout << n << endl;
	for(int i=0; i<n; i++){
		if(i != n-1) printf("%lld ", a[i]);
		else printf("%lld\n", a[i]);
	}

	//cout << solve(n, a) << endl;

	
	/*
	int n;
	n = 2;
	vector<ll> a;
	a.pb(1 + ((k+1)/2));
	a.pb(k/2);

	cout << n << endl;
	for(int i=0; i<n; i++){
		if(i != n-1) printf("%lld ", a[i]);
		else printf("%lld\n", a[i]);
	}
	*/

	/*
	int n;
	cin >> n;
	vector<ll> a;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.pb(t);
	}
	cout << solve(n, a) << endl;
	*/

	/*
	for(int i=0; i<20; i++){
		for(int j=0; j<20; j++){
			for(int k=0; k<20; k++){
				vector<int> a;
				a.pb(i);
				a.pb(j);
				a.pb(k);

				printf("%3lld ", solve(3, a));
			}
			puts("");
		}
		puts("\n");
	}
	*/



	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

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


Measured memory_bytes: 3624
N, M, K = map(int, input().split())
MOD = 998244353

n = N
fac = [1]*(n+1)
rev = [1]*(n+1)
 
for i in range(1,n+1):
  fac[i] = i*fac[i-1]%MOD
  rev[i] = pow(fac[i], MOD-2, MOD)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD
ans = 0

for i in range(K+1):
    ans += comb(N-1, N-1-i) * M * pow(M-1, N-1-i, MOD)
    ans %= MOD

print(ans)


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

typedef long long s64;

int main()
{
	//freopen("1.in","r",stdin);
	int n,k;
	cin>>n>>k;
	if(!k)
	{
		cout<<(s64)n*n;
		exit(0);
	}
	s64 ans=0;
	for(int b=1;b<=n;++b)
	for(int i=0;i<=n;i+=b)ans+=max(0,min(n+1,i+b)-(i+k));
	cout<<ans;
}

Measured memory_bytes: 256
import math
N = int(input())
Xlist = list(map(int,input().split()))

min =10**5
meandown = math.floor(sum(Xlist)/N)
meanup = math.ceil(sum(Xlist)/N)
sumdown=0
sumup = 0
for i in range(len(Xlist)):
  sumdown+= (Xlist[i]-meandown)**2
  sumup+= (Xlist[i]-meanup)**2
  
if sumdown<sumup:
  print(sumdown)
else:
  print (sumup)

Measured memory_bytes: 9140
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

n=gets.to_i
b=[]
A=get_i
flag=false
A.each do|a|
    if flag
        b.unshift(a)
    else
        b.push(a)
    end
    flag=!flag
end
b.reverse! if flag
puts b.join(" ")

Measured memory_bytes: 27484
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int a,b,c,d,e;
	cin >> a >> b >> c >> d;
	e = max(abs(a - b),abs(b-c));
	if (e > d && abs(c - a) > d){
		cout << "No" <<endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n;
    string str;
    cin >> n >> str;
    char alphabets[26];
    for(int i = 0; i < 26; i++){
        alphabets[i] = 'A' + i; 
    }
    for(int i = 0; i < str.size(); i++){
        int index = str.at(i) - 'A';
        index = (index + n) % 26;
        cout << alphabets[index];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	_, _ = fmt.Scanf("%d", &n)

	a := make([]int, n+1)

	for i := 1; i <= n; i++ {
		_, _ = fmt.Scanf("%d", &a[i])
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("node %d: key = %d, ", i, a[i])
		if i != 1 {
			fmt.Printf("parent key = %d, ", a[i/2])
		}
		if i*2 <= n {
			fmt.Printf("left key = %d, ", a[i*2])
		}
		if i*2+1 <= n {
			fmt.Printf("right key = %d, ", a[i*2+1])
		}
		fmt.Printf("\n")
	}
}



Measured memory_bytes: 1156
n=int(input())
res=[]
for i in range(n):
    s,p=map(str,input().split())
    res.append([s,int(p)])
res1=res
res=sorted(res,key=lambda x:(x[0], -x[1]))
for i in range(n):
	print(res1.index(res[i])+1)

Measured memory_bytes: 8996
#include<stdio.h>
int main()
{
    int k,i,cnt1=0,cnt2=0;
    scanf("%d",&k);
    for(i=1;i<=k;i++)
    {
        if(i%2==0)
        cnt1=cnt1+1;
        else
        cnt2=cnt2+1;
    }
    printf("%d",cnt1*cnt2);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int n,a[111111],ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	ans+=abs(a[1]);
	for (int i=2;i<=n;i++) ans+=abs(a[i]-a[i-1]);
	ans+=abs(a[n]);
	printf("%d\n",ans-abs(a[1])-abs(a[1]-a[2])+abs(a[2]));
	for (int i=2;i<n;i++)
	{
		printf("%d\n",ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));
	}
	printf("%d\n",ans-abs(a[n]-a[n-1])-abs(a[n])+abs(a[n-1]));
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, x;
  cin >> n >> x;
  vi a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  REP(i,n) {
    int sum = a[i]+a[i-1];
    ans += max(0, sum-x);
    if(sum-x > 0) a[i] -= min(a[i], sum-x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int n,i,count=0;
	scanf("%d",&n);
	char word[n+1];
	getchar();
	gets(word);
	for(i=0;i<n;i++){
		if(word[i]!=word[i+1])
			count++;
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 256
a,b = map(int, input().split(' '))
binA = format(a,"b")
binB = format(b,"b")
ans = 0
for i in range(1,50):
    if b<2**(i-1):
        break
    nm1 = b//(2**i)*(2**(i-1))-(a+2**i-1)//(2**i)*(2**(i-1))
    if b%(2**i) != 0:
        nm1 += max(0, b%(2**i)-2**(i-1)+1)
    if a%(2**i) != 0:
        nm1 += min(2**(i-1), 2**i - a%(2**i))
    if nm1 % 2 == 1:
        ans += 2**(i-1)
print(ans)

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<typename T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<typename T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T> T Min(T a, T b) { return a > b ? b : a; }
template<typename T> T Max(T a, T b) { return a < b ? b : a; }
template<typename T> void de(T a){ 
#ifdef LOCAL_DEFINE
	cout<< a << endl;
#endif
}	
const int INF = 2e5+1;
const int mod = 1e9+7;
         	
void solve(){
	string a,b,c;
	cin>>a>>b>>c;
	cout<<a[0]<<b[1]<<c[2]<<endl;
}


int main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    	cout.precision(10);
    	cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
	freopen("output.txt","w",stdout);
#endif  
        int q=1;
#ifdef LOCAL_DEFINE
        cin>>q;
#endif
        while(q--){
         	solve();
        }

#ifdef LOCAL_DEFINE
         
             
        cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif

	return 0;
}	



Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,i,j,t,rs,a[20],b[20][20],v[20][20],bl,m,vz[20];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		for(j=0;j<a[i];j++)
		{
			cin>>b[i][j]>>v[i][j];
			b[i][j]--;
		}
	}
	for(i=1;i<(1<<n);i++)
	{
		bl=1;
		m=i;
		while(bl)
		{
			bl=0;
			for(j=0;j<n;j++)
			{
				if(m&(1<<j))
				{
					for(t=0;t<a[j];t++)if(v[j][t] && !(m&(1<<b[j][t])))bl=1,m|=(1<<b[j][t]);
				}
			}
		}
		bl=0;
		for(j=0;j<n;j++)vz[j]=-1;
		for(j=0;j<n;j++)
		{
			if(!(m&(1<<j)))continue;
			for(t=0;t<a[j];t++)
			{
				if(vz[b[j][t]]==-1)vz[b[j][t]]=v[j][t];
				else if(vz[b[j][t]]!=v[j][t])bl=1;
			}
		}
		if(!bl)
		{
			for(j=0;j<n;j++)
			{
				if(!(m&(1<<j)))continue;
				for(t=0;t<a[j];t++)
				{
					if((m&(1<<b[j][t])) && !v[j][t])bl=1;
				}
			}
		}
		if(!bl)rs=max(rs,__builtin_popcount(m));
	}
	cout<<rs<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
LL a[210];
int main(){
	int n;
	while(cin>>n){
		int ans = 0;
		for(int i=1; i<=n; ++i)cin>>a[i];
		for( ; ; ){
			int cnt = 0;
			for(int i=1; i<=n; ++i)
				if(a[i]%2==0)a[i]/=2,cnt++;
			if(cnt==n)ans++;
			else break;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

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

	int ans = 1;
	int cnt = 0;
	for (int i = min(A, B); i > 1; --i) {
		if (A % i == 0 && B % i == 0) {
			++cnt;
			if (cnt == K) {
				ans = i;
				break;
			}
		}
	}

	cout << ans << '\n';
	return 0;
}


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

using namespace std;
using ll = long long;

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 ll INF = 1LL << 60;

ll p[100010][3];
ll dp[100010][3];

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

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

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + p[i][k]);
            }
        }
    }

    ll res = 0;
    for (int i = 0; i < 3; i++) {
        chmax(res, dp[n][i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 8256
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
#include<stdio.h>
using namespace std;

int main()
{
    string a;
    cin>>a;
    int cnt=0;
    for(int i=1;i<a.size();i++)
    {
        if(a[i]!=a[i-1])cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int n, K, Q;
vi a;
bool check(int ma, int mi){
    vi b(n);
    rep(i, n){
        if(a[i] < mi) b[i] = 0;
        else if(a[i] <= ma) b[i] = 1;
        else b[i] = 2;
    }

    vi h(3);

    int cnt = 0;
    vi used(n);
    for(auto& e : b){
        if(e == 0){
            h[1] = h[2] = 0;
            continue;
        }
        h[e]++;

        if(h[1] + h[2] == K){
            if(h[1] >= 1){
                cnt++;
                h[1]--;
            }
            else {
                h[2]--;
            }
        }

        if(cnt == Q){
            return true;
        }
    }

    return false;
}

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

    cin >> n >> K >> Q;
    a = vi(n); for(auto& e : a) cin >> e;

    int res = 1e9 + 10;
    rep(i, n){
        int mi = a[i];

        int lb, ub; lb = mi, ub = 1e9 + 10;
        bool ok = false;
        rep(loop, 40){
            int mid = (lb + ub) / 2;
            if(check(mid, mi)){
                ok = true;
                ub = mid;
            }
            else {
                lb = mid;
            }
        }
        if(ok) chmin(res, ub - mi);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) {
    return a < b ? a : b;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  head = 1;
  tail = n + 1;
  
  while (head != tail) {
      u = dequeue();
      c = min(q, u.t);
      u.t -= c;
      elaps += c;
      if (u.t > 0) enqueue(u);
      else {
          printf("%s %d\n", u.name, elaps);
      }
  }
  
  return 0;
}



Measured memory_bytes: 11916
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define ARRAY_LENGTH( array ) ( sizeof( array ) / sizeof( array[ 0 ] ))

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int Q;
	cin >> Q;
	vector <vector <int> > vec( Q, vector <int>( 2 ));
	int maximum = 0;
	rep( i, 0, Q ){
		cin >> vec[ i ][ 0 ] >> vec[ i ][ 1 ];
		maximum = max( maximum, max( vec[ i ][ 0 ], vec[ i ][ 1 ] ));
	}
	int* array = eratosthenes( maximum );
	int n;
	if (maximum % 2 == 1)
		n = maximum+1;
	for(int i = n+1; i >= 2; i -= 2 ){
		if ( array[ i ] == 0 || array[ ( i + 1 ) / 2 ] == 0 )
			array[ i ] = 0;
	}
	array[2] = 0;
	cumulative_sum( array, maximum );
	rep( i, 0, Q ){
		cout <<  array[ vec[ i ][ 1 ] ] - array[ vec[ i ][ 0 ]-1 ] << endl;
	}
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 h, w;
    cin >> h >> w;

    s64 ans = CEIL(h, 2) * CEIL(w, 2) + (h / 2) * (w / 2);

    if (h == 1 || w == 1) ans = 1;

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



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

int root(vector<int>&a,int n){
  if(a.at(n)==n)return n;
  else return root(a,a.at(n));
}

int main(){
  int n,m;
  cin >> n >> m;
  vector<int>a(n);
  iota(a.begin(),a.end(),0);
  for(int i=0,k,l;i<m;i++){
    cin >> k >> l;
    k--,l--;
    a.at(root(a,k))=min(root(a,k),root(a,l));
    a.at(root(a,l))=min(root(a,k),root(a,l));
  }
  set<int>ans;
  for(int i=0;i<n;i++){
    ans.insert(root(a,i));
  }
  cout << ans.size()-1 << endl;
  return 0;
}

Measured memory_bytes: 7656
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MOD 1000000009
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
#define top(i,j) val[i*m+j]
typedef long long lli;
typedef unsigned short int usi;

lli nPr(int n, int r) {
    int i;
    lli val=1;
    for(i=0; i<r; i++) {
        val = val*(n-i);
        val = val % MOD;
    }
    printf("nPr(%d,%d)=%d\n",n,r,val);
    return val;
}

lli nCr(int n, int r) {
    int i;
    lli val=1;
    r = MIN(r, n-r);
    for(i=0; i<r; i++) {
        val = val*(n-i)/(i+1);
    }
    val = val % MOD;
    printf("nCr(%d,%d)=%d\n",n,r,val);
    return val;
}

int main()
{
    int a, b, c, ans=1;
    scanf("%d %d %d",&a,&b,&c);
    ans = a*b*c/MAX3(a,b,c)/2;
    printf("%d",ans);
    return 0;
}


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

int main(){
    long long int N,result=0;
    cin >> N;
    
    for (int i=0;i<N+1;i++){
        if(i % 3 ==0 || i % 5 == 0) continue;
        result += i;
    }
    cout << result;
}

Measured memory_bytes: 3592
use std::io::*;
use std::str::FromStr;

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 gcd(x: u32, y: u32) -> u32 {
    let r = x % y;

    if r == 0 {
        return y;
    }

    return gcd(y, r);
}

fn main() {
    let x: u32 = read();
    let y: u32 = read();

    let result = if x > y { gcd(x, y) } else { gcd(y, x) };

    println!("{}", result)
}



Measured memory_bytes: 5024
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = 100005;
const LL INF = 0x3f3f3f3f3f3f3f3f;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

LL dp[MAXN][3];

void solve() {
	int n; read(n);
	int x; read(x);
	dp[1][0] = x;
	dp[1][1] = dp[1][2] = -INF;
	for (int i=2;i<=n;++i) {
		read(x);
		if (x < 0) {
			dp[i][0] = -INF;
			dp[i][1] = max(dp[i-1][0], dp[i-1][1]) + x;
			dp[i][2] = max(dp[i-1][1], dp[i-1][2]) - x;
		} else {
			dp[i][0] = max(dp[i-1][0], dp[i-1][1]) + x;
			dp[i][1] = max(dp[i-1][1], dp[i-1][2]) - x;
			dp[i][2] = dp[i-1][2] + x;
		}
	}	
	printf("%lld\n", max(dp[n][0], max(dp[n][1], dp[n][2])));
}

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


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++){
    cin>>L.at(i);
  }
  int count=0;
  sort(L.begin(),L.end());
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        if(L.at(k)<L.at(i)+L.at(j)){
          count=count+1;
        }
      }
    }
  }
  cout<<count<<endl;
}

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

int main(){
    ll N;  cin >> N;
    if(N%2==1){
        cout << 0 << endl;
        return 0;
    }

    ll div2 = 0;
    for(ll i=1; pow(2, i)<=N; i++){
        ll base = pow(2, i);
        div2 += N / base;
    }

    ll div5 = 0;
    for(ll i=1; pow(5, i)<=N; i++){
        ll base = pow(5, i) * 2;
        div5 += N / base;
    }
    cout << min(div2, div5) << endl;
}

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

bool is_prime(int k)
{
    for(int j=2;j*j<=k;j++){
        if(k%j==0) {
            return false;
        }
    }
    return true;
}

int main()
{
    // 入力
    ll N;
    cin>>N;
    ll Ncopy=N;
    int S[32];
    for(int i=0; i<32;i++){
        S[i]=0;
    }

    ll kmax=32; //log2(10^9)<30
    int k=0;
    while(N!=0){
        if(N%2==1 ||N%2==-1) {
            S[k]=1;
            N--;
        }
        N=N/2;
        if(N%2==1 ||N%2==-1){
            S[k+1]=1;
            N+=1;
        }
        N=N/2;
        k+=2;
    }

    bool printstart=false;
    ll testans=0;
    for(ll i=31;i>=0;i--){
        testans+=S[i]*pow(-2,i);
        if(printstart || i==0) cout<<S[i];
        else if(S[i]==1){
            printstart=true;
            cout<<S[i];
        }
    }
        cout<<endl;
        // cout<<testans<<endl;
        // if(testans==Ncopy) cout<<"Test OK!"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
#define all(x) (x).begin(), (x).end()
#define cmax(u,v) (u)<(v)?(u)=(v):0;
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}

inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
using namespace std;

const int mod = 1e9 + 7;
const int N = 200010;
int f[N], L[N], R[N], n, q[N];
struct Node
{
    int x, v, id;
}a[N];

bool cmp1(Node a, Node b)
{
    return a.v < b.v;
}

bool cmp2(Node a, Node b)
{
    return a.x < b.x;
}
int main()
{
	n = read();
	rep(i, 1, n)
		a[i].x = read(), a[i].v = read();
	sort(a + 1, a + 1 + n, cmp1);
    rep(i, 1, n) a[i].id = i;
    sort(a + 1, a + 1 + n, cmp2);
    int Mx = 0, Mn = n + 1;
    rep(i, 1, n)
    {
        Mx = (a[i].id > Mx) ? a[i].id : Mx;
        R[i] = Mx;
    }
    rrep(i, n, 1)
    {
        Mn = (a[i].id < Mn) ? a[i].id : Mn;
        L[i] = Mn;
    }
    int sum = 1, l = 0, r = 0;
    L[0] = 1;
    R[0] = 0;
    f[0] = 1;
    q[r ++] = 0;
    n ++;
    L[n] = R[n] = n;
    rep(i, 1, n)
    {
        while (l < r && L[i] > R[q[l]] + 1)
            sum = sum - f[q[l ++]] + mod, sum %= mod;
        f[i] = sum;
        (sum += f[i]) %= mod;
        q[r ++] = i;
    }
    printf("%d", f[n]);
    return 0;
}


Measured memory_bytes: 5760
#include <iostream> //cout
#include <cstring> //c
#include <vector> //vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


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

    if(S == "ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

const int type[3][2]={{1,2},{0,2},{0,1}};

int main(void){
	int N,K,*B,pst[100][3][2],sum=0;

	cin >> N >> K;
	B = new int[N];

	for(int i=0;i<N;i++)
		B[i]=0;

	for(int i=0;i<K;i++){
		int day;
		cin >> day;
		cin >> B[day-1];
	}


	for(int i=0;i<3;i++){
		pst[0][i][0]=1;
		pst[0][i][1]=0;
	}
	if(B[0])
		for(int j=0;j<2;j++)
			for(int k=0;k<2;k++)
				pst[0][type[B[0]-1][j]][k]=0;

	for(int i=1;i<N;i++){
		for(int j=0;j<3;j++){
			pst[i][j][0]=0;
			for(int k=0;k<2;k++)
				pst[i][j][0]+=(pst[i-1][type[j][k]][0]+pst[i-1][type[j][k]][1]);
			pst[i][j][0]%=10000;
			pst[i][j][1]=pst[i-1][j][0];
		}

		if(B[i])
			for(int j=0;j<2;j++)
				for(int k=0;k<2;k++)
					pst[i][type[B[i]-1][j]][k]=0;
	}

	for(int i=0;i<3;i++)
		sum+=(pst[N-1][i][0]+pst[N-1][i][1]);
	cout << sum%10000 << endl;

	delete [] B;

	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
using namespace std;
#pragma endregion
signed main() {
		int N,K;
		cin >> N>>K;
		REP(i, N) {
			if (pow(K, i) > N) {
				cout << i;
				return 0;
			}
		}
}

Measured memory_bytes: 256
//coded by not_surrender

#pragma GCC optimize( "Ofast" )

#include <bits/stdc++.h>

#define MAXN 100010
#define oo (1<<30)
#define MOD 998244353
#define mid ((a+b)/2)
#define L (nod*2)
#define R (nod*2+1)
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector <int> vi;

ll N, M, dp[MAXN];

int main(){

    #ifndef ONLINE_JUDGE
        //~ freopen( "a.txt", "r", stdin );
    #endif // ONLINE_JUDGE

    ios_base::sync_with_stdio( false );
    cin.tie( NULL ), cout.tie( NULL );
    
    cin >> N >> M;
    
    for ( ll i = 1, c, t; i <= N; ++i ){
		cin >> t >> c;
		for ( ll j = M; j >= t; --j )
			dp[j] = max( dp[j-t]+c, dp[j] );
	}
	
	cout << dp[M] << '\n';
	
return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}
#define printans(ans) {printf("%d\n",(ans));}
#define intscan(x) {scanf("%d", &x);}
#define Ntimes(N) for(int i=0; i<N; i++)
#define min(x,y) (((x)<(y)) ? (x) : (y))
#define max(x,y) (((x)>(y)) ? (x) : (y))
typedef int* intarray;
typedef char* string;

int main(){
    int N, p, sum, max;
    intscan(N);
    sum = max = 0;
    Ntimes(N){
        intscan(p);
        sum += p;
        max = max(p,max);
    }
    printans(sum - max/2);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 2e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=2.718281828459045235360287471352662;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
struct data
{
    int num;
    int pos;
}a[maxn];
int ans[maxn];
bool cmp(data a,data b)
{
    return a.num<b.num;
}
int main()
{
    ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].num;
        a[i].pos=i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++)
    {
        if(i<=n/2)
            ans[a[i].pos]=a[n/2+1].num;
        else
            ans[a[i].pos]=a[n/2].num;
    }
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 4608