akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm> 
#include<cmath>
#include<iostream>
#include<cstring>
#include<cstdlib> 
#define ll long long
#define N 200005
using namespace std;
int n;
ll rs[N],ls[N],a[N],ans=1e18,k[4];
int erfen(int l,int r,ll k)
{
	int ans;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(ls[mid]*2>=k) ans=mid,r=mid-1;
		else l=mid+1;
	}
	return ans;
}
int erf(int l,int r,ll k)
{
	int ans;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(rs[mid]*2>=k) ans=mid,l=mid+1;
		else r=mid-1;
	}
	return ans;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int i=1;i<=n;++i) ls[i]=ls[i-1]+a[i],rs[n-i+1]=rs[n-i+2]+a[n-i+1];
	for(int i=2;i<n-1;++i)
	{
		ll tmp=erfen(1,i,ls[i]);
		//cout<<abs((ls[i]-ls[tmp])-ls[tmp])<<" "<<abs((ls[i]-ls[tmp-1])-ls[tmp-1])<<" "<<ls[tmp-1]<<" "<<ls[i]-ls[tmp-1]<<" "<<tmp<<" ";
		if((tmp!=1&&abs((ls[i]-ls[tmp])-ls[tmp])>abs((ls[i]-ls[tmp-1])-ls[tmp-1]))||tmp==i) --tmp;
		k[0]=ls[tmp],k[1]=ls[i]-ls[tmp];
		tmp=erf(i+1,n,rs[i+1]);
		if((tmp!=n&&abs((rs[i+1]-rs[tmp])-rs[tmp])>abs((rs[i+1]-rs[tmp+1])-rs[tmp+1]))||tmp==i+1) ++tmp;
		k[2]=rs[tmp],k[3]=rs[i+1]-rs[tmp];
		//printf("%d:%d %d %d %d\n",i,k[0],k[1],k[2],k[3]);
		sort(k,k+4);
		ans=min(ans,k[3]-k[0]); 
	}
	cout<<ans;
	return 0;
 } 

Measured memory_bytes: 4992
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

using namespace std;

