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

int min(int a, int b){
    if(a>=b){
        return b;
    }else{
        return a;
    }
}

int main (){
    int a, b, c, d;
    cin>> a >> b >> c >>d;
    cout << min(a,b)+min(c,d);
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[x for x in A if x>=0]
C=[x for x in A if x<0]
ans=[]
if B and C:
    P=B.pop()
    M=C.pop()
    for x in B:
        ans.append((M,x))
        M-=x
    for x in C:
        ans.append((P,x))
        P-=x
    ans.append((P,M))
    P-=M
    print(P)
    for row in ans:
        print(*row)
elif B:
    M=B[0]
    P=B.pop()
    for x in B[1:]:
        ans.append((M,x))
        M-=x
    ans.append((P,M))
    P-=M
    print(P)
    for row in ans:
        print(*row)
else:
    P=C.pop()
    for x in C:
        ans.append((P,x))
        P-=x
    print(P)
    for row in ans:
        print(*row)

Measured memory_bytes: 63036
<?php
fscanf(STDIN,'%d%d',$A,$B);
$S=fgets(STDIN);
$count=0;
for ($i=0; $i <=$A-1 ; $i++) {
  // code...
  if(ctype_digit($S[$i])){
    $count++;
  }
}
for ($i=$A+1; $i <=$A+$B ; $i++) {
  // code...
  if(ctype_digit($S[$i])){
    $count++;
  }
}
if($S[$A]=='-'){
  $count++;
}
if($count==$A+$B+1){
  echo 'Yes';
}else{
  echo 'No';
}



 ?>


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

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define ALL(x) (x).begin(),(x).end()

int main () {
  int n, d, i;
  vector<int> ds;

  cin >> n;
  REP(i, n){
    cin >> d;
    ds.push_back(d);
  }

  sort(ALL(ds));

  for(i = 0; i < (ds[(n/2)] - ds[(n/2)-1]); i++) {}

  cout << i << endl;
  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long INF = MOD*MOD;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k,ans;
string s,t;

int main(){
	int a,b,c;cin >> a >> b >> c;
	if(a+b+c >= 22) cout << "bust\n";
	else cout << "win\n";
}

Measured memory_bytes: 256
a, b, c, x = [int(input()) for _ in range(4)]

def enable_pay(target, coin, n):
    if 0 <= target // coin <= n:
        return True
    return False

count = 0
for a_n in range(0, a+1)[::-1]:
    for b_n in range(0, b+1)[::-1]:
        s = (500 * a_n) + (100 * b_n)
        if enable_pay(x-s, 50, c):
            count += 1
print(count)

Measured memory_bytes: 3064
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                while (true) {
                        int N = sc.nextInt(), M = sc.nextInt();
                        if (N == 0 && M == 0) {
                                break;
                        }
                        int[] D = new int[N];
                        int[] Ms = new int[M];
                        for (int i = 0; i < N; i++) {
                                D[i] = sc.nextInt();
                        }
                        int now = 0;
                        boolean f = true;
                        for (int i = 0; i < M; i++) {
                                now += sc.nextInt();
                                if (f) {
                                        if (now < N - 1 && D[now] != 0) {
                                                now += D[now];
                                        }
                                        if (now >= N - 1) {
                                                System.out.println(i + 1);
                                                f=false;
                                        }
                                }
                        }
                }
        }
}

