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

int main()
{
	long long n, a, b; cin >> n >> a >> b;
	
	if (a == 0) {
		cout << 0 << endl;
		return 0;
	}

	long long ans = 0;
	long long sum = a + b;
	long long mo;

	ans += n / sum * a;
	
	mo = n % sum;
	
	if (a < mo) {
		ans += a;
	}
	else {
		ans += mo;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int):
    count = 0
    for i in range(1, N+1):
        if not (i % 3 == 0 or i % 5 == 0):
            count += i
    print(count)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
///Coder ---->>>> Kael (Joan Marcos Rivera)
///Team ACM : CyberSpace ____ IPVCE FEDERICO ENGELS
///KingOfString
///Copyright

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;

typedef long long ll;
typedef pair < string , int > par;

#define pb push_back
#define s second
#define mp make_pair
#define f first
#define maxn 100010
#define eps 1e-9
#define mod 50010
#define less(n) order_of_key(n)
#define en_pos(n) find_by_order(n) /// --- >> iterador --- >> empieza en 0

ll dp[maxn];
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,w;
    cin >> n >> w;
    ll sol=0;
    for(int i=1;i<=n;i++){
        int wi;ll v;
        cin >> wi >> v;
        for(int k=w;k>=wi;k--){
            dp[k]=max(dp[k],dp[k-wi]+v);
            sol=max(sol,dp[k]);
        }
    }
    cout << sol;


}


Measured memory_bytes: 1024
while True:    
    n, k = map(int, raw_input().split())
    if n==0: break
    t = [0]*(n+2)
    for i in xrange(k):
        t[input()] += 1
    for i in xrange(2,n+1):
        if t[i] > 0: t[i] += t[i-1]
    ans = 0
    if t[0]==0:
        for x in t:
            if ans < x: ans = x
    else:    
        nt = []
        for i in xrange(2,n+2):
            if t[i]==0:
                t[i-t[i-1]] = t[i-1]
        for i in xrange(2,n+1):
            if t[i]==0:
                nt += [t[i-1]+1+t[i+1]]
            else: nt += [t[i]]
        for x in nt:
            if ans < x: ans = x
    print ans

Measured memory_bytes: 8092
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int n;
	cin >> n;
	int l[n],r[n];
	REP(i,n) cin >> l[i] >> r[i];
	int ans=0;
	REP(i,n){
		ans+=r[i]-l[i]+1;
	}
	cout << ans << endl;

//////////////////////////////////////////////
}


Measured memory_bytes: 256
var a,b,c:ansistring;
i,j,p,l,x,y:longint;
begin
    readln(a);
    l:=length(a);
    while l>=5 do
    begin
        begin
       // writeln(a);
            b:=copy(a,1,6);
            if b='eraser'then delete(a,1,6)
            else
            begin
                b:=copy(a,1,7);
                if b='dreamer'then
                begin
                   x:=length(a);
                  //writeln(x);
                   if x>=10 then
                   begin
                       c:=copy(a,6,5);
                     //  writeln(c);
                       if c='erase'then
                       begin
                     //  writeln(c);
                         delete(a,1,5);
                       end
                       else delete(a,1,7);
                   end
                   else delete(a,1,7);
                end
                else
                begin
                    b:=copy(a,1,5);
                    if b='erase' then delete(a,1,5)
                    else
                    begin
                       b:=copy(a,1,5);
                       if (b='dream') then
                       begin
                          delete(a,1,5);
                       end
                       else
                       begin
                         writeln('NO');
                         halt;
                       end;
                   end;
                end;
            end;
        end;
        l:=length(a);
        if l=0 then
        begin
            writeln('YES');
            halt;
        end;
    end;
    writeln('NO');
end.


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int ans = -1;
    int a, b, c;
    cin >> a >> b >> c;
    ans = max(ans, a + b * 10 + c);
    ans = max(ans, a + c * 10 + b);
    ans = max(ans, b + a * 10 + c);
    ans = max(ans, b + c * 10 + a);
    ans = max(ans, c + a * 10 + b);
    ans = max(ans, c + b * 10 + a);
    cout << ans << endl;
    //system("pause");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<cstdio>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 7;