int main() {
 
   long long int A;
   long long int B;
   long long int K;

   cin >> A >> B >> K;
   
   cout << (K-A>0?0:A-K) << " " << (K-A>0?(B-(K-A)>=0?B-(K-A):0):B) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <math.h>
#include <cctype>
using namespace std;
#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
const int mod = 1e9 + 7;

int32_t main() {
    ios::sync_with_stdio(false);
    int N;
    map<string,int>m;
    cin >> N;
    forn(i,N){
        string x;
        cin >> x;
        m[x]++;
    }
    cout << "AC x " << m["AC"] << "\n";
    cout << "WA x " << m["WA"] << "\n";
    cout << "TLE x " << m["TLE"] << "\n";
    cout << "RE x " << m["RE"] << "\n";
    return 0;
}

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

int main(){
    int H,W;
    while(1) {
        cin >> H>>W;
        if (H == 0 && W ==0 ) break;
        
        for (int i = 0;i<H;i++){
            for (int j = 0;j <W;j++){
                if ((i+j)%2 == 0) cout << "#";
                else cout << ".";
            }
        cout<<endl;
        }

        cout <<endl;
     }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

template <typename T>
void read(T &x)
{
    static char ch;
    for (ch = getchar(); !isdigit(ch); ch = getchar()) ;
    for (x = 0; isdigit(ch); ch = getchar())
        x = (x<<3)+(x<<1)+ch-'0';
}

const int N = 2e5+10, p = 1e9+7;

int h, w, a, b;
ll f[N], inv[N];

ll qpow(ll x, int k)
{
    ll ret = 1;
    while (k)
    {
        if (k&1) ret = (ret*x)%p;
        k >>= 1;
        x = (x*x)%p;
    }
    return ret;
}

void pre()
{
    f[0] = 1;
    inv[0] = 1;
    for (int i = 1; i < N; ++i)
    {
        f[i] = f[i-1]*i%p;
        inv[i] = qpow(f[i], p-2);
    }
}

int main()
{
    pre();
    read(h), read(w), read(a), read(b);
    ll ans = 0, t;
    for (int i = 0, j = b; i < h-a; ++i)
    {
        t = f[i+j-1]*inv[i]%p*inv[j-1]%p*
            f[w+h-2-i-j]%p*inv[h-1-i]%p*inv[w-1-j]%p;
        //printf("%d %d %d \n", i, j, t);
        ans = (ans+t)%p;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){

    ll a,b,k;
    cin >> a >> b >> k;

    if(a+k > b-k+1){
        for(ll i = a;i <=b;i++){
            cout << i << endl;
        }
    }else{
        for(ll i = a;i < a+k;i++){
            cout << i << endl;
        }
        for(ll i = b-k+1;i <=b;i++){
            cout << i << endl;
        }


    }


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)


int main() {

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

	vector<bool>visited(n,false);
	vector<int> box(n,1);


	visited[0] = true;

	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;

		x--; y--;

		if (visited[x] == true) {
			visited[y] =true;
		}

		box[x]--;
		box[y]++;

		if (box[x] == 0) {
			visited[x] = false;
		}
	}

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		
		if (visited[i] == true) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

 using namespace std;
 typedef long long ll;

 int main() {
   int A, B, N;

   cin >> N >> A >> B;

   vector<int> P(N);

   int count_L = 0, count_M = 0, count_H = 0;

   for (int i = 0; i < N; i++) {
     cin >> P.at(i);
     if (P.at(i) <= A) count_L++;
     else if (P.at(i) > B) count_H++;
     else count_M++;
   }

   cout << min(count_L, min(count_M, count_H)) << endl;
 }


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

// #define DEBUG

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    int N, M, Q;
    cin >> N >> M >> Q;

    vector<string> S(N);
    rep(i, N) cin >> S[i];

    vector<vector<int>> sum_blue(N+1, vector<int>(M+1));
    for (int y=1; y<=N; y++) {
        for (int x=1; x<=M; x++) {
            sum_blue[y][x] = sum_blue[y][x-1] + sum_blue[y-1][x] - sum_blue[y-1][x-1] + (S[y-1][x-1] == '1');
        }
    }

    vector<vector<int>> sum_edge_x(N+1, vector<int>(M+1));
    vector<vector<int>> sum_edge_y(N+1, vector<int>(M+1));
    for (int y=1; y<=N; y++) {
        for (int x=1; x<=M; x++) {
            int tmp_x = 0, tmp_y = 0;
            if (x > 1 && S[y-1][x-1] == '1' && S[y-1][x-2] == '1') tmp_x = 1;
            sum_edge_x[y][x] = sum_edge_x[y][x-1] + sum_edge_x[y-1][x] - sum_edge_x[y-1][x-1] + tmp_x;

            if (y > 1 && S[y-1][x-1] == '1' && S[y-2][x-1] == '1') tmp_y = 1;
            sum_edge_y[y][x] = sum_edge_y[y][x-1] + sum_edge_y[y-1][x] - sum_edge_y[y-1][x-1] + tmp_y;
        }
    }

#ifdef DEBUG
    rep(y, N+1) { 
        rep(x, M+1) {
            cerr << sum_edge_x[y][x] << " ";
        }
        cerr << endl;
    }
    cerr << endl;
    rep(y, N+1) { 
        rep(x, M+1) {
            cerr << sum_edge_y[y][x] << " ";
        }
        cerr << endl;
    }
#endif

    rep(_q, Q) {
        int X1, Y1, X2, Y2;
        cin >> Y1 >> X1 >> Y2 >> X2;

        int blue_num =   sum_blue[Y2][X2]   - sum_blue[Y2][X1-1]   - sum_blue[Y1-1][X2]   + sum_blue[Y1-1][X1-1];
        int edge_x_num = sum_edge_x[Y2][X2] - sum_edge_x[Y2][X1] - sum_edge_x[Y1-1][X2] + sum_edge_x[Y1-1][X1];
        int edge_y_num = sum_edge_y[Y2][X2] - sum_edge_y[Y2][X1-1] - sum_edge_y[Y1][X2] + sum_edge_y[Y1][X1-1];

#ifdef DEBUG
        DUMP(blue_num);
        DUMP2(edge_x_num, edge_y_num);
#endif

        cout << blue_num - (edge_x_num + edge_y_num) << endl;
    }

    
}



Measured memory_bytes: 53968
#include <cstdio>
#include <cstring>
using namespace std;

long long N, Q, K;
long long adj[100005], gto[200005], gnxt[200005], glen[200005], e;
long long qu[100005], qh, qt, dis[100005];

void add_edge(long long u, long long v, long long w) {
    gto[e] = v; glen[e] = w; gnxt[e] = adj[u]; adj[u] = e++;
}

void bfs(long long s) {
    for (dis[qu[qh = qt = 0] = s] = 0; qh <= qt; ++qh)
        for (long long e = adj[qu[qh]], v = gto[e]; ~e; v = gto[e = gnxt[e]])
            if (v != K && !dis[v]) dis[v] = dis[qu[qh]] + glen[e], qu[++qt] = v;
}

int main() {
    memset(adj, -1, sizeof adj);
    scanf("%lld", &N);
    for (long long i = 1; i != N; ++i) {
        long long a, b, c; scanf("%lld%lld%lld", &a, &b, &c);
        add_edge(a, b, c); add_edge(b, a, c);
    }
    scanf("%lld%lld", &Q, &K);
    bfs(K);
    while (Q--) {
        long long x, y; scanf("%lld%lld", &x, &y);
        printf("%lld\n", dis[x] + dis[y]);
    }
    return 0;
}


Measured memory_bytes: 8832
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


template<typename T>
class BIT {
public:
    int N;
    vector<T> seg;
    BIT(int N) : N(N) {
        seg.resize(N + 1);
        for (int i = 0; i < N + 1; ++i) seg[i] = 0;
    }

    //i番目にxを加算
    void add(int i, T x) {
        ++i;
        while (i <= N) {
            seg[i] += x;
            i += i & (-i);
        }
    }

    //[0,i)の和
    T cumulative(int i) {
        T s = 0;
        while (i > 0) {
            s += seg[i];
            i -= i & (-i);
        }
        return s;
    }

    //[a,b)の和
    T sum(int a, int b) {
        return cumulative(b) - cumulative(a);
    }

    //i番目の要素
    T elem(int i) {
        return sum(i, i + 1);
    }

    //i番目に代入
    void assign(int i, T x) {
        add(i, -elem(i));
        add(i, x);
    }
};

template<typename A>
using P = pair<A, A>;

int N, Q;
vector<int> color;
vector<int> color_cnt;
vector<vector<int>> color_list;
vector<pair<P<int>,int>> query;
vector<int> ans;

int main() {
    cin >> N >> Q;
    color.resize(N);
    color_cnt.resize(N);
    color_list.resize(N);
    ans.resize(Q);
    query.resize(Q);
    for (int i = 0; i < N; ++i) {
        int c;
        cin >> c;
        --c;
        color[i] = c;
        color_cnt[i] = 0;
        color_list[c].push_back(i);
    }
    for (int i = 0; i < Q; ++i) {
        int l, r;
        cin >> l >> r;
        --l;
        --r;
        query[i] = pair<P<int>, int>(P<int>(l, r), i);
    }
    sort(query.begin(), query.end(), [](pair<P<int>, int> a, pair<P<int>, int> b) {
        if (a.first.first == b.first.first) return a.first.second < b.first.second;
        return a.first.first < b.first.first;
        });
    BIT<int> t(N);
    for (vector<int>& v : color_list) {
        if (v.empty()) continue;
        t.assign(v[0], 1);
    }
    int qc = 0;
    for (int i = 0; i < N; ++i) {
        for (;qc<query.size() && query[qc].first.first == i; ++qc) {
            ans[query[qc].second] = t.sum(query[qc].first.first, query[qc].first.second+1);
        }
        if (i == N - 1) break;
        int cur_color = color[i];
        color_cnt[cur_color]++;
        if (color_cnt[cur_color] >= color_list[cur_color].size()) continue;
        t.assign(color_list[cur_color][color_cnt[cur_color]], 1);
    }
    for (int i = 0; i < Q; ++i)PRI(ans[i]);
	return 0;
}

Measured memory_bytes: 44752
import java.util.*

private fun readInts() = readLine()!!.split(" ").map { it.toInt() }
private fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
private fun <K, V> Map<out K, V>.toMutableMap(): MutableMap<K, V> = LinkedHashMap(this)
private fun <K, V> Iterable<Pair<K, V>>.toMutableMap(): MutableMap<K, V> = this.toMap().toMutableMap()
private fun <K, V> mutableMapOf(): MutableMap<K, V> = LinkedHashMap()
private fun <K, V> mutableMapOf(vararg pairs: Pair<K, V>) = pairs.toMap().toMutableMap()

fun main(args: Array<String>) {
    val (N, M) = readInts()
    val ka = (0 until N).map { readInts() }
    val map = (1..M).map { it to 0 }.toMutableMap()

    for (line in ka) {
        for (a in line.drop(1)) map[a] = map[a]!! + 1
    }

    println(map.filter { it.value == N }.size)
}

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

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

#define MAXN 100002
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL {printf("-1\n"); return 0;}

int N, K;
int H[MAXN];
LL dp[MAXN];
int B[MAXN];

LL f(int i) {
    if (i == N-1) return 0;
    if (B[i]) return dp[i];
    B[i] = 1;

    LL& ret = dp[i] = abs(H[i+1]-H[i]) + f(i+1);
    for (int k = 2; k <= K && i+k < N; k++)
        ret = min(ret, abs(H[i+k]-H[i]) + f(i+k));

    return ret;
}

int main(int argc, char **argv)
{
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif

    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; i++) scanf("%d", &H[i]);

    printf("%lld\n", f(0));
    return 0;
}


Measured memory_bytes: 6528
# encoding: "utf-8"

from collections import defaultdict

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_del(xs):
    cnt = 0
    fst = xs[-1]
    for x in reversed(xs):
        if x != fst:
            break
        cnt += 1
    del xs[-cnt:]
    return cnt   


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort(reverse=True)
    ys = defaultdict(int)
    while xs:
        key = xs[-1]
        cnt = count_and_del(xs)
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 18460
#include <bits/stdc++.h>
using namespace std;
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N,M;
int d[200010],t[200010];


int main(int argc, char *argv[])
{
  scanf("%d",&N);
  for (int i = 0; i < N; i++) {
    scanf("%d",&d[i]);
  }
  scanf("%d",&M);
  for (int i = 0; i < M; i++) {
    scanf("%d",&t[i]);
  }
  if(M>N){
    puts("NO");
    return 0;
  }
  
  sort(d,d+N);
  sort(t,t+M);

  int tmp = N-1;
  for (int i = M-1; i >=0; i--) {
    if(tmp == -1) {puts("NO");return 0;}
    while(t[i]!=d[tmp]){
      tmp--;
      if(tmp == -1){ puts("NO");return 0;}
    }
    tmp--;
  }
  puts("YES");
  
  return 0;
}


Measured memory_bytes: 1792
'use strict';
 
process.stdin.resume();
process.stdin.setEncoding('utf-8');
 
let inputString = '';
let currentLine = 0;
 
process.stdin.on('data', function(inputStdin) {
    inputString += inputStdin;
});
 
process.stdin.on('end', function() {
    inputString = inputString.split('\n');
    main();
});
 
function readline() {
    return inputString[currentLine++];
}
 
 
// main function .... code start ... ///
function main() {
 
//var input = readline()

var n = Number(readline());
var ar = readline().split(' ').map(x => parseInt(x));

var cnt = 0;
for(var i=0; i<n; i++) {
    if(ar[i] != (i+1)) cnt ++
}
console.log(cnt == 0 || cnt == 2 ? 'YES' : 'NO');

}

//

Measured memory_bytes: 7500
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdio>
using namespace std;

struct node{
	char pos;
	char prev;
	char speed;
	double dist;

	node( int pos_, int prev_, int speed_, double dist_ )
		: pos(pos_), prev(prev_), speed(speed_), dist(dist_) {}

	bool operator< (const node &n) const{
		return dist > n.dist;	//逆
	}
};

struct road{
	char to;
	double dist;
	char c;
	
	road( int t, double d, int c_ )
		: to(t), dist(d), c(c_) {}
};

int n, m;
int s, g;

vector<vector<road> > roads;
double mindist[31][31][31];


void solve(){
	fill( mindist[0][0], mindist[31][0], 9e9 );

	priority_queue<node> pq;
	for( int i = 0; i < roads[s].size(); ++i ){
		road r = roads[s][i];
		pq.push( node( r.to, s, 1, r.dist ) );
		mindist[r.to][s][1] = r.dist;
	}
	
	while( !pq.empty() ){
		node nd = pq.top();
		pq.pop();

		if( mindist[nd.pos][nd.prev][nd.speed] != nd.dist ){
			continue;
		}
		
		if( nd.pos == g && nd.speed == 1 ){
			printf("%f\n", nd.dist );
			return;
		}
		
		for( int i = 0; i < roads[nd.pos].size(); ++i ){
			road r = roads[nd.pos][i];
			if( r.to == nd.prev ){	continue;	}
			
			for( int j = -1; j < 2; ++j ){
				if( nd.speed + j > 0 && nd.speed + j <= r.c ){
					double nextdist = nd.dist + r.dist / ( nd.speed + j );
					if( mindist[r.to][nd.pos][nd.speed + j] > nextdist ){
						mindist[r.to][nd.pos][nd.speed + j] = nextdist;
						pq.push( node( r.to, nd.pos, nd.speed + j, nextdist ) );
					}
				}
			}
		}
	}
	
	puts("unreachable");
}


int main(){
	int x, y, d, c;
	while( cin >> n >> m, n != 0 ){
		roads = vector<vector<road> >( n + 1 );
		
		cin >> s >> g;
		
		for( int i = 0; i < m; ++i ){
			cin >> x >> y >> d >> c;
			roads[x].push_back( road( y, d, c ) );
			roads[y].push_back( road( x, d, c ) );
		}
		
		solve();
	}
}

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

using namespace std;

const int N = 1e5+7;

struct Node
{
    int l, r;
    long long c;
    friend bool operator < (const Node &x, const Node &y) {
        if (x.c != y.c) return x.c < y.c;
        return x.r > y.r;
    }
} a[N];

int n, m;
long long dis[N];
set<Node> s;

bool cmpl(const Node &x, const Node &y) { return x.l < y.l; }

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        cin >> a[i].l >> a[i].r >> a[i].c;
    }
    sort(a+1, a+m+1, cmpl);
    memset(dis, -1, sizeof dis);
    dis[1] = 0;
    for (int i = 1, p = 1; i <= n; ++i) {
        while (s.size() && s.begin()->r < i) s.erase(s.begin());
        if (i > 1) {
            if (s.empty()) break;
            dis[i] = s.begin()->c;
        }
        for ( ;p <= m && a[p].l <= i; ++p) {
            a[p].c += dis[i];
            while (s.size() && s.rbegin()->c >= a[p].c && s.rbegin()->r <= a[p].r)
                s.erase((--s.end()));
            if (s.size() && s.rbegin()-> c <= a[p].c && s.rbegin()->r >= a[p].r)
                continue;
            s.insert(a[p]);
        }
    }
    cout << dis[n] << endl;
    return 0;
}


