akhauriyash/Code-Regression huggingface dataset:
def main():
    d, g = [int(e) for e in input().split()]
    P, C = zip(*[[int(e) for e in input().split()] for i in range(d)])

    A = []
    for b in [format(i, '0{}b'.format(d)) for i in range(2**d)]:
        count = 0
        score = 0
        for ci, c in enumerate(b):
            if c == '1':
                count += P[-ci - 1]
                score += P[-ci - 1]*(d - ci)*100 + C[-ci - 1]

        if score >= g:
            A.append(count)
            continue

        for i in range(P[-b.index('0') - 1]):
            count += 1
            score += 100*(d - b.index('0'))
            if score >= g:
                A.append(count)
                break

    print(min(A))

if __name__ == "__main__":
    main()


Measured memory_bytes: 40560
#include<iostream>
using namespace std;
int x;
int a[100000];
bool search(int);
int main() {
    cin >> x;
    cout << search(x) << endl;
}

bool search(int x) {
    if (x == 0 || x == 100 || x == 101 || x == 102 || x == 103 || x == 104 || x == 105) {
        return true;
    } else if (x < 100) {
        return false;
    }
    for (int i = 100; i < 106; i++) {
        int k = x - i;
        if (a[k] == 1) {
            return true;
        } else if (a[k] == 0) {
            a[k] = search(k);
            if (a[k]) {
                return true;
            } else {
                a[k] = 2;
            }
        }
    }
    return false;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

ll X, K, D;

int main() {
    cin >> X >> K >> D;
    //ll s;
    //if (X >= 0) s = 1;
    //else s = -1;
    X = abs(X);
    //割り切るまでなんかい必要かどうか
    ll Y = X / D;
    X -= min(Y, K) * D;
    K -= min(Y, K);
    if (K % 2 == 1) X -= D;
    cout << abs(X) << endl;
}

Measured memory_bytes: 3608
N = int(input())
H = list(map(int, input().split()))

now = H[-1]
ans = True
for h in H[::-1]:
    if h <= now:
        now = h
    else:
        if h-1 == now:
            now = h-1
        else:
            ans = False

if ans:
    print("Yes")
else:
    print("No")

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N, M;
    cin >> N >> M;
    vec L(M), R(M);
    REP(i,0,M) cin >> L[i] >> R[i];
    
    sort(ALL(L));
    sort(ALL(R));

    _PR(MAX(R[0]-L[M-1]+1,0));

    return 0;
}

/*



*/

Measured memory_bytes: 1792
# list(map(int, input().split()))

s = input()
q = int(input())

r = False
first = []
last = []
for i in range(q):
    ts = input().split()
    if len(ts) == 1:
        r = not r
        # print(f"reverse: {r}")
    else:
        f, c = int(ts[1]), ts[2]
        if (r and f == 1) or (not r and f == 2):
            # 最後尾
            # s += c
            last.append(c)
        else:
            # 先頭
            # s = c + s
            first.append(c)
s = "".join(first)[::-1] + s + "".join(last)
if not r:
    print(s)
else:
    print(s[::-1])


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

int main(){
   int a,b;
   cin >> a >> b;
   if(a>9 || b>9) cout << -1;
   else cout << a*b;

}
   

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

#define o cout<<"Hello did you expect this?"<<endl;
#define ll long long
#define pb push_back
#define mp make_pair//with Z
#define F first
#define S second

using namespace std;

const int N = 2e5 + 100;
const int mod = 1e9 + 7;

void hey ()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int main ()
{
	hey();
	ll x;
	cin >> x;
	int ans = 0;
	int a = -1, b = -1;
	for (int i = -1000; i <= 1000; i++)
	{
		for (int j = -1000; j <= 1000; j++)
		{
			ll f = 1;
			ll s = 1;
			for (int k = 1; k <= 5; k++)
			{
				f *= i;
				s *= j;
			}
			if (f - s == x)
			{
				a = i;
				b = j;
				break;
			}
		}
		if (a != -1)
		{
			break;
		}
	}
	cout << a << " " << b; 
}	





Measured memory_bytes: 3592
n, m = map(int, input().split())
cnt = [0] * (m + 1)

for i in range(n):
    a = list(map(int, input().split()))
    for num in a[1:]:
        cnt[num] += 1

ans = 0
for c in cnt:
    if c == n:
        ans += 1

print(ans)

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

using namespace std;