vector<pair<ll, ll>>prime_factorize(ll n) {
	vector<pair<ll, ll>>res;
	for (ll p = 2; p*p <= n; ++p) {
		if (n%p != 0)continue;
		int num = 0;
		while (n%p == 0) { ++num; n /= p; }
		res.push_back(make_pair(p, num));
	}
	if (n != 1)res.push_back(make_pair(n, 1));
	return res;
}
const int MAX = 210000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}
ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
int main() {
	int N, M;
	COMinit();
	cin >> N >> M;
	auto vec = prime_factorize(M);
	ll res = 1;
	for (auto pa : vec) {
		int num = pa.second;
		ll tmp = COM(num + N - 1, N - 1);
		res = (res*tmp) % INF;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5120
//2704 上石　彩花
import java.util.Scanner;
public class Main{
	int a,b,c,d;
	
	public void solve(){
		Scanner sc=new Scanner(System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		
		c=a*b;
		d=2*a+2*b;
		
		System.out.print(c+" ");
		System.out.println(d);
	}
	public static void main(String[]args){
		Main obj=new Main();
		obj.solve();
	}
}

Measured memory_bytes: 17160
import math

N = int(input())
dot = [0] * N
for i in range(len(dot)):
    dot[i] = input().split(" ")
    dot[i][0] = int(dot[i][0])
    dot[i][1] = int(dot[i][1])

ans = 1
for i in range(len(dot)-1):
    ans = ans  * (i + 1)

length = 0
for i in range(len(dot)):
    for j in range(len(dot)):
        x = (dot[i][0] - dot[j][0])
        y = (dot[i][1] - dot[j][1])
        length = length + math.sqrt(x*x + y*y)

print(length/N)

Measured memory_bytes: 3064
n = gets.to_i
a,b,c = 3.times.map{gets.chomp}
ans = 0
for i in 0..n-1
    if a[i] == b[i] && b[i] == c[i]
        ans += 0
    elsif a[i] == b[i] || b[i] == c[i] || c[i] == a[i]
        ans += 1
    else
        ans += 2
    end
end
puts ans

Measured memory_bytes: 1788
s = input()

a1 = a2 = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == '0':
            a2 += 1
        else:
            a1 += 1
    else:
        if s[i] == '0':
            a1 += 1
        else:
            a2 += 1

print(min(a1, a2))


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

int main(){
    int N, M;
    cin >> N >> M;
    
    if(abs(M-N)>1){
        cout << 0 << endl;
    }
    else{
        long long x = 1;
        for(long long i = 1;i<=M;i++){
            x = (x * i) % (1000000000 + 7);
            if(x == 0){
                break;
            }
        }
        //cout << "x:" << x << endl;

        long long y = 1;
        for(long long i = 1;i<=N;i++){
            y = (y * i) % (1000000000 + 7);
            if(y == 0){
                    break;
            }
        }
        //cout << "y:" << y << endl;

        long long res;
        if(abs(M-N) == 1){
            res = (x*y) % ((1000000000 + 7));
            cout << res << endl;
        }else if(abs(M-N) == 0){
            res = 2*(x*y) % ((1000000000 + 7));
            cout << res << endl;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)

int main() {
    string S;
    int w;
    cin >> S >> w;
    string ans;
    for (int i = 0; i < S.length(); ++i) {
        if (i % w == 0) {
            ans += S[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math


def read():
    a, b = input().strip().split()
    return a, b

def solve(a, b):
    x = int(a + b)
    m = math.ceil(math.sqrt(x)) + 1
    for i in range(m):
        if i * i == x:
            return 'Yes'
    return 'No'


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 3060
n=int(input())
z=[list(map(int, input().split())) for i in range(n)]
z.sort(key=lambda x:x[2])
z.reverse()

v=[]
count=0

#各頂点に対して、中心座標と仮定して検証
for i in range(101):
    for j in range(101):
        x=abs(j-z[0][0])
        y=abs(i-z[0][1])
        h=z[0][2]+abs(x)+abs(y)
                
            #候補があってるか確認
        for k in range(n):
            if z[k][2]==max(h-abs(z[k][0]-j)-abs(z[k][1]-i),0):
                count+=1
                
        if count==n:
            print(j,i,h)
            exit()
        count=0

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	while (N != 0) {
		vi A(N);
		REP(i, N) {
			cin >> A[i];
		}
		int ans = -1;
		REP(i, N) {
			REP(j, N) {
				if (i == j)continue;
				if (A[i] + A[j] > M)continue;
				chmax(ans, A[i] + A[j]);
			}
		}
		if (ans == -1) {
			cout << "NONE" << endl;
		}
		else {
			cout << ans << endl;
		}
		cin >> N >> M;
	}
	return 0;
}



Measured memory_bytes: 3124
#include<stdio.h>
int main()
{
	int a,b,i;
	scanf("%d %d",&a,&b);
	if(a>=b){ for(i=0;i<a;i++) printf("%d",b);}
	else{ for(i=0;i<b;i++) printf("%d",a);}
	return 0;
}


Measured memory_bytes: 1700
N,K=map(int,input().split())

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

print(len(Base_10_to_n(N,K)))

Measured memory_bytes: 2940
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 3010;

//head

int r, c, k;
vector<P> ite[N];
ll dp1[N], dp2[N];
ll *now = dp2, *pre = dp1;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> r >> c >> k;
  rep(i, k) {
    int r, c, v;
    cin >> r >> c >> v;
    r--; c--;
    ite[r].emplace_back(c, v);
  }
  
  rep(i, r) {
    if(ite[i].empty()) continue;
    ll jjj = 0;
    sort(all(ite[i]));
    int sh = 0;
    set<int> se[3];
    rep(j, 3) se[j].clear();
    ll val[3] = {};
    ll sum[3] = {};
    rep(j, c) {
      chmax(jjj, *(pre+j));
      if(sh != ite[i].size() and ite[i][sh].first == j) {
        ll nv = ite[i][sh++].second;
        if(sum[2]) {
          if(*se[2].begin() < nv) {
            sum[2] += nv - *se[2].begin();
            se[2].erase(se[2].begin());
            se[2].emplace(nv);
          }
        }
        else if(sum[1]) {
          sum[2] = sum[1] + nv;
          se[2] = se[1];
          se[2].emplace(nv);
        }
        if(sum[1]) {
          if(sum[2] < sum[1] + nv) {
            sum[2] = sum[1] + nv;
            se[2] = se[1];
            se[2].emplace(nv);
          }
          if(*se[1].begin() < nv) {
            sum[1] += nv - *se[1].begin();
            se[1].erase(se[1].begin());
            se[1].emplace(nv);
          }
        }
        else if(sum[0]) {
          sum[1] = sum[0] + nv;
          se[1] = se[0];
          se[1].emplace(nv);
        }
        if(sum[0]) {
          if(sum[1] < sum[0] + nv) {
            sum[1] = sum[0] + nv;
            se[1] = se[0];
            se[1].emplace(nv);
          }
          if(*se[0].begin() < nv) {
            sum[0] += nv - *se[0].begin();
            se[0].erase(se[0].begin());
            se[0].emplace(nv);
          }
          if(sum[0] < nv + jjj) {
            sum[0] = nv + jjj;
            se[0].erase(se[0].begin());
            se[0].emplace(nv);
          }
        }
        else {
          sum[0] = nv + jjj;
          se[0].emplace(nv);
        }
      }
      //cout << i << ' ' << j << ' ' << sum[1] << endl;
      *(now+j) = max({*(pre+j), sum[0], sum[1], sum[2]});
    }
    swap(now, pre);
  }

  cout << *(pre+c-1) << endl;
}

Measured memory_bytes: 6544
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL rou(LL a,LL d){if((a*10/d)%10<5)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
LL ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
LL scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}

int main(){
  LL N,M,i,ans=0;
  char C;
  scanf("%c",&C);

  printf("%c\n",C+1);
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);
        while(true){
    		String s=in.next();
    		if(s.equals("-"))break;
            int k=in.nextInt();
    		StringBuilder sb = new StringBuilder(s);
            for(int i=0;i<k;i++){
                int h=in.nextInt();
                sb.append(sb.substring(0,h));
                sb.delete(0, h);
            }
            System.out.println(sb);
        }
	}
}

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

#define PB push_back
#define X first
#define Y second
#define ws asdnasdkns
#define LL long long
#define PI acos(-1.0)
const LL mod = 1000 * 1000 * 1000 + 7;
const LL MAX = 200005;
int visited[405 * 405];
string s[405];
	int h , w;
int cnt1 = 0 , cnt2 = 0;
vector<vector<int> > g(405 * 405);
void dfs(int u)
{
	cnt1 += s[u / w][u % w] == '.';
	cnt2 += s[u / w][u % w] == '#';
	visited[u] = 1;
	for(auto v : g[u])
		if(!visited[v])
			dfs(v);
}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   //	freopen("In.txt" , "r" , stdin);
	srand(time(NULL));
	LL ans = 0;

	cin >> h >> w;
	for(int i = 0; i < h; i++)
		cin >> s[i];
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w - 1; j++)
		{
			if(s[i][j] != s[i][j + 1])
			{
				g[i * w + j].PB(i * w + j + 1);
				g[i * w + j + 1].PB(i * w + j);
			}
		}
	for(int i = 0; i < h - 1; i++)
		for(int j = 0; j < w; j++)
		{
			if(s[i + 1][j] != s[i][j])
			{
				g[i * w + j].PB((i + 1) * w + j);
				g[(i + 1) * w + j].PB(i * w + j);
			}
		}
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			if(!visited[i * w + j])
			{
				cnt1 = 0 , cnt2 = 0;
				dfs(i * w + j);
				ans += cnt1 * (LL) cnt2;
			}
	cout << ans;
}

Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll fac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll n,m;cin >> n >>m;
    vl v(n);
    rep(i,n)cin >> v[i];
    sort(all(v));
    ll count=0;
    vector<pl> c(m);
    rep(i,m)cin >> c[i].se >> c[i].fi;
    sort(all(c));
    reverse(all(c));
    ll x=0;
    while(x<m&&count<n){
        if(v[count]<c[x].fi)v[count]=c[x].fi;
        else break;
        count++;
        c[x].se--;
        if(c[x].se==0)x++;
    }
    ll ans=0;
    rep(i,n)ans+=v[i];
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
typedef long long ll;
int n, m, x;

ll ar[maxn], mid[maxn];
int main()
{
    int k, q;
    scanf("%d%d", &k, &q);
    for(int i=0;i<k;i++)scanf("%d", ar + i);
    while(q--){
        scanf("%d%d%d", &n, &x, &m);
        x %= m;
        ll s = 0;
        for(int i=0;i<k;i++){
            mid[i] = ar[i] % m;
            if(mid[i] == 0)mid[i] = m;
            s += mid[i];
        }
        ll a = s / m, b = s % m;
        a *= (n - 1) / k;
        a += b * ((n - 1) / k) / m;
        s = x + b * ((n - 1) / k) % m;
        //a += (n - 1) / k;
        for(int i=0;i<((n - 1) % k);i++)s += mid[i];
        a += s / m;
        printf("%lld\n", n - 1 - a);
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin>>s;
    long long n,i,c,ans;
    n=s.length();
    ans=0;
    c=0;
    for(i=n-1;i>0;i--){
        if(s[i]=='C'&&s[i-1]=='B'){
            c++;
            i--;
        }else if(s[i]=='A'){
            ans+=c;
        }else{
            c=0;
        }
    }
    if(i==0&&s[0]=='A'){
        ans+=c;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.size()) if(s[i] == '1') ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def resolve():
    A, B, C, K = map(int, input().split())

    ans = 0
    cnt = min(K, A)
    ans += cnt * 1
    K -= cnt
    if K < 1:
        return print(ans)

    cnt = min(K, B)
    ans += cnt * 0
    K -= cnt
    if K < 1:
        return print(ans)

    ans += K * -1

    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9140
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;;
    cin>>n;
    vector<string> vs(n);
    
    for(auto&s:vs)cin>>s;
    
    for(int i=1; i<n; i++){
        if(vs[i][0] != vs[i-1].back() || find(vs.begin(), vs.begin()+i, vs[i])!=vs.begin()+i){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    
}

Measured memory_bytes: 256
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n, m;

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

    cin >> n >> m;
    
    double p = 1;
    
    FOR(i, 0, m) p = p / 2.;

    double ans = 0.;
    double tmp = (n - m) * 100.;
    
    double pp = 1;
    double cur = 1.;
    while (fabs(pp - 0.) > EPS) {
        double c = pp * p;
        pp *= (1 - p);
        ans += c * (1900. * cur * m + tmp * cur);
        cur = cur + 1;
    }

    printf("%.0lf", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL a,b,c;
    cin >> a >> b >> c;
    if (c - a - b >= 0 && sqr(c - a - b) > 4LL * a * b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
from itertools import product
n ,m = map(int,input().split())
cake = [list(map(int,input().split())) for i in range(n)]

ans = 0;
for x, y,z in product([1,-1], repeat = 3):
    tmp = []
    for a,b,c in cake:
        tmp.append(a * x + b * y + c * z)
    tmp.sort(reverse= True)
    ans = max(ans,sum(tmp[:m]))
print(ans)


Measured memory_bytes: 3384
n = int(input())
ta = [tuple(map(int, input().split())) for _ in range(n)] 

ta_cur = list(ta[0])
for i in range(1, n):
  hi = max(-(ta_cur[0]*-1 // ta[i][0]), -(ta_cur[1]*-1 // ta[i][1]))
  ta_cur[0] = ta[i][0] * hi
  ta_cur[1] = ta[i][1] * hi

print(sum(ta_cur))


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

typedef long long ll;
typedef pair<int, int> ii;

int main()
{
    char inp[111];
    scanf("%s", inp);

    int ans = 0;
    int len = strlen(inp);
    for (int i = 0; i < len / 2; i++)
        if (inp[i] != inp[len - i - 1])
            ans++;

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

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int S=102;

int h,w,vis[S][S];
int mn[S][S],dp[S][S];
char s[S][S];

int main() {
	memset(mn,0x3f,sizeof(mn));
	memset(dp,0x3f,sizeof(dp));
	dp[0][1]=dp[1][0]=mn[0][1]=mn[1][0]=0;
	scanf("%d %d",&h,&w);
	for(int i=1;i<=h;i++) {
		scanf("%s",s[i]+1);
		for(int j=1;j<=w;j++) {
			if(s[i][j-1]=='.') mn[i][j]=dp[i][j-1];
			else mn[i][j]=mn[i][j-1];
			if(s[i-1][j]=='.') mn[i][j]=min(mn[i][j],dp[i-1][j]);
			else mn[i][j]=min(mn[i][j],mn[i-1][j]);
			if(s[i][j]=='.')
				dp[i][j]=min(dp[i][j-1],dp[i-1][j]);
			else dp[i][j]=mn[i][j]+1;
		}
	}
	printf("%d\n",dp[h][w]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define si(x) scanf("%d",&x)
#define sf(x) scanf("%lf",&x)
#define sl(x) scanf("%lld",&x)
#define pr(x) printf("%d\n",x)
#define prll(x) printf("%lld\n",x)
 
#define ll long long int
#define ull unsigned long long int
#define F first
#define S second
 
#define rep(i,x,y) for(int i=x;i<y;i++)
#define ii pair<int,int> 
#define pll pair<ll,ll> 
#define vi vector<int> 
#define vvi vector< vi > 
#define vl vector<long long int>
#define vvl vector< vl >
#define vii vector< ii >
#define vvii vector< vii >
#define priority_queue pq;
#define sz(a) ll((a).size()) 
#define pb push_back 
#define mp make_pair
 
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define SET(a,b) memset(a,b,sizeof(a))
#define all(c) (c).begin(),(c).end() 
#define tr(i,c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ison(x,i) (((x) >> (i)) & 1)	//checks if ith bit is on
#define set0(x,i) (x & ~(1 << i))		//set ith bit in x to be zero
#define clr(a) memset(a,0,sizeof(a))
 
#define MOD 1000000007
#define INF 4000000000000000000
#define MAX 100000+5
using namespace std;



int main()
{
	int n,m,k;
	si(n); si(m); si(k);
	rep(i,0,n+1)
	rep(j,0,m+1)
	{
		if(i*j + (n-i)*(m-j) == k )
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//Prints the Longest common subsequence
void printLCS( char *s1, char *s2, int m, int n )
{
   int L[m+1][n+1];
 
   //Building L[m][n] as in algorithm
   for (int i=0; i<=m; i++)
   {
     for (int j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;
       else if (s1[i-1] == s2[j-1])
         L[i][j] = L[i-1][j-1] + 1;
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }
 
   //To print LCS
   int index = L[m][n];
   //charcater array to store LCS
   char LCS[index+1];
   LCS[index] = '\0'; // Set the terminating character
   
   //Stroing characters in LCS
   //Start from the right bottom corner character
   int i = m, j = n;
   while (i > 0 && j > 0)
   {
      //if current character in s1 and s2 are same, then include this character in LCS[]
      if (s1[i-1] == s2[j-1])
      {
          LCS[index-1] = s1[i-1]; // Put current character in result
          i--; j--; index--;     // reduce values of i, j and index
      }
      // compare values of L[i-1][j] and L[i][j-1] and go in direction of greater value.
      else if (L[i-1][j] > L[i][j-1])
         i--;
      else
         j--;
   }
 
   // Print the LCS
   cout<< LCS<<endl;
}
 
/* Driver program to test above function */
int main()
{
  string s1,s2;
  cin>>s1>>s2;
  int n=s1.length(),m=s2.length();
  char	x[n+1],y[m+1];
  strcpy(x,s1.c_str());
  strcpy(y,s2.c_str());	
  printLCS(x,y,n,m);
  return 0;
}

Measured memory_bytes: 35456
#include<stdio.h>
int main(void)
{
	int st,ss;
	int goukeik;
	int goukeis=0;
	int goukeiss=0;
	int heikinnl;
	double heikinn;
	int cnt=0;
	while(scanf("%d,%d",&st,&ss)!=EOF) {
		goukeik=st*ss;
		goukeis+=goukeik;
		goukeiss+=ss;
		cnt++;
		heikinn=(double)goukeiss/cnt;
		heikinnl=heikinn+0.5;
	}
	printf("%d\n%d\n",goukeis,heikinnl);
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -MOD * MOD;
const long double pi = 3.141592653589793;
int main() { // 問題文はしっかり読め!!!
	int n;
	cin >> n;
	vector<P<int>> a(n);
	rep(i, n) {
		cin >> a[i].second >> a[i].first;
	}
	sort(all(a));
	int now = 0;
	bool flag = true;
	rep(i, n) {
		now += a[i].second;
		if (now > a[i].first) flag = false;
	}
	puts((flag) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

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

    public static void solve(Scanner sc) {
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        System.out.println("" + a.charAt(0) + b.charAt(0) + c.charAt(0));
    }
}

Measured memory_bytes: 23764
// header file
#include <iostream>
#include <cstdio>
#include <vector>  //vector<T> vec; ランダムアクセスが速い、挿入は線形時間
#include <list>  //list<T> ls; 挿入・消去速い、アクセスは線形時間
#include <algorithm>
#include <functional> // greater<int>()を使える
#include <utility>
#include <string>
#include <map>
// macro
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define R_REP(i, n) for(int i = ((int)(n - 1)); i >= 0; i--)  // Reverse n-1 ~ 0
#define R_REPN(i, n) for(int i= ((int)(n));i > 0;i--)  // Reverse n ~ 1
#define FOR(i, m, n) for(int i = m;i < n;i++)  // 指定範囲loop m ~ n-1
#define pb(vec) push_back(vec)  // 配列の一番うしろに追加
// typedef
typedef long long ll;  // int64

using namespace std;

int main(void) {
    string A, x, C;
    cin >> A >> x >> C;
    std::cout << A.at(0) << x.at(0) << C.at(0) << std::endl;

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const ll mod = 7 * 17 * (1 << 23) + 1;
const ll inf = 1e18 + 69;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll ans = 0,n, t,s=0;
	map<ll, ll> x;
	x[0]++;
	cin >> n;
	while(n--) {
		cin >> t;
		s+=t;
		ans += x[s];
		x[s]++;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,a,b,count=0;
    cin >> n;
    bool flag=true;
    vector<pair<int, int>> p(n);
    for(int i=0; i<n; i++) {
        cin >> a >> b;
        p.at(i)=make_pair(b,a); 
    }
    sort(p.begin(), p.end());
    for(int i=0; i<n; i++) {
        count += p.at(i).second;
        if(count>p.at(i).first) {
            flag=false;
            break;
        }
    }
    if(flag) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 1792
//
//  main.c
//  Practice
//
//  Created by hoshino on 2015/10/19.
//  Copyright ?? 2015??´ hoshino. All rights reserved.
//

#include <stdio.h>

int main(void) {
    int a,b;
    scanf("%d %d", &a, &b);

    printf("%d %d\n",a*b,2*(a+b));
    // insert code here...
    
    return 0;
}

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

const int INF = 1001001001;

int main(){
  int n;
  std::cin >> n;
  std::vector<int> h(n);
  std::vector<int> c(n,INF);
  rep(i,n) std::cin >> h[i];
  c[0]=0;
  rep(i,n){
    for (int k = i+1; k <= i+2 ;k++) {
      c[k]=min(c[k],c[i]+abs(h[i]-h[k]));
    }
  }
  // rep(i,n)std::cout << c[i] << '\n';
  std::cout << c[n-1] << '\n';



}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
void Print(int *a, size_t n)
{
	for (int i = 0; i < n; i++)
	{
		cout << a[i];
		if (i == n-1)
			cout << endl;
		else
			cout << " ";
	}

}
// ?????\?????????
void insertionSort(int *a, size_t n)
{
	for (int i = 1; i < n; i++)
	{
		Print(a, n);
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v)
		{
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
	}
	
}

int main()
{
	int n;
	cin >> n;
	
	int *ary = new int[n];
	
	for (int i = 0; i < n; i++)
		cin >> ary[i];
	
	insertionSort(ary, n);
	Print(ary, n);
	
	delete[] ary;
	return 0;
}

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

int main(void){
	int n, m, p, cnt, x, sum;
	while(true){
		cin >> n >> m >> p;
		if(!n&&!m&&!p) break;
		cnt = 0; sum = 0;
		for(int i = 0; i < n; ++i){
			cin >> x;
			sum += x;
			if(i == m-1) cnt = x;
		}
		if(cnt == 0){
			cout << 0 << endl;
			continue;
		}
		cout << sum * (100 - p) / cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int x[n],y[n],h[n];
  int num;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>h[i];
    if(h[i]>0)num=i;
  }
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      int now=h[num]+abs(i-x[num])+abs(j-y[num]);
      int r=0;
      for(int k=0;k<n;k++){
        int e=max(now-abs(i-x[k])-abs(j-y[k]),0);
        if(e!=h[k]){
          r=1;
          break;
        }
      }
      if(r==0){
        cout<<i<<" "<<j<<" "<<now<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define swap(x, y, type) do{type t = x; x = y; y = t;}while(0)
void upheap(int, int, int*);
void downheap(int, int, int, int*);
void heap_sort(int, int, int*);
void delete(int*, int, int, int*);
void insert(int*, int, int, int*);
main()
{
        int k, first = 0, count = 0, a[MAX];
        char command[8];
        while (1) {
                scanf("%s", command);
                if (!strcmp(command, "end")) break;
                switch (command[0]) {
                case 'i':
                        scanf(" %d", &k);
                        insert(&count, first, k, a);
                        break;
                case 'e':
                        printf("%d\n", a[first]);
                        delete(&count, first , first, a);
                        break;
                }
        }
}
void upheap(int first, int right, int *table)
{
        int child, parent, bottom = table[right];
        for (child = right; child > first; child = parent) {
                parent = (child - first + 1) / 2 - 1 + first;
                if (table[parent] >= bottom) break;
                table[child] = table[parent];
        }
        table[child] = bottom;
}
void downheap(int first, int left, int right, int *table)
{
        int child, parent, root = table[left];
        for (parent = left; parent < (right - first + 1) / 2 + first;
                 parent = child) {
                int l = 2 * parent - first + 1, r = l + 1;
                if (r <= right && table[r] > table[l]) {
                        child = r;
                } else {
                        child = l;
                }
                if (root >= table[child]) break;
                table[parent] = table[child];
        }
        table[parent] = root;
}
void heap_sort(int n, int first, int *a)
{
        int i;
        for (i = (n - first) / 2 - 1 + first; i >= first; i--) {
                downheap(first, i, n - 1, a);
        }
        for (i = n - 1; i > first; i--) {
                swap(a[first], a[i], int);
                downheap(first, first, i - 1, a);
        }
}
void delete(int *n, int first, int k, int *a)
{
        int pre = a[k];
        a[k] = a[(*n) - 1];
        (*n)--;
        if (pre > a[k]) {
                downheap(first, k, (*n) - 1, a);
        } else {
                upheap(first, k, a);
        }
}

void insert(int *n, int first, int data, int *a)
{
        (*n)++;
        a[(*n) - 1] = data;
        upheap(first, (*n) - 1, a);
}


Measured memory_bytes: 5624
#include<bits/stdc++.h>
#define MAXN 200000+10

using namespace std;

int n;
long long Ans;
set <int> s1,s2;
int a1[MAXN],a2[MAXN];

int main()
{
	scanf("%d",&n);
	n-=2;
	Ans = n;
	Ans *= Ans;
	int Q;
	memset(a1,0x3f,sizeof(a1));
	memset(a2,0x3f,sizeof(a2));
	for(scanf("%d",&Q);Q;Q--)
	{
		int x,y,flag,z;
		scanf("%d%d",&flag,&x);
		x--;
		if(flag==1)
		{
			if(s2.empty()) y = n;
			else
			{
				set<int> :: iterator it = s2.lower_bound(x);
				if(it==s2.end()) y = n;
				else
				{
					z = *it;
					y = a2[z];
				}
			}
			s1.insert(y);
			a1[y] = min(a1[y],x-1);
			Ans -= y;
		}
		else
		{
			if(s1.empty()) y = n;
			else
			{
				set<int> :: iterator it = s1.lower_bound(x);
				if(it==s1.end()) y = n;
				else
				{
					z = *it;
					y = a1[z];
				}
			}
			s2.insert(y);
			a2[y] = min(a2[y],x-1);
			Ans -= y;
		}
	}
	cout<<Ans;
}

Measured memory_bytes: 9848
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val g = Array(n) {ArrayList<Pair<Int,Int>>()}
    repeat(n - 1){
        val (u,v,w) = readLine()!!.split(" ").map{it.toInt()}
        g[u - 1].add(Pair(v - 1, w))
        g[v - 1].add(Pair(u - 1, w))
    }
    var a = IntArray(n)
    var b = BooleanArray(n)
    a[0] = 1
    b[0] = true
    var que = ArrayDeque<Int>()
    que.addLast(0)
    while(que.isNotEmpty()){
        val cur = que.getFirst()
        que.pollFirst()
        for(i in 0 until g[cur].size){
            if(b[g[cur][i].first]) continue
            if(g[cur][i].second % 2 == 0){
                a[g[cur][i].first] = a[cur]
                que.addLast(g[cur][i].first)
                b[g[cur][i].first] = true
            }
            else{
                a[g[cur][i].first] = (a[cur] xor 1)
                que.addLast(g[cur][i].first)
                b[g[cur][i].first] = true
            }
        }
    }
    val st = StringBuilder()
    for(i in 0 until n){
        st.append(a[i].toString() + '\n')
    }
    print(st.toString())
}



Measured memory_bytes: 97824
//============================================================================
// Name        : c
// Date        : Tue Feb 19 22:22:47 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define pvi(x, v) if(v) pvar(x); fora(a, x) cout << a << " "; cout << "\n"
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

void amax(int& a, int b) {
    a = max(a, b);
}

void solve() {
    int n; cin >> n;
    vi dp(3, 0);
    fori (day, 0, n) {
        vi new_dp(3, 0), aa(3);
        fori (i, 0, 3)  {
            cin >> aa[i];
        }

        fori (i, 0, 3) fori (j, 0, 3) {
            if (i != j) {
                new_dp[j] = max(new_dp[j], dp[i] + aa[j]);
            }
        }
        trace(dp, new_dp);
        dp = new_dp;
    }
    output(max(max(dp[0], dp[1]), dp[2]));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	if(N%2==0){
		printf("%d\n",N*(N-1)/2-N/2);
		for(int i=1;i<=N;++i){
			for(int j=i+1;j<=N;++j){
				if(i+j!=N+1){
					printf("%d\n",i);printf("%d\n",j);
				}
			}
		}
	}else{
		printf("%d\n",N*(N-1)/2-N/2);
		for(int i=1;i<=N;++i){
			for(int j=i+1;j<=N;++j){
				if(i+j!=N){
					printf("%d\n",i);printf("%d\n",j);
				}
			}
		}
	}
}

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

int main() {
  lint N, P; cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }

  lint a = 2;
  lint ans = 1;
  while (pow(a, N) <= P) {
    if (P % lint(pow(a, N)) == 0) {
      P /= pow(a, N);
      ans *= a;
    } else {
      a++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
void dfs(std::vector<int> &arr, std::vector<std::vector<int>> &memo, int n = 0, int s = 0) {
	if (n > 10) return;
	if (n != 0) ++memo[n - 1][s];
	for (auto i = n; i < 10; ++i) {
		auto temp = arr[i];
		arr[i] = arr[n]; arr[n] = temp;
		dfs(arr, memo, n + 1, s + temp * (n + 1));
		arr[n] = arr[i]; arr[i] = temp;
	}
}
int f(int n, int s) {
	static std::vector<std::vector<int>> memo(10, std::vector<int>(331, 0));
	static bool is_initialized = false;
	if (!is_initialized) {
		std::vector<int> arr(10);
		for (auto i = 0; i < 10; ++i) arr[i] = i;
		dfs(arr, memo);
		is_initialized = true;
	}
	if (0 <= s && s <= 330 && 1 <= n && n <= 10) return memo[n - 1][s];
	else return 0;
}
int main() {
	int n, s;
	while (std::cin >> n >> s) {
		std::cout << f(n, s) << std::endl;
	}
}


Measured memory_bytes: 3100