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

#define lld long long
#define pp pair<int,int>
#define pb push_back
#define MOD 10007
#define left lleft
#define right rright
#define INF 2000000000
#define LINF 1000000000000000000LL
#define next nnext

using namespace std;

int N;
lld a[100002],ans[100002];
priority_queue<pp> q;

int main(){
	scanf("%d",&N);
	for(int i=1; i<=N; i++){
		scanf("%lld",&a[i]);
		if(a[i] != 0) q.push({a[i],i});
	}
	lld big = q.top().first,it = q.top().second,cnt = 1;
	q.pop();
	while(big != 0){
		while(!q.empty()){
			if(q.top().first != big) break;
			it = min(it,(lld)q.top().second);
			cnt++;
			q.pop();
		}
		lld next;
		if(q.empty()) next = 0;
		else next = q.top().first;
		ans[it] += cnt*(big-next);
		big = next;
	}
	for(int i=1; i<=N; i++) printf("%lld\n",ans[i]);

	return 0;
}


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

int main() {
  char S;
  cin >> S;
  
  if(S=='a'||S=='e'||S=='i'||S=='o'||S=='u'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" <<endl;
  }
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  int cnt = 0;
  ll ans = 0;
  int mn = 2147483647;
  rep(i,n){
    if(a[i]<0){
      cnt++;
    }
    mn = min(mn,abs(a[i]));
    ans += abs(a[i]);
  }
  cout << ans - 2*mn*(cnt%2) << endl;
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int prest = 0, score = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'g') {
            prest++;
        } else if (prest > 0) {
            prest--;
        } else {
            score--;
        }
    }
    score += prest / 2;
    cout << score << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int n;
  cin>>n;
  rep(i,n){
    int a;
    cin>>a;
    cout<<"Case "<<i+1<<":"<<endl;
    rep(j,10){
      a=a*a;
      vi v(8);
      rep(k,8){
	v[k]=a%10;
	a/=10;
      }
      a=0;
      int t=1;
      rep(k,4){
	a+=v[2+k]*t;
	t*=10;
      }
      cout<<a<<endl;
    }
  }
}

