akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s; string t="Yes"; int u;
  cin>>s;
  vector<char> a(s.size());
  for(int i=0;i<s.size();i++){
   a.at(i)=s.at(i); 
  }
  sort(a.begin(),a.end());
  if(s.size()%2==0) u=1;
  else u=2;
  switch(u){
    case 1: for(int i=0;2*i<a.size()-1;i++){
               if(a.at(2*i)!=a.at(2*i+1))
               t="No";
             } break;
    case 2: t="No"; break;
  }
  cout<<t<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int n, f = 0;
	int digit = 0;
	scanf("%d", &n);
	int remain = n;
	while (n >= pow(10, digit))
	{
		digit++;
	}
	//printf("digit = %d\n", digit);

	int sub;

	while (digit>=0&&n>0)
	{
		sub = n / pow(10, digit);
		f += sub;
		n -= sub*pow(10, digit);
		//printf("sub = %d\tf = %d\tn = %d\n",sub, f, n);

		digit--;
	}
	
	if (remain%f == 0)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long int lld;

int main(){
    lld A,B,C;
    scanf("%lld %lld %lld",&A,&B,&C);
    if(A-B<C)
    {
        C = C-(A-B);
    }else{
        C = 0;
    }
    fprintf(stdout,"%lld",C);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    char[] c = s.toCharArray();
    int count = 0;
    int max = 0;

    for (int i = 0; i < s.length(); i++) {
      if (c[i] == 'A' || c[i] == 'C' || c[i] == 'G' || c[i] == 'T') {
        count++;
        max = Math.max(max,count);
      } else {
        count = 0;
      }
    }
    System.out.println(max);
  }

}


Measured memory_bytes: 21844
import java.util.*;

class Point{
	
	public final double x;
	public final double y;

	Point(double x,double y){
		this.x = x;
		this.y = y;
	}
}

public class Main {

    public static void main(String[] args) {
        
    	//input
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        Point S = new Point(0,0);
        Point E = new Point(100,0);
        
        //calculate
        ArrayList<Point> result = makeKochCurve(S,E,N);

        for (Point p:result){
			System.out.printf("%3.8f %3.8f \n",p.x,p.y);
		}
    }
    
    private static ArrayList<Point> makeKochCurve(Point p1,Point p2,int n){
    	ArrayList<Point> K = new ArrayList<Point>();

    	if(n == 0){
    		K.add(p1);
    		K.add(p2);
    		return K;
    	}

    	Point s = new Point((p1.x*2+p2.x)/3,(p1.y*2+p2.y)/3);
    	Point u = null;
    	if (p1.y == p2.y){
    		u = new Point((p1.x+p2.x)/2,(p2.x-p1.x)/2*Math.tan(Math.toRadians(30)));
    	} else if ((p2.x-p1.x>0 && p2.y-p1.y>0) || (p2.x-p1.x<0 && p2.y-p1.y<0)){
    		u = new Point(p1.x,(p1.y+p2.y*2)/3);
    	} else if ((p2.x-p1.x<0 && p2.y-p1.y>0) || (p2.x-p1.x>0 && p2.y-p1.y<0)){
    		u = new Point(p2.x,(p1.y*2+p2.y)/3);
    	}
    	Point t = new Point((p1.x+p2.x*2)/3,(p1.y+p2.y*2)/3);

    	ArrayList<Point> a = makeKochCurve(p1,s,n-1);
    	ArrayList<Point> b = makeKochCurve(s,u,n-1);
    	ArrayList<Point> c = makeKochCurve(u,t,n-1);
    	ArrayList<Point> d = makeKochCurve(t,p2,n-1);

    	K.addAll(con(con(a,b),con(c,d)));
    	return K;
    }

    private static ArrayList<Point> con(ArrayList<Point> a,ArrayList<Point> b){
    	b.remove(0);
    	a.addAll(b);
    	return a;
    }
}

Measured memory_bytes: 40412
import math
N = int(input())
A = [list(map(int,input().split())) for _ in range(N-1)]
for i in range(N):
    t = 0
    for C,S,F in A[i:]:
        if t < S:
            t = S+C
        else:
            t = math.ceil((t-S)/F)*F+S+C
    print(t)

Measured memory_bytes: 42460
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

int N, D, Q;
int d[500005];
int A[500005];
int B[500005];
int q[500005];
int near = 10000000;