double calc(pair<double, double> a, pair<int, int> b) {
    return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

double check(pair<double, double> o, vector<pair<int, int>> &p) {
    double ans = 0.0;
    for (int i = 0; i < (int)p.size(); ++i) {
        ans = max(ans, calc(o, p[i]));
    }
    return ans;
}

double tri(double x, vector<pair<int, int>> &p) {
    double l = 0.0, r = 1000.0;
    while (r > l + 1e-11) {
        double tmp = (r - l) / 3.0;
        double ll = l + tmp, rr = l + tmp + tmp;
        if (check(make_pair(x, ll), p) > check(make_pair(x, rr), p) + 1e-11) {
            l = ll;
        } else {
            r = rr;
        }
    }
    return check(make_pair(x, l), p);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
    }
    double l = 0.0, r = 1000.0;
    while (r > l + 1e-11) {
        double tmp = (r - l) / 3.0;
        double ll = l + tmp, rr = l + tmp + tmp;
        if (tri(ll, p) > tri(rr, p) + 1e-11) {
            l = ll;
        } else {
            r = rr;
        }
    }
    printf("%.10f\n", tri(l, p));
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	
	ll a, b, c, d; cin >> a >> b >> c >> d;
	
	ll dp[c + 1][d + 1][3]; memset(dp, 0, sizeof(dp));
	
	dp[a][b][0] = 1;
	rep(i, a + 1, c){dp[i][b][0] = dp[i - 1][b][0] * b % MOD;}
	rep(j, b + 1, d){dp[a][j][0] = dp[a][j - 1][0] * a % MOD;}
	
	rep(i, a + 1, c){
		rep(j, b + 1, d){
			dp[i][j][0] = (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1] + dp[i - 1][j - 1][2] % MOD) * (i - 1) % MOD * (j - 1) % MOD;
			dp[i][j][0] %= MOD;
			
			dp[i][j][1] = dp[i][j - 1][0] + dp[i][j - 1][1] * i % MOD + dp[i][j - 1][2];
			dp[i][j][1] %= MOD;
			
			dp[i][j][2] = dp[i - 1][j][0] + dp[i - 1][j][1] + dp[i - 1][j][2] * j % MOD;
			dp[i][j][2] %= MOD;
		}
	}
	
	/*rep(i, 1, c){
		rep(j, 1, d){
			cout << "(" << dp[i][j][0] << " " << dp[i][j][1] << " " << dp[i][j][2] << ") ";
		}
		cout << endl;
	}*/
	print((dp[c][d][0] + dp[c][d][1] + dp[c][d][2]) % MOD)
	
	return 0;
}

Measured memory_bytes: 214676
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, K, S;
	cin >> N >> K >> S;
	vector<int> r(N);
	int p = 1000000000;
	if (p == S) -- p;
	for (int i = 0; i < K; ++ i) r[i] = S;
	for (int i = K; i < N; ++ i) r[i] = p;
	for (int i = 0; i < N; ++ i) {
		if (i) cout << " ";
		cout << r[i];
	}
	cout << endl;
}


Measured memory_bytes: 1664
#!/usr/bin/env python3
#ABC88 C
c = [list(map(int,input().split())) for _ in range(3)]
a = [0]
b = [c[0][i] for i in range(3)]
a.append(c[1][0] - c[0][0])
a.append(c[2][0] - c[0][0])
for i in range(3):
    for j in range(3):
        if a[i] + b[j] == c[i][j]:
            continue
        else:
            print('No')
            quit()
print('Yes')


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define _GLIBCXX_DEBUG

int main(void){

    int K;
    string S;

    cin >> K;
    cin >> S;

    if(K >= S.size()){
        cout << S << endl;
    }

    else{
        for(int i = 0; i < K; i++){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }


}

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

int main()
{
	int n, t;
	double a = 0;
	
	cin >> n >> t;

	for (int i = 0; i < n; i++){
		double x, h;
		cin >> x >> h;

		if (h / x > a)
			a = h / x;
	}

	cout << setprecision(10) << a * t << endl;

	return 0;
}


Measured memory_bytes: 3276
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
using namespace std;

const long long INF = (1ll << 50);

struct Dinic {
  typedef long long flow_type;
  struct edge {
    int src, dst;
    flow_type capacity, flow;
    size_t rev;
  };
  int n;
  vector<vector<edge>> adj;
  Dinic(int n) : n(n), adj(n) { }
  void add_edge(int src, int dst, flow_type capacity) {
    adj[src].push_back({src, dst, capacity, 0, adj[dst].size()});
    adj[dst].push_back({dst, src, 0, 0, adj[src].size()-1});
  }
  flow_type max_flow(int s, int t) {
    vector<int> level(n), iter(n);
    function<int(void)> levelize = [&]() { // foward levelize
      level.assign(n, -1); level[s] = 0;
      queue<int> Q; Q.push(s);
      while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        if (u == t) break;
        for (auto &e: adj[u]) {
          if (e.capacity > e.flow && level[e.dst] < 0) {
            Q.push(e.dst);
            level[e.dst] = level[u] + 1;
          }
        }
      }
      return level[t];
    };
    function<flow_type(int, flow_type)> augment = [&](int u, flow_type cur) {
      if (u == t) return cur;
      for (int &i = iter[u]; i < adj[u].size(); ++i) {
        edge &e = adj[u][i], &r = adj[e.dst][e.rev];
        if (e.capacity > e.flow && level[u] < level[e.dst]) {
          flow_type f = augment(e.dst, min(cur, e.capacity - e.flow));
          if (f > 0) {
            e.flow += f;
            r.flow -= f;
            return f;
          }
        }
      }
      return flow_type(0);
    };
    for (int u = 0; u < n; ++u) // initialize
      for (auto &e: adj[u]) e.flow = 0;

    flow_type flow = 0;
    while (levelize() >= 0) {
      fill(iter.begin(), iter.end(), 0);
      for (flow_type f; (f = augment(s, INF)) > 0; )
        flow += f;
    }
    return flow;
  }
};