Measured memory_bytes: 2976
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int[][] cards;
	void run() {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int T=0;T<t;T++) {
			int[] num = new int[9];
			
			cards = new int[3][9];
			for(int i=0;i<9;i++) num[i] = sc.nextInt();
			
			for(int i=0;i<9;i++) {
				int j=0;
				switch (sc.next().charAt(0)) {
				case 'R': j=0; break;
				case 'G': j=1; break;
				case 'B': j=2; break;
				}
				cards[j][num[i]-1]++;
			}
			System.out.println(dfs(0, 0, 0));
		}
	}
	
	int dfs(int i, int j, int c) {
		int flg = 0;
		if( i == 3 ) {
//			debug(cards);
			if( c == 3) return 1;
			else return 0;
		}
		for(int k=j;k<9;k++) {
			if(cards[i][k] >= 3 ) {
				cards[i][k] -= 3;
				flg |= dfs(i, k, c+1);
				cards[i][k] += 3;
			}
		}
		for(int k=j;k<7;k++) {
			if(cards[i][k] >= 1 && cards[i][k+1] >= 1 && cards[i][k+2] >= 1) {
				cards[i][k] -= 1; cards[i][k+1] -= 1; cards[i][k+2] -= 1;
				flg |= dfs(i, k, c+1);
				cards[i][k] += 1; cards[i][k+1] += 1; cards[i][k+2] += 1;
			}
		}
		flg |= dfs(i+1, 0, c);
		return flg;
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  // ex: 5 (odd)
  //      
  //     0: o o o o o
  //            x
  //     2: o o o o o
  //          x   x
  //     4: o o o o o
  //        x       x
  //
  // ex: 6 (even)
  //
  //     1: o o o o o o
  //            x x
  //     3: o o o o o o
  //          x     x
  //     5: o o o o o o
  //        x         x
  ll ans = 1;
  ll n;
  cin >> n;
  int cnt[n];
  zero(cnt);
  fi(0, n) {
    int x;
    cin >> x;
    if(x >= n || (n % 2 == 0 && x == 0)) {
      cout << "0\n";
      return 0;
    }
    cnt[x]++;
  }
  if(n % 2 && cnt[0] != 1) {
    cout << "0\n";
    return 0;
  }
  int i = n % 2 == 0 ? 1 : 2;
  for(; i < n; i += 2) {
    if(cnt[i] != 2) {
      cout << "0\n";
      return 0;
    }
    (ans *= 2) %= MOD;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n, ans;
    cin >> n;
    vector<int>a(n);
    vector<pair<int,int>> o(100001),e(100001);

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

    for(int i=0; i<n; i++){
        if(i%2==0){
            e[a[i]].first++;
            e[a[i]].second = a[i];
        }else{
            o[a[i]].first++;
            o[a[i]].second = a[i];
        }
    }
    sort(e.rbegin(),e.rend());
    sort(o.rbegin(),o.rend());
    if(e[0].second != o[0].second){
        ans = n - e[0].first - o[0].first;
    }else{
        int t = max(e[0].first+o[1].first, e[1].first+o[0].first);
        ans = n - t;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 5396
#include<stdio.h>
#include <stdlib.h>
int main(void){
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(abs(b-a)<=d&&abs(b-c)<=d||abs(a-c)<=d){
		printf("Yes");
	}else{
	printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n + 1);
    for(int i = 0; i < n; i++) cin >> v[i];
    int q;
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        int b, e;
        cin >> b >> e;
        reverse(v.begin() + b, v.begin() + e);
    }
    for(int i = 0; i < n; i++)
    {
        if(i > 0) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
    return 0;
}




Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+50;
int n;
int a[N],col[N];
int main()
{
	ios::sync_with_stdio(false);
	int i,l,r,w;
	cin>>n;
	for(i=1;i<=n;i++) cin>>a[i];

	for(i=2;i<n;i++)
	{
		if(a[i]!=i&&a[i-1]!=i-1&&a[i+1]!=i+1) 
		{
			puts("No");return 0;
		}
	}
	for(l=1;l<=n;l=r+1)
	{
		r=l;
		if(a[l]==l) continue;
		while(r+2<=n&&a[r+2]!=r+2) r+=2;
		for(i=l;i<=r;i+=2) col[a[i]]=1;
		for(i=l;i<=r;i+=2)
		{
			if(col[i]==0)
			{
				puts("No");return 0;
			}
		}
		w=0;
		for(i=l;i<=r;i+=2)
		{
			if(a[i]>i) 
			{
				if(a[i]<w)
				{
					puts("No");return 0;
				}
				w=a[i];
			}
		}
		w=n+1;
		for(i=r;i>=l;i-=2)
		{
			if(a[i]<i)
			{
				if(a[i]>w) 
				{
					puts("No");return 0;
				}
				w=a[i];
			}
		}
	}
	puts("Yes");
	return 0;
}

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

int main() {
        int d, t, s;
        cin >> d >> t >>s;
        cout << (d <= t*s ? "Yes" : "No") << endl;
}

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;
  long long C, D = 0;
  if(N%(A+B)==0) {
    cout << (N/(A+B))*A << endl;
  }
  else {
    C = N/(A+B)*A;
    D = N - (N/(A+B))*(A+B);
    cout << C + min(A,D) << endl;
  }

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pa;
const int INF = (1 << 28);
int d, g;
vector<int> p;
vector<int> c;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >>d>>g;
    for(int i=0;i<d;i++) {
        int a, b;
        cin>>a>>b;
        p.push_back(a);
        c.push_back(b);
    }
int ans=INF;
for(int bit=0;bit<(1<<d);bit++){
    ll sum=0;
    int count=0;
    for(int i=0;i<d;i++){
    if(bit&(1<<i)) {
        sum+=c[i]+p[i]*(i+1)*100;
        count+=p[i];
    }
    }
    if(sum>=g){
        ans=min(ans,count);
    }
    else{
        for(int i=d-1;i>=0;i--){
            if(bit&(1<<i))continue;
            for(int j=0;j<p[i];j++){
                if(sum>=g) break;
                sum+=(i+1)*100;
                count++;
            }
        }
        ans=min(ans,count);
    }
}
cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct State{
  int x, y, d, S;
  State () {}
  State(int x, int y, int d, int S) : 
    x(x), y(y), d(d), S(S) {}
};
int dist[50][50][2][1<<10];
int get_dist(State s){
  return dist[s.y][s.x][s.d][s.S];
}
void set_dist(State s, int n){
  dist[s.y][s.x][s.d][s.S] = n;
}
void print(State s){
  //printf("x:%d y:%d d:%d S:%d dist:%d\n", s.x, s.y, s.d, s.S, get_dist(s));
}
int main(){
  int W, H;
  while(cin>>W>>H && W){
    vector<string> grid(H);
    REP(y, H) cin>>grid[y];
    int S; cin>>S;
    vector<string> sw_grid[10];
    REP(i, S){
      sw_grid[i] = vector<string>(H);
      REP(y, H) cin>>sw_grid[i][y];
    }
    queue<State> que;
    memset(dist, -1, sizeof(dist));
    REP(y, H)REP(x, W){
      if(grid[y][x] == '%'){
        dist[y][x][0][0] = 0;
        que.push(State(x, y, 0, 0));
      }
    }
    int ans = INF;
    while(!que.empty()){
      State now = que.front(); que.pop();
      print(now);
      char now_c = grid[now.y][now.x];
      if(now_c == '&'){
        ans = get_dist(now);
        break;
      }
      if(now_c == '|'){
        State next = now;
        next.d ^= 1;
        if(get_dist(next) == -1){
          que.push(next);
          set_dist(next, get_dist(now) + 1);
        }
      }
      if(isalpha(now_c)){
        int c_idx = (islower(now_c)) ? (now_c - 'a') : (now_c - 'A');
        State next = now;
        next.S ^= (1<<c_idx);
        if(sw_grid[c_idx][next.y][next.x] == '*'){
          next.d ^= 1;
        }
        if(get_dist(next) == -1){
          que.push(next);
          set_dist(next, get_dist(now) + 1);
        }
      }
      REP(r, 4){
        State next = now;
        next.x += dx[r];
        next.y += dy[r];
        char c = grid[next.y][next.x];
        int changed = 0;
        REP(i, 10) if((next.S & (1 << i)) && sw_grid[i][next.y][next.x] == '*') changed ^= 1;
        if(c == '#') continue;
        if((islower(c) || c == '_' || c == '&' || c == '%') && changed != next.d) continue;
        if((isupper(c) || c == '^') && (1 ^ changed) != next.d) continue;
        if(get_dist(next) == -1){
          que.push(next);
          set_dist(next, get_dist(now) + 1);
        }
      }
    }
    if(ans == INF) ans = -1;
    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 21996
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

set <int> Sx;

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		int t2;
		scanf("%d", &t2);
		Sx.insert(t2);
	}
	return !printf("%d\n", (int)Sx.size());
}
//*/

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

int main() {
	int d;
	std::cin >> d;
	switch (d) {
	case 25:
		std::cout << "Christmas" << std::endl;
		break;
	case 24:
		std::cout << "Christmas Eve" << std::endl;
		break;
	case 23:
		std::cout << "Christmas Eve Eve" << std::endl;
		break;
	case 22:
		std::cout << "Christmas Eve Eve Eve" << std::endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 384
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {

        if (Character.isUpperCase( scanString().charAt( 0 ) )) {
            System.out.println("A");
        } else {
            System.out.println("a");
        }
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 32788
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1e9 + 7;
using namespace std;

int32_t main()
{
    IOS
    int n,k;
    cin >> n >> k;
    for(int i = 1;i<=n;i++)
    {
        int s = i+2,j = 0;
        for(j = 2;j <= k && s <= n;j++)
        {
            s += 2;
        }
        if(j > k)
        {
            cout << "YES\n";
            return 0;
        }
    }   
    cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

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

  ll h, w; cin >> h >> w;

  if(h == 1 || w == 1){
    cout << 1;
  }else{
    cout << (h*w+1)/2;
  }



}


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

int main() {
  int d, t, s;
  string ans;
  
  cin >> d >> t >> s;
  
  if(s*t>=d){
    ans = "Yes";
  } else{
    ans = "No";
  }
  
  cout << ans << endl;
}


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

int N,M;
double L[20][3];

double culc(int x,int y){
    double v1=(L[x][0]-L[y][0])*(L[x][0]-L[y][0]);
    double v2=(L[x][1]-L[y][1])*(L[x][1]-L[y][1]);
    double v3=(L[x][2]-L[y][2])*(L[x][2]-L[y][2]);
    return v1+v2+v3;
}

double getSum(int b){
    double ret=0;
    for(int i=0;i<N;i++){
        if((b>>i&1)==0)continue;
        for(int j=i+1;j<N;j++){
            if((b>>j&1)==0)continue;
            ret+=culc(i,j);
        }
    }

    return ret;
}

void solve(){
    double ma=0;
    int comb=(1<<M)-1;
    /*
    while(comb<1<<N){
        ma=max(ma,getSum(comb));
        int x=comb&-comb,y=comb+x;
        comb=((comb&~y)/x>>1)|y;
    }
    */
    for(int i=0;i<(1<<N);i++){
        int cnt=0;
        for(int j=0;j<N;j++)if((i>>j&1)==1)cnt++;
        if(cnt!=M)continue;
        ma=max(ma,getSum(i));
    }
    printf("%lf\n",ma);
}
int main(){
    scanf("%d%d",&N,&M);

    for(int i=0;i<N;i++)
        for(int j=0;j<3;j++)
            scanf("%lf",&L[i][j]);

    solve();
    return 0;
}

Measured memory_bytes: 1248
/**
 *    author:  tourist
 *    created: 06.01.2020 23:14:22       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long l, t;
  cin >> n >> l >> t;
  vector<long long> x(n);
  vector<long long> w(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> w[i];
  }
  vector<long long> finish(n);
  for (int i = 0; i < n; i++) {
    finish[i] = ((x[i] + (w[i] == 1 ? 1 : -1) * t) % l + l) % l;
  }
  long long me = finish[0];
  sort(finish.begin(), finish.end());
  if (w[0] == 1) {
    long long cnt = 0;
    for (int i = 1; i < n; i++) {
      if (w[i] == 2) {
        long long dist = x[i] - x[0];
        long long delta = 2 * t - dist - 1;
        if (delta >= 0) {
          cnt += delta / l + 1;
        }
      }
    }
    int who = (int) (cnt % n);
    int at = (int) (find(finish.begin(), finish.end(), me) - finish.begin());
    // I want finish[who] <- finish[at]
    // finish[0] <- finish[(at - who + n) % n]
    rotate(finish.begin(), finish.begin() + (at - who + n) % n, finish.end());
  } else {
    long long cnt = 0;
    for (int i = 1; i < n; i++) {
      if (w[i] == 1) {
        long long dist = (x[0] + l) - x[i];
        long long delta = 2 * t - dist;
        if (delta >= 0) {
          cnt += delta / l + 1;
        }
      }
    }
    int who = (n - (int) (cnt % n)) % n;
    int at = (int) (find(finish.begin(), finish.end(), me) - finish.begin());
    // I want finish[who] <- finish[at]
    // finish[0] <- finish[(at - who + n) % n]
    rotate(finish.begin(), finish.begin() + (at - who + n) % n, finish.end());
  }
  for (int i = 0; i < n; i++) {
    cout << finish[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 3584
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<functional>
#include<iostream>
#define rep(i,a) for(i=0;i<a;i++)
using namespace std;
int cnt;
int glid[91][91];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
int m,n,mx;
void func(int,int);
int main(void)
{
	int i,j,k;
	while(1) {
		cin>>m>>n;
		//x==m y==n
		if(m==0&&n==0) break;
		mx=-1;
		rep(i,n)rep(j,m) cin>>glid[i][j];
		rep(i,n)rep(j,m) {
			if(glid[i][j]==1) {
				cnt=0;
				func(i,j);
			}
		}
		cout<<mx<<endl;
	}
	return 0;
}
void func(int x,int y)
{
	int i,j,k,xx,yy;
	rep(i,4) {
		xx=dx[i]+x;
		yy=dy[i]+y;
		if(xx<=m && xx>=0 && yy<=n && yy>=0 && glid[yy][xx]==1) {
			cnt++;
			if(mx<cnt) mx=cnt;
			glid[yy][xx]=0;
			func(xx,yy);
			cnt--;
			glid[yy][xx]=1;
		}
	}
}

Measured memory_bytes: 3056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    ll N ; cin >> N;

    vector<ll> diff(N);
    vector<ll> sum(N);

    REP(i,N){
        int a; cin >> a;
        diff[i] = i-a;
        sum[i] = i+a;
    }

    sort(ALL(diff));
    sort(ALL(sum));
    ll ans = 0;

    ll itr_d = 0, itr_s = 0;
    while(diff[itr_d] <= 0){
        itr_d++;
    }

    while(itr_d < N){
        if(diff[itr_d] == sum[itr_s]){
            ans+= (upper_bound(ALL(diff),diff[itr_d])-lower_bound(ALL(diff),diff[itr_d])) * (upper_bound(ALL(sum),sum[itr_s])-lower_bound(ALL(sum),sum[itr_s]));
            itr_d += upper_bound(ALL(diff),diff[itr_d])-lower_bound(ALL(diff),diff[itr_d]);
            itr_s += upper_bound(ALL(sum),sum[itr_s])-lower_bound(ALL(sum),sum[itr_s]);
        }
        else if(diff[itr_d] > sum[itr_s]){
            while(sum[itr_s] < diff[itr_d])itr_s++;
        }
        else{
            while(sum[itr_s] > diff[itr_d])itr_d++;
        }
    }

    cout << ans << endl;
    /*vector<P> height;
    vector<P> number;
    REP(i,N){
        int a; cin >> a;
        number.push_back(P(a,i));
        height.push_back(P(a,i));
    }
    sort(ALL(height));

    for(int diff = 2; diff <= N-1; diff++){
        for(int hh = 1; hh <= diff /2 ; hh++){
            int itr_high = lower_bound() - height.begin();
        }
    }*/
    


}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

class segment_tree
{
private:
const ll llinf = 1e18;
  vector<ll> ST, lazy; int N;
#define lc id << 1
#define rc id << 1 | 1
  void dolazy(int id, int l, int r)
  {
    ST[id] += lazy[id];
    if(l != r){
      lazy[lc] += lazy[id];
      lazy[rc] += lazy[id];
    }
    lazy[id] = 0;
  }

  void update(int id, int l, int r, int L, int R, ll v)
  {
    dolazy(id, l, r);
    if(l > R || L > r) return;
    if(L <= l && r <= R){
      lazy[id] += v;
      dolazy(id, l, r);
      return;
    }
    int mid = (l + r) / 2;
    update(lc, l, mid, L, R, v); update(rc, mid + 1, r, L, R, v);
    ST[id] = min(ST[lc], ST[rc]);
  }

  void Set(int id, int l, int r, int i, ll v)
  {
    dolazy(id, l, r);
    if(l > i || r < i) return;
    if(l == r){
      ST[id] = min(ST[id], v);
      return;
    }
    int mid = (l + r) / 2;
    Set(lc, l, mid, i, v); Set(rc, mid + 1, r, i, v);
    ST[id] = min(ST[lc], ST[rc]);
  }

  ll getmin(int id, int l, int r, int L, int R)
  {
    dolazy(id, l, r);
    if(l > R || L > r) return llinf;
    if(L <= l && r <= R) return ST[id];
    int mid = (l + r) / 2;
    return min(getmin(lc, l, mid, L, R), getmin(rc, mid + 1, r, L, R));
  }
#undef lc
#undef rc
public:
  segment_tree(int n)
  {
    N = n;
    ST.assign(4 * n + 5, 0);
    lazy.assign(4 * n + 5, 0);
  }
  void update(int l, int r, ll v)
  {
    update(1, 1, N, l, r, v);
  }
  ll getmin(int l, int r)
  {
    return getmin(1, 1, N, l, r);
  }
  void Set(int i, ll v)
  {
    Set(1, 1, N, i, v);
  }
};

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if(fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  int N, Q, A, B;
  cin >> N >> Q >> A >> B;
  segment_tree le(N), ri(N);
  vector<int> a(Q + 5);
  a[0] = A;
  for(int i = 1; i <= Q; ++i){
    cin >> a[i];
  }
  for(int i = 1; i <= N; ++i){
    le.update(i, i, abs(B - i) - i);
    ri.update(i, i, abs(B - i) + i);
  }
  for(int i = 1; i <= Q; ++i){
    int d = abs(a[i] - a[i - 1]);
    ll val = min(le.getmin(1, a[i]) + a[i], ri.getmin(a[i], N) - a[i]);
    le.update(1, N, d);
    ri.update(1, N, d);
    le.Set(a[i - 1], val - a[i - 1]);
    ri.Set(a[i - 1], val + a[i - 1]);
    ///cerr << val << '\n';
  }
  ll res = 1e18;
  for(int i = 1; i <= N; ++i){
    res = min(res, le.getmin(i, i) + i);
  }
  cout << res;
}


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

#if DEBUG && !ONLINE_JUDGE
    #include "/home/tushar_garg/Desktop/cpp/debug.h"
#else
    #define dbg(x...)
#endif

typedef     long long                            ll; 
typedef     pair<ll, ll>                         pl; 
typedef     vector<ll>                           vl;
typedef     vector<char>                         vc;
typedef     vector<bool>                         vb; 
typedef     vector<vl>                           vvl; 
typedef     vector<pl>                           vll; 
typedef     map<ll, ll>                          dict; 
typedef     map<ll, ll, greater <ll> >           sdict; 
typedef     map<char, ll>                        mcl;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pl>                   pqii;
typedef     priority_queue<ll, vl, greater<ll>>  pqmini;

#define rep(i, a, n) for (auto i=(a)-((a)>(n)); i!=(n)-((a)>(n)); i+=1-2*((a)>(n)))
#define trav(i, a) for(auto &i:a)
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back
#define eb emplace_back
#define flash ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define QuickSilver cin.exceptions(cin.failbit),setprecision(12),cout.precision(12);
#define fill(a, b) memset(a, b, sizeof(a)
#define get(a) rep(i,0,sz(a))cin>>a[i];
#define sz(a) (ll)(a.size())
#define all(a) a.begin(), a.end()
#define mod 1000000009

int main(){
	flash; QuickSilver;
	int n, w; cin>>n>>w;
	vvl dp(n+1, vl(w+1, 0));
	rep(i,1,n+1){
		int w1, v1; cin>>w1>>v1;
		rep(j,1,w+1)
			if(w1>j) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(v1+dp[i-1][j-w1], dp[i-1][j]);
	}
	cout<<dp[n][w]<<"\n";
    return 0;
} 

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

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

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

    ll ans = 1LL;
    rep(i, N) {
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] head = br.readLine().split(" ");
    int h = Integer.parseInt(head[0]);
    int w = Integer.parseInt(head[1]);
    int[][] ab = new int[h][2];
    for(int i = 0; i < h; i++){
      String[] data = br.readLine().split(" ");
      ab[i][0] = Integer.parseInt(data[0]);
      ab[i][1] = Integer.parseInt(data[1]);
    }
    br.close();

    // key:終点のH座標、value:始点のH座標
    SortedMap<Integer, Integer> routeMap = new TreeMap<>();
    SortedMap<Integer, Integer> distMap = new TreeMap<>();

    for(int num = 1; num <= w; num++){
      routeMap.put(num, num);
    }
    distMap.put(0, w);

    PrintWriter pw = new PrintWriter(System.out);
    for(int i = 0; i < h; i++){
      int from = ab[i][0];
      int to = ab[i][1];
      SortedMap<Integer, Integer> subMap = routeMap.subMap(from, to + 1);
      if(to < w && !routeMap.containsKey(to + 1) && !subMap.isEmpty()){
        int dist = to + 1 - subMap.get(subMap.lastKey());
        routeMap.put(to + 1, subMap.get(subMap.lastKey()));
        if(distMap.containsKey(dist)){
          distMap.put(dist, distMap.get(dist) + 1);
        } else {
          distMap.put(dist, 1);
        }
      }
      for(Integer key : subMap.keySet()){
        int dist = key - subMap.get(key);
        if(distMap.get(dist) == 1){
          distMap.remove(dist);
        } else {
          distMap.put(dist, distMap.get(dist) - 1);
        }
      }
      subMap.clear();

      if(distMap.isEmpty()){
        pw.println(-1);
      } else {
        pw.println(distMap.firstKey() + i + 1);
      }
    }
    pw.close();
  }
}

Measured memory_bytes: 79596
/*
	In the name of Allah.
*/

#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define gap ' '
#define INF 99999999
 
const int MAXN = 2 * 1e5 + 5;
ll ans = 0, n, k;

int main(){
	cin >> n >> k;
	ll c = n/k;
	ans = c * c * c;
	if(k % 2 == 0 and n >= k/2){
		c = (n-k/2)/k+1;
		ans+=c*c*c;
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3176
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main(){
    string s; cin >> s;
    map<char, int> mp;
    for(char c: s){
        mp[c]++;
    }
    bool fg = true;
    if(mp.size()!=2)fg = false;
    for(auto m: mp) if(m.second != 2) fg = false;

    if(fg) cout << "Yes" << ln;
    else cout << "No" << ln;
    
}



Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> H1, M1, H2, M2, K;
  
  ll iv = (H2-H1) * 60 + (M2-M1);


  return iv - K;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}


Measured memory_bytes: 3636
/*  HARD WORK FOREVER PAYS  */
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define turbo(){	\
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL); \
}
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
int main() 
{ 
	turbo();
	ll n,y,x,i,sum=0;
	cin>>n;
	vector<ll> ara(100005,0);
	for(i=0;i<n;i++){
		cin>>x;
		ara[x]++;
		sum+=x;
	}
	ll q,j;
	cin>>q;
	for(i=0;i<q;i++){
		cin>>x>>y;
		sum+=y*ara[x];
		sum-=x*ara[x];
		ara[y]+=ara[x];
		ara[x]=0;
		cout<<sum<<endl;
	}
	return 0;
} 

Measured memory_bytes: 3972
#include <iostream>


int main(){
    int x;
    int i=1;
    std::cin >> x;
    if (x==0){
        std::cout << i << std::endl;
    }
    std::cin >> x;
    i++;
    if (x==0){
        std::cout << i << std::endl;        
    }
    std::cin >> x;
    i++;
    if (x==0){
        std::cout << i << std::endl;        
    }
    std::cin >> x;
    i++;
    if (x==0){
        std::cout << i << std::endl;        
    }
    std::cin >> x;
    i++;
    if (x==0){
        std::cout << i << std::endl;        
    }
    return 0;
}


Measured memory_bytes: 3596
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc;
	static PrintWriter out;
	public static void main(String[] args){
		sc = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
//		out.println(solve());
		out.flush();
	}

	static void solve(){
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] prefCntList = new int[N];
		Arrays.fill(prefCntList, 0);
		Integer[] matList = new Integer[M];
		HashMap<Integer, Integer>prefMap = new HashMap<>();
		HashMap<Integer, Integer>nthMap = new HashMap<>();
		int tmp,tmp2;
		for(int i=0;i<M;i++){
			tmp = sc.nextInt();
			tmp2 = sc.nextInt();
			prefMap.put(tmp2, tmp);
			nthMap.put(tmp2, i);
			matList[i]= tmp2;
		}
		String[] strList = new String[M];
		Arrays.sort(matList);
		int tmp3,idx;
		for(int i=0;i<M;i++){
			StringBuilder bfsb = new StringBuilder();
			StringBuilder afsb = new StringBuilder();
			bfsb.append("000000");
			afsb.append("000000");
			idx = nthMap.get(matList[i]);
			tmp3 = prefMap.get(matList[i]);
			bfsb.append(tmp3);
			afsb.append(++prefCntList[tmp3-1]);
			bfsb.append(afsb.substring(afsb.length()-6));
		 	strList[idx] = bfsb.substring(bfsb.length()-12);
		}
		for(int i=0;i<M;i++){
			out.println(strList[i]);
		}
	}
}


class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 71700
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

const int mxn = 1e5 + 10;
int h[mxn];
int dp[mxn];
int n;

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	FOR(i,1,n)
		cin >> h[i];
	
	dp[n] = 0;
	dp[n - 1] = abs(h[n - 1] - h[n]);

	FORR(i,n - 2,1)
	{
		int op1 = dp[i + 1] + abs(h[i] - h[i + 1]);
		int op2 = dp[i + 2] + abs(h[i] - h[i + 2]);
		dp[i] = min(op1, op2);
	}
	cout << dp[1];

	return 0;
}


