akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int a[100005];
int dp[100005];
int n, k;
int solve(int ind)
{
	if (dp[ind] != -1) return dp[ind];
	if (ind == n) return 0;
	int  ans = INT_MAX;
	for (int i = ind + 1; i <= min(n, ind + k); i++)
	{
		ans  = min(ans , abs(a[i] - a[ind]) + solve(i)) ;

	}
	return dp[ind] =  ans;
}
int32_t main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> a[i];
	memset(dp, -1, sizeof dp);
	cout << solve(1);
	return 0;
}






Measured memory_bytes: 7680
import sys


n = int(input())
a = list(map(int, input().split()))

ans = 1

for i in a:
    if i == 0:
        print(0)
        sys.exit(0)

for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        sys.exit(0)

if ans > 10**18:
    print(-1)
else:
    print(ans)


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

guide_book_list = []

for i in range (n) :
    a_list = list((input().split()))+[i+1]
    guide_book_list.append(a_list)
    guide_book_list[0+i][1]=int(guide_book_list[0+i][1])
    guide_book_list[0 + i][1] = -(guide_book_list[0 + i][1])
# print(guide_book_list)
guide_book_list.sort()
# print(guide_book_list)
for j in range (n) :
    print(guide_book_list[0+j][2])

Measured memory_bytes: 3064
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

LL mod_pow(LL x, LL n){
    LL ans = 1;
    while(n>0){
        if((n&1)==1){
            ans = ans * x % 2019;
        }
        x = x * x % 2019;
        n >>= 1;
    }
    return ans;
}

int main() {
    string s;
    cin >> s;
    int ss=s.size();
    vector<LL> dp(ss);
    vector<int> res(2019, 0);
    LL tmp = s[ss-1] - '0';
    dp[ss-1] = tmp;
    res[dp[ss-1]]++;
    for(int i=ss-2; i>=0; i--){
        tmp = s[i] - '0';
        tmp = tmp*mod_pow(10, ss-1-i);
        dp[i] = (dp[i+1] + tmp)%2019;
        //cout << tmp << " " << dp[i-1] << " " << dp[i] << endl;
        res[dp[i]]++;
    }

    LL ans=0;
    ans=res[0]*(res[0]+1)/2;
    for(int i=1; i<2019; i++){
        ans+=res[i]*(res[i]-1)/2;
    }

    //for(int i=0; i<2019; i++){
    //    if(res[i]>=1){
    //        cout << i << " " << res[i] << endl;
    //    }
    //}

    cout << ans << endl;

    return 0;
}

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

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

  int D, N; cin >> D >> N;
  int ans = 1;
  for (int i = 0; i < D; i++) ans *= 100;
  cout << (N < 100 ? ans * N : ans * (N + 1)) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2001,INF=1<<30;

int main(){
    
    int N,K,Q;cin>>N>>K>>Q;
    vector<int> A(N),B(N-K+1);//B[i]はi~i+K-1の最小値
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    deque<int> deq(N);
    int s=0,t=0;
    for(int i=0;i<N;i++){
        while(s<t&&A[deq[t-1]]>=A[i]) t--;
        deq[t]=i;
        t++;
        
        if(i-K+1>=0){
            B[i-K+1]=A[deq[s]];
            if(deq[s]==i-K+1) s++;
        }
    }
    
    int ans=INF;
    
    if(Q==1) cout<<0<<endl;
    else{
        for(int i=0;i<N;i++){
            bool flag=false;
            //if(N-i<Q) continue;
            for(int j=max(0,i-K+1);j<=i;j++){
                if(B[j]==A[i]){
                    flag=true;
                    break;
                }
            }
            if(!flag) continue;
            
            vector<int> S[N],T={A[i]};
            int start=0,cnt=0;
            
            for(int j=0;j<N;j++){
                if(i==j) continue;
                
                if(A[j]<A[i]){
                    start=j+1;
                }else{
                    S[start].push_back(A[j]);
                }
            }
            
            for(int j=0;j<N;j++){
                if(S[j].size()>=K) cnt+=(S[j].size()-K+1);
            }
            
            if(cnt<Q-1) continue;
            
            for(int j=0;j<N;j++){
                if(S[j].size()>=K){
                    sort(all(S[j]));
                    for(int k=0;k<min(int(S[j].size()-K+1),Q-1);k++){
                        T.push_back(S[j][k]);
                    }
                }
            }
            
            sort(all(T));
            
            ans=min(ans,T[Q-1]-T[0]);
        }
        
        cout<<ans<<endl;
    }
    
}


Measured memory_bytes: 384
from collections import Counter