int main(){

    int n; cin >> n;
    vector<string> str(n);
    for(int i = 0; i < n; i++) cin >> str[i];
    vector<bool> last(26, false);
    for(int i = 0; i < n; i++) last[str[i].back() - 'a'] = true;

    for(char c = 'a'; c <= 'z'; c++) if(last[c - 'a']) {
        long long s = 26, t = 27;
        long long cnt = 0;
        Dinic G(28);


        for(int i = 0; i < n; i++){
            long long u = str[i].front() == c ? s : (long long)(str[i].front() - 'a');
            long long v = str[i].back() == c ? t : (long long)(str[i].back() - 'a');
            G.add_edge(u, v, 1);
            if(str[i].front() == c) cnt++;
        }
        if(G.max_flow(s, t) == cnt) cout << c << endl;
    }

    return 0;
}


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

using namespace std;

void solve()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	vector<int> B(M);
	for(int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	for(int i = 0; i < M; ++i)
	{
		cin >> B[i];
	}
	vector<int> point(N);
	int max = 0;
	for(int i = 0; i < M; ++i)
	{
		for(int j = 0; j < N; ++j)
		{
			if(B[i] >= A[j])
			{
				++point[j];
				if(max < point[j])
				{
					max = point[j];
				}
				break;
			}
		}
	}
	for(int i = 0; i < M; ++i)
	{
		if(max == point[i])
		{
			cout << i + 1 << endl;
		}
	}
}

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

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


class Program
{
    static void Main(string[] args)
    {
        var nq = Console.ReadLine().Split(' ');
        var n = int.Parse(nq[0]);
        var q = int.Parse(nq[1]);

        var tree = new Dictionary<int, Tree>();
        tree.Add(0, new Tree(-1, 0));
        for (var i = 1; i < n; i++)
        {
            var ab = Console.ReadLine().Split(' ');
            var a = int.Parse(ab[0]);
            var b = int.Parse(ab[1]);

            tree.Add(b - 1, new Tree(a - 1, 0));
        }

        for (var j = 0; j < q; j++)
        {
            var px = Console.ReadLine().Split(' ');
            var p = int.Parse(px[0]);
            var x = int.Parse(px[1]);

            tree[p - 1].Value += x;
        }

        for (var k = 0; k < n; k++)
        {
            if (k != 0)
            {
                Console.Write(" ");
                tree[k].Value += tree[tree[k].Parent].Value;
            }
            Console.Write(tree[k].Value);
        }
    }

    public class Tree
    {
        public int Parent;
        public long Value;

        public Tree(int parent, long value)
        {
            this.Parent = parent;
            this.Value = value;
        }
    }
}

Measured memory_bytes: 39608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int n,k;
   string s;
   cin >> n >> k;
   map<int,int> m;
   int kind = 0;
   vector<int> v;
   rep(i,n){
      int tmp;
      cin >> tmp;
      if (!m.count(tmp)) kind++;
      m[tmp]++; 
   }
   int ans = 0;
   for (auto w:m){
      v.push_back(w.second);
   }
   sort(v.begin(),v.end());
   if (kind-k == 0) ans = 0;
   else {
      rep(i,kind-k){
         ans+=v[i];
      }
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 10748
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) {
		long n = scan.nextLong();
		long m = scan.nextLong();
		long d = scan.nextLong();

        double ans = 2 * (m - 1) * (n - d);
        if (d == 0) ans = (m - 1) * (n - d);

        System.out.println(ans / Math.pow(n, 2));
    }
}


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

typedef long long int ll;
typedef vector<ll> vl;
typedef vector<string> vs;

#define N 100000

ll a[N];
ll b[N];

