akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
char str[110];
int main()
{
//	setfile();
	bool C = 0, F = 0;
	scanf("%s", str + 1);
	for (int i = 1; str[i]; ++i)
		if (str[i] == 'C') C = 1;
		else if (C && str[i] == 'F') F = 1;
	puts(C && F ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 128
import sys

sys.setrecursionlimit(2000000)

s = input()

def solve(i):
    if i == 2:
        if s[i - 1] == s[i]:
            return 2
        else:
            return solve(i - 1) + 1
    if i == 1:
        if s[i - 1] == s[i]:
            return 1
        else:
            return 2
    if i == 0:
        return 1

    if s[i] != s[i - 1]:
        return solve(i - 1) + 1
    else:
        return solve(i - 3) + 2


print(solve(len(s) - 1))


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

#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i > -1; i--)
#define forl(i, l, r) for (int i = l; i <= r; i++)
#define vc vector
#define f first
#define s second
#define pb(i) push_back(i)
#define mx(ar, n) (*max_element(ar, ar + n))
#define mn(ar, n) (*min_element(ar, ar + n))
#define mnv(v) (*min_element(v.begin(), v.end()))
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef string S;
typedef int I;

int x = 1000001 ;
bool prime[1000001] ;

void sev(){
    
    for(int i = 2; i*i <= x; i++)
    {
        
        for(int j = i*2; j <= x; j+=i)
        {
            prime[j] = true ;
        }
        
    }
    
}

int main()
{
    sev() ;
    I n ;
    while(cin >> n){
        int c = 0 ;
        for(int i = 2; i <= n; i++)
        {
            if(!prime[i]){
                c++ ;
            }
        }
        cout << c << endl ;
        
    }
    return 0;
}



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

int main() {
  string s;
  cin >> s;
  vector<int> d;
  for (int i = 0; i < s.size(); i++) {
    d.push_back(s[i] - '0');
  }
  reverse(d.begin(), d.end());

  int ret = 0;
  for (int i = 0; i < d.size(); i++) {
    if (d[i] >= 10) {
      if (i < d.size() - 1) {
        d[i + 1] += d[i] / 10;
      } else {
        d.push_back(d[i] / 10);
      }
      d[i] %= 10;
    }

    if (d[i] <= 4) {
      ret += d[i];
    } else if (d[i] == 5) {
      if (i < d.size() - 1 && d[i + 1] >= 5) {
        ret += (10 - d[i]);
        d[i + 1] += 1;
      } else {
        ret += 5;
      }
    } else if (d[i] <= 9) {
      ret += (10 - d[i]);
      if (i < d.size() - 1)
        d[i + 1] += 1;
      else
        d.push_back(1);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

int t, d, l;

void solve() {
	vl v(t);
	ll ans = 0;
	ll cnt = 0;
	rep(i, t) {
		cin >> v[i];
		if (v[i] >= l) {
			cnt = d;
		}

		if (cnt > 0&&i!=t-1)ans++;
		cnt--;
	}
	cout << ans << endl;
}

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

	while (cin >> t >> d >> l,t) {
		solve();
	}
}



Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

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

template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

int main() {
	string s, t;
	cin >> s >> t;
	string tt = t.substr(0, t.size() - 1);
	if (s == tt)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];

    bool ok = false;
    int cur = 1, ans = 0;
    REP(i, 0, N) {
        if (A[i] == cur) {
            cur++;
            ok = true;
        } else {
            ans++;
        }
    }
    if (ok) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N;
    vector<pair<int,int>> BA;
    cin >> N;
    int a,b;
    REP(i,N){
        cin >> a >> b;
        BA.push_back({b,a});
    }
    int T=0;
    sort(BA.begin(),BA.end());
    
    REP(i,N){
        T+=BA[i].second;
        if(T>BA[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 6512
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=0;
  cin>>n;
  cout<<n*n*n<<endl;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var min = int.MaxValue;
            for (var i = 1; i <= n / 2 + 1; i++)
            {
                var a = i;
                var b = n - i;
                var tmp = 0;
                while (a > 0)
                {
                   tmp += a % 10;
                   a /= 10; 
                }
                while (b > 0)
                {
                   tmp += b % 10;
                   b /= 10; 
                }
                min = Math.Min(min, tmp);
            }
            
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13140
// g++ A.cpp -Wall -Wextra -Woverflow -Wshadow -O2
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>
 
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;

int N, K;
int main() {
  ios::sync_with_stdio(false); 
  cin >> N >> K;
  LL ans = 0;
  for (int a = 1; a <= N; a++) {
    if (K % 2 == 0 && !(a % K == 0 || a % K == K / 2)) {
      continue;
    } else if (K % 2 == 1 && a % K != 0) {
      continue;
    }
    int start = (a % K == 0 ? K : a % K);
    LL num = (N - start) / K + 1;
    ans += num * num;
  }
  cout << ans << '\n';
}

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

typedef std::pair<int, int> day_reward;
typedef long long int llint;

int main(void){
  int n, m;
  std::cin >> n >> m;

  std::vector<day_reward> baito(n);
  for(int i=0; i<n; i++){
    std::cin >> baito[i].first >> baito[i].second;
  }
  std::sort(baito.begin(), baito.end());
  std::reverse(baito.begin(), baito.end());

  std::multiset<int, std::greater<int> > temp;
  llint result = 0;
  for(int i=1; i<=m; i++){
    while(true){
      auto d = std::prev(baito.end());
      if(d->first <= i){
	temp.insert(d->second);
	baito.erase(d);
      }else{
	break;
      }
    }
    if(! temp.empty()){
      auto e = temp.begin();
      result += *e;
      temp.erase(e);
    }
  }
  std::cout << result << std::endl;
  
  return 0;
}


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


int main()
{
	int n;cin>>n;
	set<string> s;
	
	for(int i=0;i<n;i++){
		string letters;
		cin>>letters;
		s.insert(letters);
	}
	cout<<s.size();
	


	
}

Measured memory_bytes: 19220
S = input()
N = len(S)

for i in range(N - 1):
    if S[i] == S[i + 1]:
        print(i + 1, i + 2)
        exit()

for i in range(N - 2):
    if S[i] == S[i + 2]:
        print(i + 1, i + 3)
        exit()

print(-1, -1)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <numeric>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
int main() {
    int n, k; cin >> n >> k;
    vector<ll> a(n); repeat (i,n) cin >> a[i];
    vector<ll> a_acc { 0 }; whole(partial_sum, a, back_inserter(a_acc));
    vector<ll> b(n); repeat (i,n) b[i] = max<int>(0, a[i]);
    vector<ll> b_acc { 0 }; whole(partial_sum, b, back_inserter(b_acc));
    ll ans = 0;
    repeat (l,n-k+1) {
        int r = l+k;
        setmax(ans, (b_acc[l] - b_acc[0])                         + (b_acc[n] - b_acc[r]));
        setmax(ans, (b_acc[l] - b_acc[0]) + (a_acc[r] - a_acc[l]) + (b_acc[n] - b_acc[r]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4084
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

template< typename T >
struct Edge {
  int from, to;
  T cost;
  Edge() {}
  Edge(int f, int t) : from(f), to(t), cost(1) {}
  Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  friend bool operator < (const Edge& lhs, const Edge& rhs) { return lhs.cost < rhs.cost; };
  friend bool operator > (const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator <= (const Edge& lhs, const Edge& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Edge& lhs, const Edge& rhs) { return !(lhs < rhs); };
};

template< typename T >
using Edges = std::vector< Edge< T > >;
template< typename T >
using Graph = std::vector< Edges< T > >;

map<int, int> e2id;
int _id(int a, int b){
  if (a > b) swap(a, b);
  return a*51+b;
}

bool dfs(Graph<int> &g, int s, int goal, int par, ll &keiro) {
  if (s == goal) {
    keiro |= (1LL<<(e2id[_id(s,par)]));
    return true;
  }
  for (auto e: g[s]) {
    if (e.to == par) continue;
    bool ok = dfs(g, e.to, goal, s, keiro);
    if (ok) {
      if (par != -1) {
        keiro |= (1LL<<(e2id[_id(s,par)]));
      }
      return true;
    }
  }
  return false;
}

int count(ll mask) {
  ll t = 1;
  int ret = 0;
  for (int i = 0; i < 55; ++i) {
    if (t & mask) ++ret;
    t *= 2;
  }
  return ret;
}

int main() {
  int n; cin >> n;
  Graph<int> g(n);
  for (int i = 0; i < n-1; ++i) {
    int a, b;
    cin >> a >> b; --a; --b;
    g[a].emplace_back(a, b);
    g[b].emplace_back(b, a);
    e2id[_id(a, b)] = i;
  }
  int m; cin >> m;
  vector<ll> lm;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b; --a; --b;
    ll keiro = 0;
    dfs(g, a, b, -1, keiro);
    lm.push_back(keiro);
    assert(keiro > 0);
  }
  vector<vector<ll>> dp(n, vector<ll>(1<<m));
  dp[0][0] = 1;
  ll ans = 0;
  for (int i = 0; i < n-1; ++i) { 
    for (int mask = 0; mask < (1<<m); ++mask) {
      if (dp[i][mask] == 0) continue;
      int bit = mask;
      ll flag = 1LL << i;
      for (int j = 0; j < m; ++j) {
        if (flag & lm[j]) bit |= (1<<j);
      }
      // cerr << i << " " << bit << " " << mask << endl;
      dp[i+1][bit] += dp[i][mask];
      dp[i+1][mask] += dp[i][mask];
      // cout << mask << " " << cnt << " " << v << " " << dp[mask] << " " << val << " " << ans << endl;
    }
  }
  cout << dp[n-1][(1<<m)-1] << endl;
}

Measured memory_bytes: 418304
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int a,b;
	cin >> a >> b;
	cout << ((b%a)?(b-a):(a+b)) << endl;
	return 0;
}


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

using namespace std;

#define REP(i, from, to) for (long long int i = (from); i < (to); i++)
#define LIN(a) \
    ll a;      \
    cin >> a;

typedef long long ll;


template <class T>
void puta(T &&t) { cout << t << "\n"; }
template <class H, class... T>
void puta(H &&h, T &&... t)
{
    cout << h << ' ';
    puta(t...);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    LIN(n)
    ll ans = 0;
    REP( i, 0, n ){
        LIN(a)
        while( a % 2 == 0 ){
            ans++;
            a/=2;
        }
    }
    puta(ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int n; std::cin >> n;
  char s[n]; std::cin >> s;
  int tmp = 1;
  if(n % 2 != 0 || n <= 1) {
    tmp = 0;
    std::cout << "No";
    return 0;
  }
  for(size_t i = 0; i < n/2; ++i)
    if(s[i] != s[n/2+i]) {
      tmp = 0; 
      break;
    }
  if(tmp == 1) std::cout << "Yes";
  else std::cout << "No";
  return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

n, m = map(int, input().split())
p = list(map(lambda x:int(x)-1, input().split()))

i2p = {}
p2i = {}

for i, pi in enumerate(p):
    i2p[i] = pi
    p2i[pi] = i

xy = [list(map(lambda x:int(x)-1, input().split())) for _ in range(m)]

uf = UnionFind(n)

for x, y in xy:
    uf.union(i2p[x], i2p[y])

ans = 0
for pi in p:
    if uf.find(pi) == uf.find(i2p[pi]):
        ans += 1

print(ans)

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

const int MAXN = 1001;
double dp[MAXN][MAXN];

double rec(int r, int m) {
  double &res = dp[r][m];
  if(res != -1.0) return res;
  res = 0.0;
  double p = (double)m/(r*2.0 - m);
  double q = (double)1/(r*2.0 - m - 1.0);
  double s = (double)m/(r*2.0 - m - 1.0);
  if(m) res += p * rec(r-1,m-1);
  if(r-m) res += (1-p) * q * (rec(r-1,m));
  if(m && r-m) res += (1-p) * s * (rec(r-1,m) + 1.0);
  if(r-m >= 2) res += (1-p) * (1-(q+s)) * (rec(r,m+2) + 1.0);
  return res;
}

int main() {
  fill(dp[0], dp[MAXN], -1.0);
  int N;
  while(cin >> N && N) {
    printf("%.10f\n", rec(N/2, 0));
  }
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

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

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int H,W;
    cin>>H>>W;
    vector<vector<int>> S(H,vector<int>(W));
    int black = 0;
    int white = 0;
    REP(i,H) {
        REP(j,W) {
            char c;
            cin>>c;
            if (c == '.') {
                S[i][j] = 0;
                white++;
            }
            else {
                S[i][j] = 1;
                black++;
            }
        }
    }
    vector<vector<int>> dist(H,vector<int>(W,-1));
    vector<vector<bool>> visited(H,vector<bool>(W,false));
    queue<pair<int,int>> que;
    visited[0][0] = true;
    dist[0][0] = 0;
    que.push(make_pair(0,0));
    while(que.size()) {
        int h = que.front().fi;
        int w = que.front().se;
        que.pop();
        REP(i,4) {
            int ty = h + dy[i];
            int tx = w + dx[i];
            if (ty < 0 || ty > H - 1) continue;
            if (tx < 0 || tx > W - 1) continue;
            if (S[ty][tx] == 0 && !visited[ty][tx]) {
                dist[ty][tx] = dist[h][w] + 1;
                que.push(make_pair(ty,tx));
                visited[ty][tx] = true;
            }
        }
    }
    if (dist[H-1][W-1] == -1) {
        cout<<-1<<endl;
    }
    else {
        cout<<white - dist[H-1][W-1] - 1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;

int main() {
	int n,i,j,pin=0,p=0;
	while (1) {
		cin >> n;
		if (n == 0) { break; }
		for (i = n+1; i < 2 * n + 1; i++) {
			for (j = 2; j <sqrt((double) i)+1; j++) {
				if (i%j == 0) {
					pin = 1;
					break;
				}
			}
			if (pin == 0) { p = p + 1; }
			else { pin = 0; }
		}if (n == 1) { cout << 1<<endl; }else{cout << p << endl;
	}
		p = 0;
	}
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3000
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

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

int main() {
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;

    bool flag = 0;
    if (v-w > 0) {
        if (abs(b-a) <= t*(v-w)) flag = 1;
    }

    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int ans = n;
  int mini = p[0];
  for (int i = 1; i < n; i++) {
    if (p[i] < mini) {
      mini = p[i];
    } else {
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}

const VI gk={1,5,10,50};
const int INF = (int)1e9+7;

void f(int a, const VI& ks, VI& dp, VI& bf){
	
	const int mx= a+17*21;
	dp.assign(mx +10, -1); bf.assign(mx+10 ,0);
	
	dp[0]=0;
	rep(i, 4) if(ks[i]>0){
		repr(j,mx,0) if(dp[j]>=0) rep2(k, 1,ks[i]+1){
			int sp = j + gk[i]*k;
			if(sp > mx) break;
			//assert(sp <= mx);
			if(dp[sp] < dp[j] +k){
				dp[sp] = dp[j] +k;
				bf[sp] = k<<3 | i;
			}
		}
	
	}
	
	//rep(i,mx) if(dp[i]>=0) printf("%d:%d ",i,dp[i]); puts("");
	//return make_pair(dp, bf);
}
VI f2(){
	const int mx= 17*21;
	VI dp(mx+1, INF); dp[0]=0;
	rep(i, 4){
		rep(j, mx)if(dp[j]<INF){
			if(j+gk[i] <= mx) amin(dp[j+gk[i]], dp[j]+1);
		}
	}
	return dp;
}

int main()
{
	//auto vw2=f2z();
	auto v2=f2();
	int a, bakasw=0;
	
	while(cin >>a){
		if(a<=0) break;
		a/=10;
		VI ks(4);
		rep(j,4) cin >>ks[j];
		VI v, bf;
		f(a, ks, v, bf);
		int mn = INF, svi=-1;
		rep2(i,a, a+17*21) if(v[i]>0){
			int w = v2[i-a] - v[i];
			if( mn >w){ mn=w; svi=i; }
		}
		//for(auto x :bf) printf("%d ",x); puts("");
		//for(auto x :v) printf("%d ",x); puts("");
		int ct[4]={};
		for(int q=0;svi > 0  ;q++){
			int p = bf[svi];
			ct[p&7] += p>>3;
			svi -= gk[p&7] * (p>>3);
			//dbg("a",p,svi,ct[0],ct[1],ct[2],ct[3]);
		}
		if(bakasw==1) cout <<"\n";
		rep(i,4) if(ct[i]>0){
			cout << gk[i]*10 <<" "<<ct[i] <<"\n";
			bakasw=1;
		}
		
	}
	return 0;
}





Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#define ll long long int

using namespace std;

int main(int argc, char const* argv[])
{
	int d, n;
	cin >> d >> n;
	int res = 1;
	for(int i = 0; i < d; i++)res *= 100;
	if(n != 100){
			cout << res * n << endl;
	}else{
			cout << res * 101 << endl;
	}
	return 0;
}


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


int main() {
    int a,b;
    cin >> a >> b;
    if (a<b) {
        cout << 'a' << ' ' << '<' << ' ' << 'b' << endl; 
    }else if (a>b) {
        cout << 'a' << ' ' << '>' << ' ' << 'b' << endl;
    }else{
        cout << 'a' << ' ' << "==" << ' ' << 'b' << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3096
<?php
list($N, $K) = array_map("intval", explode(" ", trim(fgets(STDIN))));
$hArray = array_map("intval", explode(" ", trim(fgets(STDIN))));
 
$dp[0] = 0;
for($i = 1; $i < $N; $i++){
    $dp[$i] = 10**18;
    $dpi = &$dp[$i];
    $limit = min($i, $K);
    $hi = $hArray[$i];
    for($j = 1; $j <= $limit; ++$j){
        $new = $dp[$i-$j] + abs($hi - $hArray[$i-$j]);
        if($new < $dpi){
            $dpi = $new;
        }
    }
}
echo $dp[$N-1];

Measured memory_bytes: 18932
#include<stdio.h>
#include <stdlib.h>
#define ll long long
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll a[110];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld",a+i);
	int ans=0;
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)ans+=a[i]>a[j];
	sortup(a,n);
	for(int i=0;i<n;i++)printf("%d%c",a[i],i==n-1?10:32);
	printf("%d\n",ans);
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int N, K;
int arr[505];
int rem[505];
int psa[505];
vector <int> factors;

void findFactors(int tot){
    int p = (int) sqrt(tot)+1;
    for (int i=1; i<=p; i++) {
        if (tot % i == 0) {
            factors.push_back(i);
            factors.push_back(tot/i);
        }
    }
    sort(factors.begin(), factors.end(), greater<>());
}

int main() {
    cin >> N >> K;
    int tot = 0;
    for (int i=1; i<=N; i++){
        scanf("%d", &arr[i]);
        tot += arr[i];
    }
    findFactors(tot);
    int ans;
    for (int f: factors){
        for (int i=1; i<=N; i++){
            rem[i] = arr[i] % f;
        }
        memset(psa, 0, sizeof(psa));
        sort(rem+1, rem+N+1);
        for (int i=1; i<=N; i++) psa[i] = psa[i-1]+rem[i];
        int best = INT_MAX;
        for (int i=1; i<=N; i++){
            if (psa[i]-psa[0] == (N-i)*f-(psa[N]-psa[i])) best = psa[i]-psa[0];
        }
        if (best <= K) {
            ans = f;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!(n: usize, c: i64, xv: [(i64, i64); n]);
    let x: Vec<_> = std::iter::once(0)
        .chain(xv.iter().map(|&(x, _)| x))
        .chain(std::iter::once(c))
        .collect();
    let v: Vec<_> = std::iter::once(0)
        .chain(xv.iter().map(|&(_, v)| v).scan(0, |state, v| {
            *state += v;
            Some(*state)
        }))
        .chain(std::iter::once(xv.iter().map(|&(_, v)| v).sum::<i64>()))
        .collect();
    let n = n + 1;

    let mut ans = std::i64::MIN;
    let mut once = std::i64::MIN;
    let mut twice = std::i64::MIN;
    for i in (0..n).rev() {
        once = once.max(-v[i] + x[i + 1]);
        twice = twice.max(-v[i] + 2 * x[i + 1]);
        ans = ans.max(v[i] + v[n] - 2 * x[i] - x[n] + once);
        ans = ans.max(v[i] + v[n] - x[i] - 2 * x[n] + twice);
    }
    println!("{}", ans);
}


Measured memory_bytes: 7884
#include <bits/stdc++.h>
//#define int long long
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    string ans = "No";
    if(s < t) ans = "Yes";
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> s(M);
  REP(i, M){
    cin >> k[i];
    s[i].resize(k[i]);
    REP(j, k[i]){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  vector<int> p(M);
  REP(i, M){
    cin >> p[i];
  }
  int ans = 0;
  REP(b, 1 << N){
    int light = 0;
    REP(i, M){
      int cnt = 0;
      REP(j, k[i]){
        if(b >> s[i][j] & 1){
          cnt++;
        }
      }
      if(cnt % 2 == p[i]){
        light++;
      }
    }
    if(light == M){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





ll int arr[g_size];



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

	ll int n,m,T,res,r;

	ll int maxi=-mx,mini=mx,count=0;

	ll int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	ll int ara[n_size],ara2[n_size];

    cin>>n>>T;

    f(i,0,n-1) cin>>arr[i];

    res=arr[0]+T;
    f(i,1,n-1)
    {
        r=arr[i]+T;
        if(res>=arr[i]){
            count+=(r-res);
            res=r;
        }
        else if(res<arr[i]){
            count+=T;
            res=r;
        }
    }

    cout<<count+T<<endl;

}


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

using namespace std;

#define intt long long

const int N = 200005;

int n, a[N];

map <int, int> mp;

int main() {

	cin >> n;

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

	intt ans = 0;

	for (int i = 0; i < N; i ++) {
		ans += 1LL * mp[i] * (mp[i] - 1) / 2;
	}

	for (int i = 0; i < n; i ++) {
		cout << ans - mp[a[i]] + 1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=1e5+10;
using namespace std;
inline ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
inline ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
inline void umax(ll &p,ll q){if(p<q)p=q;}
inline void umin(ll &p,ll q){if(p>q)p=q;}
inline ll read()
{
    ll x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,k,t,qu1[maxn],qu2[maxn],cnt1,cnt2;
ll a[maxn],b[maxn],c[maxn],d[maxn],e[maxn],aa,bb;
void add(ll &x,ll y){x+=y;while(x<0)x+=mod;while(x>=mod)x-=mod;}
void adda(int x,ll y){while(x<=n)add(b[x],y),x+=x&(-x);}
void addb(int x,ll y){while(x<=n)add(c[x],y),x+=x&(-x);}
ll geta(int x){ll ret=0;while(x)add(ret,b[x]),x-=x&(-x);return ret;}
ll getb(int x){ll ret=0;while(x)add(ret,c[x]),x-=x&(-x);return ret;}
int main()
{
    int i,j;
    scanf("%d%lld%lld",&n,&aa,&bb);
    rep(i,2,n+1)scanf("%lld",&a[i]);
    a[1]=-1e18;
    qu1[++cnt1]=qu2[++cnt2]=d[1]=e[1]=1;
    adda(1,1);
    addb(1,1);
    rep(i,3,n+1)
    {
        int pos=upper_bound(a+1,a+i-1,a[i]-bb)-a-1;
        ll reta=geta(pos);
        if(a[i]-a[i-1]<aa)
        {
            while(cnt1)adda(qu1[cnt1],-d[qu1[cnt1]]),d[qu1[cnt1]]=0,cnt1--;
        }
        //
        pos=upper_bound(a+1,a+i-1,a[i]-aa)-a-1;
        ll retb=getb(pos);

        if(a[i]-a[i-1]<bb)
        {
            while(cnt2)addb(qu2[cnt2],-e[qu2[cnt2]]),e[qu2[cnt2]]=0,cnt2--;
        }
        //
        addb(i-1,reta);
        e[i-1]=reta;
        qu2[++cnt2]=i-1;
        //
        adda(i-1,retb);
        d[i-1]=retb;
        qu1[++cnt1]=i-1;
    }
    ll ret=0;
    rep(i,1,n)add(ret,d[i]+e[i]);
    printf("%lld\n",ret);
    return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int a, b;
    cin >> a >> b;
    b =  b - 1;
    a = a - 1;
    cout << (b + a - 1) / a << endl;
}

Measured memory_bytes: 256
from itertools import product

H, W = map(int, input().split())
c = [[int(x) for x in input().split()] for _ in range(10)]
A = [[int(x) for x in input().split()] for _ in range(H)]

power = c
for k, i, j in product(range(10), repeat=3):
    power[i][j] = min(power[i][j], power[i][k] + power[k][j])

ans = 0
for i in range(H):
    for j in range(W):
        a_ij = A[i][j]
        if a_ij != -1:
            ans += power[a_ij][1]
print(ans)

Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <functional>
#include <iostream>
using namespace std;
#pragma warning(disable:4996)


int n;
int arr[55];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i < n; i++) {
		int cnt = 0;
		if (arr[i] != i + 1) {
			for (int j = i + 1; j < n; j++)
				if (arr[j] != j + 1)
					cnt++;
		}
		if (cnt > 1) {
			cout << "NO";
			return 0;
		}
			
	}
	cout << "YES";

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <map> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)



int main(void) {
	int d1, d2, m1, m2;
	cin >> m1 >> m2 >> d1 >> d2;
	if (d2 == 1) cout << 1;
	else cout << 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    double N,M; cin >> N >> M;
    vector <int> A(N);
    int sum=0;
    rep(i,N){
        cin >> A[i];
        sum+=A[i];
    }
    
    int cnt=0;
    double ok=sum/(4*M);
    //cout << ok << endl;
    rep(i,N){
        if (ok<=A[i]){
            cnt++;
            //cout << A[i] << endl;
        }
    }
    
    if (cnt>=M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

using namespace std;

int parent[100000];

int root(int v) {
	if (parent[v] == v) return v;
	else return parent[v] = root(parent[v]);
}

int same(int u, int v) {
	return root(u) == root(v);
}

void unite(int u, int v) {
	int r = root(u);
	int s = root(v);
	if (r == s) return;
	parent[r] = s;
}

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	vector<pair<int, int>> x(N);
	vector<pair<int, int>> y(N);
	for (int i = 0; i < N; i++) {
		int X, Y;
		cin >> X >> Y;
		x[i] = make_pair(X, i);
		y[i] = make_pair(Y, i);
	}

	sort(begin(x), end(x));
	sort(begin(y), end(y));

	vector<pair<int, pair<int, int>>> es;
	for (int i = 1; i < N; i++) {
		es.push_back(make_pair(abs(x[i].first - x[i-1].first), make_pair(x[i].second, x[i-1].second)));
		es.push_back(make_pair(abs(y[i].first - y[i-1].first), make_pair(y[i].second, y[i-1].second)));
	}
	sort(begin(es), end(es));

	for (int i = 0; i < N; i++) parent[i] = i;

	int ans = 0;
	for (int i = 0; i < es.size(); i++) {
		auto e = es[i];
		auto d = e.first;
		auto u = e.second.first, v = e.second.second;
		if (!same(u, v)) {
			unite(u, v);
			ans += d;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6516
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    s = gets.chomp

    s.chars.each_with_index do |c, i|
      if (i+1).even?
        if c == 'R'
          puts "No"
          return
        end
      else
        if c == 'L'
          puts "No"
          return
        end
      end
    end

    puts "Yes"
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2300
s=input()
a=s.count("N")
b=s.count("W")
c=s.count("S")
d=s.count("E")
ans=False
if a!=0 and c!=0:
    if (b!=0 and d!=0) or (b==0 and d==0):
        ans=True
if a==0 and c==0:
    if (b!=0 and d!=0) or (b==0 and d==0):
        ans=True
if ans==True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9064
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<pair<double,string> > crop;
    // -value,name
    REP(i,n){
      string name;
      double p,a,b,c,d,e,f,s,m;
      cin >> name >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      crop.push_back(make_pair(-(f*s*m-p)/(a+b+c+(d+e)*m),name));
    }
    SORT(crop);
    REP(i,crop.size()) cout << crop[i].second << endl;
    cout << '#' << endl;
  }
}

Measured memory_bytes: 1252
import sys

N=int(sys.stdin.readline())
A=list(map(int,sys.stdin.readline().split()))
B=list(map(int,sys.stdin.readline().split()))

ANS=""
for i in range(1,30):
    k=2**i
    XA=sorted([a%k for a in A],reverse=True)
    XB=sorted([b%k for b in B])
    XB.append(k*2)

    b0=0
    b1=0
    b2=0
    count=N*N%2

    for xa in XA:
        for j in range(b0,N+1):
            if k//2<=xa+XB[j]:
                b0=j
                break

        if b1<b0:
            b1=b0

        
        for j in range(b1,N+1):
            if xa+XB[j]>=k:
                b1=j
                break

        if b2<b1:
            b2=b1

        for j in range(b2,N+1):
            if k*3//2<=xa+XB[j]:
                b2=j
                break

        count+=b1-b0-b2

    ANS+=str(count%2)

print(int(ANS[::-1],2))


Measured memory_bytes: 145120
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    map<ll,ll> mp;
    rep(i,n) {
        mp[a[i]]++;
    }
    int q;
    cin >> q;
    ll sum = 0;
    for(int i = 1;i<=100000;i++) {
        sum += mp[i]*i;
    }
    rep(i,q) {
        int b,c;
        cin >> b >> c;
        sum -= mp[b]*b;
        sum += mp[b]*c;
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << endl;
    }
    

}

Measured memory_bytes: 9832
#include<stdio.h>

void min_swap( int *a, int *b ){
    int tmp;
    if ( *a > *b ) {
        tmp = *a;
        *a = *b;
        *b = tmp;
    }
}

int main(void){
    int x,y;
    while ( scanf("%d %d", &x, &y) ){
        if ( x == 0 && x == y ) break;
        min_swap(&x, &y);
        printf("%d %d\n", x, y);
    }
    return 0;
}


Measured memory_bytes: 2132
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N,A,B;

    cin>>N>>A>>B;

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

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int n,a;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            std::deque<int> deq(10,0);
            for (int i=0;i<n;i++) {
                cin>>a;
                deq[a]+=1;
            }
            for (int j=0;j<10;j++) {
                if (deq[j]==0) {
                    cout<<"-"<<endl;
                } else {
                    for (int k=0;k<deq[j];k++) {
                        cout<<"*";
                    }
                    cout<<endl;
                }
            }
        }
    }
}



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

int main(){
  int D,N;
  int P=1;
  cin >> D >> N;
  if(D==0){
    P=1;
  }else if(D==1){
    P=100;
  }else if(D==2){
    P=10000;
  }
  if(N == 100){
    cout << 101*P << endl;
  }else{
    cout << N*P << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Integer lenChara = Integer.valueOf(scan.nextLine());
        String targetChara = scan.nextLine();

        if (lenChara % 2 == 0) {
            int divide = lenChara / 2;
            String start = targetChara.substring(0, divide);
            String end = targetChara.substring(divide, targetChara.length());
            if (start.equals(end)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
	int a,b,c,n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b>>c;
		if((a*a)+(b*b)==(c*c)){
			cout<<"YES"<<endl;
		}
		else if((a*a)+(c*c)==(b*b)){
			cout<<"YES"<<endl;
		}
		else if((b*b)+(c*c)==(a*a)){
			cout<<"YES"<<endl;
		}
		else cout<<"NO"<<endl;
	}

	return 0;
}


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

#define N_MAX 22

using namespace std;

const int MOD = 1e9+7;

int n;

int a[N_MAX][N_MAX];

int dp[N_MAX][(1 << N_MAX)];

int cntp[(1 << N_MAX)];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            cin >> a[i][j];
    for(int mask = 0; mask < (1 << n); mask++)
        for(int j = 1; j <= n; j++)
            if((mask >> (j - 1)) & 1)
                cntp[mask]++;
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++)
        for(int mask = 0; mask < (1 << n); mask++)
        {
            if(cntp[mask] != i)
                continue;
            for(int j = 1; j <= n; j++)
                if(((mask >> (j - 1)) & 1) && a[i][j] == true)
                {
                    dp[i][mask] += dp[i - 1][mask ^ (1 << (j - 1))];
                    if(dp[i][mask] >= MOD)
                        dp[i][mask] -= MOD;
                }
        }
    cout << dp[n][(1 << n) - 1] << "\n";
    return 0;
}


Measured memory_bytes: 190720
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int a, b; cin >> a >> b;
	cout << (a == b ? "Yes" : "No") << "\n";




	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <set>
 
using namespace std;
typedef long long ll;

ll ans,mx,mn=1e10,sum;
int main(){
	string a;
	cin>>a;
	if(a[0]=='9'||a[1]=='9') cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL inf=1e9;
LL a[200010],b[200010],sum=0,Min=inf,n;
int main()
{
	scanf("%lld",&n);
	for(LL i=1;i<=n;i++) scanf("%lld %lld",&a[i],&b[i]);
	bool flag=false;
	for(LL i=1;i<=n;i++)
	{
		if(a[i]!=b[i]) flag=true;
		sum+=a[i];if(a[i]>b[i]) Min=min(Min,b[i]);
	}
	if(!flag) printf("0");
	else printf("%lld",sum-Min);
}

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

namespace PGC
{
	class Program
	{
		static void Main(string[] args)
		{
			var header = Console.ReadLine().Split();
			var stack = new Stack<int>();
			foreach (var s in header)
			{
				var a = 0;
				var b = 0;
				switch (s)
				{
					case "+":
						b = stack.Pop();
						a = stack.Pop();
						stack.Push(a + b);
						break;
					case "-":
						b = stack.Pop();
						a = stack.Pop();
						stack.Push(a - b);
						break;
					case "*":
						b = stack.Pop();
						a = stack.Pop();
						stack.Push(a * b);
						break;
					default:
						stack.Push(int.Parse(s));
						break;
				}
			}

			System.Console.WriteLine(stack.Pop());
		}
	}
}



Measured memory_bytes: 18396