S = input()
n = len(S)

dp = [0]*(n+1)

dp[n-1] = int(S[-1])

for i in range(n-2,-1,-1):
    dp[i] = (dp[i+1]+pow(10,n-i-1,2019)*int(S[i]))%2019

ans = Counter(dp)
cnt = 0
for i in ans.values():
    cnt += i*(i-1)//2
    
print(cnt)


Measured memory_bytes: 16656
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

const int N = 11;

int main() {
  string s;
  while(cin >> s) {
    double d[N];
    double v1, v2;
    replace(s.begin(), s.end(), ',', ' ');
    stringstream ss(s);
    d[0] = 0;
    for(int i = 1; i < N; ++i) {
      ss >> d[i];
      d[i] += d[i-1];
    }
    ss >> v1 >> v2;
    double x = v1/(v1+v2)*d[N-1];
    cout << (lower_bound(d,d+N,x)-d) << endl;
  }
  return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <map>

using namespace std;

int main(int argc, char *argv[]) {
	map<string, int> cnt;

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		cnt[s]++;
	}

	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		string s;
		cin >> s;
		cnt[s]--;
	}

	int max = 0;
	for(pair<string, int> p : cnt) {
		if (p.second > max) max = p.second;
	}

	cout << max << endl;

	return 0;
}

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

using namespace std;

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

const int MAX_V = 100000;
const int MAX_LOG_V = 17;

vector<P> G[MAX_V];
int root = 0;

int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];
ll dist[MAX_V];

void dfs(int v, int p, int d) {
	parent[0][v] = p;
	depth[v] = d;
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i].first != p) {
			dist[G[v][i].first] = dist[v] + G[v][i].second;
			dfs(G[v][i].first, v, d + 1);
		}
	}
}

void init(int V) {
	dfs(root, -1, 0);
	for (int k = 0; k + 1 < MAX_LOG_V; k++) {
		for (int v = 0; v < V; v++) {
			if (parent[k][v] < 0) parent[k + 1][v] = -1;
			else parent[k + 1][v] = parent[k][parent[k][v]];
		}
	}
}

int lca(int u, int v) {
	if (depth[u] > depth[v]) swap(u, v);
	for (int k = 0; k < MAX_LOG_V; k++) {
		if ((depth[v] - depth[u]) >> k & 1) {
			v = parent[k][v];
		}
	}
	if (u == v) return u;
	for (int k = MAX_LOG_V - 1; k >= 0; k--) {
		if (parent[k][u] != parent[k][v]) {
			u = parent[k][u];
			v = parent[k][v];
		}
	}
	return parent[0][u];
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		G[a].emplace_back(b, c);
		G[b].emplace_back(a, c);
	}

	init(n);
	int q, k;
	cin >> q >> k;
	k--;
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		int u = lca(x, k);
		int v = lca(y, k);
		ll ans = dist[x] + dist[k] - dist[u] * 2;
		ans += dist[y] + dist[k] - dist[v] * 2;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 22912
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
//#include<array>
#include<algorithm>
#include<queue>
#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
//#include<bitset>
//#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//配列,座標
/*array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
array<int, 4>dir_x2 = { 0,0,1,-1 };
array<int, 4>dir_y2 = { 1,-1,0,0 };
char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };*/

//Union Find
/*class UnionFind {
public:
	vector<int>data;
	UnionFind(int size) :data(size, -1) {};
	bool unionset(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x]) {
				swap(x, y);
			}
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	bool findset(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};*/

//最大公約数,最小公倍数
/*LLI gcd(LLI x, LLI y) {
	LLI  r;
	if (x < y) {
		swap(x, y);
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}
LLI lcm(LLI x, LLI y) {
	return x / gcd(x, y) * y;
}*/

//組み合わせ
/*long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; i--) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; i++) {
		ans = ans / i;
	}
	return ans;
}
long nHr(int n, int r) {
	n = n + r - 1;
	return nCr(n, r);
}*/

//素数判定
/*bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}*/

//桁数
/*LLI GetDigit(LLI num) {
	LLI digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}*/

//サンプル
/*const int n_max = 8;
array<array<bool, n_max>, n_max>graph;
int dfs(int v,int N,array<bool,n_max>visited) {
	int ret = 0;
	bool all_visited = true;
	for (int i = 0; i < N;i++) {
		if (visited[i] == false) {
			all_visited = false;
		}
	}
	if (all_visited) {
		return 1;
	}
	for (int i = 0; i < N;i++) {
		if (graph[v][i] == false) {
			continue;
		}
		if (visited[i] == true) {
			continue;
		}
		visited[i] = true;
		ret += dfs(i,N,visited);
		visited[i] = false;
	}
	return ret;
}*/

