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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};


int main() {
	int n;
	cin >> n;
	cout << (n+1)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(3);
  int i=0;
  while(n){
    a[i]=n%10;
    i++;
    n=n/10;
  }
  if(a[0]==a[2]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

ll N;
ll a[20][20];
ll dp[1<<16];
bool visited[1<<16];

ll rec(ll S){
	if(visited[S]) return dp[S];
	if(S==0) return 0;
	ll res = -LLONG_MAX/3;
	for(ll T=S;T>0;T=(T-1)&S){
		ll tmp = 0;
		if(T==S){
			REP(i, N){
				for(int j=i+1;j<N;j++){
					if((S>>i&1)&&(S>>j&1)){
						tmp += a[i][j];
					}
				}
			}
		}else{
			tmp = rec(S^T) + rec(T);
		}
		res = max(res, tmp);
	}
	dp[S] = res;
	visited[S] = true;
	return res;
}

int main(){
	cin >> N;
	REP(i, N)REP(j, N) cin >> a[i][j];
	REP(i, 1<<16) visited[i] = false;
	cout << rec((1<<N)-1) << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,K;
	cin >> N >> K;
	int tmp = 0;
	if(N % 2 == 0){
		tmp = N /2;
	}else{
		tmp = (N + 1) / 2;
	}
	if(tmp >= K){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
a=[int(i) for i in input().split()]

a.sort()

if a[0]%2==0 and  a[1]%2==0 and  a[2]%2==0:
    print(int((3*max(a)-sum(a))/2))  
elif a[0]%2==1 and  a[1]%2==1 and  a[2]%2==1:
    print(int((3*max(a)-sum(a))/2))  

else:
    count=0
    for i in range(3):
        if a[i]%2==0:
            count+=1

    if count==2:
        for i in range(3):
            if a[i]%2==0:
                a[i]=a[i]+1
        print(int((3*max(a)-sum(a))/2)+1)  
        
    if count==1:
        for i in range(3):
            if a[i]%2==1:
                a[i]=a[i]+1
        print(int((3*max(a)-sum(a))/2)+1)  




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



/*
Mistakes

- while using pairs make sure you comparator datatype it's int by default change it as per the need
- Modify comparator if you want to
*/
#define f first
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll64 int64_t
#define pb push_back
#define pll pair<long long int,long long int>
#define pi pair<int,int>
#define mi map<int,int>
#define ll long long int
#define mll map<long long int,long long int>
#define umi unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<long long int,long long int>>
#define mod 1000000007
#define fp(i,x,n) for(int i=x;i<n;i++)
#define fn(i,x,n) for(int i=x;i>n;i--)
#define fpm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define asort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysec)
#define asort_vp_first(vect) sort(vect.begin(), vect.end())
#define dsort_vp_first(vect) sort(vect.begin(), vect.end(), sortinrev)
#define dsort_vp_second(vect) sort(vect.begin(), vect.end(), sortbysecdesc)
#define vi vector<int>
#define vll vector<long long int>
#define c(x) cout<<x<<endl;
#define M 1000000007
using namespace std;
#define int long long int


signed main()
{
    int n;
    cin>>n;
   int a[n],b[n];
   fp(i,0,n)
   cin>>a[i];

   fp(i,0,n)
   cin>>b[i];
   reverse(b,b+n);

   fp(i,0,n)
   {
       if(a[i]!=b[i])
       continue;

       bool ok = false;
       fp(j,0,n)
       {
           if(i==j)
           continue;

           if(a[i]!=b[j] && a[j]!=b[i])
           {
               swap(b[i],b[j]);
               ok = true;
               break;
           }

       }
       if(!ok)
       {
           cout<<"No"<<endl;
           return 0;
       }
   }
   cout<<"Yes"<<endl;
   fp(i,0,n)
   cout<<b[i]<<" ";

}


Measured memory_bytes: 6744
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int a, b, x;
  cin >> a >> b >> x;
  if(a <= x && a + b >= x)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

typedef long long ll;

int main()
{
    ll N;
    string S;
    cin >> N;
    map<string, bool> M;
    for (int i = 0; i < N; ++i)
    {
        cin >> S;
        M[S];
    }
    cout << M.size() << endl;
}

Measured memory_bytes: 19204
n = int(input())
H = [int(h)for h in input().split()]
A = [0]*n

A[0] = 0
A[1] = abs(H[1]-H[0])

for i in range(2, n):
  A[i] = min(A[i-1]+abs(H[i]-H[i-1]), A[i-2]+abs(H[i]-H[i-2]))

print(A.pop())


Measured memory_bytes: 13928
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")



int main() {
	ll N, T;
	cin >> N >> T;
	vector<pair<ll, ll>> p(N);
	vector<vector<ll>> dp(N + 1);
	REP(i, 0, N) cin >> p[i].first >> p[i].second; 
	sort(p.begin(), p.end(), [](auto& a, auto& b) {return a.first < b.first; });
	REP(i, 0, N + 1) dp[i].resize(T, 0);
	ll ans = p[0].second;
	REP(i, 1, N) {
		REP(t, 1, T) {
			dp[i][t] = max(dp[i - 1][t], dp[i][t - 1]);
			if (t - p[i - 1].first >= 0) dp[i][t] = max(dp[i][t], dp[i - 1][t - p[i - 1].first] + p[i - 1].second);
		}
		ans = max(ans, dp[i][T - 1] + p[i].second);
	}
	PRI(ans);
	return 0;
}




Measured memory_bytes: 74048
import sys

def main():
    N = int(input())
    H = list(map(int, input().split()))
    cnt = 0
    ans = 0

    for i in range(N-1):
        if H[i] >= H[i+1]:
            cnt += 1
        else:
            if ans == 0 or ans < cnt:
                ans = cnt
            cnt = 0

    if ans == 0 or ans < cnt:
        ans = cnt

    print(ans)

main()

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

using namespace std;



int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }

    long long p = 0, cnt = 0;

    if(a[0] != 0){
        cout << -1 << endl;
        return 0;
    }

    for(int i=1;i<n;i++){
        if(a[i]-a[i-1]>1){
            cout << -1 << endl;
            return 0;
        }
    }

    for(int i=1;i<n;i++){
        if(a[i]-a[i-1]==1){
            cnt++;
        }else{
            cnt+=a[i];
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String P =sc.next();
    String M[] ={"A","F","H","W","TU","M","SU"};
    for(int i=0;i<7;i++){
      if(P.contains(M[i])){System.out.println(i+1);}
    }
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VI p(n); cin >> p;

    VI a(n), b(n);
    FOR(i, 0, n) {
        a[i] = i + 1;
        b[i] = n - i;
    }

    VI ra(n), rb(n);
    FOR(i, 0, n) {
        ra[--p[i]] += i;
        rb[p[i]] += i;
    }
    FOR(i, 1, n)ra[i] += ra[i - 1];
    rFOR(i, 0, n - 1)rb[i] += rb[i + 1];

    FOR(i, 0, n)cout << a[i] + ra[i] << ENDL(i, n);
    FOR(i, 0, n)cout << b[i] + rb[i] << ENDL(i, n);
}


Measured memory_bytes: 1024
N, M = map(int, input().split()) #N:人数、M:種類数
a = [] #好きなものの個数と何番目か。最初は空
for _ in range(N):
    a.append(list(map(int, input().split())))
b = [0] * M
for i in range(N): #i番目の人
    for j in range(1, a[i][0]+1): #j番目の食べ物
        b[a[i][j]-1] += 1 #j番目の食べ物が好きな人をカウント
ans = 0
for k in range(M):
    if b[k] == N:
        ans += 1
print(ans)


Measured memory_bytes: 38256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t a, b;

    scanf("%jd%jd", &a, &b);

    if (a < b) {
        for (size_t i = 0; i < b; i++) {
            putchar(a + '0');
        }
        putchar('\n');
    } else {
        for (size_t i = 0; i < a; i++) {
            putchar(b + '0');
        }
        putchar('\n');
    }

    return 0;
}


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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,M;
    cin >> N >> M;
    vector<int> x(M),y(M);
    for (int i=0;i<M;i++){
        cin >> x[i] >> y[i];
        x[i]--;y[i]--;
    }
    vector<int> count(N,1);
    vector<bool> red(N,false);
    red[0] = true;
    for (int i=0;i<M;i++){
        if (count[x[i]] == 1 && red[x[i]]) {
            count[x[i]]--;
            red[x[i]] = false;
            count[y[i]]++;
            red[y[i]] = true;
        } else if (count[x[i]] > 1 && red[x[i]]){
            count[x[i]]--;
            count[y[i]]++;
            red[y[i]] = true;
        } else {
            count[x[i]]--;
            count[y[i]]++;
        }
    }
    int ans = 0;
    for (int i=0;i<N;i++){
        if (red[i]) ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <iomanip>

using namespace std;
int main() {
    int n,k;
    cin>>n>>k;
    vector<double> a;
    int x;
    for (int i=0;i<n;++i){
        cin>>x;
        a.push_back((x+1)/2.0);
    }
    double sum=0;
    for (int i=0;i<k;++i)
        sum+=a[i];
    double m=sum;
    for (int i=0;i+k<a.size();++i){
        m=max(m,sum);
        sum-=a[i];
        sum+=a[i+k];
    }
    m=max(m,sum);
    cout << fixed << setprecision(10) << m;
}

Measured memory_bytes: 2420
N = int(input())
S = []
for n in range(N):
  s = input()
  if s[0] in "MARCH":
    S.append(s[0])
S_set = list(set(S))
if len(S_set) < 3:
  ans = 0
elif len(S_set) == 3:
  ans = S.count(S_set[0]) * S.count(S_set[1]) * S.count(S_set[2])
elif len(S_set) == 4:
  ans = 0
  T = [S.count(S_set[0]), S.count(S_set[1]), S.count(S_set[2]), S.count(S_set[3])]
  for i in [0, 1]:
    for j in range(i+1, len(T)-1):
      for k in range(j+1, len(T)):
        ans += T[i] * T[j] * T[k]
elif len(S_set) == 5:
  ans = 0
  T = [S.count(S_set[0]), S.count(S_set[1]), S.count(S_set[2]), S.count(S_set[3]), S.count(S_set[4])]
  for i in [0, 1, 2]:
    for j in range(i+1, len(T)-1):
      for k in range(j+1, len(T)):
        ans += T[i] * T[j] * T[k]

print(ans)

Measured memory_bytes: 4024
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> costs(n);
  vector<vector<int>> books;
  int ans = -1;
  rep(i, n) {
    cin >> costs[i];
    vector<int> b(m);
    rep(i, m) {
      cin >> b[i];
    }
    books.push_back(b);
  }
  for(int i = 0; i < (1 << n); i++) {
    vector<int> r(m, 0);
    int tmp_cost = 0;
    for (int j = 0; j < n; j++) {
      if(i >> j & 1) {
        tmp_cost += costs[j];
        rep(k, m) {
          r[k] += books[j][k];
        }
      }
    }
    bool ok = true;
    rep(k, m) {
      if (r[k] < x) {
        ok = false;
      }
    }
    if (ok) {
      if (ans == -1) {
        ans = tmp_cost;
      } else {
        ans = min(ans, tmp_cost);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  cout << (n ^ 1) << endl;
  return 0;
}

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

#define ff first
#define ss second
#define pb push_back

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 81;

int dp[N][N][N*N*2];
int h, w;
int a[N][N];
int b[N][N];

int f(int x, int y, int dif) {
	if(x >= h || y >= w){
		return 1e9;
	}
	if(x == h-1 && y == w - 1){
		return min(abs(dif + a[x][y] - b[x][y]), abs(dif + b[x][y] - a[x][y]));
	}
	int &ans = dp[x][y][dif];
	if(ans != -1) return ans;
	ans = f(x + 1, y, abs(dif + a[x][y] - b[x][y]));
	ans = min(ans, f(x + 1, y, abs(dif + b[x][y] - a[x][y])));
	ans = min(ans, f(x, y + 1, abs(dif + a[x][y] - b[x][y])));
	ans = min(ans, f(x, y + 1, abs(dif + b[x][y] - a[x][y])));
	return ans;
}

int main() {
	memset(dp, -1, sizeof dp);
	scanf("%d %d", &h, &w);
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			scanf("%d", &a[i][j]);
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			scanf("%d", &b[i][j]);
		}
	}
	printf("%d\n", f(0, 0, 0));
	return 0;
}


Measured memory_bytes: 336640
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e7+7;

int notprime[MAXN];

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

    LL ans = (n*(n+1))/2;
    for (int i = 2; i <= n; i++) {
        for (int j = i; j <= n; j+=i) {
            ans += j;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3620
from collections import Counter


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    C = Counter(A)
    ANS = 0
    for i in C:
        ANS += i * C[i]

    for _ in range(Q):
        B, X = map(int, input().split())
        ANS += X * C[B]
        C[X] += C[B]

        ANS -= B * C[B]
        del(C[B])
        print(ANS)

resolve()

Measured memory_bytes: 24252
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int tot=0; 
char s[1000];
int main(){
	scanf("%s",s);
	int len=strlen(s);
	for(register int i=0;i<len;i++){
		if(s[i]=='x'){
			tot++;
		}
	}
	if(15-tot>=8)printf("YES\n");
	else printf("NO\n");
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a==1&&b==2) cout<<'3';
	if(b==1&&a==2) cout<<'3';
	if(a==1&&b==3) cout<<'2';
	if(b==1&&a==3) cout<<'2';
	if(a==2&&b==3) cout<<'1';
	if(b==2&&a==3) cout<<'1';
	return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = (1 << 30);

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

    int n;
    cin >> n;
    vi lim(n);
    rep(i, n){ cin >> lim[i]; }
    int q;
    cin >> q;
    vi cur(n);
    int t, x, d;
    rep(i, q){
        cin >> t >> x >> d;
        x--;
        if(t == 1){
            if(cur[x] + d > lim[x]){
                cout << x + 1 << endl;
                return 0;
            }else{
                cur[x] += d;
            }
        }else{
            if(cur[x] - d < 0){
                cout << x + 1 << endl;
                return 0;
            }else{
                cur[x] -= d;
            }
        }
    }
    cout << 0 << endl;

    return 0;
}


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

using namespace std;

int main() {
    int k, n;
    cin >> k >> n;
    int a[n + 1];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    a[n] = k + a[0];
    int nax = 0;
    for (int i = 0; i < n; ++i) {
        nax = max(nax, a[i + 1] - a[i]);
    }
    cout << (k - nax) << "\n";
    return 0;
}

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

using namespace std;

#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
const ll INF = 1LL << 60;
#define MOD 1000000007ll
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it, v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)

#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z) cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define deb4(a, b, c, d) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define nl cout << endl
// void bfs(vector<int> &dist, vector<vector<int>> &edges, int index)
// {
//     queue<pair<int, int>> q;
//     dist[index] = -1;
//     q.push(mp(index, 0));
//     while (!q.empty())
//     {
//         pair<int, int> top = q.front();
//         // deb2(top.ff,top.ss);
//         q.pop();
//         if (dist[top.ff] != -1)
//             continue;
//         // deb3(top.ff,top.ss,dist[top.ff]) ;
//         dist[top.ff] = top.ss;
//         for (int i = 0; i < edges[top.ff].size(); i++)
//         {
//             if (dist[edges[top.ff][i]] == -1)
//             {
//                 q.push(mp(edges[top.ff][i], dist[top.ff] + 1));
//             }
//         }
//     }
// }
int32_t main()
{
    fast;
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int t;
    cin >> t;
    int a , b ; 
    cin>>a>>b ; 
    bool flag = false ; 
    for(int i = a ; i <= b ; i++ )
    {
        if(i%t==0)
            flag = true ;
    }
    if(flag)
        cout<<"OK"<<endl;
    else 
        cout<<"NG"<<endl;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=1000000007;
const ll INF=1000000000000000001;
int main(){
    ll n,m;cin>>n>>m;
    ll a[n],b[n];
    map<ll,ll> mp;
    rep(i,n){
        cin>>a[i]>>b[i];
        mp[a[i]]+=b[i];
    }
    ll buy=0;
    ll pri=0;
    for(auto p:mp){
        buy=min(m,p.second);
        pri+=p.first*buy;
        m-=buy;
    }
    cout << pri << endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int x,y,z; cin >>x>>y>>z;
    int count = 0;
    x -= z;
    while (x >= y + z) {
        x -= y;
        x -= z;
        count++;
    }
    
    cout << count << endl;
    return 0;
}


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

int main(){
	while(1){
		int n, q;
		int date[101];
		
		scanf(" %d %d", &n, &q); //会議にはq人以上必要
		if(n==0) break;	
		
		//初期化
		for(int i=0; i<=101; ++i) date[i]=0;
		
		for(int i=0; i<n; ++i){
			int m;
			scanf(" %d", &m);
			
			for(int j=0; j<m; ++j){
				int d;
				scanf(" %d", &d);
				date[d]++;
			}
		}
		
		int ans=0;
		for(int i=0; i<=101; ++i){
			if(date[i]>=q && date[ans] < date[i]) ans=i;	
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 1188
L, R = map(int,input().split())

if R - L >= 2019:
    print(0)
elif R-L == 1:
    print(R*L%2019)
else:
    Amari=[]
    for i in range(L,R):
        for j in range(i+1,R+1):
            k = i*j
            Amari.append(k%2019)
    print(min(Amari))


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

using namespace std;
typedef long long LL;
const LL mod=1000000007;
const int Max_Num=10010;

LL modinv(LL x){
	LL m=mod, u=1, v=0;
	while(m){
		LL t=x/m;
		x-=t*m; swap(x,m);
		u-=t*v; swap(u,v);
	}
	u%=mod;
	if(u<0) u+=mod;
	return u;
}

int main(){
	int N;
	cin >> N;
	LL A[Max_Num], Ac[Max_Num];
	rep(i,N) cin >> A[i];
	rep(i,N) Ac[i]=A[i];
	vector<int> L;
	int d=2;
	while(d*d<=1000000){
		int num=0;
		rep(i,N){
			if(A[i]%d==0){
				A[i]/=d;
				num++;
			}
		}
		if(!num) d++;
		else L.emplace_back(d);
	}
	sort(A,A+N);
	L.emplace_back(A[0]);
	rep(i,N-1){
		if(A[i+1]!=A[i]) L.emplace_back(A[i+1]);
	}
	LL M=1;
	for(auto i:L){
		M*=i;
		M%=mod;
	}
	LL ans=0;
	rep(i,N){
		ans+=M*modinv(Ac[i]);
		ans%=mod;
	}
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
import Data.Char
import Data.Bits

solve :: [Int] -> Int -> [Int]
solve xs i
  | i == 0 = [loop xs i] 
  | otherwise = loop xs i : solve xs (i-1)
  where
    loop :: [Int] -> Int -> Int
    loop [x] _ = x
    loop (x:y:xs) j 
      | j .&. 1 == 1 = x + loop (y:xs) (shiftR j 1)
      | otherwise = loop (10*x+y:xs) (shiftR j 1)

main = do
  xs <- map digitToInt <$> getLine :: IO [Int]
  print $ sum $ solve xs (2 ^ (length xs - 1) - 1)

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

int main()
{
    int x,y;
    while(1) {
        cin>>x>>y;
        if(x==0 && y==0) break;
        else if(x<=y) cout<<x<<" "<<y<<endl;
        else if(x>y) cout<<y<<" "<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int solve(int h, int w, int n) {
  vector<pair<int, int>> p;
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    p.emplace_back(x, y);
  }
  sort(p.begin(), p.end());
  int pt = 0;
  int can = 0;
  for (int i = 1; i <= h; i++) {
    bool go = can < w;
    while (pt < (int)p.size() && p[pt].first == i) {
      if (p[pt].second <= can) {
        return i - 1;
      }
      if (p[pt].second == can + 1) {
        go = false;
      }
      pt++;
    }
    if (go) {
      can++;
    }
  }
  return h;
}


int main() {
#ifdef LOCAL
  freopen("d.in", "r", stdin);
  freopen("d.out", "w", stdout);
#endif

  int h, w, n;
  while (scanf("%d%d%d", &h, &w, &n) == 3) {
    printf("%d\n", solve(h, w, n));
  }

  return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
    ifstream in("a.in");
    unsigned long long int N,A,B,ans;
    cin>>N>>A>>B;
    ans=min(B-1,N-A);
    if((A+B)%2==0) cout<<((B-A)/2);
    else cout<<min(ans,min((B+A-1)/2,(2*N+1-A-B)/2));

}

Measured memory_bytes: 256
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_prod = np.cumprod(A)
bef = A_prod[K - 1]
for i in range(K, N):
    if A[i] > A[i - K]:
        print('Yes')
    else:
        print('No')

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

int main() {
    ll n,a,b;
    cin>>n>>a>>b;
    if(n*a<b){
        cout<<n*a<<endl;
    }else{
        cout<<b<<endl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	//C問題

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scan = new Scanner(System.in);

		int n, r;

		n = scan.nextInt();
		r = scan.nextInt();

		if (n >= 10) {
			System.out.println(r);
		} else {
			System.out.println(r + 100 * (10 - n));
		}

	}

}


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

typedef long long ll;
int type[8][3]={{1,1,1},{1,1,-1},{1,-1,1},{-1,1,1},{-1,-1,1},
				{-1,1,-1},{1,-1,-1},{-1,-1,-1}};
ll n,m,a[1010],b[1010],c[1010];
vector <pair<ll,int> > v;

ll my_abs(ll x){
	ll ret=x;
	if(x<0) ret*=-1;
	return ret; 
}

ll solve(int c1,int c2,int c3){
	v.clear();
	for(int i=0;i<n;i++){
		ll sum=a[i]*c1+b[i]*c2+c[i]*c3;
		v.push_back(make_pair(sum,i));
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end()); //sort从小到大，要reverse！！！ 
	ll sum1=0,sum2=0,sum3=0;
	for(int i=0;i<m;i++){
		int x=v[i].second;
		sum1+=a[x];
		sum2+=b[x];
		sum3+=c[x];
	}
	ll ret=0;
	ret=my_abs(sum1)+my_abs(sum2)+my_abs(sum3);
	return ret;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
	ll ans=0;
	for(int i=0;i<8;i++){
		int c1=type[i][0],c2=type[i][1],c3=type[i][2];
		ans=max(ans,solve(c1,c2,c3));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <numeric>
using namespace std;
const long long INF = 1LL<<40;

int main() {
    long long N, K; cin >> N >> K;
    vector<vector<long long> > s(N);
    for (int i = 0; i < N; ++i) {
        long long t, d; cin >> t >> d; --t;
        s[t].push_back(d);
    }

    for (auto &v : s) {
        sort(v.begin(), v.end(), greater<long long>());
        if (v.empty()) v.push_back(-INF);
    }

    sort(s.begin(), s.end(), [&](vector<long long> a, vector<long long> b) {
            return a[0] > b[0];});
 
    long long cur = 0;
    priority_queue<long long> que;
    for (int i = 0; i < K; ++i) {
        cur += s[i][0];
        for (int j = 1; j < s[i].size(); ++j) que.push(s[i][j]);
    }
    for (int i = K; i < N; ++i) for (int j = 0; j < s[i].size(); ++j) que.push(s[i][j]);

    long long res = cur + K*K;
    for (long long x = K-1; x >= 1; --x) {
        long long v = s[x][0];
        long long w = que.top();
        if (v < w) {
            que.pop(); cur += w;
            que.push(v); cur -= v;
        }
        res = max(res, cur + x*x);
    }
    cout << res << endl;
}

Measured memory_bytes: 8696
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <vector>

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

using namespace std;

typedef long long ll;

int group(int n){
    if(n==2)
        return 2;
    else if(n==4 || n==6 || n==9 || n==11)
        return 1;
    else
        return 0;

}

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int r,g,b;
    cin >> r >> g >> b;
    cout <<((100*r+10*g+b)%4==0? "YES":"NO") << endl;
    return 0;
}


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

const long long int INF = 100000000000000000;

struct edge{
    int to;
    long long int cost;
};

vector<edge> g[100002];
int n;
int a,b;
long long int c;
int q,k,x,y;

long long int d[1000002];

void dfs(int n,long long int dist){

    for(int i=0; i<g[n].size(); i++){
        if(d[g[n][i].to] == 0 && g[n][i].to != k) {
            d[g[n][i].to] = dist + g[n][i].cost;
            dfs(g[n][i].to, d[g[n][i].to]);
        }
    }

    return;

}


int main() {

    cin >> n;

    for(int i=0;i<n-1;i++) {
        cin >> a >> b >> c;
        edge e;
        e.to = b;
        e.cost = c;
        g[a].push_back(e);
        e.to = a;
        g[b].push_back(e);
    }

    cin >> q >> k;

    dfs(k,0);

    while(q--){
        cin >> x >> y;
        cout << d[x] + d[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 16000
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a>b){
            System.out.println("a > b");
        }else{
            if(a<b) System.out.println("a < b");
            else System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26360
N = gets.to_i

f_min = 1000000000000000000000
a_max = Math.sqrt(N).to_i + 1
(1..a_max).each do |a|
  if N % a == 0
   b = N / a
   a_digit = Math.log10(a).to_i + 1
   b_digit = Math.log10(b).to_i + 1
   can = [a_digit, b_digit].max
   f_min = [f_min, can].min
  else
    next
  end
end

p f_min

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> a(10, vector<int>(10, 0));
    for (int i = 1; i <= N; i++) {
        int b = to_string(i)[0] - '0', c = i % 10;
        a[b][c]++;
    }
    ll ans = 0;
    rep(i, 10) rep(j, 10) {
        ans += a[i][j] * a[j][i];
    }
    cout << ans << endl;
}

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

typedef struct {
  ll B = 0;  //バン
  ll P = 1;  //パティ
  ll A = 1;  //全部
} bur;

int N;
ll X;
bur Bur[51];

void make_Bur(int n){
  for(int i = 1; i <= n; i++) { 
    Bur[i].B = 2 * Bur[i-1].B + 2; 
    Bur[i].P = 2 * Bur[i-1].P + 1;
    Bur[i].A = Bur[i].B + Bur[i].P;
  }
  return ;
}

ll dsf(ll X, int l){
  if(X == 0) return 0;
  if(l == 0) return 1;  //どうあがいてもパティ
  if(X == Bur[l].A) return Bur[l].P;
  if(X >= Bur[l].A/2+1) return Bur[l-1].P + 1 + dsf(X-Bur[l].A/2-1, l-1);
  if(X < Bur[l].A/2+1) return dsf(X-1, l-1);
  return -1;
}

int main(){
  cin >> N >> X;
  make_Bur(N);
  cout << dsf(X, N) << endl;
  //cout << Bur[N].A << " " << Bur[N].B << " " << Bur[N].P << endl;
  return 0;
}


Measured memory_bytes: 256
L,R=map(int,input().split())
k = 0
l = 2020
m = 2020
apList = [0]*2019
for i in range(L,R+1):
  k = i % 2019
  if apList[k] != 0:
    break
  else:
    apList[k] += 1
res = 2018
for i in range(2019):
  for j in range(i+1,2019):
    if apList[i] != 0 and apList[j] !=0:
      res = min(i*j %2019,res)
print(res)

Measured memory_bytes: 9136
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
long double W,H;
ll x,y;
int main(){
	cin>>W>>H>>x>>y;
	int ans=0;
	if(W/2==x&&H/2==y)ans=1;
	long double hoge=(W*H)/2;
	printf("%Lf",hoge);
	cout<<" "<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
int main(){
	int x;
	cin>>x;
	string st;
	while(x){
		if(x%3==0){
			st+='0';
			x/=3;
		}else if(x%3==1){
			st+='+';
			x/=3;
		}else{
			st+='-';
			x/=3;
			x++;
		}

	}
	reverse(all(st));
	cout<<st<<endl;
	return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int MAX_N = (int)1e8;
template<class Type> class MaxHeap
{
    public:
      Type *heap;
      int sz = 0;
      MaxHeap(int len) { heap = new Type[len]; }
      Type& operator[](size_t n) & { return heap[n]; }
      void push(Type x)
      {
          Type nu = sz;
          sz++;
          while (nu > 0)
          {
              int parent = (nu - 1) / 2;
              if (heap[parent] >= x) 
                  break;
              heap[nu] = heap[parent];
              nu = parent;
          }
          heap[nu] = x;
      }
      void pop()
      {
          Type x = heap[--sz];
          int nu = 0;
          while (nu * 2 + 1 < sz)
          {
              int a = nu * 2 + 1;
              int b = nu * 2 + 2;
              if (b < sz && heap[b] > heap[a]) 
                  a = b;
              if (heap[a] <= x) 
                  break;
              heap[nu] = heap[a];
              nu = a;
          }
          heap[nu] = x;
      }
      Type top() { return heap[0]; }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    MaxHeap<int> hp(MAX_N);
    string s;
    while(cin >> s)
    {
        if(s == "end") break;
        if(s == "insert") 
        {
            int x; cin >> x;
            hp.push(x);
        }
        else
        {
            cout << hp.top() << endl;
            hp.pop();
        }
    }
    return 0;
}




Measured memory_bytes: 7088
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#include <set>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf (int)(1e9)
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

ll a[222222];
ll ord[222222];
int main(void){
  int n;
  cin>>n;

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

  ll res=0;
  set<ll> st;
  st.insert(0);
  st.insert(n+1);
  for(int i=1;i<=n;i++){

    st.insert(ord[i]);
    auto itr=st.find(ord[i]);
    itr++;
    ll r=*itr;
    itr--;itr--;
    ll l=*itr;
    //printf("%d :: %lld ,%lld\n",i,l,r);
    res+=(ord[i]-l)*(r-ord[i])*i;
  }

  cout<<res<<endl;

  return 0;
}

Measured memory_bytes: 12800
def abc():
    h, w = map(int, input().split())
    lines = []
    for i in range(h):
        line = list(input().rstrip())
        if '#' in line:
            lines.append(line)

    for x in reversed(range(w)):
        if len([l for l in lines if l[x] == '#']) == 0:
            for l in lines:
                l.pop(x)
    for line in lines:
        print(''.join(line))


abc()


Measured memory_bytes: 3060
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int x,a,b;
    cin>>x>>a>>b;;
    if(abs(x-a)>abs(x-b))cout<<"B"<<endl;
    else cout<<"A"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> v;
    for (int i = 1; i <= 100; ++i) {
        if (a % i == 0 && b % i == 0) v.push_back(i);
    }
    reverse(all(v));
    cout << v[k - 1] << endl;
    return 0;
}

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

using namespace std;
int main()
{
	int n;
	cin >> n;
	
	
	for(int i=0;i<n;i++){
		int a[3];
		cin >> a[0] >> a[1] >> a[2];
		sort(a,a+3);
		
			
		if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2]){
			cout<< "YES" << endl;
		}else{
			cout<< "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1168
/*
 * Sum of Consecutive Integers
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2197
 */

#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main() {
  vi cnt(1001, 0);

  int n = 1;
  FOR(i, 2, 1001){
    n += i;
    for(int j = n; j < 1001; j += i) {
      cnt[j]++;
    }
  }

  while(cin >> n, n){
    cout << cnt[n] << endl;
  }
}

Measured memory_bytes: 3088
// Mo's algorithm
// 例題：数列の区間内の要素の種類数を求める  ABC174 F
 
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
 
struct Mo {
    vector<int> left, right, index; // offline query
    int window; // bucket width
    int nl, nr, ptr; // [nl,nr)
    vector<int> a; // input
    // add,delで書き換えていく
    vector<int> count, res;
    int sum;
    
    Mo(int n, vector<int> aa) : window((int)sqrt(n)), nl(0), nr(0), ptr(0), count(n+1,0), sum(0) { a = aa; }
    
    /* query [l,r) 0-indexed */
    void push(int l, int r) { left.push_back(l), right.push_back(r); }
    
    /* query sort */
    void build() {
        index.resize(left.size()); res.resize(left.size());
        iota(index.begin(), index.end(), 0);
        sort(index.begin(), index.end(), [&](int a, int b){
            if (left[a] / window != left[b] / window) return left[a] < left[b];
            if((left[a] / window) % 2) return right[a] > right[b];
            return right[a] < right[b];
        });
    }
 
    /* 問題ごとに書き換える */
    void add(int id){ if(count[a[id]]++ == 0) sum++; return; };
    void del(int id){ if(--count[a[id]] == 0) sum--; return; }
    
    /* 区間を次のquery用に伸縮させる */
    void next() {
        const auto i = index[ptr++];
        while (left[i] < nl ) add(--nl);
        while (nr < right[i]) add(nr++);
        while (nl < left[i] ) del(nl++);
        while (right[i] < nr) del(--nr);
        res[i] = sum; return;
    }
};
 
int n, q, l, r;
 
int main() {
    scanf("%d %d", &n, &q); 
    vector<int> a(n);
    rep(i,n) scanf("%d", &a[i]);
    Mo mo(n,a);
    rep(i,q){ cin >> l >> r; mo.push(--l, r); }
 
    mo.build();
    rep(i,q) mo.next();
    rep(i,q) printf("%d\n", mo.res[i]);
    return 0;
}

Measured memory_bytes: 18488