Measured memory_bytes: 7040
#include <stdio.h>

int n ,k, i, c, p;
int main() {
  scanf("%d%d\n", &n, &k); k = -2 * k;
  while(i++ < n)if((c = getchar_unlocked()) != p) k++, p = c;
  printf("%d\n", n - (k < 1 ? 1 : k));
  return 0;
}
  

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

using namespace std;
// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }



#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

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

  int N, C, K;
  cin >> N >> C >> K;

  vector<int> T(N);
  for(int i = 0; i < N; i++) { cin >> T[i]; }

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

  int count = 0;
  int people = 1;

  int limit = T[0] + K;

  int went = 0;

  for(int i = 1; i < N; i++) {
    if( T[i] <= limit && people < C ) {
      // debug(T[i]);
      people++;
    } else {
      // cout << endl;
      // debug(T[i]);
      went += people;
      people = 1;
      count++;
      limit = T[i] + K;
    }
  }

  count++;

  cout << count << "\n";

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;

template <typename X>
X BinSearch(X left, X right, function<bool(X)> judge, bool lower = true, X eps = 1) {
    while (right - left > eps) {
        X mid = (right + left) / 2;
        if (judge(mid) == lower) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return lower ? right : left;
}

int main() {
    i64 X;
    cin >> X;
    cout << BinSearch<i64>(0, X + 2, [&](i64 y) -> bool {
        return y * (y + 1) >= 2 * X;
    }) << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * @file A-Entrance-Examination.cpp
 * @author murnana
 * @brief A - Entrance Examination https://atcoder.jp/contests/abc117/tasks/abc117_a
 * @date 2019-02-03
 * 
 * @copyright Copyright (c) 2019
 * 
 */

#include <ios>
#include <iostream>
#include <iomanip>
using namespace std;

/**
 * @brief Entry point
 * 
 * @return int 
 */
int main()
{
    // 必要な勉強時間(T時間)と
    // 世界Bの速度(X倍)の値を入力から受け取る
    double T, X;
    cin >> T >> X;

    // 世界Aでは何時間進んでいるか出力する
    // https://marycore.jp/prog/cpp/stream-format-float/ より
    // 標準出力の精度を変えないと、正しい答えにならない
    cout << setprecision(10);
    cout << fixed;
    cout << (T/X) << endl;
    return 0;
}


Measured memory_bytes: 256
def intMap(): return map(int,input().split())

x,y = intMap()

ans = 'No'
if x * 2 == y: ans = 'Yes'
if x * 4 == y: ans = 'Yes'

for crane in range(x):
    turtle = x - crane
    feet = crane * 2 + turtle * 4
    if feet == y:
        ans = 'Yes'

print(ans)

Measured memory_bytes: 9188
import numpy
from collections import Counter

def comb(a,b):
    x = 1
    y = 1
    for i in range(a-b+1,a+1):
        x *= i
    for i in range(1,b+1):
        y *= i
    return int(x/y)

n = int(input())
li = [0]
for i in input().split():
    li.append(int(i))
cum = numpy.cumsum(li)
x = Counter(cum)
ans = 0
for i in x.values():
    if i>=2:
        ans += comb(i,2)
print(ans)

Measured memory_bytes: 45640
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
typedef  long long ll; 
typedef  unsigned long long ull; 
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <mypair, vector<mypair>, greater<mypair> > min_heap;
const ll mod=1e9+7;
const ll inf=1e15;
const ll N=700+10;

int main()
{
	boost;
	ll n,m;
	cin>>n>>m;
	std::vector<ll> s(n),t(m);
	for(auto &i:s) cin>>i;
	for(auto &i:t) cin>>i;	
	ll dp[n][m];
	dp[0][0]=(s[0]==t[0])+1;
	for(ll i=1;i<n;i++) dp[i][0]=dp[i-1][0]+(s[i]==t[0]),dp[i][0]%=mod;
	for(ll i=1;i<m;i++) dp[0][i]=dp[0][i-1]+(s[0]==t[i]),dp[0][i]%=mod;
	for(ll i=1;i<n;i++)
	{
		for(ll j=1;j<m;j++)
		{
			dp[i][j]=(dp[i-1][j-1]*(s[i]==t[j])+(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+mod)%mod)%mod;
		}
	}	
	cout<<dp[n-1][m-1];		
  	return 0;
}

Measured memory_bytes: 31488
n, m = gets.split.map(&:to_i)
l = gets.split.map(&:to_i)
a = [0]*n
l.each_cons(2){|s, t| s,t = t,s if s > t; a[s-1] += 1; a[t-1] -= 1 }
(1...n-1).each{ |i| a[i] += a[i-1] }
p (n-1).times.map{|i| gets.split.map(&:to_i).zip([a[i],a[i],1]).map{|a,b|a*b}.insert(1,0).each_slice(2).to_a.map{|a,b|a+b}.min}.reduce(:+)

Measured memory_bytes: 18976
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <sstream>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-10;
const int inf=1e9;
typedef pair<int,int> P;

class Point
{
public:
  double x,y;
  Point(double x,double y): x(x),y(y){}
  Point operator + (const Point &p)
  {
    return Point(x+p.x,y+p.y);
  }
  Point operator - (const Point &p)
  {
    return Point(x-p.x,y-p.y);
  }
  Point operator * (double k)
  {
    return Point(x*k,y*k);
  }
  Point operator / (double k)
  {
    return Point(x/k,y/k);
  }
  bool operator < (const Point &p) const
  {
    return x!=p.x ? x<p.x : y<p.y;
  }
  bool operator == (const Point &p) const
  {
    return fabs(x-p.x)<eps && fabs(y-p.y) < eps;
  }
};
typedef Point Vector;
double dot(Vector a,Vector b)
{
  return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b)
{
  return a.x*b.y - a.y*b.x;
}
double norm(Point a)
{
  return a.x*a.x + a.y*a.y;
}
double abs(Vector a)
{
  return sqrt(norm(a));
}
struct Segment
{
  Point p1,p2;
  Segment(Point p1,Point p2): p1(p1),p2(p2){}
};
typedef Segment Line;

class Circle
{
public:
  Point c;
  double r;
  Circle(Point c,double r):  c(c),r(r){}
};

typedef vector<Point> Polygon;


bool isorthogonal(Vector a,Vector b)
{
  return fabs(dot(a,b)-0.0)<eps;
}

bool isparallel(Vector a,Vector b)
{
  return fabs(cross(a,b)-0.0)<eps;
}
Point project(Segment s,Point p)
{
  Vector base=s.p2-s.p1;
  double r=dot(p-s.p1,base) / norm(base);
  return  s.p1 + base*r;
}
int main(int argc,char const* argv[])
{
  int q;
  double p1x,p1y,p2x,p2y;
  cin >> p1x >> p1y >> p2x >> p2y;
  Point p1=Point(p1x,p1y);
  Point p2=Point(p2x,p2y);
  Segment s=Segment(p1,p2);
  cin >> q;
  for(int i=0;i<q;i++)
    {
      int x,y;
      cin >> x >> y;
      Point p=Point(x,y);
      Point pro=project(s,p);
      cout << fixed << setprecision(9) << pro.x << ' ' << pro.y << endl;
    }
}



Measured memory_bytes: 3288
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int a, b, c; readV(a, b, c);
  writeln(b-a == c-b ? "YES" : "NO");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
  int w[150],a,b,d,i,j=0,k,n,p,x,y=0,z=0;
  char s[500],c[500];

  scanf("%d%d",&n,&x);

  for (size_t i = 0; i < n; i++)
  {
    scanf("%d",&w[i]);
  }
  for (size_t i = 0; i < n; i++)
  {
    z=z+w[i];
    if(z<=x) y++;
    else break;
  }
  printf("%d\n",y+1);
  return 0;
}

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;

string s;

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

	cin >> s;
	ll n;	cin >> n;

	int i = 0, L = (int)s.size();
	ll fRes = 0;
	
	if(s[0] == s[L - 1]){
		while(i < L && (s[i] == s[0])){
			i++;
		}
		int j = L - 1;
		while(j >= 0 && (s[j] == s[L - 1])){
			j--;
		}

		if(j <= i){
			cout << ((L * n) / 2)<< '\n';
			return 0;
		}

		L = j + 1;
	}
	
	ll extra = 0;
	
	if(i > 0){
		ll a = i;
		ll b = (ll)s.size() - 1 - (L - 1);
		extra += (a / 2) + (b / 2) + ((a + b) / 2) * (n - 1);
	}

	while(i < L){
		int j = i;
		while(j < L && s[j] == s[i]){
			j++;
		}
		fRes += (ll)(j - 1 - i + 1) / 2;
		i = j;
	}

	//cerr << fRes << '\n';

	cout << fRes * n + extra << '\n';

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        var nmxy = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var xs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var ys = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        for (int z = nmxy[2] + 1; z < nmxy[3]; z++)
        {
            if (xs.All(x => x < z) && ys.All(x => x >= z))
            {
                Console.WriteLine("No War");
                return;
            }
        }

        Console.WriteLine("War");
    }
}