//サンプル
/*vector<vector<int>>sub;
int dfs(int id) {
	if (sub[id].size() == 0) {
		return 1;
	}
	int minP = (int)1e9;
	int maxP = 0;
	for (int i : sub[id]) {
		int P = dfs(i);
		minP = min(minP, P);
		maxP = max(maxP, P);
	}
	return minP + maxP + 1;
}*/

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl
//cout << "Yes" << endl;
//cout << "No" << endl;



int main(void) {
	LLI N, K, MAX = 0;
	cin >> K >> N;
	vector<LLI>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	MAX += v[0] + (K - v[v.size() - 1]);
	for (int i = 0; i < N - 1; i++) {
		MAX = max(MAX, v[i + 1] - v[i]);
	}
	cout << K - MAX << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(){
    char S[10];cin>>S;
    sort(S,S+4);
    if(S[0]==S[1] && S[1]!=S[2] && S[2]==S[3]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
using psi = pair<string, int>;

int main()
{
    int n, max = 0;
    string s;
    cin >> n;

    map<string, int> a;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        a[s]++;
        max = a[s] > max ? a[s] : max;
    }
    for (auto x : a)
    {
        psi tmp = x;
        if (tmp.second == max)
        {
            cout << tmp.first << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 25216
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, arr[200000];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N;
	REP(i, N) {
		cin >> arr[i];
	}
	lint bitsum = arr[0], sum = arr[0], r = 0, l = 0, unstand = 0;
	while (r + 1 < N && (bitsum ^ arr[r + 1]) == sum + arr[r + 1]) {
		bitsum ^= arr[r + 1];
		sum += arr[r + 1];
		r++;
	}
	lint ans = (r + 1) * (r + 2) / 2;
	r++;
	for(; r < N; r++){
		if (sum + arr[r] != (sum ^ arr[r])) {
			unstand = bitsum & arr[r];
			unstand = unstand ^ LLONG_MAX;
			while (l < r && ((unstand | arr[l]) != LLONG_MAX)) {
				unstand |= arr[l];
				lint debug = (unstand ^ LLONG_MAX);
				bitsum &= (arr[l] ^ LLONG_MAX);
				sum -= arr[l];
				l++;
			}
			unstand |= arr[l];
			lint debug = (unstand ^ LLONG_MAX);
			bitsum &= (arr[l] ^ LLONG_MAX);
			sum -= arr[l];
			l++;
		}
		bitsum |= arr[r];
		sum += arr[r];
		ans += (r - l + 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 5236
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int toint(const string& s) {
  int ret = 0;
  for (auto& c : s) ret = ret * 10 + (c - '0');
  return ret;
}

int main() {
  string a, op, b;
  cin >> a >> op >> b;
  int x = toint(a), y = toint(b), ret;
  if (op[0] == '+') {
    ret = x + y;
  } else {
    ret = x - y;
  }
  cout << ret << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++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 ALL(a) begin(a), end(a)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int a[300][300];
bool needs[300][300];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll ans = 0;
	int n;
	cin >> n;
	REP(i, n){
		REP(j, n){
			 cin >> a[i][j];
			 //ans += a[i][j];
			 needs[i][j] = true;
		}
	}
	//cout << ans << "\n";
	REP(k, n){
		REP(i, n){
			REP(j, n){
				if(a[i][j] > a[i][k] + a[k][j]){
					cout << "-1\n";
					return 0;
				}
				else if(a[i][j] == a[i][k] + a[k][j] && i != k && j != k){
					//cout << i << " " << j << " " << k << "\n";
					//ans -= a[i][j];
					needs[i][j] = false;
				}
			}
		}
	}
	REP(i, n){
		REP(j, n){
			if(needs[i][j])ans += a[i][j];
		}
	}

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


Measured memory_bytes: 768
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

n = I()
inf = 10**6+1
a = LI()
a.sort()
ans = 0
li = [0]*inf
for x in a:
    p = li[x]
    if p != 0:
        li[x] = 2
        continue
    for i in range(x,inf,x):
        li[i] += 1
for i in a:
    if li[i] == 1:
        ans += 1
print(ans)
    

Measured memory_bytes: 31992
#include <iostream>

using namespace std;

void solve()
{
	int D;
	cin >> D;
	if (D == 22)
	{
		cout << "Christmas Eve Eve Eve" << endl;
	}
	else if (D == 23)
	{
		cout << "Christmas Eve Eve" << endl;
	}
	else if (D == 24)
	{
		cout << "Christmas Eve" << endl;
	}
	else if (D == 25)
	{
		cout << "Christmas" << endl;
	}
}

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

Measured memory_bytes: 384
from collections import deque

H,W = list(map(int, input().split()))
maze = [input() for _ in range(H)]
answer = 0

def bfs(maze,visited,sx,sy):
    stack = deque([[sy,sx]])
    visited[sy][sx] = 0
    while stack:
        y,x = stack.pop()
        count = visited[y][x]
        
        for j,k in ([1,0],[-1,0],[0,1],[0,-1]):
            new_y,new_x = y+j,x+k
            if new_x < 0 or new_x >= W or new_y < 0 or new_y >= H:
                continue
            #深さ優先
            elif maze[new_y][new_x] != "#" and visited[new_y][new_x] > count+1:
                visited[new_y][new_x] = count+1
                stack.appendleft([new_y, new_x])
    return count

inf = float('inf')

for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            visited = [[inf]*W for _ in range(H)]
            answer = max(answer,bfs(maze,visited,j,i))
print(answer)




Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#include <cmath>
#define mp make_pair
#define pii pair<int,int> 
#define ff first
#define ss second

using namespace std;

double deg,r,x=0,y=0,curdeg=0;

int main()
{
	while(true)
	{
		scanf("%lf,%lf",&r,&deg);
		if(r==0&&deg==0)
		break;
		x+=r*cos(M_PI/180*(90-curdeg));
		y+=r*sin(M_PI/180*(90-curdeg));
		curdeg+=deg;
	}
	printf("%d\n%d\n",(int)x,(int)y);
	return 0;
}

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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/(b))
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
        void solve();
        if(DO_BENCHMARK){
            clock_t clock_start = clock();
            solve();
            clock_t clock_end = clock();
            const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
            cout << "\n------------------------------------\n" << time << "[ms]\n";
        }
        else solve();
    }
}

/*------------------------------↓ここからコード↓----------------------------------*/
void solve(){
    LL N;
    cin >> N;
    vector<LL> A (N);
    LL front = 0;
    LL ans = 0;
    for(LL i = 0;i < N;i++){
        cin >> A[i];
        if(A[i] > front){
            front = A[i];
        }
        else{
            ans += front - A[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    cout << n*(n+1)/2 << endl;

    return 0;   
}


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

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int N = (int) 2e5 + 10;

int a[N], b[N];
ll s[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll sum = 0;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    sum += b[i];
    s[i] = sum;
  }
  int ans = 0;
  ll cur = 0;
  for (int i = 0; i < n; i++) {
    cur += a[i];
    if (cur > (ll) k) {
      break;
    }
    if (cur + b[0] > (ll) k) {
      ans = max(ans, i + 1);
      continue;
    }
    int low = 0, high = m - 1;
    while (low < high) {
      int mid = (low + high + 1) / 2;
      if (cur + s[mid] <= (ll) k) {
        low = mid;
      } else {
        high = mid - 1;
      }
    }
    ans = max(ans, low + 1 + i + 1);
  }
  for (int i = 0; i < m; i++) {
    if (s[i] <= (ll) k) {
      ans = max(ans, i + 1);
    }
  }
  cout << ans << '\n';
  return 0;
}


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

vector<int> vi;

signed main () {

    int n;
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
        int a;
        scanf("%d", &a);
        vi.push_back(a);
    }
    vector<int> ans;
    for ( int i = 0; i < n; i++ ) {
        bool flg = true;
        for ( int j = vi.size()-1; j != -1; j-- ) {
            if ( vi[j] == j+1 ) {
                vi.erase( vi.begin() + j );
                flg = false;
                ans.push_back(j+1);
                break;
            }
        }
        if ( flg ) {
            puts("-1");
            return 0;
        }
    }
    reverse(ans.begin(), ans.end());
    for ( int i = 0; i < ans.size(); i++ ) {
        printf("%d\n", ans[i]);
    }

    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d, g;
    cin >> d >> g;
    vector<int> p, c;
    p.resize(d), c.resize(d);
    for (int i = 0; i < d; i++) {
        cin >> p[i] >> c[i];
    }
    // 十分大きな数をansとする
    ll ans = 1 << 29;
    for (int bit; bit < (1 << d); bit++) {
        ll sum = 0; // 合計
        ll cnt = 0; // ACした問題の数
        for (int i = 0; i < d; i++) {
            if (bit & (1 << i)) {
                // i番目のボーナス + i番目のの数 * 何番目
                sum += c[i] + p[i] * 100 * (i + 1);
                // i番目までの数
                cnt += p[i];
            }
        }
        if (sum >= g) {
            // もしsumがg以上のときansを更新する
            ans = min(ans, cnt);
        } else {
            // もし超えないときは大きな値から一つずつ足す
            for (int i = d - 1; i >= 0; i--) {
                if (bit & (1 << i)) { // bitがここで立つときは上でもbitが立つからもう加えない
                    continue;
                }
                for (int j = 0; j < p[i]; j++) { // 一つずつ足す
                    if (sum >= g) { // sumがg以上になったらbreak
                        break;
                    }
                    // i番目の問題の点数を足す
                    sum += 100 * (i + 1);
                    cnt++;
                }
            }
            // 更新する
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
ll n,a;
cin>>n>>a;
if(n%500>a){
    cout<<"No"<<endl;
}
else{
    cout<<"Yes"<<endl;
}
}









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

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

    int digitCount = 1;
    while(true)
    {
        n = n / k;
        if (n == 0)
        {
            break;
        }
        digitCount++;
    }
    cout << digitCount << endl;
    return 0;
}


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int x,t;
  cin >> x >> t;
  if(x>=t){
    printf("%d\n", x-t);
  }
  else printf("0\n");
 
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
    int i,len;
    char s[4096],p[4096],s2[4096];
    scanf("%s",s);
    scanf("%s",p);
    sprintf(s2,"%s%s",s,s);
    puts(strstr(s2,p)==NULL?"No":"Yes");
    return 0;
}


Measured memory_bytes: 2144
fn hard_to_input(s: String) -> bool{
    let v: Vec<char> = s.chars().collect();
    for i in 0..v.len()-1 {
        if v[i]== v[i+1] {
            return false;
        }
    }
    true
}

fn main() {
    let s = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    };
    println!("{}", if hard_to_input(s) { "Good" } else { "Bad"} );
}


Measured memory_bytes: 4352
#include <iostream>
     
    using namespace std;
     
    int main() {
    	int a, b, c;
    	long long k;
    	cin >> a >> b >> c;
    	cin >> k;
    	cout << ((k & 1) ? (b - a) : (a - b)) << endl;
    	return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int w,h,n;
    cin >> w >> h >> n;
    int l = 0, r = w, d = 0, u = h;
    vector<int>x(n);
    vector<int>y(n);
    vector<int>a(n);
    rep(i,n) {
        cin >> x[i] >> y[i] >> a[i];
    }
    rep(i,n){
        if(a[i] == 1 && x[i] > l) l = x[i];
        if(a[i] == 2 && x[i] < r) r = x[i];
        if(a[i] == 3 && y[i] > d) d = y[i];
        if(a[i] == 4 && y[i] < u) u = y[i];
    }
    
    if(r-l <= 0 || u-d <= 0) cout << 0 << endl;
    else cout << (r-l)*(u-d) << endl;
    return 0;
}

Measured memory_bytes: 3680
X,Y = map(int,input().split())

mod = 1000000007

length=1
syo=X//mod
X=X%mod

syo_y = Y//mod
Y=Y%mod
while(True):
    syo = (syo*2)+(X*2)//mod
    X = (X*2)%mod
    if syo>syo_y:
        break
    elif syo==syo_y and X>Y:
        break
    else:
        length+=1
        
print(length)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define sec second
#define pii pair<int, int>
int n, m, k, x, y, sum, ans;
pair<int, int>a[100005];
int main () {
	scanf("%d", &n);
	for (int i=0; i<n; i++) scanf("%d", &a[i].first), a[i].second=i;
	if (n==1) {
		printf("0\n");
		return 0;
	}
	if (n==2) {
		if (a[0]<a[1]) printf("0\n");
		else printf("1\n");
		return 0;
	}
	sort(a, a+n);
	for (int i=0; i<n; i++) {
		if (abs(a[i].second-i)%2==1) ans++;
	}
	printf("%d\n", ans/2);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define N 200005
using namespace std;
const int Mod = 1e9 + 7;

int vis[N];
long long f[N];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    int n, m;
    cin >> n >> m;
    for (int i = 1, x; i <= m; ++i)
        scanf("%d", &x), vis[x] = 1;
    f[0] = 1;
    for (int i = 1; i <= n; ++i) {
        if (i - 2 >= 0) (f[i] += f[i - 2]) %= Mod;
        (f[i] += f[i - 1]) %= Mod;
        if (vis[i]) f[i] = 0;
    }
    cout << f[n] << endl;

    return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1e9+7

using namespace std;

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

  int l = 0;
  int r = w;
  int b = 0;
  int t = h;

  rep(i, n) {
    int x, y, a;
    cin >> x >> y >> a;
    switch (a) {
      case 1: l = max(l, x); break;
      case 2: r = min(r, x); break;
      case 3: b = max(b, y); break;
      case 4: t = min(t, y); break;
    }
  }

  ll ans = max(r - l, 0) * max(t - b, 0);

  cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")

from bisect import bisect_right

def main():
    N = int(input())
    L = list(map(int,input().split()))

    L.sort()
    ans = 0
    for b in range(N):
        for a in range(b+1,N):
            upper = b
            lower = bisect_right(L, L[a] - L[b])
            ans += max(0, upper - lower)
    
    print(ans)
    
if __name__ == "__main__":
    main()

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

using namespace std;

int n;
int col[100010];
vector<pair<int, int> > adj[100010];

void dfs(int u, int p, bool par){
	if(par) col[u] = 1;
	else col[u] = 0;

	for(auto v : adj[u]){
		if(v.first == p) continue;

		bool tmp = v.second & 1;

		dfs(v.first, u, tmp ^ par);
	}
}

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

	for(int i = 0; i < n - 1; i++){
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);

		adj[u].emplace_back(v, w);
		adj[v].emplace_back(u, w);
	}

	dfs(1, -1, 0);

	for(int i = 1; i <= n; i++){
		printf("%d\n", col[i]);
	}
	
	return 0;
}


Measured memory_bytes: 8320
#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;

int INF=1e9;
const char *p;

int exp();

int term(){
  if(*p=='('){
    p++;
    auto l=exp();
    if(*p!=')')throw 0;
    p++;
    return l;
  }else if('1'<=*p&&*p<='9'){
    char *e;
    auto l=strtol(p,&e,10);
    p=e;
    return l;
  }else{
    throw 0;
  }
}

int pro(){
  auto l=term();
  while(*p=='*'){
    p++;
    l*=term();
  }
  return l;
}

int aterm(){
  auto l=pro();
  while(*p=='+'||*p=='-'){
    int s=(*p=='+')-(*p=='-');
    p++;
    l+=s*pro();
  }
  return l;
}

int xterm(){
  auto l=aterm();
  while(*p=='&'){
    p++;
    l&=aterm();
  }
  return l;
}

int oterm(){
  auto l=xterm();
  while(*p=='^'){
    p++;
    l^=xterm();
  }
  return l;
}

int exp(){
  auto l=oterm();
  while(*p=='|'){
    p++;
    l|=oterm();
  }
  return l;
}

int rec(int n,int s,string e){
  p=e.c_str();
  int r;
  try{
    r=exp();
  }catch(...){
    return INF;
  }
  if(*p)return INF;
  if(n==0){
    return s*r;
  }else{
    int m=-INF;
    for(int i=0;i<=e.size();i++){
      for(int j=0;j<18;j++){
	const char *c="()*+-&^|0123456789";
	m=max(m,-rec(n-1,s,e.substr(0,i)+c[j]+e.substr(i)));
	//	if(n==2)cout<<-rec(n-1,e.substr(0,i)+c[j]+e.substr(i))<<endl;
      }
    }
    for(int i=0;i<e.size();i++){
      m=max(m,-rec(n-1,s,e.substr(0,i)+e.substr(i+1)));
      //      if(n==2)cout<<-rec(n-1,e.substr(0,i)+e.substr(i+1))<<endl;
    }
    return m;
  }
}

int main(){
  int N;
  string E;
  while(cin>>N>>E,N){
    cout<<rec((N-1)%2+1,(N%2)?-1:1,E)<<endl;
  }
}

Measured memory_bytes: 1284
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector< pair<int,int> > g(N);
    for(int i=0; i<N; i++) {
        int X, L;
        cin >> X >> L;
        g[i].first = X+L;
        g[i].second = X-L;
    }

    sort(g.begin(), g.end());

    int ans = 1;
    int now = g[0].first;
    for(int i=1; i<N; i++) {
        if(g[i].second >= now) {
            ++ans;
            now = g[i].first;
        }
    }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

int arr[200];
int main()
{
	Iint(n); int s = 0;
	for (int i = 0; i < 2*n; ++i)
	{
		scanf("%d", &arr[i]);
	}
	sort(arr, arr + 2 * n);
	for (int i = 0; i < 2*n; i+=2)
	{
		s += arr[i];
	}
	std::cout << s;

	return 0;
}











Measured memory_bytes: 256
//...START BY DOING WHAT IS NECESSARY, THEN WHAT IS POSSIBLE AND SUDDENLY YOU ARE DOING THE IMPOSSIBLE... 
// ................. WORK UNTILL YOUR IDOLS BECOME YOUR RIVALS................................

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define pb emplace_back
#define f first
#define s second
#define delrep(a)  (a).erase(unique((a).begin(),(a).end()),(a).end());
#define all(a)  (a).begin(),(a).end()
#define sz(x)   (int)x.size()
const int N=4e5+5;
using namespace std;
int get_second( pair<int, int> i ){ return i.second; }  
int trail_zero(int n){while (n % 10 == 0) n /= 10 ; return n;}
typedef long long ll;
map<ll,ll> m11;
set<int> s1;
map<int,pair<int,int>> m1;
vector<pair<int,int>>v1;
vector<int>v9[26];
char s111[N];
ll p2[N],p3[N];
ll hash1[N];
int n,m;
bool check(int a,int b) { if(a>=0 || a<n) return true; if(b>=0 || b<m) return true; else return false;}
int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
char s[500][500]; 
 vector<long long int> v[26];
 set<string> st; 
int main()
{
    ll n,ans=INT_MAX; cin>>n; string s; cin>>s;
    for(int i=0,j=n-1;i<n;i++,j--)
    {
      p2[i]+=(s[i]=='E'); p3[j]+=(s[j]=='W');
      p2[i]+=p2[i-1]; p3[j]+=p3[j+1];
    }
    for(int i=0;i<n;i++)  ans=min(ans,n-(p2[i]+p3[i]));
    cout<<ans;
}








Measured memory_bytes: 7428
import collections

S = input()
T = input()

reg = [None]*26
reg_flag = [0]*26

for i in range(len(S)):
    index = ord(S[i])-97
    if reg_flag[index] == 0:
        reg[index] = T[i]
        reg_flag[index] = 1

    if reg[index] == T[i]:
        pass
    else:
        print('No')
        exit()

reg = filter(lambda x: x != None, reg)
if collections.Counter(reg).most_common()[0][1] > 1:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 4144
#include <bits/stdc++.h>
using namespace std;
int main(){
int D;
  cin>>D;
  if(D==25){
  cout<<"Christmas";
  }else 
    if(D==24){
  cout<<"Christmas Eve";
  }else  
      if(D==23){
  cout<<"Christmas Eve Eve";
  }else  
  if(D==22){
  cout<<"Christmas Eve Eve Eve";
  }
  
}

Measured memory_bytes: 3596
#include <iostream>
#define llint long long

using namespace std;

llint T;

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

int main(void)
{
	cin >> T;
	llint a, b, c, d;
	llint g, i, mx;
	for(int t = 0; t < T; t++){
		cin >> a >> b >> c >> d;
		if(a < b) goto ng;
		if(d < b) goto ng;
		
		g = gcd(b, d);
		i = a % b;
		mx = ((b-1)-i)/g*g + i;
		if(mx > c) goto ng;
		else goto ok;
		
		ok:
		cout << "Yes" << endl;
		continue;
		ng:
		cout << "No" << endl;
		continue;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) { cout << "Bad" <<endl; }
    else { cout << "Good" << endl; }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll dp[MAX_N][2];
int A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N + 1) {
		rep(j, 0, 2) {
			dp[i][j] = -linf;
		}
	}
	dp[0][0] = 0;
	rep(i, 0, N - 1) {
		rep(j, 0, 2) {
			rep(k, 0, 2) {
				MAX(dp[i + 1][k], dp[i][j] + ((j ^ k) ? -A[i] : A[i]));
			}
		}
	}
	cout << max(dp[N - 1][0] + A[N - 1], dp[N - 1][1] - A[N - 1]) << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 2816
fun main(args : Array<String>) {
  val (n, a, b) = readLine()!!.split(" ").map { it.toLong() }
  val l = readLine()!!.split(" ").map { it.toLong() }
  print((1 until l.size).map { listOf(a * (l[it] - l[it - 1]), b).min()!! }.sum())
}

Measured memory_bytes: 57916
A, B, K = map(int, input().split())

nums = []
for num in range(A, min(A+K, B+1)):
  nums.append(num)
for num in range(max(B-K+1, A), B+1):
  nums.append(num)
ans = sorted(set(nums))
for num in ans:
  print(num)


Measured memory_bytes: 3060
#include <cstdio>
#include <string>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <map>
using namespace std;


int main () {
    int h, w;
    int count = 0;
    scanf("%d %d\n", &h, &w);
    char grid[h][w];
    int board[h + 2][w + 2];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            scanf("%c", &grid[i][j]);
        }
        scanf("\n");
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (grid[i][j] == '#') grid[i][j] = 1;
            else grid[i][j] = 0;
        }
    }
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (grid[i][j] == 1) board[i + 1][j + 1] = 1;
            else board[i + 1][j + 1] = 0;
        }
    }
    for (int i = 0; i <= h + 1; i++) {
        board[i][w + 1] = 0;
        board[i][0] = 0;
    }
    for (int i = 0; i <= w + 1; i++) {
        board[0][i] = 0;
        board[h + 1][i] = 0;
    }

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (board[i][j] == 1 && board[i][j - 1] == 0 && board[i - 1][j] == 0 && board[i + 1][j] == 0 && board[i][j + 1] == 0) {
                count--;
            }
            count++;
        }
    }
    if (count == h*w) printf("Yes\n");
    else printf("No\n");

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
char t1[1510];
char t2[1510];
char t3[1510];
int main(){
    int n;
    int a,b;
    int i,j;
    char t;
    scanf("%s",&t1);
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",&t3);
        if(strcmp(t3,"replace")==0){
            scanf("%d %d %s",&a,&b,&t2);
            for(j=0;j<b-a+1;j++){
                t1[a+j]=t2[j];
            }
        }
        else if(strcmp(t3,"reverse")==0){
            scanf("%d %d",&a,&b);
            while(a<b){
                t=t1[a];
                t1[a]=t1[b];
                t1[b]=t;
                a++;
                b--;
            }
        }
        else if(strcmp(t3,"print")==0){
            scanf("%d %d",&a,&b);
            for(j=a;j<b+1;j++){
                printf("%c",t1[j]);
            }
            puts("");
        }
    }
    return 0;
}


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

