akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

#define MAX_N (100010)

using namespace std;

typedef long long lint;

struct edge {
	int to, cost;
	edge(int to, int cost) : to(to), cost(cost) {}
	edge(){}
};

vector<edge> g[MAX_N];
bool vis[MAX_N];
int tVertex[MAX_N];
int len[MAX_N], dist[MAX_N], belong[MAX_N];
int par[MAX_N], chi[MAX_N];
int inDeg[MAX_N], outDeg[MAX_N];
int d[1024][1024];
int idx;

void findCompress(int v)
{
	vis[v] = true;
	
	for (int i = 0; i < g[v].size(); i++){
		edge e = g[v][i];
		if (!vis[e.to]){
			findCompress(e.to);
		}
	}
	
	if (!v || inDeg[v] > 1 || outDeg[v] > 1){
		tVertex[v] = idx++;
	}
}

int s;
int makeCompress(int now, int p, int cost, int id)
{
	if (~tVertex[now]){
		belong[now] = -1;
		len[id] = cost;
		d[tVertex[p]][tVertex[now]] = min(cost, d[tVertex[p]][tVertex[now]]);
		cost = 0;
		p = now;
	}
	
	if (vis[now]) return (tVertex[now]);
	if (!~tVertex[now]) belong[now] = id;
	vis[now] = true;
	par[now] = tVertex[p];
	dist[now] = cost;
	
	int r = -1;
	for (int i = 0; i < g[now].size(); i++){
		int nid = id;
		if (~tVertex[now]) nid = ++s;
		r = makeCompress(g[now][i].to, p, cost + g[now][i].cost, nid);
	}
	if (~tVertex[now]) r = tVertex[now];
	
	return (chi[now] = r);
}

int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);
	
	for (int i = 0; i < m; i++){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		--a; --b;
		for (int i = 0; i < g[a].size(); i++){
			if (g[a][i].to == b){
				g[a][i].cost = min(g[a][i].cost, c);
				goto updated;
			}
		}
		
		g[a].push_back(edge(b, c));
		outDeg[a]++; inDeg[b]++;
		updated:;
	}
	
	memset(vis, 0, sizeof(vis));
	memset(tVertex, -1, sizeof(tVertex));
	memset(par, -1, sizeof(par));
	findCompress(0);
	
	if (idx >= 1024) return (!printf("-1\n"));
	for (int i = 0; i < n; i++) if (vis[i] == false) return (!printf("-1\n"));
	
	for (int i = 0; i < 1024; i++){
		for (int j = 0; j < 1024; j++){
			d[i][j] = 1 << 25;
		}
		d[i][i] = 0;
	}
	memset(vis, 0, sizeof(vis));
	makeCompress(0, 0, 0, 0);
	
	for (int k = 0; k < idx; k++){
		for (int i = 0; i < idx; i++){
			for (int j = 0; j < idx; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	
    for (int i = 0; i < idx; i++){
        for (int j = 0; j < idx; j++){
            if (d[i][j] == 1 << 25) return (!printf("-1\n"));
        }
    }	
	lint res = 0;
	
	for (int i = 0; i < n; i++){
		int from = i, to = (i + 1) % n;
		int fl = belong[from], tl = belong[to];
		int c = chi[from], p = par[to];
		if (fl == tl && dist[from] < dist[to]){
			res += dist[to] - dist[from];
		}
		else {
			res += (!~fl ? 0 : (len[fl] - dist[from])) + d[c][p] + dist[to];
		}
	}
	
	printf("%lld\n", res);
	
	return (0);
}

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

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	long[] ary = new long[N];
    	for(int i = 0; i < N; i++){
    		 ary[i] = sc.nextInt();
    	}
    	sc.close();
    	boolean flg = true;
    	int cnt = N-1;
    	while(flg){
    		Arrays.sort(ary);
    		for(int i = 0; i < N; i++){
    			if(ary[i] > 0){
    				long min = ary[i];
	    			for(int j = i+1; j < N; j++){
	    				ary[j] = (ary[j] % min) >= 0 ? ary[j] % min : ary[j];
	        			if(ary[j] == 0) cnt--;
	    			}
	    			break;
    			}
    		}
    		if(cnt == 0) flg = false;
    	}
    	Arrays.sort(ary);
    	System.out.println(ary[N-1]);
    }
}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define PB push_back
#define pb push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len(stuff) (int) stuff.size()

#define int long long
#define float long double 
#define ll long long
#define ld long double

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const int inf = (int) 2e18;
const int upper = (int) 3e5 + 50;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

