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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, c; cin >> n >> c;
    vector<set<int>> tl(c);
    vector<pair<int, int>> d;
    for(int i = 0; i < n; i++){
        int s, t, ch; cin >> s >> t>> ch;
        ch--;
        if(tl[ch].count(s)) tl[ch].erase(s);
        else tl[ch].insert(s);
        if(tl[ch].count(t)) tl[ch].erase(t);
        else tl[ch].insert(t);
    }

    for(int i = 0; i < c; i++){
        auto itr = tl[i].begin();
        while(itr!=tl[i].end()){
            int s = *itr;
            itr++;
            int t = *itr;
            itr++;
            d.push_back(make_pair(s, t));
        }
        
    }

    sort(d.begin(), d.end());
    vector<int> ans(1,0);
    for(int i = 0; i < d.size(); i++){
        int s, t;
        tie(s, t) = d[i];
        auto itr = lower_bound(ans.begin(), ans.end(),s);
        int index = itr - ans.begin();
        if(index == 0){
            ans.push_back(t);
        } else{
            index--;
            ans[index] = t;
        }
        sort(ans.begin(), ans.end());
    }
    cout << ans.size() << endl;

    return 0;
}


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

using namespace std;

int main(){
    int n,m,x;
    long long int ans = 10000000000000000;
    cin >> n >> m >> x;

    vector<long long int>sum(m+1,0);
    vector<vector<int>>v(n,vector<int>(m+1,0));

    for(int i = 0;i < n;i++){
        for(int j = 0;j < m+1;j++){
            cin >> v[i][j];
        }
    }

    for(int bit = 0;bit < (1<<n);bit++){
        for(int i = 0;i < n;i++){
            if(bit & (1<<i)){
                for(int j = 0;j < m+1;j++){
                    sum[j] += v[i][j];
                }
            }
        }


        for(int i = 1;i < m+1;i++){
            if(sum[i] < x){
                for(int j = 0;j < m+1;j++){
                    sum[j] = 0;
                }
                break;
            }
        }

        if(sum[0] != 0){
            if(ans > sum[0])ans = sum[0];
        }

        for(int j = 0;j < m+1;j++){
            sum[j] = 0;
        }

    }

    if(ans == 10000000000000000){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int F[45];

int fibonacci(int n){
  if (n==0||n==1)return F[n]=1;
  if(F[n]!=0)return F[n];
  return F[n]=fibonacci(n-2)+fibonacci(n-1);
}

int main(){
  int i,n;
  for(i=0;i<45;i++)F[i]=0;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}

Measured memory_bytes: 596
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int c = sc.nextInt();
    int[] b = new int[m];
    for(int i = 0;i<m;i++){
      b[i] = sc.nextInt();
    }
    int[][] a = new int[n][m];
    for(int i = 0;i<n;i++){
      for(int j = 0;j<m;j++){
        a[i][j] = sc.nextInt();
      }
    }
    int count = 0;
    for(int i = 0;i<n;i++){
      int code = c;
      for(int j = 0;j<m;j++){
        code += a[i][j]*b[j];
      }
      if(code>0)count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 37796
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next()); // 人数
        int k = Integer.parseInt(sc.next()); // 制限身長
        int answer = 0;
        for (int i = 0; i < n; i++) {
            int h = Integer.parseInt(sc.next()); // 各自の身長
            if (k <= h) {
                answer++;
            }
        }
        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 57288
/*
 * https://atcoder.jp/contests/abc144/tasks/abc144_b
 */
#include <bits/stdc++.h>
 
using namespace std;

// ショートハンド
// #define ll intに変えればメモリ節約
#define ll long long


/* 
 * ループ系のマクロ
 * `REP(i, 10) { cout << i; }`のように、変数名,回数で動く
 */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/*
 * 正規表現
 */
#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false)

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
// `chmax(a, b)` aがbより小さければ、aをbに上書きする。chminは逆
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1e9 + 7;
int main() {
    INIT();

    ll n,x,y,results[20001];
    cin >> n >> x >> y;
    x--;
    y--;
    REP(i,n) {
        REPS(j,i+1,n) {
            results[min(j - i, min(abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j -x)))]++;
        }
    }
    REPS(i,1,n) {
        cout << fixed << results[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

const int MAX_N = 300000;
typedef unsigned long long ull;
typedef long long ll;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)
struct obj{
    ll w, v;
    bool operator<( const obj& right ) const {
        return w == right.w ? v > right.v : w < right.w;
    }
};

ll calcW(vector<obj> &objs, int i, int j, int k, int l, vector<int> &start){
    ll totalW = 0;
    for (int m=start[0];m<start[0]+i;m++){
        totalW += objs[m].w;
    }
    for (int m=start[1];m<start[1]+j;m++){
        totalW += objs[m].w;
    }
    for (int m=start[2];m<start[2]+k;m++){
        totalW += objs[m].w;
    }
    for (int m=start[3];m<start[3]+l;m++){
        totalW += objs[m].w;
    }
    return totalW;
}

ll calcV(vector<obj> &objs, int i, int j, int k, int l, vector<int> &start){
    ll totalV = 0;
    for (int m=start[0];m<start[0]+i;m++){
        totalV += objs[m].v;
    }
    for (int m=start[1];m<start[1]+j;m++){
        totalV += objs[m].v;
    }
    for (int m=start[2];m<start[2]+k;m++){
        totalV += objs[m].v;
    }
    for (int m=start[3];m<start[3]+l;m++){
        totalV += objs[m].v;
    }
    return totalV;
}

int main(){
    ll N, W;
    cin >> N >> W;
    vector<obj> objs(N);
    REP(i, N) cin >> objs[i].w >> objs[i].v;
    sort(objs.begin(), objs.end());
    vector<int> start(4);
    start[0] = 0;
    int j=1;
    for(int i=1;i<N;i++){
        if(objs[i].w != objs[i-1].w){
            start[j] = i;
            j++;
        }
    }
    for(int i=j;i<4;i++) start[i] = N;

    ll res = 0;
    for(int i=0;i<=start[1]-start[0];i++){
        for(int j=0;j<=start[2]-start[1];j++){
            for(int k=0;k<=start[3]-start[2];k++){
                for(int l=0;l<=N-start[3];l++){
                    if(calcW(objs, i, j, k, l, start) <= W){
                        res = max(res, calcV(objs, i, j, k, l, start));
                    }
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N;
	cin >> N;
	struct r {
		int i;
		string s;
		int p;
	};
	vector<r> v;
	rrep(i, N) {
		string s;
		int p;
		cin >> s >> p;
		v.push_back({ i,s,p });
	}
	sort(v.begin(), v.end(), [](auto x, auto y) {
		if (x.s != y.s) {
			return x.s < y.s;
		}
		else {
			return x.p > y.p;
		}
		});
	for (auto x : v) {
		cout << x.i << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <set>

using namespace std;

set< pair<short, short> > *list;

int search(pair<short, short> a, pair<short, short> b) {
    short x1 = a.first;
    short y1 = a.second;
    short x2 = b.first;
    short y2 = b.second;

    int x_diff = y1 - y2;
    int y_diff = x2 - x1;
    int square = 0;

    if (list->find(make_pair(x1+x_diff, y1+y_diff)) != list->end() && list->find(make_pair(x2+x_diff, y2+y_diff)) != list->end()) {
        int large_side = (x_diff+y_diff);
        square = large_side * large_side - (x_diff * y_diff * 2);
    }

    return square;
}
    

int main() {
    while (1) {
        short i;
        short n;
        pair<short, short> array[3000];
        int max_surface;

        scanf("%hd", &n);
        if (!n) return 0;

        list = new set< pair<short, short> >();

        for (i=0;i<n;i++) {
            short x, y;
            scanf("%hd %hd", &x, &y);
            list->insert(make_pair(x, y));
        }

        set< pair<short, short> >::iterator it = list->begin();
        for (i=0;i<n;i++) {
            array[i] = *it;
            ++it;
        }

        max_surface = 0;
        for (i=0;i<n;i++) {
            short j;
            for (j=i+1;j<n;j++) {
                int surface = search(array[i], array[j]);
                if (surface > max_surface) max_surface = surface;
            }
        }

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

        delete list;
    }
}

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

int main() {
  int n,m,q; cin>>n>>m>>q;
  vector<vector<int>> cost(n, vector<int>(n, 0));
  for (int i=0; i<m; i++) {
    int l,r; cin>>l>>r;
    l--; r--;
    cost[l][r]++;
  }
  vector<int> x(q),y(q);
  for (int i=0; i<q; i++) {
    cin>>x[i]>>y[i];
    x[i]--;
  }

  //二次元累積和
  vector<vector<int>> T(n+1, vector<int>(n+1, 0));
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      T[i+1][j+1]=T[i][j+1]+T[i+1][j]-T[i][j]+cost[i][j];
    }
  }
  for (int i=0; i<q; i++) {
    int tmp=T[y[i]][y[i]]-T[y[i]][x[i]]-T[x[i]][y[i]]+T[x[i]][x[i]];
    cout<<tmp<<endl;
  }

  return 0;
}

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

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
ios_base::sync_with_stdio(false); \
cin.tie(0);                       \
cout.tie(0);
#define test  \
int t;    \
cin >> t; \
while (t--)
#define debug(a)          \
	cerr << #a << ": ";   \
for (auto i : a)      \
	cerr << i << " "; \
cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
for (int u = 0; u < n; u++) \
	{                           \
		cout << ar[u] << " ";   \
	}                           \
	cout << endl;
#define int long long
#define M 1000000007
	vector<int> adj[100001];
	signed main()
	{
		rootdada;

		int n, m;
		cin >> n >> m;
		vi h(n);
		rep(i,0,n)
		cin >> h[i];
		rep(i,0,m) 
		{
			int x,y;
			cin >> x >> y;
			x--;
			y--;
			adj[x].pb(y);
			adj[y].pb(x);
			
		}	
		int c= 0;
		rep(i,0,n) 
		{
			int flg=1;
			for (auto it = adj[i].begin(); it != adj[i].end(); it++)
			{

				if (*it != i && h[*it] >= h[i]) {
					flg = 0;
					break;
				}
			}
			if (flg)
				c++;
		}
		cout << c << "\n";

	}

Measured memory_bytes: 9804
//ABC-139-E
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

const int MAX_N = 1000;
#define MAX_V MAX_N * (MAX_N - 1) / 2

int V;//頂点数
vector<int> G[MAX_V]; //トポロジカルソートするグラフ
vector<int> To; //トポロジカルソート後のグラフ
// To.size() == V であればトポロジカルソートができた、そうでなければできなかったと判定できる

int dp[MAX_V];
int ans = 0;

void Tsort(){
    stack<int> st; //入次数が0の頂点の集合
    int indeg[V] = {}; //頂点の入次数を管理する配列
    for(int i = 0; i < V; i++){
        for(int j = 0; j < G[i].size(); j++){
            indeg[G[i][j]]++;
        }
    }
    for(int i = 0; i < V; i++){
        if(indeg[i] == 0){
            st.push(i);
        }
    }
    while(!st.empty()){
        int u = st.top();
        st.pop();
        To.push_back(u);
        for(int i = 0; i < G[u].size(); i++){
            indeg[G[u][i]]--; //隣接する頂点の入次数を1減らす
            dp[G[u][i]] = max(dp[G[u][i]], dp[u] + 1);
            ans = max(ans, dp[G[u][i]]);
            if(indeg[G[u][i]] == 0){
                st.push(G[u][i]); //入次数が0になればstに追加
            }
        }
    }
}

signed main(){
    int n;
    cin >> n;
    int id[n][n];
    REP(i,n){
        for(int j = i + 1; j < n; j++){
            id[i][j] = V;
            V++;
        }
    }
    int num[n][n - 1];
    int a,b;
    REP(i,n){
        REP(j,n - 1){
            cin >> a;
            a--;
            b = i;
            if(a > b){
                swap(a, b);
            }
            num[i][j] = id[a][b];
        }
    }
    REP(i,n){
        REP(j,n - 2){
            G[num[i][j]].push_back(num[i][j + 1]);
        }
    }
    Tsort();
    if(To.size() != V){
        cout << -1 << endl;
        return 0;
    }
    cout << ans + 1 << endl;
    return 0;
}

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

int main()
{
  string word, buf;
  cin >> word;
  for( int i = 0; i < word.size(); i++ ) {
    word[ i ] = tolower( word[ i ] );
  }

  int cnt = 0;
  while( true ) {
    cin >> buf;
    if( buf == "END_OF_TEXT" ) {
      break;
    }
    if( buf.size() != word.size() ) {
      continue;
    }
    for( int i = 0; i < buf.size(); i++ ) {
      buf[ i ] = tolower( buf[ i ] );
    }
    if( word == buf ) {
      cnt += 1;
    }
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3144
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
 
#define X first
#define Y second
 
//#include <boost/unordered_map.hpp>
//using namespace boost;
 
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/
 
using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
//using i128 = i64;
//using u128 = u64;
 
ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}
 
ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

ll gcd(ll a, ll b)
{
	return b ? gcd(b, a%b) : a;
}
 
template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}
 
template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

template<class T>
void print(const T &a)
{
	for (auto x : a) printf("%d ", x); puts("");
}

const int MAXN = 500010;
//const int MAXM = 100010;
const int MAXK = 30;
//const i64 INF = 1000000000000000000LL;
const int INF = 1000000000;
//const int MOD = 998244353;
const int B = 31;
const int MOD = 998244353;
//const int INV2 = (MOD+1)/2;
const ld pi = 3.1415926535897932384626433;

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

#define rep(i,a,b) for (int i = (a), I = (b); i <= I; ++ i)

int days[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool leap(int y)
{
	return y%4 == 0 && y%100 != 0 || y%400 == 0;
}

int n, m;
int a[MAXN];
//vector<int> v[MAXN];

void solve()
{
	cin >> n;
	
	for (int i = 0; i < n; ++ i)
	{
		cin >> a[i];
	}
	sort(a, a+n);
	
	ll ans = 0;
	for (int i = 0; i < n; ++ i)
		for (int j = i+1; j < n; ++ j)
		{
			int k = lower_bound(a, a+n, a[i]+a[j])-a;
			ans += k-j-1;
		}
	
	cout << ans << endl;
}

int main()
{
	
	int T;
	T = 1;
	//scanf("%d", &T);
	while (T --)
	solve();
	
	return 0;
}


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

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


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int p, q, r;
    cin >> p >> q >> r;
    cout << p + q + r - max(p, max(q, r)) << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
 
$nm = explode(" ", fgets(STDIN));
 
$arr = array_pad([], intval($nm[0]), -1);
 
for ($i = 0; $i < $nm[1]; $i++) {
    $kv = explode(" ", fgets(STDIN));
    $idx = intval($kv[0]) - 1;
    $value = intval($kv[1]);
    
    if ($arr[$idx] >= 0 && $value != $arr[$idx]) {
        echo "-1";
        return;
    }

    $arr[$idx] = intval($kv[1]);
}
 
if ($arr[0] < 0 && $nm[0] > 1) $arr[0] = 1;
for($i = 0; $i < $nm[0]; $i++) {
    if ($arr[$i] < 0) $arr[$i] = 0;
}
 
$v = intval(join("", $arr));
if (strlen(strval($v)) != $nm[0]) {
    echo "-1";
}
else {
    echo $v;
}

Measured memory_bytes: 4732
N,M,X=map(int,input().split())
s=[list(map(int,input().split())) for i in range(N)]
a=10**12
from itertools import product
for i in product([0,1], repeat=N):
    c=0
    for j in range(N):
        if i[j]:
            c+=s[j][0]
    if c>a:
        continue
    for j in range(M):
        t=0
        for k in range(N):
            if i[k]:
                t+=s[k][j+1]
        if t<X:
            break
    else:
        if c<a:
            a=c
print(a if a!=10**12 else -1)

Measured memory_bytes: 68396
import java.util.*;

public class Main {
	public static void main(String[] args){
		int S,L;
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		S = a * b;
		L = 2 * (a + b);
		
		System.out.println(S+" "+L);
		
	}
}

Measured memory_bytes: 17156
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author naruse
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Pyramid solver = new Pyramid();
        solver.solve(1, in, out);
        out.close();
    }

    static class Pyramid {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int x[] = new int[n];
            int y[] = new int[n];
            int h[] = new int[n];
            int sx = 0, sy = 0, sh = 0;
            for (int i = 0; i < n; i++) {
                x[i] = in.nextInt();
                y[i] = in.nextInt();
                h[i] = in.nextInt();
                if (h[i] > 0) {
                    sx = x[i];
                    sy = y[i];
                    sh = h[i];
                }
            }
            for (int i = 0; i < 101; i++) {
                for (int j = 0; j < 101; j++) {
                    int nowh = Math.max(sh + Math.abs(i - sx) + Math.abs(j - sy), 0);
                    boolean ok = (nowh > 0);
                    for (int k = 0; k < n; k++) {
                        int checkh = Math.max(h[k] + Math.abs(i - x[k]) + Math.abs(j - y[k]), 0);
                        if (nowh != checkh) {
                            if (h[k] == 0 && checkh >= nowh) continue;
                            ok = false;
                        }
                    }
                    if (ok) {
                        out.println(i + " " + j + " " + nowh);
                        return;
                    }
                }
            }
        }

    }
}



Measured memory_bytes: 24020
n = int(input())
x = [0] * n
y = [0] * n
h = [0] * n
for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())
for a in range(101):
    for b in range(101):
        hset = set()
        for i in range(n):
            if h[i] != 0:
                hset.add(h[i] + abs(x[i]-a) + abs(y[i]-b))
        if len(hset) == 1:
            height = hset.pop()
            check = True
            for i in range(n):
                if h[i] == 0:
                    if height - abs(x[i]-a) - abs(y[i]-b) > 0:
                        check = False
                        break
            if check:
                print(a,b,height)
                exit()
print('ERROR EXIT')


Measured memory_bytes: 3064
N,K = map(int,input().split())
import numpy as np
H = np.array(input().split(), dtype = int)

INF = 10 ** 9 + 1
dp = np.full(N,INF,dtype = int)
dp[0] = 0

for i in range(1, N):
  dp[i] = min(dp[max(i - K,0):i] + np.abs(H[max(i - K,0):i] - H[i]))

print(dp[-1])

Measured memory_bytes: 38560
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) //cerr<< #x <<": "<<x<<endl
#define debug2(x,y) //cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int r, c, n;
bool on_edge(int x, int y) {
  return (x == 0 || x == r) || (y == 0 || y == c);
}

double xcenter, ycenter;
double get_atan(vi &a) {
  return atan2(a[1] - ycenter, a[0] - xcenter);
}

int main() {
  scanf("%d %d %d", &r, &c, &n);
  xcenter = r / 2.0;
  ycenter = c / 2.0;
  vvi points;
  rep (i, n) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    if (on_edge(x1, y1) && on_edge(x2, y2)) {
      vi point1 = {x1, y1, i};
      vi point2 = {x2, y2, i};
      points.push_back(point1);
      points.push_back(point2);
    }
  }
  int m = points.size();
  sort(all(points), [](vi a, vi b) {
      return get_atan(a) < get_atan(b);
      });

  deque<int> stk;
  set<int> si;
  rep (i, m) {
    int num = points[i][2];
    if (si.find(num) == end(si)) {
      si.insert(num);
      stk.push_back(num);
    } else if (stk.back() == num) {
      stk.pop_back();
    } else {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");

  return 0;
}


Measured memory_bytes: 17068
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    if(a+b <= 2*c) {
        out(a*x + b*y);
    }
    else if(x <= y) {
        if(b <= 2*c) {
            out(2*c*x + b*(y - x));
        }
        else {
            out(2*c*y);
        }
    }
    else if(y < x) {
        if(a <= 2*c) {
            out(2*c*y + a*(x - y));
        }
        else {
            out(2*c*x);
        }
    }
    
    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  int N; cin >> N;
  int a[N]; rep(i,N) cin >> a[i];
  ll cnt = 0, money = 1000;
  rep(i,N-1){
    if (a[i]<a[i+1]) {
      cnt += money/a[i];
      money %= a[i];
    }
    else if (a[i]>a[i+1]){
      money += a[i]*cnt;
      cnt = 0;
    }
  }
  money += a[N-1]*cnt;
  cout << money << endl;

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3564
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#define INT long long int
using namespace std;

int main(){
    INT a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a*c, b*d),max(a*d, b*c)) <<endl;
}


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

struct rt{
	string s;
	int p;
	int id;
};

bool operator< (const rt &a, const rt &b) {
	if(a.s!=b.s) return a.s<b.s;
	return a.p>b.p;
}

int main() {
	int n;
	cin >> n;
	vector<rt> arr(n);
	for(int i = 0; i < n; i++) {
		string s;
		int p;
		cin >> s >> p;
		rt _rt;
		_rt.s = s;
		_rt.p = p;
		_rt.id = i+1;
		arr[i] = _rt;
	}
	sort(arr.begin(),arr.end());
	for(int i = 0; i < n; i++) {
		cout << arr[i].id << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE=3000;
const int SIZE2=5010;
const int SIZE3=400;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string S;
ut N,M,K,X,L,W,H;
// ut A,B,C,D,E,F,G,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL x[2],vals[SIZE],nums[SIZE],maps[SIZE2][SIZE2],answer=zero;
VI v[2];
bool DP[4000][2];
bool able(int now){

}
signed main(){
	int a,b;
	cin >> a >> b;
	cout << (a+b+1)/2 << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
const int MAX_STU = 5;
int main(){
	int total = 0 , temp;
	int i;
	for( i = 0 ; i < MAX_STU ; i++ ){
		scanf( "%d" , &temp);
		if( temp <= 40 )
			total += 40;
		else
			total += temp;
	}
	printf( "%d\n" , total / MAX_STU );
	return 0;
}

Measured memory_bytes: 600
H,W=map(int,input().split())
a=[list(map(int,input().split())) for i in range(H)]
for h in range(H):
    for w in range(W):
        if a[h][w]%2==0:
            a[h][w]=0
        else:
            a[h][w]=1
ans=[]
for h in range(H):
    for w in range(W-1):
        if a[h][w]==1:
            a[h][w+1]=a[h][w+1]^a[h][w]
            ans.append([h+1,w+1,h+1,w+2])
for h in range(H-1):
    if a[h][-1]==1:
        a[h+1][-1]=a[h+1][-1]^a[h][-1]
        ans.append([h+1,W,h+2,W])
print(len(ans))
for i in ans:
    print(*i)


Measured memory_bytes: 70364
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int unsigned long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
#define Int unsigned long long

int min(int a,int b){
  if(a<b) return a;
  return b;
}
int max(int a,int b){
  if(a>b) return a;
  return b;
}

int gcd(Int a, Int b) {
  return b != 0 ? gcd(b, a % b) : a;
}
int lcm(Int a, Int b) {
  return a / gcd(a, b)*b;
}
// a x + b y = gcd(a, b)
int extgcd(Int a, Int b, Int &x, Int &y) {
  Int g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
 
signed main(){
  int a,b;
  cin>>a>>b;
  if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  return 0;
}
 


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

int main(){
    int n;
    int sum=0;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    int max = 0;
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<n;i++)cin >> b[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j<=i){
                //cout << "sum+=a[i]" <<endl;
                //cout << sum << "+=" << a[j] <<endl;
                sum+=a[j];
            }
            if(j>=i){
                // cout << "sum+=b[i]" <<endl;
                // cout << sum << "+=" << b[j] <<endl;
                sum+=b[j];
            }
        }
        if(max<sum){
            // cout << "i:" << i << endl;
            max=sum;
        }
        sum = 0;
    }
    cout << max << endl;
    return 0;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

/*
逆順ソート sort(ALL(vec), greater<ll>());
ペア定義 P pair = make_pair(100, 200);
集合find set.find(item);
小さい順に取り出したい優先度付きキュー
priority_queue<int, vector<int>, greater<int> > que;
配列の最大要素 *std::max_element(ALL(vec))
*/

signed main(){
	ll n, t;
	scanf("%lld %lld", &n, &t);
	ll a, count = 0, min = INF, max_diff = 0;
	rep(n){
		scanf("%lld", &a);
		if(a < min) min = a;
		a -= min;
		if(a > max_diff){
			max_diff = a;
			count = 1;
		}else if(a == max_diff){
			count++;
		}
	}
	
	printf("%lld", count);
}

Measured memory_bytes: 256
#include<stdio.h>
int a[2000001], h;
void maxHeapify(int i){
    int largest, r, l, tmp;
    r=2*i+1;
    l=2*i;
    if(l<=h&&a[l]>a[i])largest=l;
    else largest=i;
    if(r<=h&&a[r]>a[largest])largest=r;
    if(largest!=i){
        tmp=a[i];
        a[i]=a[largest];
        a[largest]=tmp;
        maxHeapify(largest);
    }
}
int main(){
    int i;
    scanf("%d", &h);
    for(i=1; i<=h; i++)scanf("%d", &a[i]);
    for(i=h/2; i>0; i--)maxHeapify(i);
    for(i=1; i<=h; i++)printf(" %d", a[i]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 2552
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>
#include <cstdint>
using namespace std;

int main() {
    uint32_t n; cin >> n;
    vector<array<uint32_t, 3>> abc(n);
    for (auto &e : abc) cin >> e[0] >> e[1] >> e[2];

    vector<array<uint32_t, 3>> dp(n + 1);
    fill(dp[0].begin(), dp[0].end(), 0);

    for (uint32_t i = 0; i < n; ++i) {
        dp[i + 1][0] = max(dp[i][1] + abc[i][0], dp[i][2] + abc[i][0]);
        dp[i + 1][1] = max(dp[i][0] + abc[i][1], dp[i][2] + abc[i][1]);
        dp[i + 1][2] = max(dp[i][0] + abc[i][2], dp[i][1] + abc[i][2]);
    }

    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << endl;
}



Measured memory_bytes: 5548
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<long long Mod>
struct mint{
    long long x;
    mint(long long x=0) :x((x% Mod+Mod)%Mod){}

    mint operator-() const { return mint(-x); }

    mint& operator+=(const mint a) {
        if((x += a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if((x += Mod-a.x) >= Mod) x -= Mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= Mod;
        return *this;
    }

    mint operator^(long long t) const {
        mint ret(1);
        mint a = *this;
        while(t){
            if(t&1){
                ret *= a;
            }
            a *= a;
            t >>= 1;
        }
        return ret;
    }
    mint inv() const { return *this ^ (Mod-2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }

    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint operator/(const mint a) const { return mint(*this) /= a; }

    friend istream& operator>>(istream& is, mint& a) { return is >> a.x; }
    friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
};

vector<int> divisor[1000001];
mint<MOD> memo[1000001];

int N;
int A[200000];
mint<MOD> a[200000];
vector<mint<MOD>> v[1000001];

signed main(){
    for(int i=2; i<=1'000'000; i++){
        for(int j=2; i*j<=1'000'000; j++){
            divisor[i*j].pb(i);
        }
    }

    scanf("%d", &N);
    rep(i, N){
        scanf("%d", A+i);
        a[i] = mint<MOD>(A[i]);
        v[A[i]].pb(a[i]);
        rep(j, divisor[A[i]].size()){
            v[divisor[A[i]][j]].pb(a[i]);
        }
    }

    mint<MOD> sum = a[0];
    mint<MOD> ans = 0;
    for(int i=1; i<N; i++){
        ans += sum*a[i];
        sum += a[i];
    }

    for(int i=2; i<=1'000'000; i++){
        if(v[i].size() <= 1) continue;

        mint<MOD> tmp = 0;
        rep(j, divisor[i].size()){
            tmp -= memo[divisor[i][j]];
        }
        tmp -= 1;
        tmp += mint<MOD>(1)/mint<MOD>(i);
        memo[i] = tmp;

        sum = v[i][0];
        for(int j=1; j<v[i].size(); j++){
            ans += tmp*sum*v[i][j];
            sum += v[i][j];
        }
    }

    printf("%lld\n", ans.x);
}

Measured memory_bytes: 220616
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 9223372036854775807
#define mini 9223372036854775807
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll c=power(a,b/2);
	if(b%2==0)
		return ((c%mod)*(c%mod))%mod;
	else
		return ((((c%mod)*(c%mod))%mod)*a)%mod;
}
int main()
{
	boost
	ll n;
	cin>>n;
	double a[n];
	for(ll i=0; i<n; i++)
		cin>>a[i];
	sort(a,a+n);
	for(ll i=1; i<n; i++)
		a[i]=(a[i]+a[i-1])/2.0;
	cout<<fixed<<setprecision(10)<<a[n-1]<<endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
struct edge {
  ll to, cost;
};

int main() {
  double D, T, S; cin >> D >> T >> S;
  double res = D / S;
  if(res <= T) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3716
import java.util.*;
public class Main{
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int n = sc.nextInt();
	  if(n%2==0)System.out.println(0.5);
	  else{
	  	int sum=0;
	  	System.out.println(((n/2.0)+0.5)/n);
	  }
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

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

Measured memory_bytes: 3488
#include<iostream>
#include<cfloat>
#include<cmath>
using namespace std;

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

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

    double d = (double)sum / n;
    double dist = DBL_MAX;
    int ans = -1;

    for(int i = 0; i < n; i++){
        double tmp = abs(d-(double)a[i]);
        if(tmp < dist){
            dist = tmp;
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int W, H, x, y, r;

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

    cin >> W >> H >> x >> y >> r;

    int diff_x = W - x;
    int diff_y = H - y;

    if (x < 0 || y < 0) {
        cout << "No" << '\n';
    } else if (diff_x >= r && diff_y >= r) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }
    return 0;
}


Measured memory_bytes: 3160
n,k=map(int,input().split())
h=input()

cnt=0
for i in range(n):
	if h[i]=="1":
		cnt+=1
	else:
		cnt=0
	if cnt>=k:
		print(-1)
		exit()

h=h[::-1]
h+="0"
idx=0
ans=[]
while 1:
	if idx+k>=n:
		ans.append(n-idx)
		break
	for i in range(k,0,-1):
		if h[idx+i]=="0":
			ans.append(i)
			idx+=i
			break
ans=reversed(ans)
print(" ".join([str(x) for x in ans]))


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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M) {
  if( N == M ) cout << YES << endl;
  else cout << NO << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  solve(N, M);
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	long long int n;
	cin >> n;
	long long int dp[70] = {};
	vector<long long int>v;
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		v.push_back(a);
		long long int tmp = a;
		long long int keta = 0;
		while (tmp > 0) {
			keta++;
			if (tmp % 2 == 1) {
				dp[keta]++;
			}
			tmp = tmp / 2;
		}
	}
	for (int i = 0; i < v.size(); i++) {
		long long int a = v[i];
		long long int tmp = a;
		long long int keta = 0;
		long long int ans = 0;
		while (keta <32) {
			keta++;
			if (tmp % 2 == 1) {
				if (dp[keta] % 2 == 0) {
					ans = ans + pow(2, keta - 1);
				}
			}
			else{
				if (dp[keta] % 2 == 1) {
					ans = ans + pow(2, keta - 1);
				}
			}
			tmp = tmp / 2;
		}
		cout << ans << " ";
	}
}

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n , x;
    cin >> n;
    map<int,int> m;
    ll sum = 0;
    loop(i,n){
        cin >> x;
        sum += x;
        m[x]++;
    }

    int q;
    int from , to;
    cin >> q;
    loop(i,q){
        cin >> from >> to;
        if(m.count(from)){
            sum += (to - from) * 1LL * m[from];
            m[to] += m[from];
            m[from] = 0;
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 7460
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n){
    int in;
    cin >> in;
    a.at(i) = in;
  }
  vector<int> gl(n+1, 0);
  rep(i, n){
    if(i == 0) gl.at(i+1) = a.at(i);
    else gl.at(i+1) = __gcd(gl.at(i), a.at(i));
  }
  vector<int> gr(n+1, 0);
  rrep(i, n){
    if(i == n-1) gr.at(i) = a.at(i);
    else gr.at(i) = __gcd(gr.at(i+1), a.at(i));
  }

  int ans = 0;
  rep(i, n){
    int add;
    // cerr << i << " " << gl.at(i) << " " << gr.at(i+1) << endl;
    if(gl.at(i) == 0) add = gr.at(i+1);
    else if(gr.at(i+1) == 0) add = gl.at(i);
    else add = __gcd(gl.at(i), gr.at(i+1));
    ans = max(ans, add);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1408
require 'pp'

def gets; ARGF.gets; end

class Solver

  def main
    n = gets.chomp.to_i
    s = gets.chomp

    ans = 0
    x = 0
    s.each_char do |c|
      if c == 'I'
        x += 1
        ans = x if ans < x
      else
        x -= 1
      end
    end

    puts ans
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2044