int main(){
	ll n, k, buf, cnt, ans;
	cin >> n >> k;

	vector< pair<ll, ll> > p(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		p[i] = make_pair(a[i], b[i]);
	}

	sort(p.begin(), p.end());

	cnt = 0;
	buf = p[0].second;
	for (;;) {
		if (buf >= k) {
			cout << p[cnt].first << endl;
			return 0;
		}
		cnt ++;
		buf += p[cnt].second;
	}


}


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

const double eps=1e-10;
long long a[100006],N=1e18;

int main()
{
	int n;
	long long tmp=1;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%lld",a+i);
	sort(a+1,a+n+1); 
	for(int i=1;i<=n;++i) {
		if(a[i]==0) {puts("0");return 0;}
		if(N/a[i]>=tmp) tmp*=a[i];
		else {puts("-1");return 0;}
	}
	cout<<tmp;
}

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

const int mod = 1000000007;

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    ll ans = 0;
    rep(i, N){
        cin >> A[i];
    }
    rep(i, 60){
        ll c1 = 0;
        rep(j, N){
            if(A[j]>>i&1){
                c1++;
            }
        }
        ll c0 = N - c1;
        ll cc = (c1*c0) % mod;
        ll p = pow(2, i);
        p %= mod;
        p = (cc * p) % mod;
        ans += p;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll a, b, t;

	cin >> a >> b >> t;

	cout << t / a * b << endl;
}

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

using namespace std;

using ll = long long;
using Pii = pair<int, int>;

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

    auto&& prev = s[0];
    int ans = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (prev != s[i]) {
            ++ans;
            prev = s[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll tmp1=n/(a+b);
    ll tmp2=n%(a+b);
    if(tmp2>=a){
        tmp2=a;
    }
    cout<<tmp1*a+tmp2<<endl;
}
    

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

int main(){
    int w,a,b;
    cin >> w >> a >> b;
    if(a-w<=b&&b<=a+w)cout << 0 << endl;
    else{
        cout << abs(b-a)-w << endl;
    }
    return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  if (A + B >= A - B) {
    if (A + B >= A * B) {
      cout << A + B << '\n';
    } else {
      cout << A * B << '\n';
    }
  } else {
    if (A - B >= A * B) {
      cout << A - B << '\n';
    } else {
      cout << A * B << '\n';
    }
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,N,H,W,ans;
  cin>>N>>H>>W;
  if(N+H+W>=22){
    cout<<"bust"<<endl;
  }else{
    cout<<"win"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys

stdout_write = sys.stdout.write

for line in sys.stdin:
  a, b, c = (int(i) for i in line.strip().split())
  cnt = 0
  if (a * c) <= b:
    cnt = c
    break

  for _ in range(c):
    if (b - a) < 0:
      break
    b -= a
    cnt += 1

stdout_write('{}\n'.format(cnt))

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[n+1];
    int count = 0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]%2==1 && i%2==1)
        count++;
    }
    cout<<count<<"\n";
}


Measured memory_bytes: 3632
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
 
 
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
int tc;
const int N=1e6+5,M=3e5+5,MOD=1e9+7,OO=1e9;

int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	//file();
 	
 	int a, b;

 	cin>>a>>b;

 	if(a!=1 && b!=1)cout<<1<<endl;
 	else if(a!=2 && b!=2)cout<<2<<endl;
 	else	cout<<3<<endl;
}

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

int main() {
  int N, K;
  string str;
  cin >> N >> str >> K;
  
  for(int i = 0; i < N; i++){
    if(str.at(i) != str.at(K - 1)){
      str.at(i) = '*';
    }
  }
  
  cout << str << endl;
}
      
      
  
  

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	int n;
	cin >> n;
	cout << 48-n << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
money = 1000
p = 0
def buy(m,a):
    global money
    global p
    num = m // a
    money -= num*a
    p += num
def sell(s,a):
    global money
    global p
    money += s*a
    p = 0
if a[0] <= a[1]:
    dx = 1
else:
    dx = -1
if dx == 1:
    buy(1000,a[0])
for i in range(n-2):
    if a[i+1] < a[i+2]:
        dy = 1
    elif a[i+1] == a[i+2]:
        dy = 0
    else:
        dy = -1
    if dx == 1 and dy == -1:
        sell(p,a[i+1])
    elif dx == -1 and dy == 1:
        buy(money,a[i+1])
    if dy != 0:
        dx = dy
sell(p,a[n-1])
print(money)

Measured memory_bytes: 61964
//Created Time:2019年10月05日 星期六 20时00分41秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 1000002

using namespace std;

char s[N];
long long k, n;

