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

int main(){
    int N;
    cin >> N;
    long nums[N * 3];
    for(int i = 0; i < N * 3; i++){
        cin >> nums[i];
    }
    long left_max[N + 1];
    priority_queue<long, vector<long>, greater<long>> left_max_queue;
    long all = 0;
    for(int i = 0; i < N; i++){
        left_max_queue.push(nums[i]);
        all += nums[i];
    }
    left_max[0] = all;
    for(int i = 0; i < N; i++){
        left_max_queue.push(nums[N + i]);
        all += nums[N + i] - left_max_queue.top();
        left_max_queue.pop();
        left_max[i + 1] = all;
    }
    long right_min[N + 1];
    priority_queue<long, vector<long>, less<long>> right_min_queue;
    all = 0;
    for(int i = N * 3 - 1; i >= N * 2; i--){
        right_min_queue.push(nums[i]);
        all += nums[i];
    }
    right_min[0] = all;
    for(int i = 0; i < N; i++){
        right_min_queue.push(nums[N * 2 - i - 1]);
        all += nums[N * 2 - i - 1] - right_min_queue.top();
        right_min_queue.pop();
        right_min[i + 1] = all;
    }
    long ans = -1e18;
    for(int i = 0; i <= N; i++){
        ans = max(ans, left_max[i] - right_min[N - i]);
    }
    cout << ans << endl;
}


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

using namespace std;

int main(){
  int n, m, q;
  cin >> n >> m >> q;
  int d[509][509];
  memset(d, 0, sizeof(d));
  for(int i=0;i<m;i++){
    int l, r;
    cin >> l >> r;
    d[l][r] += 1;
  }
  for(int i=1;i<=n-1;i++){
    d[i][i+1] += d[i][i] + d[i+1][i+1];
  }
  for(int i=2;i<n;i++){
    for(int j=0;j+i<=n;j++){
      d[j][j+i] += d[j][j+i-1]+d[j+1][j+i]-d[j+1][j+i-1];
    }
  }
  for(int i=0;i<q;i++){
    int l, r;
    cin >> l>> r;
    cout << d[l][r] << endl;
  }
}