int n, m;
bool possible[upper];
int cnt[upper];

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	 
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	memset(possible, false, sizeof possible);
	possible[1] = true;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cnt[i] = 1;

	for (int i = 1; i <= m; i += 1) {
		int a, b; cin >> a >> b;
		if (possible[a]) possible[b] = true;
		cnt[a]--, cnt[b]++;
		if (cnt[a] == 0) possible[a] = false;
	}
	int ans = 0;
	for (int i = 1; i <= n; i += 1) {
		if (possible[i]) ans++;
	}
	cout << ans;
 	end_routine();		
}


Measured memory_bytes: 1280
# n = int(input())
# a = list(map(int, input().split()))
# ans = [[i] for i in range(1, n+1)]
# print(ans)
# for i in range(n):
#     print(ans[i], a[i])
#     ans[i].apeend(a[i])
#     ans[a[i]-1].append(i)
# print(ans)
# これなんでダメだったかわからん

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

adlist = [[] for i in range(n)]  # 交流のあるやつ同士の隣接リスト
for i in range(n):  # 1から順に見ていく
    x = i+1
    y = b[i]
    adlist[x-1].append(y)
    adlist[y-1].append(x)
# print(adlist)
count = 0
for i in range(n):
    if adlist[i].count(b[i]) == 2:
        count += 1
print(count//2)

Measured memory_bytes: 89756
#include<bits/stdc++.h>
#define ll long long
ll n,k;
const int N=2e5+5;

using namespace std;
int main(){
      cin>>n>>k;
      ll a[n];
      ll dp[n+2];
                for(int i=0;i<n;i++)cin>>a[i];
	        for(int i=0;i<=n;i++)dp[i]=LLONG_MAX;
                 dp[0]=0;
		 for(int i=0;i<n-1;i++)
		 {
		       
		       for(int j=i+1;j<=i+k and j<n;j++)
		        dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
		       
		 }
	   
	   
	   cout<<dp[n-1]<<"\n";
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   }


Measured memory_bytes: 1792
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  200005
vector<int>adj[N];
int dp[N];
void dfs(int node, int par)
{
	dp[node]+=dp[par];
	for(auto i:adj[node])
	if(i!=par)
	{
		dfs(i,node);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n,m,i,j,k;
		cin>>n>>m;
		for(i=0;i<n-1;i++){
			int x,y;
			cin>>x>>y;
			adj[x].push_back(y);
			adj[y].push_back(x);
		}
		
		while(m--){
			int x,w;
			cin>>x>>w;
			dp[x]+=w;
		}
		dfs(1,0);
		for(i=1;i<=n;i++)cout<<dp[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 23552
from bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i]+L[j]) - 1 - j
print(ans)


Measured memory_bytes: 3188
N=int(input())
a=list(map(int,input().split()))
a.sort()
M=0
s=0
for i in range(a[0],a[N-1]+1):
    t=0
    for j in range(s,N):
        if a[j]==i:
            t+=1
            s=j+1
        elif i+1<=a[j]<=i+2:
            t+=1
        else:
            break
    if t>M:
        M=t
print(M)

Measured memory_bytes: 14008
def test(a):
    print(*a)
    for i in range(len(a) - 1):
        a = [abs(a1 - a0) for a0, a1 in zip(a, a[1:])]
        # print(' ' * i, *a)
        print(*a)


# test([2, 3, 1, 1, 3, 1, 2, 3, 1, 2])
# test([2, 3, 1, 1, 3, 2, 2, 3, 1, 2])
# test([2, 3, 1, 1, 3, 3, 2, 3, 1, 2])
# test([1, 2, 0, 1, 2, 2, 2, 0, 0, 2, 1])
# test([1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0])
# test([0, 0, 0, 0, 0, 1, 0, 0, 1, 2, 0, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ])
# test([0] * 21 + [2] + [0] * 21)
# exit()

def solve(n, aaa):
    # シェルピンスキーの三角形
    if '2' not in aaa:
        factor = '3'
        effect = 2
    else:
        factor = '2'
        effect = 1
    # print(factor, effect)

    try_list = []
    m = n - 1
    while m:
        l = 1 << (m.bit_length() - 1)
        m ^= l
        try_list.append((l, m))
    # print(try_list)

    ans = 0
    for i, a in enumerate(aaa):
        if a == factor:
            for l, m in try_list:
                if i >= l:
                    i -= l
                if i == 0:
                    ans ^= effect
                    break
                elif i > m:
                    break
    return ans


n = int(input())
aaa = input()
print(solve(n, aaa))


Measured memory_bytes: 54252
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
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 void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct node
{
	int a,b;
}p[100010];
bool cmp(node a,node b){return a.a<b.a;}
priority_queue<int>q;
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),m=read()+1;
    for(int i=1;i<=n;i++)p[i].a=read()+1,p[i].b=read();
    sort(p+1,p+n+1,cmp);
    int ans=0,now=1;
    for(int i=2;i<=m;i++)
    {
    	while(p[now].a<=i && now<=n)q.push(p[now].b),now++;
    	if(!q.empty())ans+=q.top(),q.pop();
    }pr2(ans);
    return 0;
}

