akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
vector<vector<int> > graph;
vector<bool> visited;
vector<int> dp;
int N, M;
stack<int> s;
vector<int> sorted;

void topo_sort_util(int u){
    visited[u] = true;
    for(auto v : graph[u]){
	if(!visited[v]){
	    topo_sort_util(v);
	}
    }
    s.push(u);
}

void topo_sort(){
    visited.assign(N,false);
    for(int i = 0; i < N; i++){
	if(!visited[i]){
	    topo_sort_util(i);
	}
    }
    for(int i = 0; i < N; i++){
	sorted[i] = s.top(); s.pop();
    }
}

int main(){
    cin>>N>>M;
    graph.assign(N, vector<int>());
    sorted.assign(N, 0);
    dp.assign(N, 0);
    for(int i = 0; i < M; i++){
	int x, y; cin>>x>>y; x--; y--;
	graph[x].push_back(y);
    }
    topo_sort();
    int tot_max = 0;;
    for(auto u : sorted){
	for(auto v : graph[u]){
	    dp[v] = max(dp[u]+1, dp[v]);
	    tot_max = max(dp[v], tot_max);
	}
    }
    cout<<tot_max<<endl;
}


Measured memory_bytes: 8960
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define intt long long
#define pii pair<intt,intt>

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define IO ios_base::sync_with_stdio(false);cin.tie();
#define endl '\n'

const intt max4 = 10004;
const intt maxx = 100005;
const intt max6 = 1000006;
const intt max7 = 10000007;

const intt lg4 = 13;
const intt lg5 = 17;
const intt lg6 = 20;

const intt INF = 2LL * 1000000000;

/***************/