int main(){
	scanf("%s%lld", s, &k);
	n = strlen(s);
	int l = 0, lc = 0, bg = 0; long long res = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == lc) ++l;
		else {
			if(l && !bg) bg = l;
			res += 1LL * k * (l >> 1);
			lc = s[i];
			l = 1;
		}
	}
	if(l == n)
		res = 1LL * k * n >> 1;
	else {
		if(s[n - 1] == s[0]) {
			res -= 1LL * (bg >> 1) * (k - 1);
			res += 1LL * ((bg + l) >> 1) * (k - 1) + (l >> 1);
		} else res += 1LL * (l >> 1) * k;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
from functools import *
from collections import *
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
 
M = 10**9+7
N = int(input())

@lru_cache(maxsize=None)
def mod_inv(x):
  if x == 1:
    return 1
  return M // x * -mod_inv(M%x) % M

weight = [0]*(N+1)
size = [0]*(N+1)
def calc_subtree(v):
  W = 1
  S = 1
  for child in Edge[v]:
    Edge[child].remove(v)
    w, s = calc_subtree(child)
    W = W * w % M
    S += s
  weight[v] = W * S % M
  size[v] = S
  return weight[v], size[v]

ans = [0]*(N+1)
def set_ans(v, a):
  ans[v] = a
  for child in Edge[v]:
    n = size[child]
    set_ans(child, ans[v] * n * mod_inv(N-n) % M)

Edge = defaultdict(set)
fact = N
for i in range(1, N):
  fact = fact * i % M
  a, b = map(int, input().split())
  Edge[a].add(b)
  Edge[b].add(a)
  
calc_subtree(1)
set_ans(1, mod_inv(weight[1]) * fact % M)
for i in range(1, N+1):
  print(ans[i])



Measured memory_bytes: 89464
n, m = map(int, input().split())
a = list(map(int, input().split()))
j = -1
num = float("inf")
for i in range(n):
    if a[i] < num:
        num = a[i]
        j = i

ans = 0
k = i
while k > 0:
    k = max(0, k - m + 1)
    ans += 1

l = i
while l < n - 1:
    l = min(n - 1, l + (m - 1))
    ans += 1

print(ans)

Measured memory_bytes: 13880
n=int(input())
dic=[[] for i in range(n)]
for i in range(n):
    a=list(map(int,input().split()))
    a=a[2:]
    dic[i]=list(map(lambda x:x-1,a))

from collections import deque
d=deque()
d.append(0) #始点
completed=[False]*n
distance=[999]*n
distance[0]=0
while d:
    now=d.popleft()
    completed[now]=True
    for x in dic[now]: #次の頂点探し
        if completed[x]==False: #その頂点に進んでもよいか
            distance[x]=min(distance[now]+1,distance[x])  #処理
            d.append(x)
for i in range(n):
    if distance[i]==999:
        distance[i]=-1
    print(i+1,distance[i])
    


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

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m,j,k,x,y,a,b,t;
	string s;
	
	cin >> n;
	if(n<10)
	{
		cout << n;
		return 0;
	}
	for(i=0;i<10;i++)
		v.pb(i);
	for(i=1;i<100000;i++)
	{
		ll l=v[i]%10;
		for(j=0;j<10;j++)
			if(abs(l-j)<2)
			{
				v.pb(v[i]*10+j);
//				cout << v.back() << endl;
				if(v.size()==n+1)
				{
					cout << v.back();
					return 0;
				}
			}
	}

	return 0;
}

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

int main() {
	int N;
	int max = 0, second = 0;
	cin >> N;
	
	vector <int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		if (A.at(i) > max) {
			max = A.at(i);
		}
		else if (A.at(i) > second) {
			second = A.at(i);
		}
	}

	for (int i = 0; i < N; i++) {
		if (A.at(i) != max) {
			cout << max << endl;
		}
		else {
			cout << second << endl;
		}
	}

	return 0;

}

Measured memory_bytes: 2432
#include<cstdio>
#include<iostream>
using namespace std;
int n,m;
char a[55][55];
int main(){
	scanf("%d %d\n",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			a[i][j]=getchar();
		}
		getchar();
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]=='.'){
				int sum=0;
				if(a[i-1][j]=='#')sum++;
				if(a[i+1][j]=='#')sum++;
				if(a[i][j-1]=='#')sum++;
				if(a[i][j+1]=='#')sum++;
				if(a[i+1][j+1]=='#')sum++;
				if(a[i+1][j-1]=='#')sum++;
				if(a[i-1][j+1]=='#')sum++;
				if(a[i-1][j-1]=='#')sum++;
				printf("%d",sum);
			}
			else
				putchar('#');
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using vi  = vector<int>;
using ii  = pair<int,int>;
using vii = vector<ii>;
using ll  = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())
#define REP(i, a, b) for (auto (i) = (a); (i) <= (b); (i)++)
#define PER(i, a, b) for (auto (i) = (a); (i) >= (b); (i)--)
#define ITR(i, x) for (auto (i) = (x).begin(); (i) != (x).end(); (i)++)