Measured memory_bytes: 1660
import sys
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    Anum = dict()
    for a in A:
        if a in Anum: Anum[a] += 1
        else: Anum[a] = 1
    q = [0, 0]
    for key in Anum:
        if Anum[key] >= 2: q.append(-key)  
        if Anum[key] >= 4: q.append(-key)
    heapify(q)
    x = heappop(q)
    y = heappop(q)
    print(x * y)


    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 17988
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

array<string, 4> keywords = {"dream", "dreamer", "erase", "eraser"};

bool Solve(const string& S)
{
    if (S.empty()) return true;

    for (const string& keyword : keywords)
    {
        if (S.find(keyword) == 0)
        {
            if (Solve(S.substr(keyword.length())))
            {
                return true;
            }
        }
    }

    return false;
}

bool Solve2(const string& S)
{
    queue<string> que;
    que.push(S);
    while (!que.empty())
    {
        string s = que.front();
        if (s.empty())
        {
            return true;
        }
        que.pop();
        for (const auto& keyword : keywords)
        {
            if (s.find(keyword) == 0)
            {
                que.push(s.substr(keyword.length()));
            }
        }
    }
    return false;
}

int main()
{
    string S;
    cin >> S;
    cout << (Solve2(S) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  string s; cin >> s;
  if (s == "AAA" or s == "BBB") cout << "No\n";
  else cout << "Yes\n";
  return 0;
}



Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

type Work = (i32, i32);

fn input_int_tuple() -> (i32, i32) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let n: i32 = input();
    let mut works: Vec<Work> = Vec::new();
    for _ in 0..n {
        works.push(input_int_tuple());
    }
    works.sort_by(|a, b| b.1.cmp(&a.1));
    let mut now = 0;
    while works.len() != 0{
        let (amount, deadline) = works.pop().unwrap();
        now += amount;
        if now > deadline {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 6396
#include <stdio.h>

int rest(int x, int y)
{
	x = x % y;
	if(x == 0)
		printf("%d\n", y);
	return x;
}

int main(void)
{
	int x, y;
	while(scanf("%d %d", &x, &y)==2)
	{
		if(x<y)
		{
			y = rest(y, x);
			if(y == 0)
				break;
		}
		while(x >= 1 && y >= 1)
		{
			x = rest(x, y);
			if(x == 0)
				break;
			
			y = rest(y, x);
		}
	}
	return 0;
}

Measured memory_bytes: 592
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int a[MAXN],f[MAXN];
vector<int> e[MAXN];
bool dfs(int x,int father)
{
	for (auto v:e[x])
	{
		if (v==father) continue;
		dfs(v,x);
		if (a[x]>a[v]&&!f[v]) return f[x]=1;
	} 
	return f[x]=0;
}
int main()
{
	int n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<n;i++)
	{
		int u=read(),v=read();
		e[u].PB(v);
		e[v].PB(u);
	}
	for (int i=1;i<=n;i++)
		if (dfs(i,0)) printf("%d ",i);
	return 0;
}


Measured memory_bytes: 16896
#include <stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  
  int flag = 0;
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      if(N == i*j) flag = 1;
    }
  }
  
  if(flag == 0){
    printf("No");
  }else{
    printf("Yes");
  }
}

Measured memory_bytes: 128
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }

    int sum = 0;
    for (int x : a) sum += x;
    double border = sum / 4.0 / m;
    if (count_if(a.begin(), a.end(), [=](int x){return x >= border;}) >= m) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

struct test{
    int a;
    int b;
    int c;
    int d;
};
vector<test> queries;


int check(const vector<int> & array)
{
    int score(0);
    for(auto q:queries){
        if(array[q.b-1] - array[q.a-1] == q.c) score += q.d;
    }

    return score;
}

int dfs(int cnt, int min_value, int max_value, int length, vector<int> & array){

    int ans(0);

    if(cnt==length){
        return check(array);
    }
    for(int i=min_value; i<=max_value; ++i){
        array[cnt] = i;
        ans = max( ans, dfs(cnt+1, i, max_value, length, array));
    }

    return ans;
}