Measured memory_bytes: 5144
#include <cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>


using namespace std;
typedef long long ll;

const ll MAXN=1e5+10;

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


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <cstdlib>
using namespace std;
int INF = 10000;
int dy[4] = {1,0,-1,0};
int dx[4] = {0,1,0,-1};
typedef pair<int,int> P;

int main(){
  int R, C;
  cin >> R >> C;

  char ch[R][C];
  int black = 0;
  for(int i=0;i<R;i++){
    for(int j=0;j<C;j++){
      cin >> ch[i][j];
      if(ch[i][j]=='#') black++;
    }
  }

  int dis[R][C];
  for(int i=0;i<R;i++){
    for(int j=0;j<C;j++){
      dis[i][j] = INF;
    }
  }

  queue<P> maze;
  maze.push(make_pair(0,0));
  dis[0][0] = 1;

  while(!maze.empty()){
    P loc = maze.front();
    maze.pop();
    for(int i=0;i<4;i++){
      int y = loc.first + dy[i];
      int x = loc.second + dx[i];
      if(0<=y && y<R && 0<=x && x<C && ch[y][x]=='.' && dis[y][x]==INF){
        maze.push(make_pair(y,x));
        dis[y][x] = dis[loc.first][loc.second]+1;
      }
    }
  }
  int goal = dis[R-1][C-1];

  if(goal == INF) cout << -1 <<endl;
  else cout << R*C - black - goal <<endl;

    

  return 0;
}

Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $array_pos = explode(" ", fgets(STDIN));

  $sum_sqr=0;
  for($i=0;$i<$n;$i++)
  {
    $sum_sqr = $sum_sqr+ $array_pos[$i];
  }

  $p1 = floor($sum_sqr / $n);
  $p2 = $p1+1;
  
  $cost1 = 0;
  $cost2 = 0;
  for($i=0;$i<$n;$i++)
  {
    $cost1 = $cost1 + pow($array_pos[$i]-$p1, 2);
    $cost2 = $cost2 + pow($array_pos[$i]-$p2, 2);
  }