Measured memory_bytes: 35812
import java.io.*;
import java.util.*;

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int N, M;
        {int[] a = in.ii(); N = a[0]; M = a[1];}
        ArrayList<int[]> list = new ArrayList<>();
        for(int i = 0; i < N; i++){
            list.add(in.ii());
        }
        list.sort((x, y) -> x[0]-y[0]);
        list.add(new int[]{M+1, 0});
        
        long ans = 0;
        PriorityQueue<Integer> q = new PriorityQueue<>((x, y) -> -x+y);
        for(int i = 1, j = 0; i <= M; i++){
            while(list.get(j)[0] == i){
                q.add(list.get(j)[1]);
                j++;
            }
            Integer tmp = q.poll();
            ans += tmp == null ? 0 : tmp;
        }
        out.println(ans);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        ArrayList<Integer> li(){
            String[] ss = ss();
            ArrayList<Integer> li = new ArrayList<>();
            for(int j = 0; j < ss.length; j++) li.add(Integer.parseInt(ss[j]));
            return li;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 49832
gets;
S,*f='? '+?0*N=200;
*A=?!;
N.times{|i|S[i+2]=?1;i.times{|j|
S[j+2]=?1;
puts S;
S[j+2]=?0;
f<<->{gets=="1
"&&A<<" (#{i},#{j})"}
};S[i+2]=?0};
$>.flush;f.map &:call;
print *A

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])
typedef long long ll;

int main() {
    int N;
    cin >> N;
    std::set<int> s;
    bool b = true;
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        auto itr = s.find(A);
        if(itr != s.end()){
            b = false;
            break;
        } else {
            s.insert(A);
        }
    }
    if(b){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


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

int main() {
  int N,M;
  cin >> N >> M;
  int l = 0;
  if (N < M) {
    vector<int> X(M);
    for (int i = 0; i < M; i++) cin >> X.at(i);
  
    sort(X.begin(),X.end()); 
    vector<int> D(M-1);
    for (int i = 0; i < M-1; i++) D.at(i) = X.at(i+1) - X.at(i);
    sort(D.begin(),D.end());
    for (int i = 0;i < M-N; i++) l += D.at(i);
  }
  
  cout << l << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

long long XOR(long long N){
  if(N == -1) return 0;
  if(N%4 == 1) return 1;
  if(N%4 == 2) return 1^N;
  if(N%4 == 3) return 0;
  return N;
}

int main(void){
  long long A,B;
  scanf("%lld%lld",&A,&B);

  printf("%lld\n",XOR(A-1)^XOR(B));

  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Work {
  int begin, end, pos;
  Work(int s, int t, int x) {
    begin = s;
    end   = t;
    pos   = x;
  }
  bool operator<(const Work& another) const {
    return pos < another.pos;
  }
  bool operator>(const Work& another) const {
    return pos > another.pos;
  }
};

struct Event {
  int time, pos, mode;
  Event(int a, int b, int c) {
    time = a;
    mode = b;
    pos  = c;
  }
  bool operator<(const Event& another) const {
    if (time == another.time) {
      return mode < another.mode;
    } else {
      return time < another.time;
    }
  }
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  std::vector<Work> work;
  for (int i = 0; i < n; i++) {
    int s, t, x;
    cin >> s >> t >> x;
    work.push_back(Work(s, t, x));
  }

  std::vector<int> query;
  for (int i = 0; i < q; i++) {
    int d;
    cin >> d;
    query.push_back(d);
  }
  std::sort(query.begin(), query.end());

  std::vector<Event> event;
  for (auto w : work) {
    event.push_back(Event(w.begin - w.pos, 1, w.pos));
    event.push_back(Event(w.end - w.pos, 0, w.pos));
  }

  std::sort(event.begin(), event.end());
  std::set<int> closed;
  int qi = 0;
  for (int ei = 0; ei < event.size(); ei++) {
    Event e = event[ei];

    if (e.mode == 1) {
      closed.insert(e.pos);
    } else {
      assert(closed.find(e.pos) != closed.end());
      closed.erase(e.pos);
    }
    if (ei == event.size() - 1 || e.time != event[ei + 1].time) {
      //クエリ全部処理した||ある時間のクエリは全部処理した
      while ((ei == event.size() - 1 && qi < q) ||
             (ei != event.size() - 1 && qi < q &&
              query[qi] <= event[ei + 1].time - 1)) {
        if (closed.empty()) {
          cout << -1 << endl;
        } else {
          cout << *(closed.begin()) << endl;
        }
        qi++;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 18412
#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;

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;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int N = 1 << 19;  // limit for array size
int n;  // array size
PII t[2 * N];

void modify(int p, int value) {  // set value at position p
	int pos = p;
	for (t[p += n] = MP(value,pos); p > 1; p >>= 1) t[p >> 1] = max(t[p], t[p ^ 1]);
}

PII query(int l, int r) {  // max on interval [l, r)
	PII res(-1, -1);
	for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
		if (l & 1) res = max(res, t[l++]);
		if (r & 1) res = max(res, t[--r]);
	}

	return res;
}

int main()
{
	int N;
	scanf("%d", &N);
	vector<int> V;

	int M = 1 << N;

	REP(i, M)
	{
		int S;
		scanf("%d", &S);
		V.push_back(S);
	}
	sort(V.begin(), V.end());
	reverse(V.begin(), V.end());

	// do drzewa przedzialowego
	n = M;
	modify(0, N);

	// pierwsze wystapienia
	map<int, int> Mp;
	Mp[V.front()] = 0;

	FOR(i, 1, M)
	{
		// znajdz max wartosc slotow dla potencjalnych rodzicow (wartosci > akt)

		if (Mp.find(V[i]) == Mp.end())
			Mp[V[i]] = i;

		int	pos = Mp[V[i]];

		auto mx = query(0, pos);

		int tmp = mx.first - 1;

		if (tmp < 0)
		{
			printf("No\n");
			return 0;
		}

		// zmien stara wartosc
		modify(mx.second, tmp);

		// zobacz, czy mozesz dodac nowa
		if (tmp)
			modify(i, tmp);
	}

	printf("Yes\n");

	return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

//#include <Processthreadsapi.h>
//#include <iostream>
//#include <Synchapi.h>
//#include <windows.h>
//#include <process.h>
//
//DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//    main2(nullptr);
//    return 0;
//}
//int main() {
//    auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
//    WaitForSingleObject(h, INFINITE);
//}


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

using namespace std;

const int mod = 1e9 + 7;

long long add(long long a, long long b) {
    long long res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

long long sub(long long a, long long b) {
    long long res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

long long mul(long long a, long long b) {
    return (((a % mod) * (b % mod)) % mod);
}

long long potolok(long long a, long long b){   // ���������� ����� ��� �����
    return (a + b - 1) / b;
}


long long gcd(long long x, long long y){
    if(y == 0){
        return x;
    }
    if(x > y){
         return gcd(y, x % y);
    }
    else{
         return gcd(x, y % x);
    }
}

bool cmpr(int x, int y){            // ���������� �� ���������� ��������
    if(abs(x) < abs(y)) return true;
    else{
        return false;
    }
}

bool comp(pair<int, int> x, pair<int, int> y){  // ���������� �� ������ ����������
    if(x.first < y.first)return true;
    else if(x.first == y.first){
        if(x.second < y.second)return true;
        else return false;
    }
    else{
        return false;
    }
}

int main(){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long tmp1 = a * c, tmp2 = a * d, tmp3 = b * c, tmp4 = b * d;
    vector<long long> v;
    v.push_back(tmp1);
    v.push_back(tmp2);
    v.push_back(tmp3);
    v.push_back(tmp4);
    cout << *max_element(v.begin(), v.end()) << endl;
 }


Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
//#include <windows.h>
#include <algorithm>
#include <cstdio>
#include <list>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF 1000000007
using namespace std;
typedef long long LL;
//typedef pair<int,int> P;
//typedef priority_queue<P, vector<P>, greater<P> > minPQ;
struct edge {int to,cost;};
//const int SIZE = 1<<18;

int main() {
	int K,S;
	cin >> K >> S;
	LL cnt = 0;
	REP(i,K+1) {
		REP(j,K+1) {
			if(S-(i+j)>=0 && S-(i+j)<=K) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    array<int, 3> A, B;

    cin >> N;
    cin >> A[0] >> A[1] >> A[2];
    cin >> B[0] >> B[1] >> B[2];

    // maximize our capital upon arriving to B
    int BC = 0;
    for (int g = 0; g * A[0] <= N; g++) {
        for (int s = 0; g * A[0] + s * A[1] <= N; s++) {
            int b = (N - g * A[0] - s * A[1]) / A[2];

            int diff = max(0, g * (B[0] - A[0]))
                     + max(0, s * (B[1] - A[1]))
                     + max(0, b * (B[2] - A[2]));
            BC = max(BC, N + diff);
        }
    }

    // BC up to 2.5e7
    assert(BC < 3e7);

    vll dp(BC + 1);
    dp[0] = 0;
    for (int a = 1; a <= BC; a++) {
        dp[a] = a;
        for (int t = 0; t < 3; t++)
            if (a >= B[t]) dp[a] = max(dp[a], dp[a - B[t]] + A[t]);
    }

    cout << dp.back() << endl;

    return 0;
}



Measured memory_bytes: 195584
#include <stdio.h>


int main(void){
	int h,w,n,i;
	scanf("%d %d",&h,&w);
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++){scanf("%d",&a[i]);}
	int index=w*h;
	int c[index];//i+j*w

	int sum=0;
	int temp=0;
	for(i=0;i<n;i++){
		for(int j=sum;j<sum+a[i];j++){
			if(j/w%2==0){
				c[j]=i;
			}
			else{temp=(j/w)*w+w-1-(j-(j/w)*w);
				c[temp]=i;}
		}
		sum+=a[i];
	}
	
	for(int j=0;j<h;j++){
		for(i=0;i<w;i++){
			temp=j*w+i;
			printf("%d ", c[temp]+1);
		}
		printf("\n");
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int DP[10001][101];
int main() {
	int N, W;
	cin >> N >> W;
	int  v[100], w[100];
	for (int i = 0; i < N; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i = 1; i <= W; i++) {
		for (int j = 1; j <= N; j++) {
			if (i - w[j - 1] < 0) {
				DP[i][j] = DP[i][j - 1];
			}
			else {
				DP[i][j] = max(DP[i][j - 1], DP[i - w[j - 1]][j] + v[j - 1]);
			}
		}
	}
	cout << DP[W][N] << endl;
	cin >> N;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll ab = 0;
    ll a = 0, b = 0, a2 = 0;
    cin >> N;
    rep(i, N) {
        string s;
        cin >> s;
        if(s.front() == 'B' && s.back() == 'A') a2++;
        else if(s.front() == 'B') b++;
        else if(s.back() == 'A') a++;
        rep2(i, 1, s.size()) {
            if(s[i - 1] == 'A' && s[i] == 'B') ab++;
        }
    }
    ll ans = ab + min(a, b);
    if(a + b == 0) ans += max(0LL, a2 - 1);
    else ans += a2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    l.push_back(INF);
    sort(ALL(l));

    int ans = 0;
    rep(i, n){
        for(int j = i + 1; j < n; j++){
            int pos = lower_bound(ALL(l), l[i] + l[j]) - l.begin();
            ans += pos - j - 1;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
S = input()
L = len(S)

INF = float('inf')
dp = [[INF]*2 for _ in range(L)]
dp[0][0] = int(S[-1])
dp[0][1] = 10-int(S[-1])
S = S[::-1]
for i,c in enumerate(S[1:]):
    c = int(c)
    d = 10-c
    dp[i+1][0] = min(dp[i+1][0], dp[i][0]+c)
    dp[i+1][1] = min(dp[i+1][1], dp[i][0]+d)
    c += 1
    d -= 1
    if c==10:
        dp[i+1][1] = min(dp[i+1][1], dp[i][1])
    else:
        dp[i+1][0] = min(dp[i+1][0], dp[i][1]+c)
        dp[i+1][1] = min(dp[i+1][1], dp[i][1]+d)
print(min(dp[-1][0], dp[-1][1]+1))

Measured memory_bytes: 207000
while True:
	n=int(input())
	if n==0:
		break
	A=[]
	for i in range(n):
		x=int(input())
		A.append(x)

	B=[int()]*n
	B[0]=A[0]
	for i in range(1,n):
		if A[i]>=A[i]+B[i-1]:
			B[i]=A[i]
		else:
			B[i]=A[i]+B[i-1]
	print(max(B))

Measured memory_bytes: 7796
#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } }
// macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    let (a, b) = readl!(i32, i32);
    if a <= b {
        println!("{}", a);
    } else {
        println!("{}", a-1);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>

using namespace std;

const int MAX_N=1e5+1;

int data[MAX_N];

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>data[i];
	sort(data,data+n);
	reverse(data,data+n);
	int t=0;
	for(int i=0;i<n;i++)if(data[i]-i>0)t=i;
	if((data[t]-t)%2==0){
		cout<<"First"<<endl;
	}
	else{
		int cnt=0;
		for(int i=t;i<n;i++){
			if(data[i]-t>0)cnt++;
		}
		if(cnt%2==0){
			cout<<"First"<<endl;
		}
		else cout<<"Second"<<endl;
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

bool cmp(pint a, pint b) {return a.second < b.second;}
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    ll ans = 0;
    rep(i, n - 1) {
        ans += (i+1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

vector<ll> to[1000], from[1000];
ll dist[1000][1000];
vector<bool> r1(1000, false), rn(1000, false);

void dfs1(ll v){
  if(r1[v]) return;
  r1[v] = true;
  for(ll u : to[v]){
    dfs1(u);
  }
}

void dfsn(ll v){
  if(rn[v]) return;
  rn[v] = true;
  for(ll u : from[v]){
    dfsn(u);
  }
} 

int main(void){
  ll n, m;
  cin >> n >> m;
  REP(i, m){
    ll a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    to[a].emplace_back(b);
    from[b].emplace_back(a);
    dist[a][b] = -c;
  }
  dfs1(0);
  dfsn(n-1);
  vector<bool> ok(n, false);
  REP(i, n) ok[i] = r1[i] && rn[i];
  vector<ll> d(n, 1ll<<60);
  d[0] = 0;
  bool upd;
  REP(i, n){
    upd = false;
    REP(v, n){
      if(!ok[v]) continue;
      for(ll u : to[v]){
        if(!ok[u]) continue;
        if(d[v] + dist[v][u] < d[u]){
          d[u] = d[v] + dist[v][u];
          upd = true;
        }
      }
    }
    if(!upd) break;
  }
  if(upd) cout << "inf" << endl;
  else cout << -d[n-1] << endl;
  return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define maxn 120000 
using namespace std;
typedef long long LL;
LL M; 
vector<int> G[maxn];
LL up[maxn], down[maxn];
void DFS_down(int u, int fa = 0){
	down[u] = 1;
	for(int v : G[u]) if(v != fa){
		DFS_down(v, u);
		down[u] = down[u] * (1 + down[v]) % M;
	}
}
void DFS_up(int u, int fa = 0){
	for(int v : G[u]) if(v != fa) up[v] = up[u];
	LL pre = 1;
	for(int v : G[u]) if(v != fa){
		up[v] = up[v] * pre % M;
		pre = pre * (down[v] + 1) % M;
	}
	LL suf = 1;
	reverse(G[u].begin(), G[u].end());
	for(int v : G[u]) if(v != fa){
		up[v] = up[v] * suf % M;
		suf = suf * (down[v] + 1) % M;
	}
	for(int v : G[u]) if(v != fa){
		up[v] = (up[v] + 1) % M;
		DFS_up(v, u);
	}
}
int main(){
	ios::sync_with_stdio(false);
	int N;
	cin >> N >> M;
	for(int i = 1; i < N; i += 1){
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	DFS_down(1);
	DFS_up(up[1] = 1);
	for(int i = 1; i <= N; i += 1) cout << down[i] * up[i] % M << endl;
}

Measured memory_bytes: 13184
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 1234567;
int a[123][123];


int main() {
    long long x;
    cin>>x;
    for (int i=-1000;i<=1000;i++)
    for (int j=-1000;j<=1000;j++) {
        long long a=1ll*i*i*i*i*i;
        long long b=1ll*j*j*j*j*j;
        if (a-b==x) {
            cout<<i<<" "<<j;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    if(m>n){
        for(int i=0;i<m;i++){
            cout<<n;
        }
    cout<<endl;
    }
    else{
        for(int i=0;i<n;i++){
            cout<<m;
        }
        cout<<endl;
    }
    return 0;
}


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

int main(){
  int x,n;
  cin >> x >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  vector<vector<int>> a(102,vector<int>(2));
  for(int i=0;i<102;i++){
    a.at(i).at(0)=i;
    a.at(i).at(1)=i;
  }
  for(int i=0;i<n;i++){
    a.at(p.at(i)).at(1)=0;
  }
  for(int i=0;i<102;i++){
    a.at(i).at(0)=abs(x-a.at(i).at(1));
  }
  sort(a.begin(),a.end());
  cout << a.at(0).at(1) << endl;
}

Measured memory_bytes: 3644
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        x: [usize;n],
    }

    let mut x_tmp: Vec<usize> = x.clone();
    x_tmp.sort();
    let m1 = x_tmp[n/2-1];
    let m2 = x_tmp[n/2];
    for i in 0..n {
        if x[i]<m2 {
            println!("{}",m2);
        } else {
            println!("{}",m1);
        }
    }

}


Measured memory_bytes: 7716
#include<iostream>
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
using namespace std;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}

int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll arr[n+1];
		rep(i,1,n+1)
		cin>>arr[i];
		ll dp[n+1];
		dp[1]=0;
		dp[2]=abs(arr[2]-arr[1]);
		for(ll i=3;i<=n;i++)
		{
			dp[i]= min( dp[i-1] + abs(arr[i]-arr[i-1]), dp[i-2] + abs(arr[i]-arr[i-2]));
			
			//cout<<i<<" "<<dp[i]<<endl;
		}
		cout<<dp[n];
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 1792
// Created by ...Lusifer
#include<bits/stdc++.h>
using namespace std;
 
#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
	int n;
	cin>>n;
	int T[n+1];
	ll sum=0;
	for(int i=1;i<=n;i++){
		cin>>T[i];
		sum+=T[i];
	}
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int p,x;
		cin>>p>>x;
		cout<<sum-T[p]+x<<endl;
	}
	
	return ;
}
 
int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();
 
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int X, Y;
int a[2010];
int n, z, w;
PII  dp[2010][2010];

signed main(void)
{
  cin >> n >> z >> w;
  REP(i, n) cin >> a[i];

  if(n == 1) {
    cout << abs(w-a[0]) << endl;
  } else {
    cout << max(abs(w-a[n-1]), abs(a[n-2]-a[n-1])) << endl;
  }

  return 0;
}


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

string in;
//char in[120];
pair<pair<string,int>,int> p[110];

int main(){
  int a;
  cin >> a;
  for(int i=0;i<a;i++){
    int t;
    cin >> in >> t;
    //scanf("%s%d",in,&t);
    p[i]=make_pair(make_pair(in,-t),i);
  }
  sort(p,p+a);
  for(int i=0;i<a;i++){
    printf("%d\n",p[i].second+1);
  }
}


Measured memory_bytes: 256
#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 pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

const int dx[]={-1,0,1,1};
const int dy[]={1,1,1,0};
int dfs(int t[5][4],int cnt){
    int ret=cnt;
    rep(i,cnt)rep(j,4){
        int x=i%4,y=i/4;
        int tx=x+dx[j],ty=y+dy[j];
        if(tx>=0&&tx<4&&ty<5&&ty*4+tx<cnt&&t[y][x]==t[ty][tx]){
            int nt[5][4],c=0;
            rep(k,cnt){
                int kx=(k-c)%4,ky=(k-c)/4;
                int lx=k%4,ly=k/4;
                if(lx==x&&ly==y||lx==tx&&ly==ty){
                    ++c;continue;
                }
                nt[ky][kx]=t[ly][lx];
            }
            int a=dfs(nt,cnt-2);
            ret=min(a,ret);
            if(ret==0) return 0;
        }
    }
    return ret;
}
int main(){
    int n,tbl[5][4];
    cin>>n;
    while(n--){
        rep(i,5)rep(j,4) cin>>tbl[i][j];
        cout<<dfs(tbl,20)<<endl;
    }
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int maxv=0;
    int x=0;
    rep(i,n){
        if(s[i]=='I') x+=1;
        else x-=1;
        maxv=max(maxv,x);
    }

    cout<<maxv<<"\n";
    return 0;
}

Measured memory_bytes: 3640
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res="";
		//int res = 0; ;
		//int t = int.Parse(Console.ReadLine());
		//string str = Console.ReadLine();
		int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = int.Parse(Console.ReadLine());

		//int num = vals[0];


		int res = 0;

		int x = vals[2] - vals[0];
		int y = vals[3] - vals[1];
		int x3 = vals[2]-y;
		int y3 = vals[3]+x;
		int x4 = x3 - x;
		int y4 = y3 - y;

		Console.WriteLine(x3+" "+y3+" "+x4+" "+y4);

		return;
	}


	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); }
		return nums;
	}
	
	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
		return re;
	}

}

Measured memory_bytes: 11092
#include <stdio.h>
#include <string.h>

int main(void){
	int p, sum, d, e, f, s, m, n, i, j, x, max_i;
	double tmp1, eff[50];  
	char str[50][21], C, tmp2[21];
	while(1){
		scanf("%d%*c",&n);
		if(n == 0)
			break;
		for(i = 0;i < n;i++){ 
			j = 0;           
			while((C = getchar()) != ' ')      
				str[i][j++] = C;            
			str[i][j] = '\0';
			scanf("%d",&p); 
			sum = 0;     
			for(j = 0;j < 3;j++){   
				scanf("%d",&x);          
				sum += x;      
			}   
			scanf("%d%d%d%d%d%*c",&d,&e,&f,&s,&m);   
			for(j = 0;j < m;j++)            
				sum += d + e;      
			eff[i] = (double)(m * f * s - p) / sum; // 期作 * 1つの種からできる実の数 * 実の価格 - 種の値段 
		}
		for(i = 0;i < n - 1;i++){   
			max_i = i;           
			for(j = i + 1;j < n;j++){   
				if(eff[max_i] < eff[j])     
					max_i = j;        
				else if(eff[max_i] == eff[j] && strcmp(str[max_i],str[j]) > 0)  
					max_i = j;        
			}           
			if(i != max_i){    
				tmp1 = eff[i];     
				strcpy(tmp2,str[i]);       
				eff[i] = eff[max_i];              
				strcpy(str[i],str[max_i]);          
				eff[max_i] = tmp1;          
				strcpy(str[max_i],tmp2);      
			}       
		}       
		for(i = 0;i < n;i++) 
			printf("%s\n",str[i]);     
		printf("#\n");     
	}
	
	return 0; 
} 

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

int main(){
    int N;
    int X[200000];
    pair<int, int> x_idx[200000];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> X[i];
        x_idx[i].first = X[i];
        x_idx[i].second = i;
    }
    //cout << "a" << endl;
    sort(x_idx, x_idx + N);
    int idx_rank[200000], rank_idx[200000];
    for(int i = 0; i < N; i++){
        idx_rank[x_idx[i].second] = i;
        rank_idx[i] = x_idx[i].second;
    }
    for(int i = 0; i < N; i++){
        if(idx_rank[i] < N/2){
            cout << X[rank_idx[N/2]] << endl;
        }else{
            cout << X[rank_idx[N/2-1]] << endl;
        }
    }

    
    
}


Measured memory_bytes: 6144
from fractions import gcd


n, m = map(int, input().split())
s = input()
t = input()
x = gcd(n, m)
l = n*m//x
for i in range(x):
    if s[i*(n//x)] != t[i*(m//x)]:
        print(-1)
        exit()
print(l)

Measured memory_bytes: 5688
n,k = [int(i) for i in input().split()]
hv = [False]*n
for i in range(k):
   d = int(input())
   a = [int(i) for i in input().split()]
   for j in a:
      hv[j-1] = True
print(hv.count(False))
#print(hv)

Measured memory_bytes: 9120
import sys

f = sys.stdin.readline()
xx = f.split(' ')
x = [int(str) for str in xx]

n = x[0]
a = x[1]
b = x[2]


ab = a + b

d = int(n / ab)
m = n % ab

if ( a > m):
	sum = a * d + m
else:
	sum = a * d + a

print sum
sys.stdout.flush()


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

signed main() {
    int n;
    cin >> n;
    if(n < 1000){
        cout << "ABC" << endl;
    } else cout << "ABD" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
 
  int main(){
    ll n;cin>>n;
    vector<pair<ll, ll>> p(n);
    ll a,b;
    for (int i = 0; i < n; i++){
      cin >> a >> b;
      p.at(i) = make_pair(a, b);
    }
    sort(p.begin(), p.end());
    ll count=0;
    for (int i = 0; i < n-1; i++)
    {
      if(abs(p.at(i+1).first-p.at(i).first)<p.at(i+1).second+p.at(i).second)
      {
        count++;
         if(p.at(i).first+p.at(i).second<p.at(i+1).first+p.at(i+1).second)
          {
             p.at(i+1).first=p.at(i).first;
             p.at(i+1).second=p.at(i).second;
          }
      }
      
    }
    cout<<n-count;
  }
    


Measured memory_bytes: 1792
#include<iostream>
#include <cstddef>
#include<set>
#include<stack>
#include <deque>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<cmath>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#define  ll  long long
#define ull unsigned long long
#define  sl(a)  scanf("%lld",&a)
#define  si(a)  scanf("%d",&a)
#define mem(n,m) memset(n,m,sizeof(n))
#define PI acos(-1)
#define pb    push_back
#define pf    push_front
#define vll   vector<ll>
#define pll   pair<ll,ll>
#define mp  make_pair
#define vpll vector< pair <ll,ll> >
#define vplpll vector<pair<ll,pair<ll,ll> > >
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S(X) ( (X) * (X) )
#define forab(i, a, b) for(i = a; i <= b; i++)
#define forn(i, n) for(i = 0; i < n; i++)
#define print(a,b) printf("Case %lld: %lld\n",a,b)
using namespace std;
ll powd(ll a,ll b){if(b==1){return a;}if(b%2==1){return powd(a,b-1)*a;}else{ll x=powd(a,b/2); return x*x;}}
ll powm(ll a,ll b,ll m){if(b==0){return 1;}if(b==1){return a%m;}if(b%2==1){return ((powm(a,b-1,m)%m)*(a%m))%m;}else{ll x=powm(a,b/2,m); return ((x%m)*(x%m))%m;}}
ll gcd(ll a,ll b){if(a==0){return b;}return gcd(b,a%b);}
typedef multiset<ll> mlset;
typedef set<ll> mset;
typedef struct node* pnode;
ll a[105];
ll check(ll a,ll b,ll c)
{
    ll p[4];
    p[0]=a;
    p[1]=b;
    p[2]=c;
    sort(p,p+3);
    if(p[0]+p[1]>p[2])
        return 1;
    return 0;
}
int main()
{
    ll n;
    sl(n);
    for(ll i=0;i<n;i++)
    {
        sl(a[i]);
    }
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            for(ll k=j+1;k<n;k++)
            {
                if(check(a[i],a[j],a[k])&&a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
                {
                    sum++;
                }
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++) // ex)REP(i,10) i=0~i=9
#define REPR(i, n) for(int i = n;i >= 0;i--) // ex)REPR(i,10) i=10~i=0
#define FOR(i, m, n) for(int i = m;i < n;i++) //ex)FOR(i,3,10) i=3~i=9
#define FORR(i, m, n) for(int i = m;i >= n;i--) 
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end()); //
#define llong long long //64bitに拡張
#define pb(a) push_back(a)　
#define INF 999999999 //大きな値
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//座標上を探索
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
llong N;
llong M;
llong T[100];
llong P[100];
llong X[100];
llong c[100];
llong sum = 0;
llong answer = 0;
cin >> N;
for(int i=0;i<N;i++){ 
cin >> T[i];
sum += T[i]; 
}
cin >> M;
for(int j=0;j<M;j++){ 
cin >> P[j] >> X[j];
}

for(int k=0;k<M;k++){
answer = sum - T[P[k]-1] + X[k];
cout << answer << endl;
}
return 0;
}



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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    int D;
    long G;
    long[] p;
    long[] c;

    public void Do()
    {
        cin = new Scanner();
        D = cin.nextInt();
        G = cin.nextLong();
        p = new long[D];
        c = new long[D];
        for (int i = 0; i < D; i++)
        {
            p[i] = cin.nextLong();
            c[i] = cin.nextLong();
        }
        Console.WriteLine(dfs(0, 0));
    }

    long solveToG(int isComplete)
    {
        long score = 0;
        long num = 0;
        int restMax = 0;
        for (int i = 1; i <= D; i++)
        {
            if ((isComplete >> i & 1) == 1)
            {
                score += c[i - 1] + i * 100 * p[i - 1];
                num += p[i - 1];
            }
            else
            {
                restMax = i;
            }
        }

        if (score >= G)
        {
            return num;
        }

        long need = (G - score + 100 * restMax - 1) / (restMax * 100);
        if (need <= p[restMax - 1])
        {
            return num + need;
        }
        return 100000000;
    }

    long dfs(int n, int isComplete)
    {
        if (n == D)
        {
            return solveToG(isComplete);
        }

        return Math.Min(dfs(n + 1, isComplete), dfs(n + 1, isComplete + (1 << n + 1)));
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

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

using namespace std;

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

    int L;
    int ans;
    int height = 0;
    for (int i = 1; i <= N; i++)
    {
        cin >> L;

        height += L;
        if (height > X)
        {
            ans = i;
            break;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
def solve(n, y):
	tmp1000 = n * 1000
	if tmp1000 > y:		#全部を1000円としたときy円を超えたらNG
		return -1, -1, -1
	diff = y - tmp1000		
	
	for y in range(diff // 4000 + 1):
		tmp5000 = y * 4000
		if (diff - tmp5000) % 9000 == 0:	#ちょうど9000円札でy円となった
			x = (diff - tmp5000) // 9000
			if x + y <= n:			#10000円札と5000円札の枚数でN枚より多くなっていたらNG
				return x, y, n - x - y
	return -1, -1, -1
    
print(*solve(*map(int, input().split())))

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    string x;cin>>x;
    string::iterator sp=x.begin();
    string::iterator tp=x.begin();
    ++tp;
    while(tp!=x.end())
    {
        if(*sp!='S'||*tp!='T'){
            sp++;tp++;
        }else{
            x.erase(sp,tp+1);
            tp=sp;sp--;
        }
    }
    printf("%d",x.size());
    return 0;
}
/*

*/

Measured memory_bytes: 640