int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    int a,b,c,d;

    for(int i=0;i<Q;++i){
        cin >> a >> b >> c >> d;
        queries.push_back({a,b,c,d});
     }

    vector<int> series(10,0);

    cout << dfs( 0, 1, M, N, series ) << endl;

    return 0;
}


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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(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 long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5;

int n;
string s, t;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> s >> t;
    for0(i, n)
    {
        cout << s[i] << t[i];
    }
    return 0;
}


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

int main() {
   int a,b,c,d;
   
   cin>>a>>b>>c>>d;

   if(a+b>c+d) cout<<"Left"<<endl;

   else if(a+b<c+d) cout<<"Right"<<endl;

   else cout<<"Balanced"<<endl;

}

Measured memory_bytes: 256
#include<fstream>
#include<string>
#include<iostream>
#include<sstream>
#include<iterator>
#include<cmath>
#include<stdio.h>

using namespace std;

int main(){
 string txt;
 cin >> txt;
  if(txt=="Sunny")cout << "Cloudy" << endl;
  if(txt=="Cloudy")cout << "Rainy" << endl;
  if(txt=="Rainy")cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
   int n,m,i,j,k;
   char s[1000];
   while(~scanf("%s",s))
   {n=0;
       k=strlen(s);
       for(i=0;i<k;i++)
       {
           if(s[i]=='+')
           {
             n++;
           }
           else if(s[i]=='-')
           {
               n--;
           }
       }printf("%d\n",n);
   }
    return 0;
}


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

using namespace std;

int main(){


  while(1){

    int a, b;
    string op;
    cin>>a>>op>>b;
    if(op == "?") break;

    int ans;
    if(op == "+") ans = a + b;
    if(op == "-") ans = a - b;
    if(op == "*") ans = a * b;
    if(op == "/") ans = a / b;


    cout<<ans<<endl;
  }
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x[100002],y[100002],t[100002];
    cin>>n;
    for(int i=1;i<=n;i++)
	{
        cin>>t[i]>>x[i]>>y[i];
    }
    for(int i=1;i<=n;i++)
        if(x[i]+y[i]>t[i]||(t[i]-x[i]-y[i])%2!=0)
		{
        	cout<<"No\n";
        	return 0;   
        }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1408
/*https://atcoder.jp/contests/dp/tasks/dp_g*/
#include <bits/stdc++.h>
#include <sstream> 
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define pi 2*acos(0.0)
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repe(i,a,b) for(ll i=a;i<=b;++i)
#define CPrint(c)  for(auto i:(c)) { cout<<i<<" "; } nl 
#define eb   emplace_back
#define ef   emplace_front
#define pb   push_back
#define pf   push_front
#define popb pop_back
#define popf pop_front
#define mp   make_pair
#define sz(a) int((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
//Allows to traverse any type of macro
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
//debuggers
#define trace2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define trace3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define trace4(w,x,y,z) cout<<#w<<"="<<w<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
typedef long long ll;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;
const int lim = 1e5+5;
ll n,m;
vector<ll>dist(lim);
/*
DAG as input
add a fake vertex and carry out path and
 for every vertex we need the longest distance to the vertex
*/
ll in_degree[lim];
vector<ll>adj[lim];
vector<bool> visited(lim,false);
void dfs(ll a)
{
	if(!visited[a])
	{
		visited[a] = true;
for(ll b:adj[a])
{
	dist[b] = max(dist[b],dist[a]+1);
	--in_degree[b];
	if(in_degree[b]==0)
	{
		dfs(b);
	}
	}
}
}
int main()
{
	cin >> n >> m;
	ll a,b;
	for(int i=0;i<m;i++)
	{
		cin >> a >> b;
		adj[a].eb(b);
		++in_degree[b];
	}
	for(int i=1;i<=n;i++)
	{
		if(!visited[i] && in_degree[i]==0)
		{
			dfs(i);
		}
	}
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
		ans = max(ans,dist[i]);
	}

cout << ans << endl;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int _m[110][110];
int W, H, S, T;

template <int n, int m>
inline int safeAt(int (&a)[n][m], int x, int y, int d){
    if(0 <= x && x < m && 0 <= y && y <= n){
        return a[y][x];
    }
    return d;
}

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

    while(true){
        int N;
        std::cin >> N;
        if(!N){break;}
    
        std::cin >> W >> H;

        memset(_m, 0, sizeof(_m));
    
        for(int i=0;i<N;++i){
            int x, y;
            std::cin >> x >> y;
            --x; --y;
        
            ++_m[y][x];
        }

        for(int i=0;i<H;++i){
            for(int j=0;j+1<W;++j){
                _m[i][j+1] += _m[i][j];
            }
        }

        for(int j=0;j<W;++j){
            for(int i=0;i+1<H;++i){
                _m[i+1][j] += _m[i][j];
            }
        }

        std::cin >> S >> T;

        int res = 0;
        for(int i=0;i+T<=H;++i){
            for(int j=0;j+S<=W;++j){
                res = max(res, safeAt(_m, j+S-1, i+T-1, 0) - safeAt(_m, j+S-1, i-1, 0) - safeAt(_m, j-1, i+T-1, 0) + safeAt(_m, j-1, i-1, 0));
            }
        }

        std::cout << res << std::endl;
    }
}