string to_string(string s) { return '\"' + s + '\"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A,B> p)
{ return "(" + to_string(p.F) + ", " + to_string(p.S) + ")"; }
template <typename T> string to_string(T v) {
	int f = 0; string res = "{";
	for (const auto &x: v)
		res += (f++ ? ", " : "") + to_string(x);
	return res + "}";
}
void debug_out() { cerr << "]\n"; }
template <typename T, typename... V>
void debug_out(T a, V... v)
{ cerr << to_string(a); if (sizeof...(v)) cerr << ", "; debug_out(v...); }

#ifdef LOCAL // add -DLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = [", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif // debug(var1, var2, ...);

const int M = 40;
const int N = 1e5;
ll a[N+5];
ll bit[M+5];
ll sum[M+5];

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n; ll k;
	cin >> n >> k;
	ll tmp = k;
	int m = 0;
	while (tmp)
	{
		tmp >>= 1;
		m++;
	}
	REP(i, 0, n-1) cin >> a[i];

	REP(i, 0, n-1) REP(j, 0, m-1)
	{
		if (a[i] & (1LL << j))
			bit[j] -= (1LL << j);
		else
			bit[j] += (1LL << j);
	}

	REP(j, 0, m-1)
	{
		if (bit[j] > 0)
			sum[j] += bit[j];
		if (j > 0)
			sum[j] += sum[j-1];
	}

	ll init = 0;
	REP(i, 0, n-1) init += a[i];
	ll best = init;
	ll curr = 0;

	curr = init;
	REP(j, 0, m-1)
	{
		if (k & (1LL << j))
			curr += bit[j];
	}
	best = max(curr, best);

	REP(j, 0, m-1) if (k & (1LL << j))
	{
		curr = 0;
		REP(j2, j+1, m-1)
		{
			if (k & (1LL << j2))
				curr += bit[j2];
		}
		if (j > 0)
			curr += sum[j-1];
		best = max(best, init + curr);
	}

	cout << best << '\n';
	return 0;
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
#define N 200000 + 5
#define rep(i, l, r) for(int i = l; i <= r; ++i)
int n, a[N], b[N];
int read(){
	char c; int x = 0, f = 1;
	c = getchar();
	while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int main(){
	n = read();
    rep(i, 1, n) a[i] = read(), b[i] = read();
    sort(a + 1, a + n + 1), sort(b + 1, b + n + 1);
    if(n & 1) printf("%d", b[(n + 1) / 2] - a[(n + 1) / 2] + 1);
    else printf("%d", b[n / 2] + b[n / 2 + 1] - a[n / 2] - a[n / 2 + 1] + 1);
	return 0;
}

Measured memory_bytes: 5328
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    int N; cin >> N;
    int A, B; cin >> A >> B;

    cout << min(N * A, B) << endl;
    return 0;
}


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

int main()
{
	int a[10], b[10];
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	sort(a, a + 10);
	for (int i = 0; i < 10; i++) {
		cin >> b[i];
	}
	sort(b, b + 10);
	int x = 0, y = 0;
	for (int i = 0; i < 3; i++) {
		x += a[9 - i];
	}
	for (int i = 0; i < 3; i++) {
		y += b[9 - i];
	}
	cout << x << ' ' << y << endl;
	return 0;
}



Measured memory_bytes: 3140
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class XTower {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<pair<P, P>> vec(n);
      rep(i, n) {
        int w, s, v; cin >> w >> s >> v;
        vec[i].first = {w+s, v};
        vec[i].second = {w, s};
      }
      sort(all(vec));
      vector<ll> dp(10001);
      ll ans = 0;
      rep(i, n) {
        ll w = vec[i].second.first;
        ll s = vec[i].second.second;
        for(int j=s; j>=0; j--) {
          chmax(ans, dp[j] + vec[i].first.second);
          if (j+w <= 10000) {
            chmax(dp[j+w], dp[j] + vec[i].first.second);
          }
        }
      }
      cout << ans << endl;

    }
};

signed main() {
  XTower solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define ff first
#define ss second
#define p pair<int,int>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi acos(-1)
struct str{
    int ax,ay,bx,by;
};
int main()
{
    fast;
    int h,w;
    cin>>h>>w;
    vector<str>ans;
    int a[h+5][w+5];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
           cin>>a[i][j];

        }
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w-1;j++)
        {
            if(a[i][j]&1)
            {
                a[i][j+1]++;
                ans.pb({i+1,j+1,i+1,j+2});
            }
            else continue;
        }
        if(i==h-1)continue;
        if(a[i][w-1]&1)
        {
            a[i+1][w-1]++;
            ans.pb({i+1,w,i+2,w});
        }
    }
    cout<<ans.size()<<endl;
    for(auto i:ans)
    {
        cout<<i.ax<<" "<<i.ay<<" "<<i.bx<<" "<<i.by<<endl;
    }
}



