akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = max({
        10 * a + b + c,
        a + 10 * b + c,
        a + b + 10 * c
    });

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

Measured memory_bytes: 256
n , q = map(int, input().split())

tree = [[] for i in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)

op = [0] * (n+1)
for i in range(q):
    p, x = map(int, input().split())
    op[p] += x

for root, reaf in enumerate(tree):
    for i in reaf:
        op[i] += op[root]

print(*op[1:])

Measured memory_bytes: 47892
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

bool solve() {
	int a, b, c; cin >> a >> b >> c;
	cout << a + b + c - max({ a,b,c }) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(9);
	//init();
	//while (cin >> n>>m>>l,n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<int> set;
    int a;
    rep(i, n) cin >> a, set.insert(a);
    cout << set.size() << endl;

    return 0;
}

Measured memory_bytes: 512
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
/*
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;

#define INF (1 << 30)
//#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

#define INFL ((1 << 31) - 1)

class RMQ {
	vector<ll> data;
	int size;
	int suffix;
	
public:
	RMQ() {}
	RMQ(int n) {
		suffix = -1;
		resize(n);
	}

	void resize(int n) {
		size = 1;
		while (size < n) {
			size <<= 1;
		}
		data.resize(size * 2 - 1, INFL);
	}

	ll operator[](int i) const {
		return data[i + size - 1];
	}

	ll& operator[](int i) {
		update();
		suffix = i;
		return data[i + size - 1];
	}

	void update() {
		if (suffix < 0)
			return;
		int k = suffix + size - 1;
		suffix = -1;
		while (k > 0) {
			k = (k - 1) / 2;
			data[k] = std::min(data[k * 2 + 1], data[k * 2 + 2]);
		}
	}

	ll min(int a, int b) {
		update();
		suffix = -1;
		return min(a, b, 0, 0, size);
	}

	ll min(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)
			return INFL;
		if (a <= l && r <= b)
			return data[k];
		int m = (l + r) / 2;
		return std::min(min(a, b, k * 2 + 1, l, m), min(a, b, k * 2 + 2, m, r));
	}
};

int main() {
	int n, q, c, x, y;
	cin >> n >> q;
	RMQ rmq(n);
	while (q--) {
		cin >> c >> x >> y;
		if (c) {
			cout << rmq.min(x, y + 1) << endl;
		}
		else {
			rmq[x] = y;
		}
	}

	return 0;
}

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

int main() {
  string s;
  int64_t n, c = 1, d = 0, e = 1;
  cin >> s >> n;
  if(s.size() == 1){
    cout << n/2 << endl;
  }
  else{
    s += s.at(0);
    int j = 1;
    while(s.at(j) == s.at(0)){
      e++;
      j++;
      if(j == s.size()-1) break;
    }
    if(j < s.size() - 1){
      for(int i = j; i < s.size() - 1; i++){
        if(s.at(i) == s.at(i+1)) c++;
        else{
          d += (c/2);
          c = 1;
         }
      }
 
      if(s.at(0) == s.at(s.size() - 2)){
        d += (c+e-1)/2;
      }
      else d += c/2 + e/2; 
      int64_t a = d*n;
      if(s.at(0) == s.at(s.size() - 2) && c % 2 == 0 && e % 2 == 1){
        a--;
      }
      cout << a << endl;
    }
    else{
      int64_t a = n*(s.size()-1)/2;
      cout << a << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int n,cnt=0,sum=0;
    cin>>n;
    vector<int> s(n);
    rep(i,n) {
        cin>>s[i];
        sum+=s[i];
        if (s[i]%10==0) cnt++;
    }
    if (cnt==n) cout<<0<<endl;
    else if(sum%10!=0) cout<<sum<<endl;
    else {
        sort(s.begin(),s.end());
        rep(i,s.size()) {
            if (s[i]%10!=0) {
                sum-=s[i];
                cout<<sum<<endl;
                return 0;
            }
        }
    }
}


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

{
    long long i,t,a[100000],ans=1,limit=1000000000000000000;
    cin>>t;
    for(i=0;i<t;i++)
        cin>>a[i];

    for(i=0;i<t;i++)
    {
        if(a[i]==0)
        {
            cout<<'0'<<endl;
            return 0;
        }
    }



    for(i=0;i<t;i++)
    {
        if(limit/ans < a[i])
        {
            cout<<"-1"<<endl;
            return 0;
        }

        ans=ans*a[i];
    }

     cout<<ans<<endl;

}


Measured memory_bytes: 4392
h, w = gets.to_s.split.map{|i|i.to_i}
n = gets.to_s.to_i
a = gets.to_s.split.map{|i|i.to_i}

cur = 0
h.times do |i|
  
  c = 0
  r = []
  while c < w
    
    t = [w-c, a[cur]].min
    r += [cur+1] * t
    c += t
    a[cur] -= t
    cur += 1 if t == 0
  end
  
  r.reverse! if i.odd?
  
  puts r.join(" ")
end

Measured memory_bytes: 3964
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	switch s {
		case "Sunny":
			fmt.Println("Cloudy")
		case "Cloudy":
			fmt.Println("Rainy")
		case "Rainy":
			fmt.Println("Sunny")
	}
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }
ll lcm(ll x, ll y){ return (x  / gcd(x, y) * y ); }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, q, k;
	cin >>n;
	vector<vector<pii>> r(n);
	rep(i, n-1){
		int a, b, c;
		cin >>a >>b >>c;
		r[a-1].emplace_back(b-1, c);
		r[b-1].emplace_back(a-1, c);
	}
	VL dst(n, -1);
	cin >>q >>k;
	
	auto dfs =[&](auto dfs, int s) ->void{
		for(auto& x: r[s]){
			if(dst[x.first] <0){
				dst[x.first] = dst[s] + x.second;
				dfs(dfs, x.first);
			}
		}
	};
	dst[k-1]=0;
	dfs(dfs, k-1);
	
	while(q--){
		int x, y; cin >>x >>y;
		cout << dst[x-1] + dst[y-1] <<"\n";
	}
	return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  char A[N];
  char B[N];
  for(int i=0;i<N;i++)cin >> A[i];
  for(int i=0;i<N;i++)cin >> B[i];
  for(int i=0;i<N;i++){
  	cout << A[i];
    cout << B[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    vector<int> p(3);
    rep(i,3) cin>>p[i];
    sort(etob(p));
    int ans=p[0]*10+p[1]+p[2];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<utility>
#include<algorithm>
#include<cctype>
using namespace std;
	


int main(){
	int a[15];
	int b[15];
	int num[15];
	string str[15];
	
	for(int i=0;i<9;i++){
	cin>>str[i]>>a[i]>>b[i];
	}
	
	for(int i=0;i<9;i++){
		
		num[i]=a[i]*200+b[i]*300;
	}
	
	for(int i=0;i<9;i++){
	cout<<str[i]<<" "<<a[i]+b[i]<<" "<<num[i]<<endl;
	}

	
	return 0;
	
}








Measured memory_bytes: 2988
#!/usr/bin/env python3
N = int(input().strip())
v = [int(str) for str in input().strip().split()]

a1_dict = dict()
a2_dict = dict()

for i in range(0, N, 2):
    a1_dict[v[i]] = a1_dict.get(v[i], 0) + 1
    a2_dict[v[i + 1]] = a2_dict.get(v[i + 1], 0) + 1

a1_list = sorted(a1_dict.items(), key=lambda x: x[1], reverse=True)
a2_list = sorted(a2_dict.items(), key=lambda x: x[1], reverse=True)

if a1_list[0][0] != a2_list[0][0]:
    print(N - a1_list[0][1] - a2_list[0][1])
else:
    a1_list.append((0, 0))
    a2_list.append((0, 0))
    if a1_list[1][1] > a2_list[1][1]:
        print(N - a1_list[1][1] - a2_list[0][1])
    else:
        print(N - a1_list[0][1] - a2_list[1][1])

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

int main (){
  string str1,str2,str3;
  cin >> str1 >> str2 >> str3;
  char a='A'-'a';
  cout <<(char)(str1[0]+a)<<(char)(str2[0]+a)<<(char)(str3[0]+a)<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな

signed main(){
    int n;cin>>n;
    int a[114514];
    int ans=0;
    int count=0;
    rep(i,0,n){
        cin>>a[i];
        if(a[i])count+=a[i];
        else{
            ans+=count/2;
            count=0;
        }
    }
    ans+=count/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let n = Int(readLine()!)!
    var ac = 0
    var wa = 0
    var tle = 0
    var re = 0
    for _ in 0..<n {
        let s = readLine()!
        if s == "AC" {
            ac += 1
        } else if s == "WA" {
            wa += 1
        } else if s == "TLE" {
            tle += 1
        } else {
            re += 1
        }
    }
    print("AC x", ac)
    print("WA x", wa)
    print("TLE x", tle)
    print("RE x", re)
}

main()


Measured memory_bytes: 7820
# 完全二部グラフで大丈夫なら全部大丈夫(最悪で大丈夫かどうか)
# 簡単のためN=3kとする(3の倍数以外でもほとんど同じなので)
# 0,1,2がk個ずつ

# 1-1,2-2間に辺があるとダメ(これだけを避ければよい)
#   1-2,1-0,2-1,2-0,0-0はOKなので

# 二部グラフで片側の頂点が2k以上(もう一方がk個以下)の場合
#   2k以上の方に1,2を割り当てて、反対側をすべて0にする

# 両方とも(k,2k)の場合
# 両方k以上なのでLを1、Rを2で埋めて残りを0で埋める


def main():
    from collections import deque
    from itertools import chain
    import sys
    input = sys.stdin.readline

    # INPUT
    N = int(input())

    graph = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].add(b)
        graph[b].add(a)

    # BFS
    dq = deque([0])
    parity = [-1] * N
    parity[0] = 0

    vs = [[] for _ in range(2)]
    vs[0].append(0)

    while dq:
        v = dq.popleft()
        p = parity[v]
        np = 1 ^ p
        for u in graph[v]:
            if ~parity[u]: continue
            parity[u] = np
            vs[np].append(u)
            dq.append(u)

    # SOLVE
    k = N // 3  # 3の倍数の個数

    g1 = iter(range(1, N + 1, 3))
    g2 = iter(range(2, N + 1, 3))
    g3 = iter(range(3, N + 1, 3))
    if len(vs[0]) <= k:
        # parity=0を3の倍数で埋める
        # 残りを余った数で埋める
        for v in vs[0]:
            parity[v] = next(g3)  # g3の方がvs[0]より数多い

        g123 = chain(g1, g2, g3)

        for v in vs[1]:
            parity[v] = next(g123)

    elif len(vs[1]) <= k:
        # parity=1を3の倍数で埋める
        # 残りを余った数で埋める
        for v in vs[1]:
            parity[v] = next(g3)  # g3の方がvs[1]より数多い

        g123 = chain(g1, g2, g3)

        for v in vs[0]:
            parity[v] = next(g123)

    else:
        # parity=0を(mod3=1)で埋める
        # parity=1を(mod3=2)で埋める
        # 残りを3の倍数で埋める

        g13 = chain(g1, g3)
        for v in vs[0]:
            parity[v] = next(g13)
            # k<=len(g1)<=k+1,len(vs[0])>=k+1
            # 右辺がg1だけだと不足する恐れ

        g23 = chain(g2, g3)
        for v in vs[1]:
            parity[v] = next(g23)
            # k<=len(g2)<=k+1,len(vs[1])>=k+1
            # 右辺がg2だけだと不足する恐れ

    print(*parity)


if __name__ == '__main__':
    main()


Measured memory_bytes: 82792
fn main() {
    let m: isize = read();
    let ans = 24 + 24 - m;
    println!("{}", ans);
}

// 以下関数

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

pub const MOD: u64 = 10e9 as u64 + 7;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

struct edge {
    int from, to; ll cost;
    edge(int s, int t, ll w = 0) : from(s), to(t), cost(w) {}
};
int main() {
    init();

    int n;
    cin >> n;
    vector<VI> a(n, VI(n)), wh(n, VI(n, -1));
    FOR(i, 0, n)FOR(j, 0, n - 1) {
        cin >> a[i][j];
        wh[i][--a[i][j]] = j;
    }

    int v = n * (n - 1) / 2;
    vector<vector<edge>> g(v);

    vector<VI> id(n, VI(n));
    int o = 0;
    FOR(i, 0, n)FOR(j, i + 1, n)id[i][j] = o++;

    VI in(v, 0);
    FOR(i, 0, n)FOR(j, 0, n - 2) {
        int x = i, y = a[i][j], X = i, Y = a[i][j + 1];
        if (x > y)swap(x, y);
        if (X > Y)swap(X, Y);
        g[id[x][y]].emplace_back(id[x][y], id[X][Y]);
        in[id[X][Y]]++;
    }
    
    VI len(v, 0);
    queue<int> que, ans;
    FOR(i, 0, v)if (in[i] == 0) {
        que.push(i);
        len[i] = 1;
    }

    while (!que.empty()) {
        int now = que.front(); que.pop();
        ans.push(now);
        for (edge next : g[now]) {
            if (--in[next.to] == 0) {
                que.push(next.to);
                chmax(len[next.to], len[now] + 1);
            }
        }
    }

    if (v == ans.size()) {
        int mlen = 0;
        for (int i : len)chmax(mlen, i);
        cout << mlen << "\n";
    }
    else cout << "-1\n";
}


Measured memory_bytes: 54912
#include<iostream>
#include<stdio.h>
#include<vector>
#include<complex>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long int llint;
int n, m;

int main() {
	cin >> n >> m;
	vector < pair<int, pair<int, int>>> py(m);
	vector<pair<int, int>>ans(m);
	for (int i = 0;i < m;i++) {
		cin >> py[i].first >> py[i].second.first;
		py[i].second.second = i;
	}
	sort(py.begin(), py.end());
	int cnt = 1;
	for (int i = 0;i < m;i++) {
		if (0 < i) {
			if (py[i].first != py[i - 1].first) {
				cnt = 1;
			}
			else {
				cnt++;
			}
		}
		ans[py[i].second.second].first = py[i].first;
		ans[py[i].second.second].second = cnt;
	}
	for (int i = 0;i < m;i++) {
		printf("%06d%06d\n", ans[i].first, ans[i].second);
	}
	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
	int a, b;
	char op;

	do{
		cin >> a >> op >> b;

		switch (op) {
		case '+': cout << a + b << "\n"; break;
		case '-': cout << a - b << "\n"; break;
		case '*': cout << a * b << "\n"; break;
		case '/': cout << a / b << "\n"; break;
		case '?': break;
		}
	}while (op != '?');
}

Measured memory_bytes: 1164
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;



int main(){
  int a; cin >> a;
  cout << a+a*a+a*a*a << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int A[200000];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int N; cin >> N;
    Tree<pi> T;
    F0R(i,N) {
        cin >> A[i];
        T.insert({A[i],i});
    }
    F0R(i,N) {
        T.erase({A[i],i});
        cout << T.find_by_order(N/2-1)->f << "\n";
        T.insert({A[i],i});
    }
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 15488
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)

int main(void){
    int n,m;
    cin >> n >> m;
    vector<int> p(n,0);
    int a;
    string b;
    int ac = 0; 
    int wa = 0;
    rep(_,m){
        cin >> a >> b;
        if(p[a-1] != -1){
            if(b=="AC"){
                wa += p[a-1];
                p[a-1] = -1;
                ac++;
            }else{
                p[a-1]++;
            }
        }
    }
    cout << ac << ' ' << wa << endl;
    return 0;
}

Measured memory_bytes: 640
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
//const n = +input[0];
//const a = [];
//for(let i=0;i<n;i++){
//	a.push(input[i+1].split(" ").map((x:string):number=>+x));
//}

//const [n, m] = input[0].split(" ").map((x: string): number => +x);
//const a = input[1].split(" ").map((x: string): number => +x);

function compareFunc(a, b){
    return a-b;
}

const [n, a, b]: number[] = input[0].split(' ').map((x: string): number => +x);

const ans = Math.min(n*a, b);
console.log(ans);

Measured memory_bytes: 9420
#include <stdio.h>

int main (){
  int N,M,i;
  scanf("%d %d",&N,&M);
  int A[M],sum = 0;
  for(i = 0;M > i;i++){
	scanf("%d",&A[i]);
    sum = sum + A[i];
  }
  if(sum > N){
    printf("-1");
  }else{
    printf("%d",N-sum);
  }
  return 0;
}


Measured memory_bytes: 1728
n,m=map(int,input().split())
num=[-1]*(n)
total=""
ans=-1
if n==1 and m==0:
    print(0)
    exit()
for i in range(m):
    a,c=map(int,input().split())
    if num[a-1]==-1 or num[a-1]==c:
        num[a-1]=c
    elif num[a-1]!=-1 and num[a-1]!=c:
        print(ans)
        exit()
for i in range(n):
    if num[i]==-1:
        if i==0:
            num[i]=1
        else:
            num[i]=0
for i in range(n):
    total+=str(num[i])
total=int(total)
total=str(total)
if len(total)==n:
    ans=int(total)
print(ans)

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 *1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1010;
int A[MAX];

int main()
{
	//freopen("in.txt","r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, m)
	{
		scanf("%d", &A[i]);
	}

	FOR (i, 1, m - 1)
	{
		if (A[i] % 2 == 1)
		{
			swap(A[0], A[m-1]);
			swap(A[0], A[i]);
		}
	}

	FOR (i, 1, m-1)
	{
		if (A[i] & 1)
		{
			cout<<"Impossible"<<endl;
			return 0;
		}
	}

	FOR (i, 0, m)
	{
		cout<<A[i]<<' ';
	}
	cout<<endl;

	if (m == 1)
	{
		if (A[0] == 1) cout<<"1\n1"<<endl;
		else cout<<2<<endl<<A[0] - 1<<' '<<1<<endl;
		return 0;
	}

	if (A[0] == 1) m--;
	cout<<m<<endl;
	if (A[0] != 1) cout<<A[0] - 1;
	else m++;
	FOR (i, 1, m - 1)
	{
		cout<<' '<<A[i];
	}

	cout<<' '<<A[m-1]+1<<endl;


}


Measured memory_bytes: 256
import sys,os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations
sys.setrecursionlimit(10**6)

s=list(input())
for i in range(len(s)):
    if s[i]==s[i].lower():
        s[i]=s[i].upper()
    else:
        s[i]=s[i].lower()
print("".join(s))


Measured memory_bytes: 6512
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const adjLists = Array.from(Array(n), () => []);
  const d = [];
  lines.forEach((l, i) => l.split(' ').splice(2).forEach(e => adjLists[i].push(e-1)));
  bfs(adjLists, d);
  for (let i = 0; i < n; i++) {
    console.log(i + 1, d[i]);
  }
})();

function bfs(adjLists, d) {
  const WHITE = 0, GRAY = 1, BLACK = 2;
  const color = Array.from(adjLists, () => WHITE);
  d[0] = 0;
  for (let i = 1; i < adjLists.length; i++) d[i] = -1;
  queue = [0];
  let u;
  while ((u = queue.shift()) !== undefined) {
    adjLists[u].forEach(v => {
      if (color[v] === WHITE) {
        color[v] = GRAY;
        d[v] = d[u] + 1;
        queue.push(v);
      }
    });
    color[u] = BLACK;
  }
}



Measured memory_bytes: 16720
input = readlines()

n = input.shift.chomp.to_i

cnt = 0
input.each do |vals|
  d1, d2 = vals.chomp.split("\s").map{|x| x.to_i}
  if d1 == d2
    cnt += 1
  else
    cnt = 0
  end
  if cnt == 3
    puts 'Yes'
    exit()
  end
end

puts 'No'


Measured memory_bytes: 14376
#include <stdio.h>

int main()
{
    int a, b, c;
    int M,m;
    scanf("%d%d%d",&a,&b,&c);
    if (a>=b&&a>=c)M=a;
    else if (b>=a&&b>=c)M=b;
    else M=c;
    if (a<=b&&a<=c)m=a;
    else if (b<=a&&b<=c)m=b;
    else m=c;
    printf("%d\n", M-m);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int l,r,d;
    cin>>l>>r>>d;
    int c=0;
    for(int i=l;i<=r;i++)
    {
    	if(i%d==0)
    	{
    		c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
typedef pair<int,int> pi;

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	int A,B,C;
	cin >> A >> B >> C;
	(A+B+C > 21) ? cout << "bust" : cout << "win";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define ss(a) scanf("%s",a)
#define mem(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
const double pi = acos(-1.0);
using namespace std;
const int maxn = 5005;
const int mod = 1e9+7;
int main(){
	int a, b, c;
	scanf("%d%d%d",&a, &b, &c);
	if(a <= b * c) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3684
import sys

N = long(raw_input())

def bin_search(l, r):
	if (r - l) <= 1: return r
	m = (l + r) / 2
	if (((m + 1) * m) / 2) > N:
		return bin_search(l, m)
	else:
		return bin_search(m, r)

x = bin_search(1, 10**7)
d = (x * (x + 1)) / 2 - N
for y in range(1, x+1, 1):
	if y == d: continue
	print str(y)


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> pos, neg;
    int tries = 22;
    for (int i = 0; i < (1 << tries); i++) {
        ll k = 0;
        for (int j = 0; j < tries; j++) {
            if (i & (1 << j)) {
                k |= (1LL << (2 * j));
            }
        }
        pos.pb(k);
    }
    for (int i = 0; i < (1 << tries); i++) {
        ll k = 0;
        for (int j = 0; j < tries; j++) {
            if (i & (1 << j)) {
                k |= (1LL << (2 * j + 1));
            }
        }
        neg.pb(k);
    }
    for (ll p : pos) {
        ll k = p - n;
        auto it = lower_bound(all(neg), k);
        if (it != neg.end() && *it == k) {
            ll ans = p | k;
            string s = std::bitset<64>(p | k).to_string();
            while (SZ(s) > 1 && *(s.begin()) == '0') {
                s.erase(s.begin());
            }
            cout << s << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 84192
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

template< typename T >
struct WeightedUnionFind {
    vector< int > data;
    vector< T > ws;

    WeightedUnionFind() {}

    WeightedUnionFind(int sz) : data(sz, -1), ws(sz) {}

    int find(int k) {
        if(data[k] < 0) return k;
        auto par = find(data[k]);
        ws[k] += ws[data[k]];
        return data[k] = par;
    }

    T weight(int t) {
        find(t);
        return ws[t];
    }

    bool unite(int x, int y, T w) {
        w += weight(x);
        w -= weight(y);
        x = find(x), y = find(y);
        if(x == y) return false;
        if(data[x] > data[y]) {
            swap(x, y);
            w *= -1;
        }
        data[x] += data[y];
        data[y] = x;
        ws[y] = w;
        return true;
    }

    T diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(void) {
    int N, M;
    cin >> N >> M;
    WeightedUnionFind<int> uf(N);
    while(M--) {
        int L, R, D;
        cin >> L >>R >> D;
        --L; --R;
        if(uf.find(L) != uf.find(R)) {
            uf.unite(L, R, D);
        } else if(uf.diff(L, R) != D) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


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

int main(){
 int n;
 cin>>n;
 int card[4][13]={};
 for(int i=0;i<n;i++){
 string suit;
 int num;
 cin>>suit>>num;

 if(suit=="S")card[0][num-1]=1;
 if(suit=="H")card[1][num-1]=1;
 if(suit=="C")card[2][num-1]=1;
 if(suit=="D")card[3][num-1]=1;
 }
 string str[4]={"S","H","C","D"};
 for (int i=0;i<4;i++){
 for (int j=0;j<13;j++){
  if(card[i][j]==1) continue;
  cout<<str[i]<<" "<<j+1<<endl;
 }
}

}


Measured memory_bytes: 3116
// review
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
const int MAXN = 1010;
const ll INF = 1e14;

int n;
ll x[MAXN], y[MAXN];
char mode[4] = {'L', 'R', 'U', 'D'};
int du[4] = {-1, 1, 1, -1};
int dv[4] = {-1, 1, -1, 1};

void solve() {
  int parity = (x[0] + y[0]) & 1;
  for (int i=0;i<n;i++) {
    if (parity != ((x[i] + y[i]) & 1)) {
      cout << -1 << endl;
      return;
    }
  }

  vector<ll> arms;
  for (int i=38;i>=0;i--) {
    arms.push_back(1LL << i);
  }
  if (parity == 0) {
    arms.push_back(1LL);
  }

  cout << arms.size() << endl;
  for (int i=0;i<arms.size();i++) {
    cout << arms[i] << " ";
  }
  cout << endl;

  for (int i=0;i<n;i++) {
    ll u = x[i] + y[i];
    ll v = x[i] - y[i];
    for (int j=0;j<arms.size();j++) {
      ll minDist = INF;
      int direction;
      for (int k=0;k<4;k++) {
        ll nu = u - du[k] * arms[j];
        ll nv = v - dv[k] * arms[j];
        if (minDist > abs(nu) + abs(nv)) {
          minDist = abs(nu) + abs(nv);
          direction = k;
        }
      }
      u = u - du[direction] * arms[j];
      v = v - dv[direction] * arms[j];
      cout << mode[direction];
    }
    cout << endl;
  }
}

int main() {
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> x[i] >> y[i];
  }
  solve();
}


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

vector<int> v;
int n, m, q;
vector<pair<pair<int, int>, pair<int, int>>> abcd;

int dfs(int depth, int pre){
    int res = 0;
    if(depth == n){
        for(auto& e : abcd){
            int a, b, c, d;
            tie(a, b) = e.first, tie(c, d) = e.second;
            if(v[b] - v[a] == c) res += d;
        }
    }else{
        for(int i = pre; i < m; i++){
            v.push_back(i);
            res = max(res, dfs(depth + 1, i));
            v.pop_back();
        }
    }
    return res;
}

int main() {
    cin >> n >> m >> q;
    abcd.resize(q);
    for(auto& e : abcd){
        int a, b, c, d;
        cin >> a >> b >> c >> d, a--,  b--;
        e = {{a, b}, {c, d}};
    }
    cout << dfs(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ar[][] = new int[n][3];
        for(int i=0;i<n;i++){
            ar[i][0] = sc.nextInt();
            ar[i][1] = sc.nextInt();
            ar[i][2] = sc.nextInt();
        }
        System.out.println(solve(ar));
    }
    public static int solve(int ar[][]){
        int n = ar.length;
        for(int i=1;i<n;i++){
            ar[i][0] += Math.max(ar[i-1][1],ar[i-1][2]);
            ar[i][1] += Math.max(ar[i-1][0],ar[i-1][2]);
            ar[i][2] += Math.max(ar[i-1][1],ar[i-1][0]);
        }
        return Math.max(ar[n-1][0],Math.max(ar[n-1][1],ar[n-1][2]));
    }
}

Measured memory_bytes: 63544
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using i64 = int_fast64_t;

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

    i64 n;
    cin >> n;
    vector<i64> A(n);
    REP(i, n){
        cin >> A[i];
        A[i] -= (i + 1);
    }

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

    i64 m = (n % 2 ? A[n/2] : (A[n/2] + A[n/2 - 1]) / 2);
    
    i64 ans = 0;
    REP(i, n){
        ans += abs(A[i] - m);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    for(auto &x : a){
        cin >> x;
    }
    int lt = 0, rt = 0;
    for(int i = 0; i < m; i++){
        if(a[i] < x){
            lt++;
        }else{
            rt++;
        }
    }
    cout << min(lt, rt);
    return 0;
}


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

int main(){
  int M, N;
  cin >> M >> N;
  vector<int> road(M);
  for(int i=0; i<M; i++)
    road.at(i) = 0;
  for(int i=0; i<N; i++){
    int a, b;
    cin >> a >> b;
    road.at(a-1)++;
    road.at(b-1)++;
  }
  for(int i=0; i<M; i++)
    cout << road.at(i) << endl;
  return 0;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
data=list(map(int,input().split()))
ans=0
for i in range(0,n):
  datai=list(map(int,input().split()))
  D=c
  for k in range(0,m):
    D=D+data[k]*datai[k]
  if D>0:
    ans=ans+1 
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    string t;
    cin>>t;
    if(t[0]==t[1]&&t[1]==t[2]||t[1]==t[2]&&t[2]==t[3]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,q,ca[100001];
    cin>>n>>k>>q;
    for(int i=0;i<100001;++i)
        ca[i]=0;
    for(int i=0;i<q;++i)
        {
            int a;
            cin>>a;
            ca[a-1]++;
        }
    for(int i=0;i<n;++i)
        if(k-(q-ca[i])<=0)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
    return 0;
}

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

#define _CRT_SECURE_NO_DEPRECATE 
#define endl "\n"
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
#define sz(x) ((int)x.size())

typedef long long       ll;
typedef vector<int>     vi;
typedef pair<int, int>  ii;
typedef vector<ii>     vii;
typedef set<int>        si;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define IT(it, x) for(auto it : x)

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; }
 
int main()
{
   si s;
   s.insert(1);s.insert(2);s.insert(3);
   int a, b;
   cin >> a >> b;
   s.erase(a);s.erase(b);
   cout << *s.begin();     
   return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iterator>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <iomanip>
#include <limits>
#include<functional>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <numeric>
//#include<unordered_map>
#define inf  2e9
#define seed 131
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) ((x)&(-x))
#define lrtnb srand(unsigned(time(NULL)))
#define lrtlh ios::sync_with_stdio(0)
#define lowb(a,n,x) lower_bound(a,a+n,x) - a
#define uppb(a,n,x) upper_bound(a,a+n,x) - a
#define lson l,mid,i<<1;
#define rson mid+1,r,i<<1|1;
#define ALL(x) x.begin(),x.end()
#define inv inline void
#define INS(x) inserter(x,x.begin())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> Si;
typedef set<ll> Sl;
ll gcd(ll n, ll m) { long long r; if (n < m)swap(n, m); while (m) { r = n % m; n = m; m = r; }return n; }
ll lcm(ll b, ll y) { return b * y / gcd(b, y); }
double dis(double x1, double y1, double x2, double y2) { double ans = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2); return sqrt(ans); }
double random(double start, double en) { return start + (en - start)*rand() / (RAND_MAX + 1.0); }
void read(int &n) { char c = '+'; int x = 0; bool flag = 0; while (c<'0' || c>'9') { c = getchar(); if (c == '-')flag = 1; }while (c >= '0'&&c <= '9')x = x * 10 + c - 48, c = getchar(); n = flag == 1 ? -x : x; }

int main() {
	int n;
	int a[110];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >>a[i];
	}
	int MIN = 100000000;
	for (int i = -100; i <= 100; i++) {
		int sum = 0;
		for (int j = 0; j < n; j++) {
			sum += (a[j] - i)*(a[j] - i);
		}
		MIN = min(MIN, sum);
	}
	cout << MIN << endl;
	//system("pause");
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, c, x, v;

	cin >> n >> c;

	vector<pair<ll, ll>> p;

	REP(i, n) {
		cin >> x >> v;
		p.push_back(make_pair(x, v));
	}

	vector<ll> s1(n + 1);
	s1[0] = 0;
	ll now = 0;

	REP(i, n) {
		s1[i + 1] = s1[i] + (p[i].second - p[i].first + now);
		now = p[i].first;
	}

	vector<ll> s2(n + 1);
	s2[0] = 0;
	now = c;

	REP(i, n) {
		s2[i + 1] = s2[i] + (p[n - 1 - i].second + p[n - 1 - i].first - now);
		now = p[n - i - 1].first;
	}

	ll ans = 0;
	ll sum = 0;
	pair<ll, ll> z;

	priority_queue<pair<ll, ll>> q;
	q.push(make_pair(-INF, n + 1));

	REP(i, n) {
		q.push(make_pair(s2[i + 1], n - i));
	}

	ans = max(ans, q.top().first);
	
	REP(i, n) {
		sum = s1[i + 1];
		while (i + 1 >= q.top().second) {
			q.pop();
		}
		z = q.top();
		if (z.first > p[i].first) {
			sum += z.first - p[i].first;
		}
		ans = max(ans, sum);
	}
	
	priority_queue<pair<ll, ll>> q2;
	q2.push(make_pair(-INF, 0));

	REP(i, n) {
		q2.push(make_pair(s1[i + 1], i + 1));
	}
	
	ans = max(ans, q2.top().first);

	REP(i, n) {
		sum = s2[i + 1];
		while (n - i <= q2.top().second) {
			q2.pop();
		}
		z = q2.top();
		if (z.first > c - p[n - 1 - i].first) {
			sum += z.first - c + p[n - 1 - i].first;
		}
		ans = max(ans, sum);
	}

	cout << ans << endl;
}

Measured memory_bytes: 9072
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n, z, w;
	cin >> n >> z >> w;
	
	vi a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	if(n == 1) cout << abs(a[n - 1] - w) << endl;
	else cout << max(abs(a[n - 2] - a[n - 1]), abs(a[n - 1] - w));
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

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

typedef long long ll;
int main(){
    int N;
    cin >> N;
    vector<double> v(N);
    for(int i=0;i<N;i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    for(int i=1;i<N;i++){
        sort(v.begin()+i,v.end());
        v[i]=(v[i]+v[i-1])/2;
    }

    cout << v[N-1] << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){

faster;
ll n; cin>>n;
vector<ll> c(3);
vector<ll> dp(3);
vector<ll> a(3,0);

f(i,0,3){
  cin>>dp[i];
}

f(i,0,n-1){

  f(x,0,3){
    cin>>c[x];
  }

  f(y,0,3){

    f(z,0,3){
      if(y!=z){
        a[z]=max(a[z],dp[y]+c[z]);
      }
    }

  }

  dp=a;

}

ll f=max(dp[1],dp[2]);
cout << max(f,dp[0])<< endl;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long

void solve()
{
	int H,n;cin>>H>>n;
	int x;
	int sum=0;
	for(int i=0;i<n;i++)
	cin>>x,sum+=x;
	if(sum<H)
	cout<<"No";
	else
	cout<<"Yes";
}
int main()
{
	//int t;cin>>t;
	//while(t--)
	solve();
}


Measured memory_bytes: 256
import sys
def 解():
    iH,iW = [int(_) for _ in input().split()]

    aS = ["."*(iW+2)]+["."+sLine+"." for sLine in sys.stdin.readlines()]+["."*(iW+2)]

    for i in range(1,iH+1):
        for j in range(1,iW+1):
            if aS[i][j] == "#":
                if "#" not in [aS[i-1][j],aS[i+1][j],aS[i][j-1],aS[i][j+1]]:
                    print("No")
                    exit()
    print("Yes")
解()


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>

int main(){
    int N, Y;
    std::cin >> N >> Y;

    int res_x=-1, res_y=-1, res_z=-1;
    for(int x=0; x<=N; x++){
        for(int y=0; y<=N; y++){
            int z = N - x - y;
            if(Y == 10000*x + 5000*y + 1000*z && z>=0){
                res_x = x;
                res_y = y;
                res_z = z;
            }
        }
    }

    std::cout << res_x << " " << res_y << " " << res_z << std::endl;
}


Measured memory_bytes: 256