Measured memory_bytes: 4592
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func divFloor(a, b int) int {
	return (a + (b - 1)) / b
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	d, g := nextInt(), nextInt()
	p, c := make([]int, d), make([]int, d)
	for i := 0; i < d; i++ {
		p[i], c[i] = nextInt(), nextInt()
	}

	// 合計点，解いた問題数を返す
	var rec func(solved []bool, id, point, sum int) (int, int)
	rec = func(solved []bool, id, point, sum int) (int, int) {
		if id == d {
			if point < g {
				for i := d - 1; i >= 0; i-- {
					if !solved[i] && 100*(i+1)*p[i] >= (g-point) {
						x := divFloor((g - point), 100*(i+1))
						point, sum = point+100*(i+1)*x, sum+x
						break
					}
				}
			}
			if point < g {
				return 0, 10000
			}
			return point, sum
		}
		// 解かない場合
		solved[id] = false
		r0, s0 := rec(solved, id+1, point, sum)
		// 解く場合
		solved[id] = true
		point += 100*(id+1)*p[id] + c[id]
		sum += p[id]
		r1, s1 := rec(solved, id+1, point, sum)
		if r0 >= g && r1 >= g {
			return g, min(s0, s1)
		} else if r0 >= g {
			return r0, s0
		} else if r1 >= g {
			return r1, s1
		}
		return 0, 10000
	}

	_, ans := rec(make([]bool, d), 0, 0, 0)

	puts(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
#define  fi first
#define  se second 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int dx[4]={-1,0,1,0}, dy[4]={0,-1,0,1} ,INF=1e9+9;


int main()
{
    int a,b;
    cin>>a>>b;
    cout<<b+b-a<<endl;
    
    return 0;
}

Measured memory_bytes: 256
/*
 * atcoder/abc125/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * 10 -4 -8 -11 3
 *
 * 最大値を求めるだけなので、
 * もしすべてをプラス符号にすることが出来るなら sum(abs(A_i))
 * 負が偶数個ならできそう.
 * 負が奇数個の場合は１つだけ出来ない.
 * 任意のA_iを負として残せるのでf(i) = argmin(abs(A_i)) を最小化するiだけを２回引けば良い
 *
 * ただし0が1つでも含まれる場合任意のA_iを非負に出来る.
 */
int N;
void solve() {
  cin >> N;
  ll a;
  ll total = 0;
  bool zero = false;
  int mc = 0; // minus count
  ll ma = 100000000000000000; // min abs value
  loop(n,0,N) {
    cin >> a;
    zero |= a == 0;
    mc += a < 0;
    a = abs(a);
    if (a!=0) {
      chmin(ma, a);
    }
    total += a;
  }

  if (zero or mc % 2 == 0) cout << total << endl;
  else cout << total - 2 * ma << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


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


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

	for (int i = 1;i <= n;i++) {
		if (i % 3 == 0) {
			cout << " " << i;
		}
		else {
			int x = i;
			
			while (x)
			{
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}

				x /= 10;
			}
		}
	}

	cout << "\n";

    return 0;
}



Measured memory_bytes: 3092
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main()
{
    ll h,w;
    cin >> h >> w;
    vector<vector<char>> c(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
        }
    }
    vector<vector<ll>> s(h,vector<ll>(w));
    vector<vector<ll>> t(h,vector<ll>(w));
    rep(i,h){
        ll cnt=0;
        rep(j,w){
            if(c[i][j]=='.'){
                cnt++;
                s[i][j]=cnt;
            }
            else{
                cnt=0;
            }
        }
        cnt=0;
        rep(j,w){
            if(s[i][w-1-j]==0) cnt=0;
            else{
                cnt=max(cnt,s[i][w-1-j]);
                s[i][w-1-j]=cnt;
            }
        }
    }
    rep(i,w){
        ll cnt=0;
        rep(j,h){
            if(c[j][i]=='.'){
                cnt++;
                t[j][i]=cnt;
            }
            else{
                cnt=0;
            }
        }
        cnt=0;
        rep(j,h){
            if(t[h-1-j][i]==0) cnt=0;
            else{
                cnt=max(cnt,t[h-1-j][i]);
                t[h-1-j][i]=cnt;
            }
        }
    }
    ll ans=0;
    rep(i,h){
        rep(j,w){
            ans=max(ans,s[i][j]+t[i][j]-1);
        }
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 66944
//Littleboy123 Template 1.7
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

//pragmas

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")t
// #pragma GCC optimization ("unroll-loops")


typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef unsigned long long int ull;
typedef long double ld;
typedef unsigned long long ull;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(int (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(int (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(int (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(int (a)=(b);(a)>=(c);--(a))
#define TC(n) cout << "Case #" << (n) << ": "
#define DEBUG(x) cout << "DEBUG " << #x << ' ' << x << '\n';
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

void init(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void infile(){
    freopen("walk.in", "r", stdin);
}

void outfile(){
    freopen("output.txt", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = modex(a, b/2LL, mod);
    tmp = (tmp * tmp) % mod;
    if(b & 1LL)
        tmp = (tmp * a) % mod;
    return tmp;
}

ll ex(ll a, ll b){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = ex(a, b/2LL);
    tmp = (tmp * tmp);
    if(b & 1LL)
        tmp = (tmp * a);
    return tmp;
}

//End of template

ll memo[200005];
ll pref[200005];
ii arr[15];

bool compar(ii a, ii b){
    return a.fi < b.fi;
}

int main(){
    init();

    ll n, k, mod;
    mod = 998244353;
    cin >> n >> k;
    memo[n] = 1;
    pref[n] = 1;
    FOR(i, 0, k){
        cin >> arr[i].fi >> arr[i].se;
    }
    sort(arr, arr+k, compar);
    ll pos, cnt;
    FORNE(i, n-1, 1){
        cnt = 0;
        FOR(j, 0, k){
            if(i + arr[j].fi > n){
                break;
            }
            pos = min(n, i+(ll)arr[j].se);
            cnt += pref[i+arr[j].fi];
            if(pos != n){
                cnt -= pref[pos+1];
            }
            cnt %= mod;
        }
        memo[i] = cnt;
        pref[i] = memo[i] + pref[i+1];
        pref[i] %= mod;
    }
    ll ans = memo[1];
    ans %= mod;
    if(ans < 0){
        ans += mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6744
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "")
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

const ll INF = 5e15;

int main() {
    ll N;
    cin >> N;
    V<ll> P(N);
    for(ll &e : P) {
        cin >> e;
        e--;
    }
    {
        auto tmp = P;
        for(ll i = 0; i < N; i++) P[tmp[i]] = i;
    }
    DEBUG(P);
    P.push_back(N);
    string ans;
    V<bool> watched(N + 10, false);
    ll want = 0;
    ll pre = INF;
    bool padded = false;
    for(ll i = 0; i < N; i++) {
        ans += '(';
        watched[P[i]] = true;
        bool added = false;
        for(; watched[want] && want < N; want++) {
            ans += ')';
            added = true;
        }
        if(!added) {
            DEBUG(pre);
            DEBUG(P[i]);
            if(pre < P[i] && !padded) {
                cout << ":(\n";
                return 0;
            }
        }
        pre = P[i];
        DEBUG(ans);
        padded = added;
    }
    cout << (ans.size() == 2 * N ? ans : ":(") << endl;
    return 0;
}



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

struct Card{
    char suit, value;
};

void BubbleSort(struct Card A[], int N){
    int flag =1;
    int swap = 0;
    while(flag){
        flag = 0;
        for(int i = N-1; i >= 1; i--){
            if(A[i].value < A[i-1].value){
                Card tmp = A[i];
                A[i] = A[i-1];
                A[i-1] = tmp;
                flag = 1;
                swap++;
            }
        }
    }
}

void SelectionSort(struct Card A[], int N){
    int swap = 0;
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(A[j].value < A[minj].value){
                minj = j;
//                swap++;
            }
        }
        if(A[minj].value != A[i].value){
            Card tmp = A[minj];
            A[minj] = A[i];
            A[i] = tmp;
            swap++;
        }
//        swap(data[minj], data[i]);
    }

}
void print(struct Card A[], int N){
    for(int i = 0; i < N; i++){
        cout<<A[i].suit<<A[i].value;
        if(i != N-1){
            cout<<" ";
        }else{
            cout<<endl;
        }
    }
}
bool isStable(struct Card A[], struct Card B[], int N){
    for(int i = 0; i < N; i++){
        if((A[i].value != B[i].value) || (A[i].suit != B[i].suit)){
            return false;
        }
    }
    return true;
}
int main(){
    int a;
    cin>>a;
    Card C1[100], C2[100];
//    vector<string> data(a);
    for(int k = 0; k < a; k++){
        cin>>C1[k].suit>>C1[k].value;
    }
    for(int i = 0; i < a; i++){
        C2[i] = C1[i];
    }
    BubbleSort(C1,a);
    SelectionSort(C2,a);
    print(C1,a);
    if(isStable(C1,C1,a)){
        cout<<"Stable"<<endl;
    }else{
        cout<<"Not stable"<<endl;
    }
    print(C2,a);
    if(isStable(C1,C2,a)){
        cout<<"Stable"<<endl;
    }else{
        cout<<"Not stable"<<endl;
    }
}


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


struct union_find{

    vector<long> par;
    vector<long> prisize;   //属するグラフの頂点数

    //union find初期化
    union_find(long n){
        par.resize(n);  //vectorのサイズを変更する
        prisize.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            prisize[i] = 1;
        }
    }

    //union find 木の根を求める
    long find(long x){
        if(par[x] == x){
            return x;
        }
        else{
            return par[x] = find(par[x]);
        }
    }

    //union find xとyの属する集合を結合
    void unite(long x, long y){
        x = find(x);
        y = find(y);
        if(x == y){
            return;
        }
        if(prisize[x] > prisize[y]){
            swap(x, y);
        }
        par[x] = y;
        prisize[y] += prisize[x];
    }

    //union find xとyが同じ集合に属するか否か
    bool same(long x, long y){
        return find(x) == find(y);
    }

    long size(long i){
        return prisize[find(i)];
    }
};
    
int main(){

    long n, m;
    cin>>n>>m;

    union_find tree(n);
    vector<long> F(m+1);
    vector<pair<long, long> > bridge(m);
    F[m] = n*(n-1)/2;

    for(int i=0; i<m; i++){
        long a, b;
        cin>>a>>b;
        a--, b--;
        bridge[i] = make_pair(a, b);
    }

    for(int i=m-1; i>=0; i--){
        long a, b;
        a = bridge[i].first;
        b = bridge[i].second;

        if(tree.same(a, b)){
            F[i] = F[i+1];
        }
        else{
            F[i] = F[i+1] - (tree.size(a)*tree.size(b));
            tree.unite(a, b);
        }
    }

    for(int i=1; i<=m; i++){
        cout<<F[i]<<endl;
    }


    return 0;
}

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

int main() {
    int a, b, c;
    cin>>a>>b>>c;
    vector<int> A;
    A.push_back(a);
    A.push_back(b);
    A.push_back(c);
    sort(A.begin(), A.end());
    cout<<A[0]+A[1];
    return 0;
}

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

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

const long long INF = 1LL << 60;

long long dp[100010];

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &h[i]);
    }
    for (int i = 0; i < 100010; i++) {
        dp[i] = INF;
    }
    dp[0] = 0;
    
    for (int i = 0; i < N; i++) {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

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

    return 0;
}

Measured memory_bytes: 1408
a,b = map(int,input().split())
#if((a<0 or a>16) or (b<0 or b>16) or (a+b>16)):
    #print("error\n")
count=16
flag=False
pic=0 # 0=a,1=b
while(count>0):
    if(pic==0):
        a-=1
        count-=1
        pic=1    
    elif(pic==1):
        pic=0
        b-=1
        count-=1
    if(a<=0 and b<=0):
        flag=True
        break
if(flag==True):
    print("Yay!")
else:
    print(":(")

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

#define BR "\n"
#define SP " "

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;

  if ( x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H ) {
    cout << "Yes" << BR;
  } else {
    cout << "No" << BR;
  }

  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

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

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

struct Data {
  ll x;
  ll y;
  ll h;
};

struct Data2 {
  ll x;
  ll y;
  ll h;
  ll flag;
};

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

  vector<Data> D;

  rep(i, N) {
    ll x, y, h;
    cin >> x >> y >> h;
    if (h != 0) {
      D.pb({x, y, h});
    }
  }

  if (D.size() <= 1) {
    cout << D[0].x << " " << D[0].y << " " << D[0].h << endl;
    return 0;
  }

  vector<Data2> same;
  Data d0 = D[0];
  Data d1 = D[1];
  rep(i, 101) {
    rep(j, 101) {
      ll h1 = max((ll)0, d0.h + abs(d0.x - i) + abs(d0.y - j));
      ll h2 = max((ll)0, d1.h + abs(d1.x - i) + abs(d1.y - j));
      if (h1 == h2 && h1 != 0) {
        same.pb({i, j, h1, true});
      }
    }
  }

  rep2(i, 2, D.size()) {
    Data d = D[i];
    rep(j, same.size()) {
      Data2 s = same[j];
      ll h1 = max((ll)0, d.h + abs(d.x - s.x) + abs(d.y - s.y));
      if (h1 != s.h) {
        same[j].flag = false;
      }
    }
  }

  rep(i, same.size()) {
    Data2 s = same[i];
    if (s.flag) {
      cout << s.x << " " << s.y << " " << s.h << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 644
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999


int main() {
	char a, b;
	cin >> a >> b;
	cout << (a == b ? 'H' : 'D') << endl;

	return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef unsigned long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> cnt(100, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    rep(j, 80) {
      if (a % 2) cnt[j]++;
      a /= 2;
    }
  }

  ll ans = 0;
  rep(i, 61) {
    ll x = cnt[i];
    ll y = n - cnt[i];
    ll tmp = x * y % MOD;
    rep(j, i) tmp = tmp * 2 % MOD;
    ans = (ans + tmp) % MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

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

  if (a >= -1000 && b >= -1000 && a <= 1000 && b <=1000) {
    if (a < b) {
      puts("a < b");
    } else if (a > b) {
      puts("a > b");
    } else {
      puts("a == b");
    }
  }

  return 0;
}

Measured memory_bytes: 580
#include <cstdio>
#include <algorithm>

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

using namespace std;

typedef long long ll;

int n;
int s[4000];
int sn;
int index[4001];
int id[4000];

int main(){
	while(1){
		scanf("%d", &n);
		if(n == 0){
			break;
		}

		fill(index, index + 4001, -1);

		rep(i, n){
			int a, x, y;
			scanf("%d%d%d", &a, &x, &y);

			if(index[a] == -1){
				index[a] = sn;
				id[sn] = a;
				s[sn++] = 0;
			}
			s[index[a]] = min(ll(1e6), s[index[a]] + ll(x) * y);
		}

		bool none = true;
		rep(i, sn){
			if(s[i] >= int(1e6)){
				printf("%d\n", id[i]);
				none = false;
			}
		}
		if(none){
			puts("NA");
		}

		sn = 0;
	}
	return 0;
}

Measured memory_bytes: 1068
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

n, m = map(int, input().split())
s = list(input())
t = list(input())
g = gcd(n, m)
l = lcm(n, m)
x_s = [i for i in range(1, l + 1, m // g)]
x_t = [i for i in range(1, l + 1, n // g)]
j = 0
c = 1
for i in range(len(x_s)):
    while True:
        if j + 1 == len(x_t):
            break
        if x_s[i] > x_t[j]:
            j += 1
        else:
            break
    if x_s[i] == x_t[j]:
        if not s[i] == t[j]:
            c = 0
print(l if c == 1 else -1)

Measured memory_bytes: 11016
// AOJ 2511 Sinking islands
// 2018.2.28 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 202

/* UNION-FIND library */
int id[MAX], size[MAX]; int cnt;
void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; }
int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; }
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q) { int i = root(p), j = root(q); if (i == j) return;
cnt++; if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j];
}

int N, M;
int h[MAX], t[MAX];
typedef struct { int a, b, c; } C;
C c[20000];
char mk[MAX];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int tcmp(int *a, int *b) { return *a - *b; }
int ccmp(C *a, C *b) { return a->c - b->c; }

int uniq(int *a, int n)
{
	int i, j;
	for (i = 0, j = 1; j < n; j++) {
		while (j < n && a[j] == a[i]) j++;
		if (j < n) if (++i != j) a[i] = a[j];
	}
	return i+1;
}

int check(int tm)
{
	int i, a, b, s;

	s = 0; memset(mk, 0, N);
	init(N); cnt = 1;
	for (i = 0; i < N; i++) if (h[i] >= tm && !mk[i]) mk[i] = 1, s++;
	for (i = 0; i < M; i++) {
		a = c[i].a, b = c[i].b;
		if (h[a] >= tm && h[b] >= tm &&	!connected(a, b)) unite(a, b);
		if (cnt == s) return 0;
	}
	return 1;
}

int main()
{
	int i, j, k, tsz, tm, ans;
	int a, b;

	while (N = in()) {
		init(N); cnt = 1;

		M = in();
		for (i = 0; i < N; i++) h[i] = t[i] = in();
		for (i = 0; i < M; i++) {
			c[i].a = a = in()-1, c[i].b = b = in()-1, c[i].c = in();
			unite(a, b);
		}
		if (cnt < N) { puts("0"); continue; }

		qsort(t, N, sizeof(int), tcmp);
		tsz = uniq(t, N);
		qsort(c, M, sizeof(C), ccmp);

		for (i = 1; i < tsz; i++) if (check(t[i])) break;
		k = i-1, tm = t[k];

		ans = 0;
		init(N);
		for (i = 0; i < M; i++) {
			a = c[i].a, b = c[i].b;
			if (h[a] >= tm && h[b] >= tm &&	!connected(a, b))
				ans += c[i].c, unite(a, b);
		}
		for (j = k-1; j >= 0; j--) {
			for (i = 0; i < M; i++) {
				a = c[i].a, b = c[i].b;
				if (h[a] >= t[j] && h[b] >= t[j] && !connected(a, b))
					ans += c[i].c, unite(a, b);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2232
def main():
    n,l = map(int,input().split())

    aji_list = [0]*n

    count = 0

    for i in range(n):
        aji_list[i] = l + i

    if aji_list[0] >= 0:
        for i in range(1,n):
            count += aji_list[i]
    else:
        if aji_list[n-1] >= 0:
            for i in range(n):
                count += aji_list[i]
        else:
            for i in range(n-1):
                count += aji_list[i]

    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
# numpy使うときは、PyPyは不可
import numpy as np

N, K = map(int, input().split())
P = (np.array(list((map(int, input().split())))) + 1)

"""
ans = 0

for num in range(len(p)):
    tmp = p[num:num+K].sum()
    if ans < tmp:
        ans = tmp

print(float(ans))

"""

# 回答
Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = P.cumsum()

length_K_sums = Pcum[K:] - Pcum[0:-K]
print(length_K_sums.max() / 2)

Measured memory_bytes: 33948
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long v = sc.nextLong();
        long b = sc.nextLong();
        long w = sc.nextLong();
        long t = sc.nextLong();
        if (v <= w) {
            System.out.println("NO");
        } else {
            if (Math.abs(v - w) * t >= Math.abs(a - b)) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }

}

Measured memory_bytes: 35728
/// You just can't beat the person who never gives up

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+5 ;

int n ,a[N] ;
bool Never_give_up(){
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%d",a+i);
    sort(a,a+n) ;
    long long ans = a[n-1] ;
    int cnt = 2 ,i = n-2 ;
    while(cnt<n){
        ans += a[i] ;
        ++cnt ;
        if(cnt==n) break ;
        ans += a[i] ;
        ++cnt ;
        --i ;
    }
    cout << ans << endl ;
    return 0 ;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt" ,"r" ,stdin);
    freopen("output.txt" ,"w" ,stdout);
#endif
    int t = 1 ;
    //scanf("%d",&t);
    while(t--) Never_give_up();
    return 0;
}

Measured memory_bytes: 4548
#include <bits/stdc++.h>
//#define int long long

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n, m;
    cin >> n >> m;

    int ans = 1;
    for(int i = 2; i*i <= m; i++){
        if(m % i == 0 && m / i >= n) ans = max(i, ans);
        if(m % i == 0 && m / (m/i) >= n) ans = max(m/i, ans);
    }

    if(n == 1) ans = m;
    cout << ans << endl;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int n,t;
vector<P<int,int>> v;

int Rec(int i,int j){
  static int mem[3001][3001];
  static bool used[3001][3001];
  if(j >= t || i >= n)return 0;
  if(used[i][j]) return mem[i][j];
  used[i][j] = true;
  return mem[i][j] = max(Rec(i+1,j+v[i].first)+v[i].second,Rec(i+1,j));
}

int main(){
  cin >> n >> t;
  for(int i = 0; i < n; ++i){
    int a,b; cin >> a >> b;
    v.emplace_back(a,b);
  }
  sort(v.begin(), v.end());
  cout << Rec(0,0) << endl;
  return 0;
}


Measured memory_bytes: 46984
line = gets.chomp
n = line.size
array1 = []
array2 = []

(0..((n-3)/2)).each do |i|
   array1.push(line[i])
end

((n+1)/2..(n-1)).each do |i|
   array2.push(line[i])
end

if array1 == array2
  puts "Yes"
else
  puts "No"
end
  


Measured memory_bytes: 1788
/*
// [S]=n
// [T]=k
// first k element = last k element in S
f(S) = STST 
F(2) = g(S) x2

g(S) = ST
g(ST) = STS
g(STS) = STSST
g(sz) = g(sz-1) + g(sz-2)
//can't prove

*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 2*1e5+10;

string s;
ll l,r,len[maxn],cnt[100][maxn],ans[30];
int KMP[maxn];

int pre_calc(string s, int type) {
    memset(KMP,0,sizeof(KMP));
    //cout<<s<<endl;
    int n= s.length();
    for (int i=0;i<n;i++) {
        if (i==0) KMP[i]=-1;
        else {
            KMP[i] = KMP[i-1];
            while (1) {
                //cout<<i<<" "<<KMP[i]<<endl;
                if (s[KMP[i]+1] == s[i]) {
                    KMP[i]++;
                    break;
                }
                if (KMP[i]==-1) break;
                KMP[i] = KMP[KMP[i]];
            }
        }
    }
    //cout<<"fuk"<<endl;
    int tmp = KMP[n-1];
    //cout<<tmp<<endl;
    if (type==1) while (tmp*2+2>=n) tmp=KMP[tmp];
    else while (tmp*2+2>n) tmp=KMP[tmp];
    return tmp+1;
}

void calc(ll LEN,ll coe) {
    int T1 = pre_calc(s,1);
    string s2 = "";
    for (int i=0;i<s.length()-T1;i++) s2+=s[i];
    int T2 = pre_calc(s2,2);
    int sz=0;
    //cout<<T1<<" "<<T2<<endl;
    for (int i=T2;i<s2.length()-T2;i++) {
        len[sz]++;
        cnt[sz][s2[i]-'a']++;
    }
    sz++;
    for (int i=0;i<T2;i++) {
        len[sz]++;
        cnt[sz][s2[i]-'a']++;
    }
    sz++;
    while (len[sz-1]<=LEN) {
        len[sz] = len[sz-1] + len[sz-2];
        for (int i=0;i<26;i++) cnt[sz][i] = cnt[sz-1][i] + cnt[sz-2][i];
        sz++;
        ///cout<<len[sz-1]<<endl;
    }
    for (int i=sz-1;i>=2;i--) {
        if (LEN>=len[i]) {
            LEN-=len[i];
            for (int j=0;j<26;j++) ans[j]+= coe*cnt[i][j];
        }
    }
    for (int i=0;i<LEN;i++) ans[s[i]-'a']+=coe;

}

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>s;
    cin>>l>>r;
    calc(r,1);
    calc(l-1,-1);
    for (int i=0;i<26;i++) cout<<ans[i]<<" ";
}



Measured memory_bytes: 140288
#include<bits/stdc++.h>
#define re register
#define rep(i,a,b) for(re int i=a,i##end=b; i<=i##end; i++)
#define drep(i,a,b) for(re int i=a,i##end=b; i>=i##end; i--)
#define repp(i,a,b) for(re int i=a,i##end=b; i<i##end; i++)
#define drepp(i,a,b) for(re int i=a,i##end=b; i>i##end; i--)
#define Erep(i,x) for(int i=head[x]; ~i; i=Edge[i].nxt)
#define ms(x,a) memset(x,a,sizeof x)
#define se second
#define fi first
#define lowbit(x) (x&-x)
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define coint const int
typedef long long ll;
using namespace std;
template<class T>inline T rd(){
	static char ch;static bool neg;static T x;
	for(neg=0,ch=0; ch>'9'||ch<'0'; neg|=(ch=='-'),ch=getchar());
	for(x=0; ch<='9'&&ch>='0'; x=(x<<1)+(x<<3)+(ch-'0'),ch=getchar());
	return neg?-x:x;
}
template<class T>inline T Max(const T &x, const T &y){
	return x>y?x:y;
}
template<class T>inline T Min(const T &x, const T &y){
	return x<y?x:y;
}
coint N=1e5+5;


int main(){
	ll n=rd<int>();
	printf("%lld\n",n*(n-1)/2);
	return 0;
}



Measured memory_bytes: 256
input = gets(nil)

input.split("\n").each do |l|
  n = l.to_i
  a = 0
  0.upto(9) do |i1|
    0.upto(9) do |i2|
      0.upto(9) do |i3|
        0.upto(9) do |i4|
          a += 1 if i1+i2+i3+i4 == n
        end
      end
    end
  end
  puts a
end

Measured memory_bytes: 6100
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;
fn gcd(a: i64, b: i64) -> i64 { if b == 0 { a } else { gcd(b, a % b) } }

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let xs: Vec<i64> = (0..n).map(|_| sc.cin()).collect();

    let mut memo1: Vec<i64> = vec![0; n];  // memo1[i] = gcd(xs[0..=i])
    memo1[0] = xs[0];
    for i in 1..n {
        memo1[i] = gcd(memo1[i - 1], xs[i]);
    }

    let mut memo2: Vec<i64> = vec![0; n];  // memo2[i] = gcd(xs[i..n])
    memo2[n-1] = xs[n-1];
    for i in (0..n-1).rev() {
        memo2[i] = gcd(xs[i], memo2[i + 1]);
    }

    let mut ans = 1;
    for i in 0..n {
        if i == 0 {
            // trace!(memo2[1]);
            ans = max!(ans, memo2[1]);
        } else if i == n-1 {
            // trace!(memo1[n-2]);
            ans = max!(memo1[n-2], ans);
        } else {
            // trace!(gcd(memo1[i-1], memo2[i+1]));
            ans = max!(ans, gcd(memo1[i-1], memo2[i+1]));
        }
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 12256
let x = require('fs').readFileSync('/dev/stdin', 'UTF-8');
let array = x.split(" ");
array[0] = parseInt(array[0]);
array[1] = parseInt(array[1]);
let area = array[0]*array[1];
let rectangle = (array[0]+array[1])*2;
console.log(area + " " + rectangle);


Measured memory_bytes: 15128
#include <iostream>
#include <vector>
#define ll long long 
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int main(void){
    ll a,n; cin>>n>>a;
    vl x(n);
    for(int i=0;i<n;++i) cin>>x[i];
    vvvl dp(n,vvl(n+1,vl(50*n+1,0)));
    
    for(int i=0;i<n;++i) for(int j=1;j<n+1;++j){
        //cout<<i<<" "<<j<<endl;
        if(i+1 == j){
            ll sum = 0;
            rep(k,i+1) sum += x[k];
            dp[i][j][sum] = 1;
            break;
        } rep(k,50*n+1){
            if(k-x[i] >= 0) dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
            else dp[i][j][k] = dp[i-1][j][k];
            if(j == 1 && x[i] == k) dp[i][j][k] += 1;
        }
    }
    ll ans = 0;
    rep(i,n+1) ans += dp[n-1][i][a*i];
    cout<<ans<<endl;
}


Measured memory_bytes: 51200
#include<stdio.h>
#define MAX 1000000
int n,A[MAX+1];;

void maxHeapify(int);

int main(){
  int i;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }

  for(i=n/2;i>=1;i--){
    maxHeapify(i);
  }
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  
  return 0;
}

void maxHeapify(int i){
  int left,right,big,temp;
  left=2*i;
  right=2*i+1;

  if(left<=n && A[left]>A[i])big=left;
  else big=i;
  if(right<=n && A[right]>A[big])big=right;

  if(big!=i){
    temp=A[i];
    A[i]=A[big];
    A[big]=temp;
    
    maxHeapify(big);
  }
  
}



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

int main() {
  int N, Alice = 0, Bob = 0, tmp;

  cin >> N;
  vector<int> cards(N);
  
  for(int i = 0; i < N; i++){
    cin >> cards.at(i);
  }
  
  for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
      if(cards.at(i) < cards.at(j)){
        tmp = cards.at(i);
        cards.at(i) = cards.at(j);
        cards.at(j) = tmp;
      }
    }
  }
  
  for(int i = 0; i < N; i++){
    if (!(i % 2)) Alice += cards.at(i);
    else Bob += cards.at(i);
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete

f :: Int -> (Int, Int, Array Int Int) -> Char -> (Int, Int, Array Int Int)
f n (i, s, arr) c = (ni, ns, arr//[(i, nx)])
  where
    x = arr!i
    ni = (i + 1) `mod` n
    ns = case c of 
      'M' -> s
      'S' -> s + x + 1
      'L' -> 0
    nx = case c of
      'M' -> x + 1
      'S' -> 0
      'L' -> x + 1 + s
    

main = do
    n <- getInt
    unless (n==0) $ do
        cs <- getLine
        putStrLn $ sjoin $ (\(_,s,arr) -> (sort . elems $ arr) ++ [s]) $ foldl (f n) (0, 0, listArray (0,n-1) $ repeat 0) cs
        main
    


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

const int N = 5010;
int64_t dp[N];
pair<int64_t, int64_t> part[N];

int main() {
    int n;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> part[i].first >> part[i].second;
        // h_i, p_i
    }
    
    dp[0] = 0;
    for (int used = 1; used <= n; used++) {
        dp[used] = LLONG_MAX;
    }

    sort(part, part+n, [](const auto &a, const auto &b) {
            return a.first + a.second < b.first + b.second;
        });

    for (int i = 0; i < n; i++) {
        for (int used = i+1; used >= 1; used--) {
            if (dp[used-1] != LLONG_MAX && part[i].first >= dp[used-1]) {
                dp[used] = min(dp[used], part[i].second + dp[used-1]);
            }
        }
    }

    for (int used = n; used >= 1; used--) {
        if (dp[used] != LLONG_MAX) {
            cout << used << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;
long long int dp[100005][3];
int main(){
    int n;
    cin>>n;
    vector <long long int> arr[n+1];
    for(int i = 1;i<=n;i++){
        long long int a , b , c;
        cin>>a>>b>>c;
        arr[i].push_back(a);
        arr[i].push_back(b);
        arr[i].push_back(c);
    }
    for(int i = 1;i<=n;i++){
        dp[i][0] = arr[i][0]+ max(dp[i-1][1] , dp[i-1][2] );
        dp[i][1] = arr[i][1]+ max(dp[i-1][0] , dp[i-1][2] );
        dp[i][2] = arr[i][2]+ max(dp[i-1][1] , dp[i-1][0] );
    }
    cout<< max(max(dp[n][0] , dp[n][1] ),dp[n][2] );
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, K, X, Y; std::cin >> N >> K >> X >> Y;
  
  int a = std::min(N,K);
  int b = std::max(0, N-K);
  std::cout << a*X + b*Y << std::endl;


  return 0;
}


Measured memory_bytes: 256
def main():
    S = input()
    K = int(input())
    output = solve(S, K)
    print(output)
    return

def solve(S, K):
    """
    解答のコード
    """
    for i in range(K):
        if S[i] != "1":
            return S[i]
    return "1"

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, long long M, std::vector<long long> A){
  ll sum = 0;
  for(auto x : A)
    sum+=x;
  if(N-sum<0)
    std::cout << -1 << std::endl;
  else
    std::cout << N-sum << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  std::vector<long long> A(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, M, std::move(A));
  return 0;
}



Measured memory_bytes: 3300
import Data.List

main = do
  s <- getLine
  k <- readLn
  putStrLn $ (f [] (sort (init (tails s))) k) !! (k-1)

f acc _ 0 = acc
f acc (x:xs) n
  | las >= n  = acc ++ take n as
  | otherwise = f (acc ++ as) xs (n-las)
  where 
    as = filter (`notElem` acc) (tail (inits x))
    las = length as

Measured memory_bytes: 1660
n,m,q = map(int,input().split())
A = [0]*q
B = [0]*q
C = [0]*q
D = [0]*q



for i in range(q):
    a,b,c,d = map(int,input().split())
    A[i] = a
    B[i] = b
    C[i] = c
    D[i] = d

walist = []
for i in range(2**(n+m-1)):
    if bin(i).count("1") == n:
        wa = 0
        seq = []
        value = 1
        for j in range(n+m-1):
            if (i>>j)&1 == 1:
                seq += [value]
            else:
                value += 1
        for k in range(q):
            if seq[B[k]-1] - seq[A[k]-1] == C[k]:
                wa += D[k]
        walist += [wa]

print(max(walist))


Measured memory_bytes: 12400
#!/usr/bin/env python3

s = list(input())
len_s = len(s)

count = 0
for i in range(len_s):
    if s[i] != s[len_s - 1 - i]:
        # print(s[i], s[len_s - 1 - i])
        s[len_s - 1 - i] = s[i]
        count += 1

print(count)


Measured memory_bytes: 2940