Measured memory_bytes: 6320
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] S = Console.ReadLine().Split(' ');
            int A = int.Parse(S[0]);
            int B = int.Parse(S[1]);

            if (A < 10 && B < 10)
            {
                Console.WriteLine(A * B);
            }
            else
            {
                Console.WriteLine("-1");
            }
        }
    }
}

Measured memory_bytes: 13140
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		vll a(n);
		vpii bc(m);

		for(int i=0;i<n;i++)
		{
			scanf("%lld", &a[i]);
		}
		sort(a.begin(), a.end());

		for(int i=0;i<m;i++)
		{
			scanf("%d%d", &bc[i].second, &bc[i].first);
		}
		sort(bc.rbegin(), bc.rend());

		int t=0;
		for(int i=0;i<m;i++)
		{
			for(int j=bc[i].second;j>0;j--)
			{
				if(t>=n) break;
				if(a[t]>bc[i].first) break;
				a[t++]=bc[i].first;
			}
		}
		ll ans=0;
		for(int i=0;i<n;i++)
		{
			ans+=a[i];
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


int main(){
	int n; cin >>n;
	vector<int> a(n);
	cinf(n,a);
	vector<int> left(n);
	vector<int> right(n);
	left[0]=a[0];
    right[n-1]=a[n-1];
	for(int i=1;i<n;i++){
		left[i]=GCD(left[i-1],a[i]);
	}
	for(int j=n-2;j>=0;j--){
		right[j]=GCD(right[j+1],a[j]);
	}
	ll res=1;
	ll ans=0;
	for(int i=0;i<n;i++){
		if(i==0)res = right[1];
		else if(i==n-1)res = left[n-2];
		else res=GCD(left[i-1],right[i+1]);
		ans=max(ans,res);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
using System;

namespace abcb154
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            int len = a.Length;
            string text = "";
            for(int i =1; i<=len; i++)
            {
                text = text + "x";
            }
            Console.WriteLine(text);


           
        }
    }
}


Measured memory_bytes: 13140
using System.Text;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        var d = new Dictionary<long, int>();
        var asum = 0L;
        for (int i = 0; i < n; i++)
        {
            if (d.ContainsKey(a[i])) d[a[i]]++;
            else d[a[i]] = 1;
            asum += a[i];
        }
        getAns(d, asum);
    }
    static void getAns(Dictionary<long, int> d, long asum)
    {
        var sb = new StringBuilder();
        var q = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < q; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var b = long.Parse(line[0]);
            var c = long.Parse(line[1]);
            if (d.ContainsKey(b))
            {
                asum += (c - b) * d[b];
                if (d.ContainsKey(c)) d[c] += d[b];
                else d[c] = d[b];
                d.Remove(b);
            }
            sb.Append(asum.ToString() + "\n");
        }
        Console.Write(sb);
    }
}


Measured memory_bytes: 54600
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int ans =0;
  vector<int> data(n);
  
  for(int i=0;i<n;i++)
      cin >> data.at(i);
  
  for(int i=1;i<n-1;i++){
    int pmin = min(data.at(i-1),data.at(i+1));
    pmin = min(pmin,data.at(i));
    int pmax = max(data.at(i-1),data.at(i+1));
    pmax = max(pmax,data.at(i));
    if(pmin!=data.at(i) && pmax!=data.at(i))
      ans++;
  }
 cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
 
#define MOD (long long int)(1e9+7)
#define ll long long int

int ki(int a,int c[100][100],int h, int w,int m){
	if((m/w)%2==0){
		c[m/w][m%w]=a;
	}else{
		c[m/w][w-m%w-1]=a;
	}
	m++;
	return m;
}