int main() {

  cin >> N >> D;
  A[0] = D;

  for(int i = 0; i < N; i++) {
    cin >> d[i];
    if(A[i] > abs(A[i]-d[i])){
      A[i+1] = abs(A[i] - d[i]);
    }
    else A[i+1] = A[i];
  }

  cin >> Q;
  for(int i = 0; i < Q; i++) cin >> q[i];

  B[N] = 1;

  for(int i = N; i > 0; i--) {
    if(B[i] <= (d[i-1] / 2)) {
      B[i-1] = B[i];
    }
    else B[i-1] = B[i] + d[i-1];
  }

  for(int i = 0; i < Q; i++) {
    if(A[q[i] - 1] >= B[q[i]]) cout << "YES" <<endl;
    else cout << "NO" <<endl;
  }
}
      
      
    
    
    
  


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

int main() {
    int size;
    int prev;
    int now;

    cin >> size;
    cin >> prev;

    long long totalStools = 0;

    for (int i = 1; i < size; i++) {
        cin >> now;
        if (now < prev) {
            totalStools += prev - now;
        }
        else if (now > prev) {
            prev = now;
        }
    }

    cout << totalStools << endl;
}


Measured memory_bytes: 3184
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

!function () {
  function splitNum(line) {
    return (Array.isArray(line) ? line : line.split(/\s+/)).map(function (n) {
      return parseInt(n);
    });
  }

  function* range(start, end) {
    for (var i = start; i < end; i++) {
      yield i;
    }
  }

  !function (input) {
    var lines = input.split("\n");

    var _splitNum = splitNum(lines[0]),
        _splitNum2 = _slicedToArray(_splitNum, 3),
        r = _splitNum2[0],
        D = _splitNum2[1],
        x2000 = _splitNum2[2];

    var x = x2000;
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = range(0, 10)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        _step.value;
        x = r * x - D;
        console.log(x);
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }
  }(require("fs").readFileSync("/dev/stdin", "utf8"));
}();


Measured memory_bytes: 22332
#include <stdio.h>
#include <math.h>
#include <string.h>

int gcd(int a,int b){
    if(a<b){
        int now=a;
        a=b;
        b=a;
    }

    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }

    return b;
}



/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}