echo $cost1 > $cost2 ? $cost2 : $cost1;


Measured memory_bytes: 3576
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int X[12];
vector<string>ans;
int main()
{
	int I, J;
	scanf("%d%d", &I, &J);
	for (int i = 0; i < (1 << (I + J)); i++){
		for (int j = 0; j < 12; j++)X[j] = 0;
		for (int j = 0; j < I + J; j++){
			X[j] = (i >> j) & 1;
		}
		int cou1 = 0, cou2 = 0;
		bool F = true;
		for (int j = 0; j < I+J; j++){
			if (X[j] == 1)cou1++;
			else cou2++;
			if(j!=I+J-1)if ((cou1 == 5 && cou2 <= 3) || (cou1 <= 3 && cou2 == 5))F = false;
		}
		if (cou1 == I&&cou2 == J&&F){
			string S="";
			for (int j = 0; j < I + J; j++){
				if (X[j] == 1)S += 'A';
				else S += 'B';
			}
			ans.push_back(S);
		}
	}
	for (int i = 0; i < ans.size(); i++){
		for (int j = i + 1; j < ans.size(); j++){
			if (ans[i]>ans[j])swap(ans[i], ans[j]);
		}
	}
	for (int i = 0; i< ans.size(); i++){
		cout << ans[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n,k;
    cin >> n >> k;
    vector<ll> v(n,0);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end());
    ll ans = INF;
    rep(i,n-k+1){
        ans = min(ans, abs(v[i] - v[i+k-1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

ll a[26];
char s[20];
map<pair<ll, ll>, ll> mp;

int main(){
	int n; scanf("%d", &n);
	REP(i, n){
		scanf("%s", s);
		fill(a, a+26, 0);
		REP(j, 10) a[s[j]-'a']++;
		ll k = 0;
		REP(j, 13) k=k*10+a[j];
		ll l = 0;
		REP(j, 13) l=l*10+a[13+j];
		mp[MP(k, l)]++;
	}
	ll ans = 0;
	for(auto p : mp){
		ll x = p.second;
		ans += x * (x-1) / 2;
		DEBUG("%013lld%013lld %lld\n", p.first.first, p.first.second, x);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/
const int MAX_N = 10000000;

int n;
string s;
bitset<26> dat[MAX_N];

void update(int k, char a);
void init(int n_)
{
    n = 1;
    while (n < n_)
        n *= 2;

    rep(i, n_)
    {
        update(i, s[i]);
    }
}

//k番目の値をaに変更
void update(int k, char a)
{
    k += n - 1;

    dat[k] = 0;
    dat[k].set(a - 'a', true);

    while (k > 0) {
        k = (k - 1) / 2;
        dat[k] = (dat[k * 2 + 1] | dat[k * 2 + 2]);
    }
}

//[a,b)の最小値を求める

bitset<26> query(int a, int b, int k, int l, int r)
{
    if (r <= a || b <= l)
        return bitset<26>(0);
    if (a <= l && b >= r)
        return dat[k];

    bitset<26> vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    bitset<26> vr = query(a, b, 2 * k + 2, (l + r) / 2, r);

    return (vl | vr);
}

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

    int N;
    int Q;
    cin >> N >> s >> Q;

    init(N);


    rep(_, Q)
    {
        int q;
        cin >> q;
        --q;
        if (!q) {
            int i;
            char c;
            cin >> i >> c;
            --i;
            update(i, c);
        } else {
            int l, r;
            cin >> l >> r;
            --l;
            auto ans = query(l, r, 0, 0, n);
            cout << ans.count() << endl;
        }
    }
}


Measured memory_bytes: 8988
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n=INT()
    p = [INT() for _ in range(n)]

    p_max = max(p)

    print(sum(p) - int((p_max/2)))

if  __name__=='__main__':
    main()

Measured memory_bytes: 5144
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  LL k; cin>>k;
  LL an = 0;
  for1(i,k){
  	for1(j,k){
  		for1(p,k){
  			an+=__gcd(__gcd(i,j),p);
  		}
  	}
  }
  cout<<an<<endl;
  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second

int main()
{
    ll n;cin >> n;
    ll arr[n];
    map<ll,ll> m1;
    for(ll i=0;i<n;i++) {cin >> arr[i];}
    sort(arr,arr+n);
    ll ans = arr[n-1];
    ll cnt=1;
    ll p = n-2;
    while(cnt<n-1)
    {
        cnt++;
        ans = ans + arr[p];
        if(cnt==n-1) break;
        ans = ans + arr[p];
        cnt++;
        if(cnt==n-1) break;
        p--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5188