int32_t main(){
    int n;
    cin >> n;
    vector<vector<int>> arr(3, vector<int>(n, 0));
    for(int i = 0 ; i < n ; i ++){
        cin >> arr[0][i] >> arr[1][i] >> arr[2][i];
    }
    vector<vector<int>> dp(3, vector<int>(n, 0));
    dp[0][0] = arr[0][0];
    dp[1][0] = arr[1][0];
    dp[2][0] = arr[2][0];
    for(int i = 1 ; i < n ; i ++){
        dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + arr[0][i];
        dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + arr[1][i];
        dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + arr[2][i];
    }
    cout << max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1])) << endl;
    return 0;
}


Measured memory_bytes: 5744
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 +c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
string s;
void Solve() {
    cin >> s;
    bool f = 0;
    for(int i = s.length() - 1 ; i >= 0 ; --i) {
    if(s[i] == 'F') f = 1;
    if(s[i] == 'C' && f) {
        puts("Yes");return;
    }
    }
    puts("No");
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  cout << 800 * n - 200 * (n/15) << "\n";
  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>

using namespace std;

int main() {
	int n, w[300000], e[300000], ans = 999999;
	string s;

	cin >> n >> s;

	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'W') {
			w[i + 1] = w[i] + 1;
		}
		else {
			w[i + 1] = w[i];
		}
	}
	for (int i = n - 1; i > 0; i--) {
		if (s[i] == 'E') {
			e[i - 1] = e[i] + 1;
		}
		else {
			e[i - 1] = e[i];
		}
	}
	for (int i = 0; i < n; i++) {
		if (ans > w[i] + e[i]) {
			ans = w[i] + e[i];
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<25)     //33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int a[1010];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) {
    int a[3];
    REP(j, 3) cin >> a[j];
    sort(a, a+3);
    if(a[2]*a[2] == a[1]*a[1] + a[0]*a[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

  return 0;
}

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

ll n,m;
vector<string> v(1008);
ll memo[1008][1008];

bool check(ll i,ll j)
{
    return (i<n && j<m);
}
ll fil(ll i,ll j)
{
    if(memo[i][j]!=-1)return memo[i][j];
    if(i==n-1 && j==m-1)return 1;
    if(i>=n || j>=m)return 0;

    ll ans=0;
    if(check(i+1,j) && v[i+1][j]=='.')
    {
        ans=fil(i+1,j);
    }
    if(check(i,j+1) && v[i][j+1]=='.')
    {
        ans= (ans%mod) + (fil(i,j+1)%mod);
    }
    ans%=mod;
    return memo[i][j]=ans;
}
int main()
{
    cin>>n>>m;
    for(ll i=0;i<n;i++)cin>>v[i];
    memset(memo,-1,sizeof(memo));
    cout<<fil(0,0)%mod<<endl;
}


Measured memory_bytes: 9344