Measured memory_bytes: 3080
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if((a*b)&1)
		printf("Odd");
	else
		printf("Even");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc064.contest.atcoder.jp/tasks/abc064_d>
問題文============================================================
 ( と ) で構成される N 文字の文字列 S が与えられる。S にいくつかの ( または ) を挿入することで正しい括弧列を作りたい。
 ただし、正しい括弧列は次のように定義されている：
 
 () は正しい括弧列である。
 X が正しい括弧列であるとき、(、X、) をこの順につなげたものは正しい括弧列である。
 X、Y が正しい括弧列であるとき、X と Y をこの順につなげたものは正しい括弧列である。
 それ以外の括弧列は正しくない。
 そのとき、作れる最も文字数が少ない正しい括弧列を求めなさい。このようなものが複数ある場合は、辞書順最小のものを求めなさい。
 
=================================================================

解説=============================================================

 良くあるパターン
 
 stackを使って 左括弧の情報（数）を保持しておき、
 dequeを用いて、復元を行えば良い
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;
    deque<char> dq;
    stack<char> st;
    for(int i = 0; i < N;i++){
        if(S[i] == '('){
            st.push('(');
            dq.push_back('(');
        }else{
            dq.push_back(')');
            if(st.empty()){
                dq.push_front('(');
            }else{
                st.pop();
            }
        }
    }
    while(!st.empty()) {dq.push_back(')'); st.pop(); }
    cout << string(dq.begin(),dq.end()) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	string s;
	cin >> s;
	int r = 0; int w = 0;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'W')
			w++;
		else
			r++;
	}
	int ans = min(w, r);
	int cnt = 0;
	for (int i = r; i < n; i++)
	{
		if (s[i] == 'R')
			cnt++;
	}
	ans = min(ans, cnt);
	cout << ans;
	return 0;
}



Measured memory_bytes: 3748
from numpy import cumsum
from bisect import bisect
N = int(input())
A = [int(i) for i in input().split()]
X = [v - i - 1 for i, v in enumerate(A)]
X.sort()
S = cumsum(X)
ans = float('inf')
for bc in set(X):
    i = bisect(X, bc)
    a = -1 * S[i - 1] + bc * i + (S[N - 1] - S[i - 1]) + -1 * bc * (N - i)
    ans = min(ans, a)
print(ans)

Measured memory_bytes: 43284
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll a,b,c; cin >> a >> b >> c;
  
 
  if(c <= b+a) cout << b+c << endl;
  else cout << 2*b+a+1 << endl;
}

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

namespace AtCorder
{
	public class Program
	{
		static int[] ls;
		static void Main(string[] args)
		{
			var abq = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int a = abq[0];
			int b = abq[1];
			int q = abq[2];

			var s = new long[a];
			for (int i = 0; i < a; i++) {
				s[i] = long.Parse(Console.ReadLine());
			}

			var t = new long[b];
			for (int i = 0; i < b; i++) {
				t[i] = long.Parse(Console.ReadLine());
			}

			var sb = new StringBuilder();
			for (int i = 0; i < q; i++) {
				long x = long.Parse(Console.ReadLine());

				long sn = LowerBound(x, s);
				long tn = LowerBound(x, t);

				long lengthRR = long.MaxValue;
				long lengthLR = long.MaxValue;
				long lengthRL = long.MaxValue;
				long lengthLL = long.MaxValue;

				if (sn != a && tn != b) {
					lengthRR = Math.Max(s[sn] - x, t[tn] - x);
				}

				if (sn != 0 && tn != 0) {
					lengthLL = Math.Max(x - s[sn - 1], x - t[tn - 1]);
				}

				if (sn != a && tn != 0) {
					long ls = s[sn] - x;
					long lt = x - t[tn - 1];
					lengthRL = Math.Min(
						ls * 2 + lt,
						lt * 2 + ls);
				}

				if (sn != 0 && tn != b) {
					long ls = x - s[sn - 1];
					long lt = t[tn] - x;
					lengthLR = Math.Min(
						ls * 2 + lt,
						lt * 2 + ls);
				}

				long length = Math.Min(
					lengthRR,
					Math.Min(lengthLR,
						Math.Min(lengthRL, lengthLL)));

				sb.AppendLine(length.ToString());
			}

			Console.WriteLine(sb.ToString());
		}