int main(void){
    int h,n;
    scanf("%d%d",&h,&n);

    int i;
    for(i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        h-=a;
    }

    if(h<=0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	REP(i, N) scanf("%d", &A[i]);
	REP(i, N) scanf("%d", &B[i]);
	
	vector<pii> Ai(N), Bi(N);
	REP(i, N) {
		Ai[i] = pii(A[i], i);
		Bi[i] = pii(B[i], i);
	}
	sort(ALL(Ai)); sort(ALL(Bi));
	
	bool ng = false;
	REP(i, N) ng |= Ai[i].fi > Bi[i].fi;
	if (ng) {
		puts("No");
		return 0;
	}
	
	bool ans = false;
	FOR(i, 1, N) if (Bi[i - 1].fi >= Ai[i].fi) ans = true;
	
	vector<int> ord(N);
	REP(i, N) ord[Ai[i].se] = Bi[i].se;
	int cnt = 0;
	REP(i, N) {
		while (ord[i] != i) {
			swap(ord[i], ord[ord[i]]);
			cnt++;
		}
	}
	ans |= cnt <= N - 2;
	
	puts(ans ? "Yes" : "No");
	return 0;
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define V vector
#define P pair
#define M map
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

int main(){
    ins(a);
    cout << ((a<1200)? "ABC" : "ARC") << endl;
    return 0;
}


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 800;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

vector<int> dx = {0, 0, -1, 1};
vector<int> dy = {-1, 1, 0, 0};

int n, m, k;
char a[N][N];
int d[N][N];

void bfs(int x, int y)
{
    rep(i, 0, n)
        rep(j, 0, m)
            d[i][j] = inf;
    d[x][y] = 0;
    queue<pair<int, int> > q;
    q.push({x, y});
    while (!q.empty())
    {
        x = q.front().fi, y = q.front().se;
        q.pop();
        rep(i, 0, 4)
            if (x + dx[i] >= 0 && x + dx[i] < n && y + dy[i] >= 0 && y + dy[i] < m && a[x + dx[i]][y + dy[i]] == '.')
            {
                if (d[x + dx[i]][y + dy[i]] == inf)
                {
                    d[x + dx[i]][y + dy[i]] = d[x][y] + 1;
                    q.push({x + dx[i], y + dy[i]});
                }
            }
    }
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    cin >> n >> m >> k;
    rep(i, 0, n)
        rep(j, 0, m)
            cin >> a[i][j];
    int x, y;
    rep(i, 0, n)
        rep(j, 0, m)
            if (a[i][j] == 'S')
            {
                x = i;
                y = j;
                a[i][j] = '.';
            }
    bfs(x, y);
    int ans = inf;
    rep(i, 0, n)
        rep(j, 0, m)
            if (d[i][j] <= k)
            {
                int len = min(min(i, n - i - 1), min(j, m - j - 1));
                ans = min(ans, 1 + (len + k - 1) / k);
            }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 505;

int N;
char mat[MAXN][MAXN];
int row[MAXN], col[MAXN];

void load() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%s", mat[i]);
}

int solve() {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      row[i] += mat[i][j] == '#';
      col[j] += mat[i][j] == '#';
    }
      
  if (!(*max_element(col, col + N)))
    return -1;
    
  int cnt = 0;
  for (int i = 0; i < N; i++)
    cnt += col[i] < N;
  
  int sol = N + 1;
  for (int i = 0; i < N; i++) 
    sol = min(sol, N - row[i] + !col[i]);
  
  return cnt + sol;
}

int main() {
  load();
  printf("%d\n", solve());
  return 0;
}

Measured memory_bytes: 384
n, t = map(int, input().split())
a = list(map(int, input().split()))
lowest = a[0]
highest = a[0]
baibai = []
for i in range(n):
    if lowest > a[i]:
        lowest = a[i]
    #print(highest, lowest)
    baibai.append(a[i]-lowest)

max_baibai = max(baibai)
ans = baibai.count(max_baibai)
#print(baibai)
print(ans)


Measured memory_bytes: 90864
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int H, W;
int d[10][10];

int main() {
	cin >> H >> W;
	REP(i, 10) REP(j, 10) scanf("%d", &d[i][j]);
	REP(k, 10) REP(i, 10) REP(j, 10) chmin(d[i][j], d[i][k] + d[k][j]);
	
	int ans = 0;
	REP(i, H) REP(j, W) {
		int a; scanf("%d", &a);
		if (a == -1) continue;
		ans += d[a][1];
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int N; cin >> N;
  int block[2], cnt = 0;
  for(int i = 1; i <= N; ++i) {
    cin >> block[0] >> block[1];
    cnt += block[1] - block[0] + 1;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
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 gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

    vector<int>x(5);
    rep(i,5)cin>>x[i];

    rep(i,5){
        if(x[i]==0)cout<<i<<endl;

        
    }

    
	
  
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    vector<int> num;
    for(int i=1;true;i++){
        int x;
        cin >> x;
        if(x == 0) break;
        cout << "Case " << i << ": " << x << endl;
    }
}


Measured memory_bytes: 3072
from heapq import heapify, heappush, heappop

def divisor(n):
    divisors = []
    i = 1
    while i * i <= n:
        if n % i == 0:
            divisors.append(i)
            if i != n / i:
                divisors.append(n // i)
        i += 1
    divisors.sort()
    return divisors


N, K = map(int, input().split())
A = list(map(int, input().split()))
divisors = divisor(sum(A))
for d in divisors[::-1]:
    heap = []
    s = 0
    for a in A:
        x = a // d * d - a
        heap.append(x)
        s += -x
    heapify(heap)
    n = 0
    for _ in range(s // d):
        x = heappop(heap)
        if x + d > K:
            break
        else:
            if x + d > 0:
                n += x + d
            heappush(heap, x + d)
    else:
        if sum(abs(x) for x in heap) <= 2 * K:
            print(d)
            exit()


Measured memory_bytes: 53980
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void){
   int n;
   cin >> n;
   string s;
   cin >> s;
   char moji[26];
   int count = 0;
   string a, b;
   int ans = 0;
   for(int i = 1; i <= s.length()-1; i++){
        a = s.substr(0, i);
        b = s.substr(i, s.length()-i);
        count = 0;
    int ca, cb;
        for(int k = 0; k < 26; k++){
            ca = 0; cb = 0;
            moji[k] = 'a'+k;
            for(int j = 0; j < a.length(); j++)
                if(moji[k]==a[j])
                    ca++;
            for(int j = 0; j < b.length(); j++)
                if(moji[k]==b[j])
                    cb++;
            if(ca>=1 && cb>=1)
                count++;
        }
        
       //cout << count << endl;
        ans = max(ans, count);
   }
   cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
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; }
//-------------------
int a,b,c;
int main(){
	cin >> a >> b >> c;
	if((a <= c && c <= b )||( b <= c && c <= a) ) cout << "Yes";
	else cout << "No";

    return 0;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
d = {(0, 0): 0, (1, 0): 0}
for i in range(n):
  d[i % 2, v[i]] = d.get((i % 2, v[i]), 0) + 1
to_sort = [[], []]
for i in d:
  to_sort[i[0]].append((d[i], i[1]))
to_sort[0].sort()
to_sort[1].sort()
if to_sort[0][-1][1] != to_sort[1][-1][1]:
  ans = n - to_sort[0][-1][0] - to_sort[1][-1][0]
else:
  ans = n - max(to_sort[0][-1][0] + to_sort[1][-2][0], to_sort[0][-2][0] + to_sort[1][-1][0])
print(ans)

Measured memory_bytes: 27484
/* **********************************************

    File Name: main.cpp

    Auther: zhengdongjian@tju.edu.cn

    Created Time: 2015/8/26 ????????? ?????? 1:42:58

*********************************************** */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX = 32;

struct Node {
	double a;
	double b;
	double c;
	double sq(double x)const {
		x = fabs(x);
		return x * x;
	}
	double dis(const Node& y)const {
		return sq(a - y.a) + sq(b - y.b) + sq(c - y.c);
	}
} color[MAX], vec[MAX];
istream& operator>>(istream& in, Node& n) {
	in >> n.a >> n.b >> n.c;
	return in;
}
bool vis[MAX];
int n, m;
double ans;

void dfs(int id, int now) {
	if (now == m) {
		int re = 0;
		for (int i = 0; i < n; ++i) {
			if (vis[i]) {
				vec[re++] = color[i];
			}
		}
		double tp = 0.0;
		for (int i = 0; i < re; ++i) {
			for (int j = i + 1; j < re; ++j) {
				tp += vec[i].dis(vec[j]);
			}
		}
		if (tp > ans) ans = tp;
		return;
	}
	if (id >= n) return;
	vis[id] = true;
	dfs(id + 1, now + 1);
	vis[id] = false;
	dfs(id + 1, now);
}

int main() {
	while (cin >> n >> m) {
		for (int i = 0; i < n; ++i) {
			cin >> color[i];
		}
		memset(vis, false, sizeof(vis));
		ans = 0.0;
		dfs(0, 0);
		cout << fixed << setprecision(10) << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1292
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
    int A, B, T;
    cin >> A >> B >> T;
    int cnt = 0;
    int k = 1;
    for(int i = 1; i <= T+0.5; i++) {
        if(i == k*A) {
            cnt += B;
            k++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 384
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!
function main(input) {
    var x = input.split(' ');
    var n = parseInt(x[0]);
    var a = parseInt(x[1]);
    var b = parseInt(x[2]);
    if(a * n > b){
        console.log(b);
    }
    else{
        console.log(a * n);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7628
package main

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

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b > 0 {
		a, b = b, a%b
	}
	return a
}

func primeFactorize(n int) [][2]int {
	var result [][2]int
	rn := int(math.Sqrt(float64(n)))
	for i := 2; i < rn+1; i++ {
		if n%i != 0 {
			continue
		}
		t := [2]int{i, 0}
		for n%i == 0 {
			n /= i
			t[1]++
		}
		result = append(result, t)
	}
	if n != 1 {
		result = append(result, [2]int{n, 1})
	}
	return result
}

func main() {
	A := readInt()
	B := readInt()

	fmt.Println(len(primeFactorize(gcd(A, B))) + 1)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>

#define N 15
using namespace std;

int n, m;
vector<int> v[N];
bool p[N], p2[N];

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

    int tmp, a;
    for (int i = 1; i <= m; ++i) {
        cin >> tmp;
        while (tmp--) {
            cin >> a;
            v[a].push_back(i);
        }
    }
    for (int i = 1; i <= m; ++i) {
        cin >> tmp;
        if (tmp == 1)
            p[i] = true;
        else
            p[i] = false;
    }

    int statue, ans = 0;
    for (statue = 0; statue < pow(2, n); ++statue) {
        for (int i = 1; i <= m; ++i)
            p2[i] = 0;
        tmp = statue;
        for (int i = 1; i <= n; ++i) {
            if (tmp % 2 == 1) {
                for (int j = 0; j < v[i].size(); ++j)
                    p2[v[i][j]] = !p2[v[i][j]];
            }
            tmp>>=1;
        }
        bool flag = true;
        for (int i = 1; i <= m; ++i) {
            if (p2[i] != p[i]){
            	flag = false;
            	break;
            }
        }
        if (flag){
        	ans++;
        //	cout << statue << endl;
        }
            
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T; cin >> T;

    vector<char> prev(K);
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        if (T[i] == prev[i % K]) {
            prev[i % K] = '\n';
            continue;
        }
        if (T[i] == 'r') ans += P;
        if (T[i] == 's') ans += R;
        if (T[i] == 'p') ans += S;
        prev[i % K] = T[i];
    }
    cout << ans << endl;

}


Measured memory_bytes: 512
S = input()

S = S[::-1]

T = ['dream','dreamer','erase','eraser']
for i in range(4):
    T[i] = T[i][::-1]

i = 0
flag = True
while i<len(S):
    for t in T:
        j = len(t)
        if S[i:i+j] == t:
            i += j
            break
            print(i)
    else:
        flag = False
        break

if flag:
    print('YES')
else:
    print('NO')




Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int p ,q ,r;
    
    cin >> p >> q >> r;

    if(p > q){
        if(p > r) cout << q + r << endl;
        else cout << p + q << endl;
    }else{
        if(q > r)cout << p + r << endl;
        else cout << p + q << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <climits>
#include <utility>

using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rep1(i,n) for(int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

int K,N;
int rui[2000100];

signed main()
{
	cin>>K>>N;
	vector<int> a(2*N+1);
	rep1(i,N)cin>>a[i];
	rep1(i,N)a[i+N]=a[i]+K;
	for (int i = 1; i <= 2 * N; ++i) {
		rui[i] += a[i]-a[i-1];
		rui[i] += rui[i-1];
	}

	int ans=LLONG_MAX/2;

	for (int i = 1; i <= N; ++i) {
		ans = min(ans, rui[i+N-1]-rui[i]);
	}
	cout<<ans<<endl;

	//rep(i,2*N)printf("%lld\n",a[i]);
}


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

using namespace std;

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

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

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

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

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

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

int main(){
  ll w,h;
  cin>>h>>w;
  ll ans = 1e18;
  if((h*w)%3==0){
    ans = 0;
  }else{
    CHMIN(ans,w);
    CHMIN(ans,h);
  }
  FOR(i,1,w){
    ll l = h*i;
    ll r = h*(w-i);
    ll ru = (h/2)*(w-i);
    ll rd = r-ru;
    CHMIN(ans,max({l,ru,rd})-min({l,ru,rd}));
  }
  swap(h,w);
  FOR(i,1,w){
    ll l = h*i;
    ll r = h*(w-i);
    ll ru = (h/2)*(w-i);
    ll rd = r-ru;
    CHMIN(ans,max({l,ru,rd})-min({l,ru,rd}));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define int long long
using namespace std;
 main()
{
    int a,i,b,j;
   cin>>a;
   int aa[a],bb[a],cc[a];
   cin>>aa[0]>>bb[0]>>cc[0];
   for(i=1;i<a;i++)
   {
       cin>>aa[i]>>bb[i]>>cc[i];
       aa[i]+=max(bb[i-1],cc[i-1]);
       bb[i]+=max(aa[i-1],cc[i-1]);
       cc[i]+=max(bb[i-1],aa[i-1]);
   }
   cout<<max(max(aa[a-1],bb[a-1]),cc[a-1])<<endl;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        String p = sc.next();
        sc.close();
        if(s.length()<p.length()){
            System.out.println("No");
        }else{
            s = s + s;
            if(s.contains(p)){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 26324
#include <string.h>
#include<stdio.h>
int main(void)
{
	int i,sum=0;
	char x[1001];
	scanf("%s",x);
	do{
		
		for(i=0;i<1001;i++){
			if(x[i]==0){
				printf("%d\n",sum);
				break;
			}else{
				sum+=x[i]-0x30;
			}
		}
		sum=0;
		scanf("%s",x);
	}while(x[0]!=0x30);

	return 0 ;
}

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

int main() {
  int N;
  cin >> N;
  int pos = 0;
  vector<int> A(N);
  for (int &e : A) {
    cin >> e;
    int p = 0;
    while(e % 2 == 0) {
      e /= 2;
      p += 1;
    }
    pos += p;
  }
  
  cout << pos << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}

template<typename T>
T gcd(T x, T y){
    if (x == 0 || y == 0) {
        return 0;
    }

    while (x != y){
        if (x > y) {
            x -= y;
        }else{
            y -= x;
        }
    }
    return x;
}

// }}}
/* vim:set foldmethod=marker: */

void solve(){
    int a,b,c;
    cin >> a >> b >> c;

    if (a <= c && c <= b) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


// map の key, value を全て抜き出す。
// for (auto itr = mp.begin(); itr != mp.end(); itr++) {
//     cout << "key" << itr->first << " value" << itr->second << endl;
// }

// 文字列の検索
// string s="abc";
// if (s.find('d') == string::npos){
//     cout << "find" << endl;
// }else{
//     cout << "not find" << endl;
// }


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] params = sc.nextLine().split(" ");
        int n = Integer.parseInt( params[0] );
        int k = Integer.parseInt( params[1] );

        params = sc.nextLine().split(" ");
        long[] hs = new long[n];
        for( int i = 0 ; i < n ; i++ ){
            hs[i] = Long.parseLong( params[i] );
        }

        Arrays.sort(hs);

        if( n <= k ){
            System.out.println( 0 );
            return;
        }

        long ans = 0;
        for( int i = 0 ; i < n - k ; i++ ){
            ans += hs[i];
        }

        System.out.println( ans );

    }

}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  int N;
  cin>>N;
  llvec A(N, 0);
  rep(i, N){
    ll tmp; cin >> tmp;
    A[tmp-1]=i+1;
  }

  DUMP(i, A);
  return 0;
}


Measured memory_bytes: 1536
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)

import numpy as np
cum=list(np.cumsum(a))

cnt=0
for i in range(n-1,-1,-1):
    if i==n-1:
        cnt+=1
        continue

    if 2*cum[i]>=a[i+1]:
        cnt+=1
    else:
        break

print(cnt) 



Measured memory_bytes: 35548
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define prsp(v) loop(i,0,v.size())cout<<v[i],sp;nl;
#define prpsp(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S,sp;nl;
#define prnl(v) loop(i,0,v.size())cout<<v[i],nl;nl;
#define prpnl(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S,nl;nl;
#define MOD 1000000007
#define mod(n) (((n%MOD)+MOD)%MOD)
#define all(x) x.begin(),x.end()

const int N = 1e5+5;

int main() 
{
    fastio();

    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    int sm[n]={},cum[n+1]={};
    loop(i,0,n-1)
    {
        if( s[i]=='A' && s[i+1]=='C' )
            sm[i]++;
    }
    loop(i,0,n)
    {
        cum[i+1] = cum[i] + sm[i];
        // cout<<cum[i+1]<<" ";
    }

    loop(i,0,q)
    {
        int l,r;
        cin>>l>>r;
        ll ans = cum[r] - cum[l-1];
        ans -= ( sm[r-1] == 1 );
        // ans -= ( sm[l] == 1 );
        cout<<ans,nl;
    }


    return 0;
}

Measured memory_bytes: 1872
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> dp, arr;
vector<int> adj[200001];
int ans[200001];
void dfs(int i, int p) {
	auto it = lower_bound(dp.begin(), dp.end(), arr[i]);
	int rec = *it;
	*it = arr[i];
	ans[i] = lower_bound(dp.begin(), dp.end(), INT_MAX) - dp.begin() - 1;
	for(int a: adj[i]) {
		if(a != p)
			dfs(a, i);
	}
	*it = rec;
}
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	dp = arr = vector<int>(n+1);
	fill(dp.begin(), dp.end(), INT_MAX);
	dp[0] = 0;
	for(int i=1; i<=n; i++) {
		cin >> arr[i];
	}
	for(int i=0; i<n-1; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1, 0);
	for(int i=1; i<=n; i++) {
		cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 30296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
ll add(ll a,ll b){ return (a+b)%mod; }
ll mul(ll a,ll b){ return (a*b)%mod; }

typedef vector<ll> vec;

int n;
vector<int> G[205];


ll dp[205][205][205];

void init(){
  dp[0][0][0]=1;
  for(int i=0;i<=200;i++){
    for(int j=0;j<=200;j++){
      for(int k=0;k<=200;k++){
        ll num=dp[i][j][k];
        
        dp[i+1][j][k]=add(dp[i+1][j][k],num);
        
        dp[i][j+1][k]=add(dp[i][j+1][k],num);
        
        dp[i+1][j+1][k+1]=add(dp[i+1][j+1][k+1],num);
      }
    }
  }

}

vec calc(vec a,vec b){
  
  vec res( a.size()+b.size()-1 );
  for(int i=1;i<(int)a.size();i++){
    for(int j=1;j<(int)b.size();j++){
      for(int k=0;k<=min(i,j);k++){
        ll key=mul(a[i],b[j]);
        res[i+j-k]=add(res[i+j-k],  mul(dp[i][j][k],key) );
      }
    }
  }
  return res;
}

vec update(vec a){
  a.insert(a.begin()+1,0);
  return a;
}


vec solve(int pos){
  
  if(G[pos].empty()){
    vec res(2,0);
    res[1]=1;
    return res;
  }
  
  vec res=solve(G[pos][0]);
  for(int i=1;i<(int)G[pos].size();i++){
    res=calc(res, solve(G[pos][i]) );
  }

  return update(res);
}

int par[205];
int main(){
  memset(par,-1,sizeof(par));
  
  init();
  
  cin>>n;

  
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    G[a].push_back(b);
    par[b]=a;
  }
  vec ans;
  
  for(int i=0;i<n;i++)
    if(par[i]==-1)ans=solve(i);
  
  ll sum=0;
  for(int i=0;i<(int)ans.size();i++){
    sum=add(sum,ans[i]);
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 67560
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	string s, t, u;
	cin >> s >> t >> a >> b >> u;
	a -= (s==u);
	b -= (t==u);
	cout << a << " " << b << "\n";
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n=int(input())
x=list(map(int,input().split()))
p=[0]*100
y=[0]*n
i=0
j=0
while i<100:
  def ppp(q):
    return (q-i)*(q-i)
  y=list(map(ppp,x))
  p[i]=np.sum(y)   
  i=i+1
r=min(p)
print(r)

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

#define ll long long
#define N 200010
ll p = (ll)1e9 + 7;
int n, m, c[N];
ll f[N], g[N];
void up(ll &x) { if (x >= p) x -= p; }

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) 
			scanf("%d", c + i);
		memset(g, 0, sizeof g);
		m = 1;
		for (int i = 2; i <= n; ++i)
			if (c[i] != c[i - 1])
				c[++m] = c[i];
		f[1] = 1; g[c[1]] = 1;
		for (int i = 2; i <= m; ++i)
		{
			f[i] = (f[i - 1] + g[c[i]]) % p;
			up(g[c[i]] += f[i - 1]);
		}
		printf("%lld\n", f[m]);
	}
	return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> ans;
vector<vector<int>> tree;
vector<ll> a;
ll N; 
const ll INF =ll(1e18) +5;
const ll MAXN = 2*(1e5) +5;
ll dp[MAXN];

void dfs(int t,int p){
    int i = lower_bound(dp, dp+MAXN, a[t]) - dp;
    //cerr << "t=" << t <<"i=" <<i << endl;
    ll old = dp[i];
    dp[i] = a[t];
    ans[t] = i;
    if(p>=0){
         ans[t] = max(ans[t],ans[p]);
    }
   
    // cerr << "ans=" <<ans[t] << endl;
   
    for(int child:tree[t]){
        if(child ==p){
            continue;
        }
        dfs(child,t);
    }
    dp[i] = old;
}


int main(){
    scanf("%lld",&N);
    ans.resize(N);
    a.resize(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    tree.resize(N);
    // cerr <<"a"  << endl;
    for(int i = 0 ; i < N-1 ; i++){
        int u,v;
        cin >> u >>v;
        --u;--v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    for(ll i=0;i<MAXN;i++){
        dp[i] = INF;
    }
    // cerr <<"do dfs" << endl;
    dp[0] = -INF;
    dfs(0,-1);
    for(int i=0;i<N;i++){
        cout << ans[i] << endl;
    }
    return 0;
}


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

typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int MID = 1e5 + 3;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

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

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

int main() {
  ll n,d; cin>>n>>d;
  vector<vector<ll>> pos(n,vector<ll>(2,0));
  for(int i=0; i<n; i++) cin>>pos[i][0]>>pos[i][1];
  // D<=sqrt(pos[i][0]^2+pos[i][1]^2)
  // ピタゴラスですね
  int ans=0;
  for(auto v:pos) {
    if(pow(d,2)>=pow(v[0],2)+pow(v[1],2)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 14344
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;cin>>n;
	ll s=100,c=0;
	while(s<n){
		c++;
		s=s+(s/100);
	}
	cout<<c;
	return 0;
} 

Measured memory_bytes: 3648
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CChristmasEve {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints(), k = in.ints();
            int[] h = in.ints(n);
            Arrays.sort(h);
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i <= n - k; i++) {
                ans = Math.min(ans, h[i + k - 1] - h[i]);
            }
            out.println(ans);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

        public int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

    }
}



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

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

ll dp[3001][3001];

int main() {
  string s, t;
  int k = 0;
  cin >> s >> t;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 0; j < t.size(); ++j) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
    }
  }

  string res = "";
  int i = (int)s.size(), j = (int)t.size();
  while (i > 0 && j > 0) {
    if (dp[i][j] == dp[i - 1][j])
      --i;
    else if (dp[i][j] == dp[i][j - 1])
      --j;
    else
      res = s[--i] + res, --j;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 73940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define ll long long int 
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define P(x) printf("%d\n",(x))
#define Sl(x) scanf("%lld",&(x))
#define Pl(x) printf("%lld\n",(x))
#define pb push_back
#define f first
#define s second

ll dp[1003][1003] ;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m ; cin >> n >> m ;
	char a[1003][1003] ;
	for(int i = 1; i <= n ; i++){
		for(int j = 1; j <= m ; j++){
			cin >> a[i][j];
		}
	}
	dp[1][1] = 1 ;
	for(int i = 1; i <= n ; i++){
		for(int j = 1; j <= m ; j++){

			if( i == 1 && j==1)continue ;

			if(a[i][j] == '.'){

				if(j == 1) {
					dp[i][j] = dp[i-1][j] ;
				}
				else if ( i == 1){
					dp[i][j] = dp[i][j-1] ;
				}
				else{
					dp[i][j] = (dp[i][j-1]+dp[i-1][j])%mod ;
				}

			}
			else{
				dp[i][j] = 0;
			}

			//cout <<dp[i][j] << " " ;

		}
		//cout << "\n" ;
	}
	cout << dp[n][m] ;
  	return 0;
}

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

int main() {
  int n, k, q, t;
  cin >> n >> k >> q;
  vector<int> a(n);
  rep(i,n) a.at(i)=k-q;
  rep(i, q){
    cin >> t;
    ++a.at(t-1);
  }
  rep(i,n){
   if(a.at(i)>0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	char dic[100000][2]={};
	char m[100000]={};
	int i=0,ii=0,j=0;
	int foo=1;
	int n,mn;
	unsigned char tem,memo;
	while(ii<5){
	cin>>n;
	if(n==0)break;
	for(i=0;i<n;i++){
		for(j=0;j<2;j++){
			cin>>dic[i][j];
		}
	}
	//cout<<dic[1][0]<<dic[1][1]<<endl;
	cin>>mn;
	for(i=0;i<mn;i++){
		cin>>m[i];
	}
	for(i=0;i<mn;i++){
			for(j=0;j<n;j++){
		    
				if(m[i]==dic[j][0]){
					m[i]=dic[j][1];
					foo=1;
			}
			if(foo==1)break;
		}
			foo=0;
		}
	for(i=0;i<mn;i++){
		cout<<m[i];
	}
	cout<<endl;
	//foo=0;
	ii++;
	}
	return 0;
}

Measured memory_bytes: 3276