Measured memory_bytes: 13396
h = int(input())
w = int(input())
n = int(input())
def paint(num):
    if num >= n:
        print(1)
    else:
        k = 0
        c = 0
        while k < n:
            k +=num
            c+=1
        print(c)

if h <= w:
    paint(w)
else:
    paint(h)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
bool echo(string s,int x){
for(int i=0;i<x/2;i++){
  if(s.at(i)!=s.at(i+(x/2))){
  return false;  
  }
}
return true;  
}

int main() {
  int a;
  string b;
  cin >> a >> b;
  if(a%2==1){
  cout << "No" << endl;
  }
  else if(echo(b,a)==false){
  cout << "No" << endl;
  }
  else{
  cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
def solve():
  S = input()
  front = int(S[0:2])
  back = int(S[2:4])
  if front == 0 and back == 0: return 'NA'
  f, b = False, False
  if front in range(1, 13): f = True
  if back in range(1, 13): b = True
  if front == 0 and b: return 'YYMM'
  if f and back == 0: return 'MMYY'
  if f and b: return 'AMBIGUOUS'
  if f and not b: return 'MMYY'
  if not f and b: return 'YYMM'
  if not f and not b: return 'NA'
  return 'NA'

print(solve())

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

const long long MOD = 998244353;

void solve(long long N, std::vector<long long> D)
{
    if (D[0] != 0) {
        cout << 0 << endl;
        return;
    }

    vector<ll> nums(N);
    for (auto d : D) {
        nums[d]++;
    }

    ll ans = 1;
    for (ll i = 1, n = N - 1; i < N && n > 0; ++i) {
        auto prev_node = nums[i - 1];
        auto now_node = nums[i];
        if (now_node == 0) {
            ans = 0;
        }
        n -= now_node;
        while (now_node--) {
            ans *= prev_node;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> D(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&D[i]);
    }
    cin.tie(nullptr);
    cout.tie(nullptr);
	ios_base::sync_with_stdio(false);
    solve(N, std::move(D));
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        for(int i = -k+1; i < k; i++){
            System.out.print((x+i)+" ");
        }
    }
}


class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 21204
n = int(input())
vacs = [list(map(int, input().split())) for _ in range(n)]
dp = [[0 for _ in range(3)] for _ in range(n)]
dp[0] = vacs[0]

for i in range(1, n):
	dp[i][0] = vacs[i][0] + max(dp[i-1][1], dp[i-1][2])
	dp[i][1] = vacs[i][1] + max(dp[i-1][0], dp[i-1][2])
	dp[i][2] = vacs[i][2] + max(dp[i-1][0], dp[i-1][1])

print(max(dp[-1]))

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

long long pow(int b, int p) {
  if (p == 0)
    return 1;
  if (p % 2 == 1)
    return b * pow(b, p - 1);
  else {
    long long t = pow(b, p / 2);
    return t * t;
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  cout << k * pow(k - 1, n - 1);
}


Measured memory_bytes: 256
use proconio::input;
use std::vec::Vec;

fn main() {
    input! {
        n: u32,
        k: u32,
        mut a: [u32; n],
    }
    a.sort();
    let mut ans = 0;
    for i in 0..k {
        ans += a[i as usize];
    }
    println!("{}", ans);
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
using P = pair<int,int>; 

int main(){
    int N,Q;
    cin >> N >> Q;

    vector<vector<int>> tree(N+1);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    vector<int> visited(N+1,false);
    vector<int> wei(N+1, 0);
    rep(i,Q){
        int v,w;
        cin >> v >> w;
        wei[v] += w;
    }

    queue<int> que;
    que.push(1);
    while(!que.empty()){
        int pre = que.front();
        que.pop();
        visited[pre] = true;
        for(int child : tree[pre]){
            if(visited[child]) continue;
            wei[child] += wei[pre];
            que.push(child);
        }
    }

    for(int i=1;i<=N;i++){
        cout << wei[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 16372
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = list(map(int, input().split()))

MOD = 10**9 + 7
ans = 0
s = 0
i = N - 1
for n in range(N - 2, -1, -1):
    s += As[i]
    s %= MOD
    i -= 1
    ans += s * As[n]
    ans %= MOD

print(ans)
    


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

int main(){
    int a, b;
    cin >> a >> b;
    if(a < b){
        cout << "a < b" << endl; 
    }else if(a == b){
        cout << "a == b" << endl; 
    }else{
        cout << "a > b" << endl; 
    }
    return 0;
}


Measured memory_bytes: 3080
w, h, n = map(int, input().split())
x0, x1, y0, y1 = 0, w, 0, h
for i in range(n):
	x, y, a = map(int, input().split())
	if a == 1:
		x0 = max(x0, x)
	elif a == 2:
		x1 = min(x1, x)
	elif a == 3:
		y0 = max(y0, y)
	else:
		y1 = min(y1, y)

if x1 > x0 and y1 > y0:
	print((x1 - x0) * (y1 - y0))
else:
	print(0)



Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

const int MaxN = 2e5;
int n, N, c[MaxN + 5];
int ishead[MaxN + 5], istail[MaxN + 5];
pair <int, int> a[MaxN + 5];

void Init()
{
	N = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &a[i].first, &a[i].second);			
		N = max(N, a[i].second);
	}
	N++;
}

int Solve_1()
{
	for (int i = 0; i <= N; i++) ishead[i] = istail[i] = 0;
	for (int i = 1; i <= n; i++) {
		ishead[a[i].first]++;
		istail[a[i].second]++;
	}
	int ret = 0, pred = 0;
	for (int i = 0; i <= N; i++) {
		ret = max(ret, pred);
		pred += ishead[i] - istail[i];
	}
	return ret;
}

int Lowbit(int x) {return x & (-x);}

void Add(int x, int t) 
{
	for (int i = x; i <= N; i += Lowbit(i)) c[i] += t;
}

int Sigma(int x) 
{
	int ret = 0;
	for (int i = x; i > 0; i -= Lowbit(i)) ret += c[i];
	return ret;
}

int Solve_2()
{
	for (int i = 0; i <= N; i++) c[i] = 0;
	sort(a + 1, a + n + 1);
	int ret = 0, p = 1;
	for (int i = 1; i <= n; i++) Add(a[i].first + 1, 1);
	for (int i = 0; i <= N; i++) {
		int last = p;
		while (p <= n && a[p].first == i) {
			ret = max(ret, Sigma(a[p].second) - Sigma(a[p].first));	
			p++;
		}
		int p = last;
		while (p <= n && a[p].first <= i) {
			Add(a[p].first + 1, -1);
			Add(a[p].second, 1);
			p++;
		}
	}
	return ret;
}

int main()
{
	while (~scanf("%d", &n)) {
		Init();
		printf("%d %d\n", Solve_2(), Solve_1());
	}
	return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> cards(n);
    for (size_t i = 0; i < n; ++i) cin >> cards[i];
    int alice = 0;
    int bob = 0;
    sort(cards.begin(), cards.end(), greater<int>());
    for (size_t i = 0; i < n; ++i) {
        if (i % 2 == 0) alice += cards[i];
        else bob += cards[i];
    }
    cout << alice - bob << endl;
    return EXIT_SUCCESS;
}

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

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

	int sum = 0;
	for (int i = 0; i < n.length(); i++) {
		sum += n.at(i) - '0';
	}
	int num = stoi(n);

	string ans = "No";
	if (num % sum == 0) {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/*  In the name of ALLAH */

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
 

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



int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
    
    int n;
    cin>>n;
    int arr[n];
    rep(i,0,n)cin>>arr[i];
    int ans = POSITIVE_INFINITY;
    for(int i  = -100; i <=100;i++){
        int res = 0;
        for(int j = 0; j < n;j++){
            res+=(arr[j]-i)*(arr[j]-i);
        }
        ans = min(res,ans);
    }
    cout<<ans<<endl;


 

 
    
 
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;


const int BIG_NUM = 1e8;
const ll INF = 1000000000000000000;

const int ALPHABET = 26;

int main() {
	int n;
	cin >> n;
	
	map<ll, ll> m;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		m[a]++;
	}

	ll ans = 0;
	for (auto it = m.begin(); it != m.end(); it++) {
		ans += it->first * it->second;
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int b, c;
		cin >> b >> c;
		
		ans += (c - b) * m[b];

		m[c] += m[b];
		m[b] = 0;

		cout << ans << endl;

	}


	

}

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

ll solve(ll h) {
	if (h <= 1) return 1;
	
	return 2 * solve(h/2) + 1;
}

int main() {
	ll result = 1, H = 0;

	cin >> H;
	

 	cout << solve(H) << endl;
	return 0;
}


Measured memory_bytes: 256
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define fe(vec,lambda) std::for_each(vec.begin(), vec.end(), lambda );
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define printv(val) std::for_each(val.begin(),val.end(),[](auto x){cout<<x<<"\n";});
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}
inline bool operator<(const pii &lhs,const pii &rhs){return(lhs.second<rhs.second);}
template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){vector<pair<T,T>> out(input.size()-1);rep(i,input.size()-1){out[i].first =input[i  ];out[i].second=input[i+1];}return(out);}
vector<char> String_to_vector_char(const string& input){vector<char> out(input.size());rep(i,input.size()){out[i]=input[i];}return out;}
void YesNo(bool flag){ cout<<(flag? "Yes":"No");}

ll a,b,c,d,n,x;
vector<ll>v[3];
map<ll,ll>m;
string s,s2,s3,s4;
void input(){
    cin>>s>>s2;
}
void src(){
    if(s[0]==s2[0]){
        cout<<"=";
    }else if(s[0]<s2[0]){
        cout<<"<";

    }else{
        cout<<">";
    }

}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
x = [list(map(int, input().split())) for i in range(2)]
sum = 0
max = 0
for i in range(N):
    for k in range(i, N):
        sum += x[1][k]
    for j in range(i+1):
        sum += x[0][j]
    if max < sum:
        max = sum
    sum = 0
print(max)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
#define ve vector<int> 
const int N=100005;
int n,k; 
ve vec[N];
ve mul (ve a,ve b)
{
	ve f(n);
	for (int u=0;u<n;u++)	f[u]=a[b[u]];
	return f;
}
ve inv (vector<int> a)
{
	ve f(n);
	for (int u=0;u<n;u++)	f[a[u]]=u;
	return f;
}
ve Pow(ve x,int y)
{
	ve f(n);
	for (int u=0;u<n;u++) f[u]=u;
	while (y>0)
	{
		if (y&1) f=mul(f,x);
		x=mul(x,x);y>>=1;
	}
	return f;
}
void print (ve x)
{
	for (int u=0;u<n;u++) printf("%d ",x[u]+1);
	printf("\n");
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int u=1;u<=n;u++)	{int x;scanf("%d",&x);vec[1].push_back(x-1);}
	for (int u=1;u<=n;u++)	{int x;scanf("%d",&x);vec[2].push_back(x-1);}
	for (int u=3;u<=6;u++) vec[u]=mul(vec[u-1],inv(vec[u-2]));
	ve A=mul(mul(vec[2],inv(vec[1])),mul(inv(vec[2]),vec[1]));
	A=Pow(A,(k-1)/6);
	print(mul(mul(A,vec[(k-1)%6+1]),inv(A)));
	return 0;
}

Measured memory_bytes: 8416
#include <stdio.h>
#include <string.h>
int main(){
    int count=0;
    char w[11]= {0},m[101] = {0};
    scanf("%s",w);   //検索単語
    while (1){
        scanf("%s",m);  //検索先文章
        if (strcmp("END_OF_TEXT",m)==0){
         break;
        }
        for (int i=0;i<101;i++){
            if (m[i]>='A'&&m[i]<='Z'){
                m[i]=m[i]+32;
            }
        }
        if (strcmp(w,m)==0){
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}




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

int linearSearch( int s[], int nums, int t ){
	
	int i=0;
	while( s[i] != t )
		i++;
	return i != nums;
}

int main()
{
	int *s, *t;
	int nums, numt;
	cin>>nums;
	s=new int[nums+1];
	for( int i=0; i<nums; i++ ){
		cin>>s[i];
	}

	cin>>numt;
	t=new int[numt];
	for( int i=0; i<numt; i++ ){
		cin>>t[i];
	}


	int ans=0;

	for( int i=0; i<numt; i++ ){
		s[nums]=t[i];
		ans +=linearSearch(s, nums, t[i]);

	}
	cout<<ans<<endl;
}

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

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

    int h[n];
    rep(i,n) cin >> h[i];
    sort(h, h+n);

    int ans = 1<<30;
    rep(i,n) {
        if (i+k-1>=n) break;
        int hmax = h[i+k-1];
        int hmin = h[i];
        ans = min(ans, hmax-hmin);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
	int h,w;
    cin >> h >> w;
    string image[h];

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

    for(int i=0;i < h+2;i ++)
    {
        for(int j=0;j < w+2;j ++)
        {
            if(i == 0 || i == h+1 || j == 0 || j == w+1)
            {
                cout << "#";
            }
            else
            {
                cout << image[i-1][j-1];
            }
        }
        cout << endl;
    }
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

class UnionFind
{
  public:
    UnionFind(int n)
        : mN(n)
    {
        REP(i, n)
        {
            mNodeTbl.push_back(i);
            mRankTbl.push_back(0);
        }
    }

    int find(int x)
    {
        if (x == mNodeTbl[x])
            return x;
        return mNodeTbl[x] = find(mNodeTbl[x]);
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    void unit(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (mRankTbl[x] < mRankTbl[y])
        {
            mNodeTbl[x] = y;
        }
        else
        {
            mNodeTbl[y] = x;
            if (mRankTbl[x] == mRankTbl[y])
                mRankTbl[x]++;
        }
    }

  private:
    int mN;
    vector<int> mNodeTbl;
    vector<int> mRankTbl;
};

pll B[100005];
//! そのノードに属するVertexの数
ll VN[100005];

int main()
{
    ll N, M;
    cin >> N >> M;
    REP(i, M)
    {
        cin >> B[i].first >> B[i].second;
    }
    REP(i, N)
    {
        VN[i] = 1;
    }

    UnionFind uf(N);

    ll sum = N * (N - 1) / 2;
    vector<ll> ans(M, 0);
    for (int i = M - 1; i >= 0; --i)
    {
        ans[i] = sum;
        pll n = B[i];
        if (uf.same(n.first, n.second))
            continue;

        ll a = VN[uf.find(n.first)];
        ll b = VN[uf.find(n.second)];
        sum -= (a * b);
        uf.unit(n.first, n.second);
        VN[uf.find(n.first)] = a + b;
    }

    REP(i, M)
    {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5492