intt powmod (intt a, intt b, intt mod) {
    intt res = 1;
    a %= mod;
    for (; b; b >>= 1) {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

intt gcd (intt a, intt b) {
    while (b > 0) {
        intt t = a % b;
        a = b, b = t;
    }
    return a;
}

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

intt is_prime (intt n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (intt i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/**************************/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    IO;
    intt n, k;
    cin >> n >> k;
    intt res = 1;
    for (intt i = 1; i <= n; i++) {
        res = min (res * 2, res + k);
    }
    cout << res << endl;
    return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    int a_1 = 0;
    int a_2 = 0;
    int a_4 = 0;

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

        if (a % 4 == 0) {
            ++a_4;
        } else if (a % 2 == 0) {
            ++a_2;
        } else {
            ++a_1;
        }
    }

    if (a_4 >= a_1 || (a_4 + 1 == a_1 && a_2 == 0)) {
        puts("Yes");
    } else {
        puts("No");
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int vs[100000+10];

int main(void) {
  int n, k;
  scanf("%d%d", &n, &k);
  REP(i, n) {
    cin >> vs[i];
  }
  sort(vs, vs + n);
  priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > q1; // 小さい方から出る
  priority_queue<pair<int,int> > q2; // でかい方から出る
  int res = 2e9;
  REP(i, n) {
    q1.push(make_pair(vs[i], i));
    q2.push(make_pair(vs[i], i));
    if(i >= k-1) {
      int mini = -1;
      int maxi = -1;
      while(!q1.empty()) {
        auto cur = q1.top();
        if(cur.second > i-k) {
          mini = cur.first;
          break;
        }
        q1.pop();
      }
      while(!q2.empty()) {
        auto cur = q2.top();
        if(cur.second > i-k) {
          maxi = cur.first;
          break;
        }
        q2.pop();
      }
      res = min(res, maxi-mini);
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>
int main(){

	int A,B,C,D,L,daya,dayb;

	scanf("%d",&L);
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&D);

	if (A%C == 0){
		daya = (A/C);
	}else{
		daya = (A/C)+1;
	}

	if (B%D == 0){
		dayb = (B/D);
	}else{
		dayb = (B/D+1);
	}


	if(daya >= dayb){
		printf("%d\n",L-daya);
	}else{
		printf("%d\n",L-dayb);
	}



	return 0;
}

Measured memory_bytes: 596
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  for(int i=0;i<t.size();i++){
    cout<<s[i]<<t[i];
  }
  if(s.size()>t.size())
    cout<<s[s.size()-1]<<endl;
  else
    cout<<endl;
}

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int amari = N % 1000;
		if (amari == 0) { Console.WriteLine(amari); }
		else {
			int amari2 = 1000 - amari;
			Console.WriteLine(amari2);
		}
		
		
	}
}

Measured memory_bytes: 27464
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <math.h>
#include <set>
#define MAXN 100050
#define INF (1<<28)
#define LLINF (1LL<<40)
#define LL long long
#define ri register int
using namespace std;
int n, k, x[MAXN], a, b, ans; 
int main()
{
	ans = 1e9;
	scanf("%d%d", &n, &k);
	for(ri i = 1; i <= n; ++i) scanf("%d", &x[i]);
	for(ri i = 1; i <= n-k+1; ++i) {
		a = x[i], b = x[i+k-1];
		if(b <= 0) ans = min(ans, -a);
		else if(a >= 0) ans = min(ans, b);
		else ans = min(ans, min(-a, b)*2+max(-a, b));
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 640
N,M=map(int,input().split())
edges = [[] for _ in range(N)]
for _ in range(M):
    x,y,z = map(int,input().split())
    edges[x-1].append(y-1)
    edges[y-1].append(x-1)
from collections import deque
queue = deque()
ans = 0
index = 0
checked = [False for _ in range(N)]
while index < N:
    if checked[index]:
        index += 1
        continue
    ans += 1
    queue.append(index)
    checked[index] = True
    while len(queue) > 0:
        v = queue.popleft()
        for w in edges[v]:
            if checked[w]:
                continue
            queue.append(w)
            checked[w] = True
    index += 1
print(ans)

Measured memory_bytes: 23868
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	long res = 0, sumB = 0;
	long N, M; cin >> N >> M;
	long A[100009], B[100009]; for (long i = 1; i <= N; i++) cin >> A[i] >> B[i];
	long myarg[100009]; for (long i = 1; i <= N; i++) myarg[i] = i;

	sort(myarg + 1, myarg + N + 1, [&](long a, long b) {return A[a] < A[b]; }); // myarg[1]軒目から順番に買っていく。

	for (int i = 1; i <= N; i++) {

		if (M > sumB + B[myarg[i]]) { res += A[myarg[i]] * B[myarg[i]]; sumB += B[myarg[i]]; }
		else { cout << res + A[myarg[i]] * (M - sumB) << endl; return 0; }
	}
}

Measured memory_bytes: 2560
N = int(input())
A = list(map(int, input().split()))

A.sort()
sum_A = [0]

for a in A:
    sum_A.append(sum_A[-1] + a)

sum_A.sort(reverse=True)
A.sort(reverse=True)

ans = 1
for i, s in enumerate(sum_A):
    if i == 0:
        continue
    if A[i-1] <= s * 2:
        ans += 1
    else:
        break

print(ans)

Measured memory_bytes: 64360
#include<stdio.h>
int min(int a,int b){
	return a<b?a:b;
}
int main(void){
	int n,k,x,y,a;
	scanf("%d %d",&n,&k);
	while(k--){
		scanf("%d %d",&x,&y);
		a=min(x,min(y,min(n+1-x,n+1-y)))%3;
		a=a?a:3;
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main(){
    fastcin();

    string s;
    cin >> s;
    cout << (s[1]=='B' ? "ARC" : "ABC") << endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    ll A[N];
    ll sum = 0;
    REP(i, 0, N) {
        cin >> A[i];
        sum += A[i];
    }
    ll border = sum / (4 * M);
    if (sum % (4 * M) == 0) {
        border--;
    }
    ll num = 0;
    REP(i, 0, N) {
        if (A[i] > border) {
            num++;
        }
    }
    bool ok = true;
    if (num < M) {
        ok = false;
    }
    yesno(ok);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()


#define  INF 1000000000000
int main(){
    int n;
    cin >> n;
    ll a[301][301];
    rep(i, n)rep(j, n)cin >> a[i][j];

    bool isuse[301][301];
    rep(i, n)rep(j, n)rep(k, n){
        if(a[i][j] > a[i][k]+a[k][j]){
            cout << -1;
            return  0;
        }
        if(a[i][j] == a[i][k]+a[k][j] && a[i][k] > 0  && a[k][j] >  0){
            isuse[i][j]=true;
        }
    }
    ll res = 0;
    rep(i, n)rep(j, n)if(!isuse[i][j])res+=a[i][j];
    cout << res/2;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {
  ll h,w,k,sx,sy,gx,gy;
  cin>>h>>w>>k>>sx>>sy>>gx>>gy;
  sx--;sy--;gx--;gy--;

  vector<string> p(h);
  rep(i,h){
    cin>>p[i];
  }

  vector<vector<ll>> ans(h,vector<ll> (w,INF));
  deque<ll> que;
  ans[sx][sy]=0;
  ll st=sx*w+sy;
  que.pb(st);

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

  while(!que.empty()){
    ll z=que.front();
    que.pop_front();
    
    ll x=z/w;
    ll y=z%w;
    rep(i,4){
      repo(j,k+1){
        ll nx=x+j*dx[i];
        ll ny=y+j*dy[i];

        if(nx<0||ny<0||nx>=h||ny>=w) break;
        if(p[nx][ny]=='@') break;

        if(ans[nx][ny]!=INF && ans[nx][ny]!=ans[x][y]+1) break;

        if(ans[nx][ny]==INF){
          ans[nx][ny]=ans[x][y]+1;
          que.pb(nx*w+ny);
        }
      }
    }
  }

  if(ans[gx][gy]==INF) cout << -1 << endl;
  else cout << ans[gx][gy] << endl;

}

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

#define ul unsigned long int
#define ull unsigned long long
#define li long long int


int main()
{
  ul h,w;
  cin>>h>>w;

  while (h>0|w>0) {
    for (ul i = 0; i < h; i++)
    {
      for (ul j = 0; j < w; j++)
        cout << ((i+j)%2 ? "." : "#");
      cout << endl;
    }
    cout << endl;

    cin >> h >> w;
  }

  return 0;
}



Measured memory_bytes: 3112
#include <iostream>

void resolve() {
   using namespace std;
  int k,a,b;
  cin >> k >> a >> b;
  for(int i=0; i<1000; i++) {
    if(a <= k*i && k*i <= b) {
      cout << "OK" << endl;
      return;
    }
  }
  cout << "NG" << endl;
  return;
}

int main() {
	resolve();
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
struct BIT {
    long long n;
    vector<long long> dat;

    void initialize(long long n_input){
        n = n_input + 1;
        dat.resize(n+1);
        for(int i = 0; i<=n; i++) dat[i] = 0;
    }

    long long sum(long long i){
        long long s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    long long sum_between(long long i, long long j){
        return i <= j ? sum(j) - sum(i-1) : 0;
    }

    void add(long long i, long long x){
        while(i <= n){
            dat[i] += x;
            i |= i+1;
        }
    }
};

int main(){
    int i, j, k;
    long long N;
    cin >> N;
    vector<int> A(N), AS(N);
    for(i=0; i<N; i++){
        scanf("%d", &A[i]);
        AS[i] = A[i];
    }
    sort(AS.begin(), AS.end());
    int ub = N;
    int lb = 0;
    BIT bit;

    long long border = ((N*(N+1)/2) + 1)/2;
    while(ub-lb>1){
        int mid = (ub+lb)/2;
        int midn = AS[mid];
        bit.initialize(2*N+1);
        int sum = 0;
        bit.add(sum+N, 1);
        long long result = 0;
        //cout << endl << midn << endl;
        for(i=0; i<N; i++){
            sum += A[i] >= midn ? 1 : -1;
            result += bit.sum(sum+N);
            bit.add(sum+N, 1);
            //cout << result << endl;
        }
        if(result>=border){
            lb = mid;
        }else{
            ub = mid;
        }
    }
    cout << AS[lb] << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}

struct UnionFind {
	vector<ll> par;
	UnionFind(int n) : par(n) {
		rep(i, n)par[i] = i;
	}
	
	int root(int n) {
		if (par[n] == n)return n;
		return par[n] = root(par[n]);
	}
	void unite(int x, int y) {
		int rx = root(x), ry = root(y);
		//cout << rx << " " << ry << endl;
		if (rx == ry)return;
		par[rx] = ry;
		
	}
	void setroot() {
		rep(i, par.size()) {
			root(i);
		}
	}
	

};

int main() {
	int n,m;
	cin >> n >> m;
	vector<ll> p(n);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}
	UnionFind uf(n);
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		
		uf.unite(x, y);
	}
	ll ans = 0;
	uf.setroot();
	
	rep(i, n) {
		if (uf.par[p[i]] == uf.par[i]) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int h=fsc.nextInt();
        int w=fsc.nextInt();
        int n=fsc.nextInt();
        fsc.close();
        int max=Math.max(h, w);
        System.out.println((n+max-1)/max);
        
    }
    

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


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

int main(){
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  string result;
  rep(i,n){
    result += s.at(i);
    result += t.at(i);
  }
  cout << result << endl;
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>

using namespace std;
static const int MAX =  200000;


int main(){

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

    int  maxv = -2000000000;
    int minv = R[0];

    for(int i = 1; i < n; i++){
        maxv = max(maxv,R[i] - minv);
        minv = min(minv,R[i]);
    }

    cout << maxv << endl;

    return 0;

}



Measured memory_bytes: 3884
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int A, B;
    cin >> A >> B;
    string s;
    if(A == B) s = "Draw";
    else if(A == 1) s = "Alice";
    else if(B== 1) s="Bob";
    else if(A > B) s="Alice";
    else s = "Bob";
    cout << s << endl;
}


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

using namespace std;

int main()
{
	int n;
  cin>>n;
  //vector<int> v(n);
  int max = 0;
  long long int output = 0;
  for( int i = 0 ; i < n ; i++ )
  {
  	int temp;
    cin>>temp;
    if( temp >= max )	max = temp;
    else
    {
      output = output + (max-temp);
    }
  }
  
  cout<<output<<endl;
  return 0;
}

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

using namespace std;

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

int main(){
  string s;
  int h,w;
  cin>>h>>w;
  vector<string> a(h);
  for(int i=0;i<h;i++) cin>>a[i];
  int i;
  for(int i=0;i<w+2;i++) cout<<'#';
  cout<<endl;
  for(int i=0;i<h;i++){
    cout<<'#'<<a[i]<<'#';
    cout<<endl;
  }
  for(int i=0;i<w+2;i++) cout<<'#';
  cout<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int a, b;
	double x, y;
	scanf("%d %d", &a, &b);
	x = a;
	y = b;
	printf("%d %d %.5lf\n", a / b, a % b, x/y); 
	return 0;
}


Measured memory_bytes: 2128
#include <iostream>
#include<string>

using namespace std;

int main(void) {

	string X;
	cin >> X;
	int A, B, C, D;

	A = X[0] - '0';
	B = X[1] - '0';
	C = X[2] - '0';
	D = X[3] - '0';

	int num;
	for (int i = 0; i < 8; i++) {
		int tmp = A;
		num = i;
		if (num % 2 == 0) { tmp += B; }
		else { tmp -= B; }

		num /= 2;
		if (num % 2 == 0) { tmp += C; }
		else { tmp -= C; }

		num /= 2;
		if (num % 2 == 0) { tmp += D; }
		else { tmp -= D; }

		if (tmp == 7) {
			num = i;
			cout << A;
			if (num % 2 == 0) { cout << "+"; }
			else { cout << "-"; }
			cout << B;
			num /= 2; 
			if (num % 2 == 0) { cout << "+"; }
			else { cout << "-"; }
			cout << C;
			num /= 2;
			if (num % 2 == 0) { cout << "+"; }
			else { cout << "-"; }
			cout << D;
			cout << "=7" << endl;
			break;
		}
	}

	//system("pause");
	return 0;
}

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

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null; }
        String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try { tokenizer = new StringTokenizer(reader.readLine()); } 
                catch (IOException e) { throw new RuntimeException(e);} }
            return tokenizer.nextToken(); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        
        int n = r.nextInt();
        int[] a = new int[n+1];
        for(int i = 1; i <= n; i++){
            a[i] = r.nextInt();
        }
        int sum = 0;
        for(int i = 1; i <= n; i++){
            sum += r.nextInt();
        }
        int[] c = new int[n];
        for(int i = 1; i <= n-1; i++){
            c[i] = r.nextInt();
        }

        for(int i = 1; i <= n-1; i++){
            if(a[i] + 1 == a[i+1]){
                sum += c[a[i]];
            }
        }
        pw.println(sum);
        pw.close();
    }
}

/**
                _        _                 _                                                
               | |      | |               | |                                               
   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___  
  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \ 
 | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/ 
                                __/ |                               ______ __/ |            
                               |___/                               |______|___/             
 */

Measured memory_bytes: 22228
N = int(input())
B = list(map(int,input().split()))
 
ans = 0
 
if N >= 3:
  for n in range(1,N-1):
    b = B[n]
    b_before = B[n-1]
    ans += min(b, b_before)
    
  ans += B[0]
  ans += B[-1]
 
else:
  ans = B[0] * 2
 
  
print(ans)

Measured memory_bytes: 3060
#include <iostream>

const int MAXN = 100005;
int S[MAXN];
int n;
int k;
int q;

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin >> n >> k >> q;
    for (int i=0;i<q;++i)
    {
        int a;
        std::cin >> a;
        --k;
        ++S[a];
    }
    for (int i=1;i<=n;++i)
        std::cout << (S[i]+k <= 0 ? "No" : "Yes") << std::endl;
    return 0;
}

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

typedef long long ll;

int N,Q;
ll D;
ll d[500005];
ll si[500005];
ll ans[500005];
ll cu[500005];

ll fir=1e9;

int main(){
  scanf("%d %lld",&N,&D);
  
  ll pos=D;
  for(int i=0;i<N;i++){
    si[i]=pos;
    scanf("%lld",&d[i]);
    if( abs(pos-d[i]) < pos ){
      pos=abs(pos-d[i]);
    }
    if(pos==0){
      fir=min(fir,(ll)i+1);
    }
  }
  
  ll cur=0;  
  for(int i=N-1;i>=0;i--){
    if(cur+1>=d[i])cur=cur+d[i];
    else{

      if(d[i]<=cur+cur+1){
        cur=cur+d[i];
      }
      
    }
    //    cout<<i<<' '<<cur<<endl;
    cu[i]=cur;
  }
  
  scanf("%d",&Q);
  while(Q--){
    int id;
    scanf("%d",&id);
    id--;
    if( fir<=id ){
      printf("NO\n");
      continue;
    }

    if(id==N-1){
      printf("YES\n");
      continue;
    }

    //    cout<<cu[id+1]<<' '<<si[id]<<endl;
    if(cu[id+1]<si[id])printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 15488
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};


int main(){
  int n;
  string s;
  cin >> n >> s;
  int bcnt=0,wcnt=0;
  rep(i,2*n){
    if(i%2==0){
      if(s[i]=='B'){
        s[i] = 'W';
      } else {
        s[i] = 'B';
      }
    }
  }
  rep(i,2*n){
    if(s[i]=='B'){
      bcnt++;
    } else {
      wcnt++;
    }
  }
  if(bcnt!=wcnt){ cout<<0<<endl; return 0; }

  mint ans = 1;
  ll cnt = 0;
  rep(i,2*n){
    if(s[i]=='B'){
      ans *= cnt;
      cnt--;
    } else {
      cnt++;
    }    
  }
  REP(i,2,n+1) ans*=i;
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ull gcd(ull x,ull y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp(pair<ll,ll> x,pair<ll,ll> y)
{
    if(x.first<y.second)
        return true;
    else if(x.first==y.second)
        return x.second<y.second;
    else
        return false;
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

class cmp      //comparator for priority_queue 
{               //declaration: priority_queue<int,vector<int>,cmp>
public:         
    bool operator()(pair<int,int> A,pair<int,int> B)
    {
        if(abs(A.first-A.second)==abs(B.first-B.second))
            return A.first>B.first;
        return abs(A.first-A.second)<abs(B.first-B.second);
    }
};
// int prime[100005]={0};
// void sieve(void)
// {
//  int i,j;
//  for(i=0;i<100005;i++)
//         prime[i]=1;
//  prime[0]=0,prime[1]=0;
//  for(i=2;i<=sqrt(100005);i++){
//      if(prime[i]){
//          for(j=i*i;j<100005;j+=i){
//              prime[j]=0;
//          }
//      }
//  }
    
// }
void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
}

void solve()
{   
    int n,k;
    cin>>n>>k;
    int ar[n+1]={0};
    int d;
    int x;
    for(int i=1;i<=k;i++){
        cin>>d;
        for(int j=0;j<d;j++)
        {
            cin>>x;
            ar[x]=1;
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(ar[i]==0) cnt++;
    }
    cout<<cnt;
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
	public static void main(String[]args){
		Scanner scan= new Scanner(System.in);
		String n1 = scan.next();
		String n2 = scan.next();
		
		Integer a = new Integer(n1);
		Integer b = new Integer(n2);
	
		int side = 2*(a+b);
		int area = a*b;
		
		System.out.println(area + " " +side);

		
	}
}

Measured memory_bytes: 17120
#include <stdio.h>
int a[1000001];
int main(){
    int K;
    scanf("%d",&K);
    a[1]=7%K;
    for(int i=2;i<=K;i++)a[i]=(a[i-1]*10+7)%K;

    for(int i=1;i<=K;i++)if(a[i]==0){
        printf("%d\n",i);
        return 0;
    }
    printf("-1\n");
}


Measured memory_bytes: 5540
num=[]
num=[int(i) for i in input().split()]
kakuritu_arr = []

i = 1
while i <= num[0]:
    x = i
    y = 0
    while True:
        if x >= num[1]:
            break
        x = x * 2
        y += 1
    kakuritu_arr.append((1/num[0]) * (1/2) ** y)
    i +=1

result = 0
for temp in kakuritu_arr:
    result += temp
print(result)

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

 
int main() {
    int mod=1000000007;
    int n,m;
    cin>>n>>m;
    map<int,int> M;
    rep(i,m){
        int a;
        cin>>a;
        M[a]=1;
    }
    vector<ll> dp(n+1);//0~nまでのn+1コ
    dp[0]=1;
    if(M[1])dp[1]=0;
    else dp[1]=1;

    for(int i=2;i<=n;i++){
        dp[i]=dp[i-1]+dp[i-2];
        dp[i]%=mod;
        if(M[i])dp[i]=0;
    }

    cout<<dp[n]%mod<<endl;

}

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

int main() {
    int n;
    cin >> n;
    map<int, int> m;
    rep(i, n - 1) {
        int tmp;
        cin >> tmp;
        if(m.find(tmp) == m.end())
            m[tmp] = 1;
        else {
            m[tmp] += 1;
        }
    }
    rep(i, n) { cout << m[i + 1] << endl; }

    return 0;
}

Measured memory_bytes: 13008
# include<iostream>

using namespace std;
int main(){
	int S=0,N,count;
	cin >> N;
	count = N;
	while(1){
		S+=count%10;
		if(count<10){
			break;
		}
		count/=10;
	}
	if(N%S==0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;

int main(){
  int h,w; cin>>h>>w;
  vector<string> m(h);
  for(int i=0;i<h;i++){
    cin>>m[i];
  }long long ans=0;
  int my[4]={0,0,-1,1};
  int mx[4]={-1,1,0,0};
  vector<vector<bool>> flag(h,vector<bool>(w,false));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(flag[i][j]) continue;
      queue<P> que;
      que.push(P(i,j));
      flag[i][j]=true;
      long long a=0,b=0;
      while(!que.empty()){
        P p=que.front(); que.pop();
        int y=p.first,x=p.second;
        char base=m[y][x];
        if(base=='#') b++;
        else a++;
        for(int k=0;k<4;k++){
          int ny=y+my[k],nx=x+mx[k];
          if(ny>=h ||ny<0 ||nx<0 ||nx>=w) continue;
          if(flag[ny][nx] || m[ny][nx]==base) continue;
          flag[ny][nx]=true;
          que.push(P(ny,nx));
        }
      }
      ans+=a*b;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define 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 RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

 int n;cin>>n;
 int a[n],b[n],c[n];
 int ans = 0;
 REP(i,n){
  int t;cin>>t;
  t--;
  a[i] = t;
 }
 REP(i,n){
  cin>>b[i];
 }
 REP(i,n){
  cin>>c[i];
 }
 REP(i,n){
  ans += b[i];
 }
 REP(i,n-1){
  if(a[i] + 1 == a[i+1]){
    ans += c[a[i]];
  }
 }
 cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF=2e18;
string S;
ll ans[100010];
int main(){
    cin>>S;
    ll ma=0;
    ll oddCnt=0;
    ll evnCnt=0;
    for(int i=0;i<S.length()-1;i++){
        if(S[i]=='R'){
            if(i%2==1){
                oddCnt++;
            }
            else{
                evnCnt++;
            }
        }
        if(S[i]=='R' && S[i+1]=='L'){
            if(i%2==1){
                ans[i]+=oddCnt;
                ans[i+1]+=evnCnt;
            }else{
                ans[i+1]+=oddCnt;
                ans[i]+=evnCnt;
            }
            oddCnt=0;
            evnCnt=0;
        }
    }
    reverse(ans,ans+S.length());
    reverse(S.begin(),S.end());
    for(int i=0;i<S.length()-1;i++){
        if(S[i]=='L'){
            if(i%2==1){
                oddCnt++;
            }
            else{
                evnCnt++;
            }
        }
        if(S[i]=='L' && S[i+1]=='R'){
            if(i%2==1){
                ans[i]+=oddCnt;
                ans[i+1]+=evnCnt;
            }else{
                ans[i+1]+=oddCnt;
                ans[i]+=evnCnt;
            }
            oddCnt=0;
            evnCnt=0;
        }
    }
    reverse(ans,ans+S.length());
    for(int i=0;i<S.length();i++){
        cout<<ans[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
//#include <queue>
//#include <bits/stdc++.h>
#include <string>
#include <sstream>
#include <cmath>
#include <fenv.h>
#include <algorithm>
#include <cstdio>

using namespace std;

void lex_sort(string &s,string dir="up")
{
	for(int i=0;i < s.length(); ++i){
		for(int j=i+1; j < s.length();++j){
			if(s[i]>s[j]){
				char tmp = s[j];
				s[j] = s[i];
				s[i] = tmp;
			}
		}
	}
	if(dir=="down"){
		reverse(s.begin(),s.end());
	}
}
void solve(string s, string t)
{
	lex_sort(s);
//	cout << s << endl;
	lex_sort(t,"down");
	if(s < t)
		cout <<"Yes" << endl;
	else
		cout <<"No" << endl;

}

int main(){

	string s,t; cin >> s; cin >> t;
	solve(s,t);

//	solve("yx","xya");
//	solve("ratcode","atlas");
//	solve("cd","abc");
//	solve("w","ww");
//	solve("zzz","zzz");

	return 0;
}


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

int main(){
    std::string s;
    std::cin >> s;

    if ((s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) || (s[0] == s[2] && s[1] == s[3] && s[2] != s[1]) || (s[0] == s[3] && s[1] == s[2] && s[3] != s[1]))
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <utility>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

// 基本的な演算
//namespace BasicMath {
    // 絶対値を求める
    static inline UInt Abs(const Int a);
    // 二つの値の最小値を求める関数
    static inline Int Min(const Int a, const Int b);
    // 絶対値を求める
    UInt Abs(const Int a) {
        return a > 0 ? a : -a;
    }
    // 二つの値の最小値を求める関数
    Int Min(const Int a, const Int b) {
        if (a <= b) {
            return a;
        } else {
            return b;
        }
    }
//}
//using namespace BasicMath;

// ビット演算
//namespace Bits {
    // 整数x の 下から i 桁目が1かどうかを返す
    static inline bool IsFlagUp(Int x, Int i);
    // 整数x の 下から i 桁目が1かどうかを返す
    bool inline IsFlagUp(Int x, Int i) {
        return ((x & (1 << i)) != 0);
    }
//}
//using namespace Bits;

int main(void) {
    Int n, a, b, c;
    cin >> n >> a >> b >> c;
    VI l(n);
    for (Int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    Int size = pow(2, n);
    VI bamboo(size);
    VI cost(size);
    for (Int i = 0; i < size; ++i) {
        bamboo[i] = 0;
        cost[i] = 0;
        for (Int j = 0; j < n; ++j) {
            if (IsFlagUp(i, j)) {
                bamboo[i] += l[j];
                cost[i]++;
            }
        }
    }
    VI da(size);
    VI db(size);
    VI dc(size);
    for (Int i = 1; i < size; ++i) {
        da[i] = Abs(bamboo[i] - a) + 10 * (cost[i] - 1);
        db[i] = Abs(bamboo[i] - b) + 10 * (cost[i] - 1);
        dc[i] = Abs(bamboo[i] - c) + 10 * (cost[i] - 1);
    }
    Int answer = INT_MAX;
    for (Int i = 1; i < size; ++i) {
        for (Int j = 1; j < size; ++j) {
            for (Int k = 1; k < size; ++k) {
                bool flag = true;
                for (Int x = 0; x < n; ++x) {
                    bool xa = IsFlagUp(i, x);
                    bool xb = IsFlagUp(j, x);
                    bool xc = IsFlagUp(k, x);
                    if (xa && xb) {
                        flag = false;
                    }
                    if (xb && xc) {
                        flag = false;
                    }
                    if (xc && xa) {
                        flag = false;
                    }
                }
                if (flag) {
                    answer = Min(answer, da[i] + db[j] + dc[k]);
                }
            }
        }
    }
    cout << answer << endl;
    return 0;
}



Measured memory_bytes: 4040
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void){
    int n,a=0;
    scanf("%d",&n);
    int p[n];
    for(int i=0;n>i;++i)
    scanf("%d",&p[i]);
    for(int i=0;n>i;++i){
        if(p[i]==i+1)
        ++a;
    }
    if(a==n||a==n-2)
    printf("YES");
    else
    {printf("NO");}
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

#define MAX_NUM 2000000
#define MAX_VALUE 10000

void print_array(int A[], int n) {
  for(int i=0; i<n; i++) {
    printf("%d", A[i]);
    if(i != n-1) {
      printf(" ");
    }
  }
}

void counting_sort(int A[], int B[], int n) {
  int cnt[MAX_VALUE];
  for(int i=0; i<MAX_VALUE; i++) {
    cnt[i] = 0;
  }

  for(int i=0; i<n; i++) {
    cnt[A[i]]++;
  }

  for(int i=1; i<MAX_VALUE; i++) {
    cnt[i] = cnt[i] + cnt[i-1];
  }

  for(int i=n-1; i>-1; i--) {
    B[cnt[A[i]]-1] = A[i];
    cnt[A[i]]--;
  }
}

int main() {
  int n;
  int* A = (int*)malloc(sizeof(int) * MAX_NUM);
  int* B = (int*)malloc(sizeof(int) * MAX_NUM);
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> A[i];
  }

  counting_sort(A, B, n);

  print_array(B, n);
  printf("\n");

  return 0;
}

Measured memory_bytes: 18864
#include <bits/stdc++.h>
using namespace std;
int n;
int L[2003];
int bl(int a,int b){
    int mn=max(L[a]-L[b]+1,L[b]-L[a]+1);
    int l=b+1,r=n,ans=-1,mid;//[]
    while(l<=r){
        mid=(r-l)/2+l;
        // printf("%d %d %d\n",l,r,mid);
        if(L[mid]<mn)l=mid+1;
        else{
            ans=mid;
            r=mid-1;
        }
    }
    return ans;
}
int br(int a,int b){
    int mx=L[a]+L[b]-1;
    int l=b+1,r=n,ans=-1,mid;//[] 1 2 3 4
    while(l<=r){
        mid=(r-l)/2+l;
        // printf("%d %d %d\n",l,r,mid);
        if(L[mid]>mx)r=mid-1;
        else{
            ans=mid;
            l=mid+1;
        }
    }
    return ans;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&L[i]);
    sort(L+1,L+n+1);
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int l,r;
            l=bl(i,j);
            r=br(i,j);
            if(l==-1||r==-1)continue;
            ans+=max(0,r-l+1);
            // printf("a:%d b:%d l:%d r:%d ans:%d\n",i,j,l,r,ans);
            // system("pause");
            /*
            for(int k=j+1;k<=n;k++){
                if(L[i]+L[j]>L[k]&&L[i]+L[k]>L[j]&&L[j]+L[k]>L[i])ans++;
            }
            */
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

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

    int arr[n];
    int i;
    long long int sum=0;
    for (i=0;i<n;i++) {
        cin>>arr[i];
    }
    sort(arr,arr+n,greater<int>());

    for (i=0;i<a;i++) {
        sum+=arr[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    int K, A, B; cin >> K >> A >> B;
    int ans;
    if(A >= K || A >= B - 2) ans = K + 1;
    else{
        ans = A;
        K -= (A - 1);
        ans += (B - A) * (K / 2);
        ans += (K % 2);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
  char a, b;
            cin >> a >> b;
            if (a < b)
              cout << string(b - '0', a) << "\n";
            else
              cout << string(a - '0', b) << "\n";
  return 0;
           }

Measured memory_bytes: 256
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;

for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}


Measured memory_bytes: 2508
#![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use std::collections::BinaryHeap;
use std::io::Read;

const U32_LARGE: u32 = 1 << 30;

fn read<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let b: Vec<u32> = (0..n - 1).map(|_| read()).collect();
    let mut res = 0;
    res += b[0];
    res += b[n - 2];
    for w in b.windows(2) {
        let bx = w[0];
        let by = w[1];
        if bx < by {
            res += bx;
        } else {
            res += by;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
// ------------------------------------
// Date:2018/ 3/ 8
// Problem:ARC 082 Together c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int INF = 1000000001;

int A[101010];

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

  memset(A, 0, sizeof(A));
  int N, tmp, mMax = -INF;
  cin >> N;
  REP(i, N) {
    cin >> tmp;
    ++A[tmp];
  }

  int cnt;
  REP(i, 101001) {
    cnt = max(cnt, A[i] + A[i + 1] + A[i + 2]);
  }
  cout << cnt << endl;
  
  return 0;
}



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

int main(){

    int N;
    long long int M=0,A=0,R=0,C=0,H=0;
    cin>>N;
    for(int i=0;i<N;i++){
        string S;
        cin>>S;
        if(S.at(0)=='M') M++;
        if(S.at(0)=='A') A++;
        if(S.at(0)=='R') R++;
        if(S.at(0)=='C') C++;
        if(S.at(0)=='H') H++;
    }
    vector<long long int> S={M,A,R,C,H};
    long long int ans=0;
    for(int i=0;i<=2;i++){
        for(int j=i+1;j<=3;j++){
            for(int k=j+1;k<=4;k++){
                ans=ans+S.at(i)*S.at(j)*S.at(k);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384