		static long LowerBound(long target, long[] values)
		{
			long left = -1;
			long right = values.Length;
			while (right - left > 1) {
				long mid = (left + right) / 2;
				if (values[mid] >= target) {
					right = mid;
				} else {
					left = mid;
				}
			}

			return right;
		}
	}
}


Measured memory_bytes: 26448
n = input().strip()
k = int(input().strip())
le = len(n)
dp = [[[0] * 2 for _ in range(5)] for _ in range(101)]
dp[0][0][0] = 1

for i in range(le):
    for cnt in range(4):
        for smaller in range(2):
            fig = int(n[i])
            for d in range(10):
                tmp1 = i + 1
                tmp2 = cnt
                tmp3 = smaller
                if d != 0:
                    tmp2 += 1
                if k < cnt:
                    continue
                if smaller == 0:
                    if fig < d:
                        continue
                    elif d < fig:
                        tmp3 = 1
                dp[tmp1][tmp2][tmp3] += dp[i][cnt][smaller]
print(dp[le][k][0] + dp[le][k][1])


Measured memory_bytes: 41456
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

long long solve(const vector<int> &a) {
  int n = a.size();
  vector<long long> sum(n + 1);
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + a[i];
  }
  long long ans = LLONG_MAX;
  int l = 1, r = 3;
  for (int mid = 2; mid <= n - 2; mid++) {
    while (l + 1 < mid && 
      abs((sum[mid] - sum[l]) - (sum[l] - sum[0])) > 
      abs((sum[mid] - sum[l+1]) - (sum[l+1] - sum[0]))
      ) l++;
    if (r <= mid) r = mid + 1;
    while (r + 1 < n && 
      abs((sum[n] - sum[r]) - (sum[r] - sum[mid])) > 
      abs((sum[n] - sum[r+1]) - (sum[r+1] - sum[mid]))
      ) r++;
    long long vals[4] = { sum[n] - sum[r], sum[r] - sum[mid], sum[mid] - sum[l], sum[l] };
    sort(vals, vals + 4);
    ans = min(ans, vals[3] - vals[0]);
  }
  return ans;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  long long ans = solve(a);
  printf("%lld\n", ans);
  return 0;
}


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

#define int long long
typedef pair <int, int> pii;
map <pii, int> M;

int32_t main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		M[pii(to_string(i)[0] - '0', i % 10)]++;
	}
	int ans = 0;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			ans += M[pii(i, j)] * M[pii(j, i)];
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,m,a[101],b[101],e,end=0,ans=1,flg=1;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		if(a[i]==1&&end<=b[i]){
			end=b[i];
		}
	}
	if(end==0)goto OUT;
	while(end<n){
		flg=0;
		e=end;
		for(int i=0;i<m;i++){
			if(a[i]<=end+1){
				if(e<b[i]){
					e=b[i];flg=1;
				}
			}
		}
		if(flg==0)break;
		end=e;
		ans++;
	}
	OUT:
	if(end<n){
		cout<< "Impossible" <<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}	

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;

const int INF = 100000000;

typedef pair<int, int> P;