int main(void){
	int h,w,n;
	int c[100][100];
	cin>>h>>w>>n;
	int a;
	int memo=0;
	for(int i=1;i<n+1;i++){
		cin>>a;
		for(int j=0;j<a;j++){
			memo = ki(i,c,h,w,memo);
		}
	}

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout<<c[i][j]<<" ";
		}
		cout<<endl;
	}

	return 0;	
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll; 
const ll INF = 1LL << 60;
const ll MOD = 998244353;
typedef pair<int, int> P;
int A[100001], B[100001], C[100001];
ll dp[100001][1 << 4];
map<P, int> mp;
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}
int out(int y, int x, int val) {
	if (mp.count(P(y, x)) == 0) return 0;
	if (mp[P(y, x)] == (val & 1)) return 0;
	return 1;
}
int popcount(int x) {
	int ret = 0;
	while (x > 0) {
		if (x & 1) ret++;
		x >>= 1;
	}
	return ret;
}
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i] >> C[i];
		A[i]--; B[i]--;
		mp[P(A[i], B[i])] = C[i];
		if (abs(A[i] - B[i]) >= 3) {
			if (mp.count(P(B[i], A[i])) && mp[P(B[i], A[i])] != C[i]) {
				cout << 0 << endl;
				return 0;
			}
			mp[P(B[i], A[i])] = C[i];
		}
	}
	ll fr = 0;
	for (int i = 0; i < N; i++) fr += N - (min(N - 1, i + 2) - max(0, i - 2) + 1);
	for (auto p : mp) if (abs(p.first.first - p.first.second) > 2) fr--;
	fr /= 2;
	ll t = mod_pow(2, fr);
	for (int mask = 0; mask < (1 << 4); mask++) {
		if (popcount(mask) % 2) continue;
		int NG = 0;
		for (int y = 0; y < 2; y++) for (int x = 0; x < 2; x++) {
			NG |= out(y, x, mask >> (y * 2 + x));
		}
		if (NG == 0) dp[1][mask]++;
	}
	for (int i = 2; i < N; i++) {
		for (int mask = 0; mask < (1 << 5); mask++) {
			if (popcount(mask) % 2) continue;
			if (out(i, i, mask >> 4)) continue;
			if (out(i - 1, i, mask >> 3)) continue;
			if (out(i - 2, i, mask >> 2)) continue;
			if (out(i, i - 1, mask >> 1)) continue;
			if (out(i, i - 2, mask >> 0)) continue;
			for (int mask2 = 0; mask2 < (1 << 4); mask2++) {
				if (popcount(mask2) % 2) continue;
				int nmask = (mask2 >> 3) & 1;
				nmask |= ((mask >> 1) & 1) << 1;
				nmask |= ((mask >> 3) & 1) << 2;
				nmask |= ((mask >> 4) & 1) << 3;
				if (popcount(nmask) % 2 == 0) (dp[i][nmask] += dp[i - 1][mask2]) %= MOD;
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < (1 << 4); i++) (ans += dp[N - 1][i]) %= MOD;
	(ans *= t) %= MOD;
	cout << ans << endl;
 }

Measured memory_bytes: 19584
n = int(input())
b = list(map(int, input().split()))

a = []

for i in range(n):
    for j in range(len(b)-1, -1, -1):
        if b[j] == j+1:
            x = b.pop(j)
            a.append(x)
            break

if len(a) != n:
    print(-1)
    exit()

for i in a[::-1]:
    print(i)

Measured memory_bytes: 3064
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int R = sc.nextInt();
    if (N >= 10){
      System.out.println(R);
    }else{
      System.out.println(R+100*(10-N));
    }
  }
}

Measured memory_bytes: 21844
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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(){
   double a,b;
cin>>a>>b;
double x;
cin>>x;
if(x==a*a*b){
    cout<<0<<endl;
    return 0;
}
double tmp;
if (x<=a*a*b/2) tmp=x/a;
else  tmp=(a*a*b-x)/a;
double m;
tmp*=2.0;
if (x>a*a*b/2)b=tmp/a;
m=tmp/(long double)b;
 tmp=atan(b/m);
 
tmp=tmp/M_PI*180.0;
cout<<tmp<<endl;
}


Measured memory_bytes: 384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#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(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class DWalkAndTeleport {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    rep(i, N) cin >> X[i];
    int ans = 0;
    rep(i, N - 1) {
      ans += min(B, A * (X[i + 1] - X[i]));
    }
    cout << ans << endl;
  }
};


signed main() {
  DWalkAndTeleport solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>                                                 
                                                                  
int main(void){                                                   
   int D,T,S;                                                     
   scanf("%d %d %d",&D, &T, &S);                                  
                                                                  
   if(T*S >= D){                                                  
      printf("Yes");                                              
   } else {                                                       
      printf("No");                                               
   }                                                              
   return 0;                                                      
}


Measured memory_bytes: 1736
import java.util.*;
class Main{
	public static void main(String args[]) throws Exception {
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt(),B=sc.nextInt(),C=sc.nextInt();
		String str="No";
		if(C>=A&&C<=B)
			str="Yes";
		System.out.println(str);
	}
}

Measured memory_bytes: 23764
n = int(input())
s = [0,0,0,0]
for nnn in range(n):
    nn = input()
    if nn == "AC":
        s[0] += 1
    elif nn == "WA":
        s[1] += 1
    elif nn == "TLE":
        s[2] += 1
    else:
        s[3] += 1

print("AC x {}".format(s[0]))
print("WA x {}".format(s[1]))
print("TLE x {}".format(s[2]))
print("RE x {}".format(s[3]))

Measured memory_bytes: 9128