int main(void){
    int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    int h, w;
    cin >> h >> w;

    vector<vector<char>> maze(h, vector<char>(w));

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            cin >> maze[i][j];
        }
    }

    int ms = h*w;

    vector<vector<int>> ans(ms, vector<int>(ms));

    //cout << "ms:" << ms << endl;
    for(int i = 0;i < ms-1;i++){
        if(maze[i/w][i%w] != '#'){
            for(int j = i+1;j < ms;j++){
                //cout << "i:" << i << " j:" << j << endl;
                //cout << "debug" << endl;
                if(maze[j/w][j%w] != '#'){
                    //cout << "in" << endl;
                    int sx, sy, gx, gy;
                    sx = i%w; sy = i/w; gx = j%w; gy = j/w;
                    queue<P> que;
                    vector<vector<int>> disc(h, vector<int>(w));

                    for(int k = 0;k < h;k++)
                        for(int l = 0;l < w;l++)
                            disc[k][l] = INF;

                    que.push(P(sx, sy));
                    P temp = que.front();
                    disc[sy][sx] = 0;

                    while(que.size()){
                        P p = que.front(); que.pop();
                        if(p.first == gx && p.second == gy) break;

                        for(int k = 0;k < 4;k++){
                            int nx = p.first + dx[k], ny = p.second + dy[k];

                            if(0 <= nx && nx < w && 0 <= ny && ny < h
                            && maze[ny][nx] != '#' && disc[ny][nx] == INF){
                                que.push(P(nx,ny));
                                disc[ny][nx] = disc[p.second][p.first] + 1;
                            }
                        }
                    }

                    ans[i][j] = disc[gy][gx];
                    //cout << "a" << endl;
                }
            }
        }
    }

    int max = 0;

    for(int i = 0;i < ms;i++){
        for(int j = 0;j < ms;j++){
            if(max < ans[i][j]) max = ans[i][j];
        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 896
N = int(input())
A = list(int(a) for a in input().split())
A.extend([0])

money = 1000
stock = 0

for i in range(N):
    if A[i] < A[i+1] and money >= A[i]:
        stock += money // A[i]
        money %= A[i]
    if A[i] > A[i+1]:
        money += stock * A[i]
        stock = 0

print(money)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
 // const ll INF = 1000000000000000000LL;

int main() {
	string s,t;
	cin >> s >> t;
	vector<int> start(26,-1);
	vector<int> goal(26,-1);
	for(int i=0;i<s.size();i++){
		int a = s[i]-'a';
		int b = t[i]-'a';

		if(start[a] !=-1 || goal[b]!=-1){
			if(start[a]!=b ||goal[b]!=a){
				cout << "No" << endl;
				return 0;
			}
		}
		else{
			start[a]=b;
			goal[b]=a;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int x; cin >> x;
	int64_t sum = 0;
	for(int k = 1; ; ++k) {
		sum += x;
		if(sum % 360 == 0) {
			cout << k << '\n';
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3620
/// TAKOYAKI FESTIVAL 2019......At coder contest 143
#include<iostream>
using namespace std;

#define ar array
#define endl '\n'
#define max 10000
int main()
{
    int mal=0;
    int ar[max];
    int n;
    cin>>n;

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

    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            mal=mal+(ar[i]*ar[j]);
        }
    }
    cout<<mal<<endl;
}


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

int main(){
    int a, b, c, S, M, L;
    cin >> a >> b >> c;
    if ((a <= b) && (b <= c)) S = a, M = b, L = c;
    else if ((a <= c) && (c <= b)) S = a, M = c, L = b;
    else if ((b <= a) && (a <= c)) S = b, M = a, L = c;
    else if ((b <= c) && (c <= a)) S = b, M = c, L = a;
    else if ((c <= a) && (a <= b)) S = c, M = a, L = b;
    else if ((c <= b) && (b <= a)) S = c, M = b, L = a;

    cout << S << " " << M << " " << L << endl;

    return 0;

}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 17;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 




////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////

int n,c,ans,x[110000],v[110000],cl[110000],anti[110000],mc[110000],ma[110000];

signed main(){
  cin>>n>>c;rep(i,n)cin>>x[i+1]>>v[i+1];x[n+1] = c;
  repd(i,1,n+1){
    cl[i] = cl[i-1] + v[i] - (x[i] - x[i-1]);
    chmax(ans, cl[i]);
  }
  repd(i,1,n+1){
    anti[i] = anti[i-1] + v[n-i+1] - (x[n-i+2] - x[n-i+1]);
    chmax(ans, anti[i]);
  }
  repd(i,1,n+1)mc[i] = max(mc[i-1], cl[i]);
  repd(i,1,n+1)ma[i] = max(ma[i-1], anti[i]);
  rep(i,n+1)chmax(ans, cl[i] - x[i] + ma[n-i]);
  rep(i,n+1)chmax(ans, anti[i] - (c - x[n-i+1]) + mc[n-i]);
  cout << ans << endl;
}


Measured memory_bytes: 5120
#include<stdio.h>

int main(){

	int i,l[10],v[2],sToe,sum;
	double x;

	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v[0],&v[1])!=EOF){
		sToe=0;
		for(i=0;i<10;i++) sToe+=l[i];
		x=(double)sToe/(v[0]+v[1]);
		sum=0;
		for(i=0;i<10;i++){
			if(sum<x*v[0] && x*v[0]<=sum+l[i]){
				printf("%d\n",i+1);
				break;
			}
			sum+=l[i];
			
		}

	}





	return 0;

}

Measured memory_bytes: 596
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e8;

signed main() {
	int N, M;
	cin >> N >> M;
	vector<int>a(M);
	vector<int>dp(N + 1, -INF);
	dp[0] = 1;
	dp[1] = 1;
	rep(i, M) {
		cin >> a[i];
		dp[a[i]] = 0;
	}
	rep(i, N - 1) {
		if (dp[i + 2] == 0)continue;
		dp[i + 2] = (dp[i + 1] + dp[i]) % MOD;
	}
	cout << dp[N];
}

Measured memory_bytes: 1792
from sys import exit
import math
x,y = map(int, input().split())
seppen = x + y

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


if seppen%3 != 0:
    print(0)
    exit()
else:
    dan = int(seppen/3)
    kyori = y - dan

    mod = 10**9+7 #出力の制限
    N = dan
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
    if kyori < 0 or kyori > dan:
        print(0)
    else:
        a = cmb(dan,kyori,mod)
        print(a)

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

int main(){
    long double a,b,c;
    cin >> a >> b >> c;
    long double a_sqrt=sqrt(a);
    long double b_sqrt=sqrt(b);
    long double c_sqrt=sqrt(c);
    if(sqrt(sqrt(sqrt(a_sqrt+b_sqrt)))<sqrt(sqrt(sqrt(c_sqrt))))
    cout << "Yes";
    else
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<(#x)<<" is "<<(x)<<endl
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
    cin>>a[i];
}long long int sum=0;
 int temp=a[0];
for(int i=1;i<n;i++)
{
    if(temp>a[i])
   sum=sum+(temp-a[i]);
   else
    temp=a[i];
}cout<<sum;
}









Measured memory_bytes: 4400
import math

A, B, H, M = list(map(int, input().split()))

H_delta = H + M/60

xh = A * math.cos(2 * math.pi * H_delta/12)
yh = A * math.sin(2 * math.pi * H_delta/12)
xm = B * math.cos(2 * math.pi * M/60)
ym = B * math.sin(2 * math.pi * M/60)

dx = xh - xm
dy = yh - ym

result = (dx**2 + dy**2) ** (1/2)

print(result)


Measured memory_bytes: 62452
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  string s; cin >> s;
  int cnt[3] = {};
  int n = s.size(), lim = (n + 1) / 2;
  for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;

  if (abs(cnt[0] - cnt[1]) <= 1
      && abs(cnt[1] - cnt[2]) <= 1
      && abs(cnt[2] - cnt[0]) <= 1) {
        YES();
    } else {
      NO();
    }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define GYOU_MAX 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define s_pri(str) printf("%s\n",str);
#define PRINT(str) printf(#str "\n")
#define v_pri(val) printf("%d\n",val);
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define pi acos(-1.0)
#define sca(x) scanf("%d",&x);

typedef long long int ll;

/*
puts("aa");
//*/

int count_digit_min(ll  x,ll  y) {
	int count_x = 1;
	int count_y = 1;
	while (x / 10 > 0) {
		x /= 10;
		count_x++;
	}

	while (y / 10 > 0) {
		y /= 10;
		count_y++;
	}

	if (count_x >= count_y) {
		return count_x;
	}
	else {
		return count_y;
	}
}
int count_digit(ll x) {
	int count = 1;

	while (x / 10 > 0) {
		x /= 10;
		count++;
	}

	return count;
}

int main(void) {
	
	ll  N;
    scanf("%lld", &N);
	int a;
	int min = 11;
	for (int i = 2; i <= sqrt(N); i++) {
		if (N%i == 0) {
			if (count_digit_min(i, N / i) < min) {
				//printf("%d %d\n", i, N / i);
				min = count_digit_min(i, N / i);
			}
		}
		
	}
	if (min == 11) {
		min = count_digit(N);
	}

	printf("%d\n", min);


	return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
	
	char [] data;
	boolean [] flg;
	long dfsres;
	
	private void dfs(int ind,int start, int max){
		if(max == ind){
			long nowsum = 0;
			long temp = 0;
			for(int i =0; i < data.length; i++){
				nowsum += (long)(data[i] - '0');
				if(i == data.length - 1)break;
				
				if(! flg[i]){
					nowsum *= 10;
				}
				else{
					temp += nowsum;
					nowsum = 0;
				}
			}
			temp += nowsum;
			dfsres += temp;
			return;
		}
		
		for(int i = start; i < data.length-1; i++){
			if(flg[i]) continue;
			
			flg[i] = true;
			dfs(ind + 1,i + 1, max);
			flg[i] = false;
		}
		return;
	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		long mod = 1000000007;
		while(sc.hasNext()){
			data = sc.next().toCharArray();
			int len = data.length;
			flg = new boolean[len];
			
			dfsres = 0;
			for(int i = 0; i < len; i++){
				dfs(0,0,i);
			}
			System.out.println(dfsres);
			
		}

	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 9428
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Same Integers
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);

  if (a < b) swap(a, b);
  if (a < c) swap(a, c);

  int d = (a - b) / 2, e = (a - c) / 2;
  b += d * 2, c += e * 2;
  int f = (a - b) + (a - c);

  int sum = d + e + (3 - f) % 3;
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 256