akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste
// #include "UnionFind.h"
// #include "power.h"

bool sorting(pair<int, int> &a, pair<int, int> &b) {
    return a.first < b.first;
}

signed main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> drink(N);
    for (int i = 0; i < N; ++i) {
        cin >> drink[i].first >> drink[i].second;
    }
    int ans = 0;
    sort(drink.begin(), drink.end(), sorting);
    for (int i = 0; i < N; ++i) {
        if (M - drink[i].second < 0) {
            ans += (drink[i].first * M);
            break;
        } else {
            ans += (drink[i].first * drink[i].second);
            M -= drink[i].second;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    cin>>n;
    vi v(n);
    ll sum=0;
    rep(i,0,n-1) {
        cin>>v[i];
        v[i]*=2;
        if(i!=n-1){
        if(i%2==0) sum+=v[i];
        else sum-=v[i];
    }
    }
    ll a=(sum+v[n-1])/2;
    cout<<a<<" ";
    rep(i,0,n-2){
        cout<<v[i]-a<<" ";
        a=v[i]-a;
    }
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 2176
import numpy as np


N = int(input())
A_arr = [int(v) for v in input().split()]  
Q = int(input())
sum = np.sum(A_arr)
num_arr = np.zeros(100001, dtype = int)
for a in A_arr:
  num_arr[a] += 1
for i in range(Q):
  Bi, Ci = [int(v) for v in input().split()]   
  replace_num = num_arr[Bi]
  sum += replace_num * (Ci - Bi)
  print(sum)
  num_arr[Ci] += num_arr[Bi]
  num_arr[Bi] = 0
  
  

Measured memory_bytes: 38828
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

#define MOD 1000000007

lld f(lld a){
    return a<0 ? -1 * a : a;
}

int main(){
    lld n, m, l;
    scanf("%lld %lld", &n, &m);
    l = f(n - m);
    if(l <= 1){
        lld x=1, y=1, ans;
        while(n>1){
            x *= n;
            n--;
            x = x % MOD;
        }
        while(m>1){
            y *= m;
            m--;
            y = y % MOD;
        }
        ans = x * y % MOD;
        if(l == 0){
            ans = ans * 2 % MOD;
        }
        printf("%lld", ans);
    }else{
        printf("0");
    }

    return 0;
}

Measured memory_bytes: 128
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

  int a,b;
  cin >> a >> b;
  int ans = max(a-b,max(a+b,a*b));
  cout << ans << endl;

return 0;
}
///....


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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef long long int lli;
typedef long double float64;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
    for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
        << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
    << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;


inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);

/////////////////////////////////////////////////////////////////////

/*bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/

template<class T> inline T gcd(T a,T b) //NOTES:__gcd(0,0) gives exception
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}



const int MAX_N = 123;

//ll arr[MAX_N];

int main() {
    int N,A,B;
    scanf("%d%d%d",&N,&A,&B);
    printf("%d",min(N*A,B));
	return 0;
}


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

int main() {

	int A, B, C;

	cin >> A>>B>>C;

	if (A < B) {
	
	
		if (A < C && C < B) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	
	
	}
	else {
		if (B < C && C < A) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	
	
	}

	
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = []

flag = 0  #unknown:0, increasing:1, decreasing:2
ans = 1
cur = a[0]

for i in a:
    if (flag == 1 and i < cur) or (flag == 2 and i > cur):
        ans += 1
        flag = 0
    elif flag != 1 and cur < i:
        flag = 1
    elif flag != 2 and cur > i:
        flag = 2
    cur = i
print(ans)

Measured memory_bytes: 14224
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define int ll
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=200010;
int n,a[N],tot,t[N],ans;
multiset<int>se;
signed main(){
	n=gi();for(int i=1;i<=n;i++){
		a[i]=gi();se.insert(a[i]);
	}
	for(ll i=1;i<=2e9;i<<=1ll)t[++tot]=i;
	while(!se.empty()){
		int x=*se.rbegin();se.erase(se.find(x));
		for(int j=1;j<=tot;j++)
			if(x<t[j] && se.find(t[j]-x)!=se.end()){se.erase(se.find(t[j]-x)),ans++;break;}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 11136
#include<cstdio>
#include<algorithm>
#include<list>
using namespace std;
int n, r1, r2, EC, Deg[101000], chk[201000], R[201000];
list<int>E[101000];
struct Edge{
    int b, e, num;
}w[401000];
void Make_Edge(int a, int b, int num){
    Deg[a]++,Deg[b]++;
    E[a].push_back(EC);
    E[b].push_back(EC+1);
    w[EC++] = {a,b,num};
    w[EC++] = {b,a,num};
}
void DFS(int a){
    while(!E[a].empty()){
        auto it = E[a].begin();
        int t = *it;
        E[a].erase(it);
        if(chk[w[t].num]) continue;
        chk[w[t].num] = 1;
        DFS(w[t].e);
        if(w[t].num <= n+1) R[w[t].b]++, R[w[t].e]--;
    }
}
int main(){
    int i, a;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&a);
        if(a==-1)r1 = i;
        else Make_Edge(a, i, i);
    }
    for(i=1;i<=n;i++){
        scanf("%d",&a);
        if(a==-1)r2 = i;
        else Make_Edge(a, i, i+n+1);
    }
    Make_Edge(r1, 0, n+1);
    Make_Edge(r2, 0, n+n+2);
    for(i=0;i<=n;i++){
        if(Deg[i]%2){
            puts("IMPOSSIBLE");
            return 0;
        }
    }
    for(i=0;i<=n;i++){
        DFS(i);
    }
    puts("POSSIBLE");
    for(i=1;i<=n;i++)printf("%d ",R[i]);
}

Measured memory_bytes: 30592
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,m;
string a,b;
int32_t main(){
CODE_START;
cin>>a;
cin>>b;
n=a.size();
m=b.size();
if(n==m){
    for(ll i=0;i<n;i++)
    {
        cout<<a[i]<<b[i];
    }
}else  {
    for(ll i=0;i<m;i++)
    {
        cout<<a[i]<<b[i];
    }
    cout<<a[n-1];
}
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n,i;
	long long l[87];
	scanf("%d",&n);
	l[0]=2;
	l[1]=1;
	for(i=2;i<=n;i++)
	{
		l[i]=l[i-1]+l[i-2];
	}
	printf("%lld\n",l[n]);
	return 0;
}

Measured memory_bytes: 128
// Abhishek Chaturvedi- abhishekchaturvedi10oct //

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define endl            "\n"
#define inf             2e18+1
#define ninf            -2e18+1
#define mod             1000000007
#define eps             1e-9
#define ff              first
#define ss              second
#define int             long long
#define ld              long double
#define str             string 
#define pb              emplace_back
#define mp              make_pair
#define vi              vector<int>
#define si              set<int>
#define pii             pair<int,int>
#define psi             pair<str,int>
#define mii             map<int,int>
#define msi             map<str,int>
#define maxheap         priority_queue<int>
#define minheap         priority_queue<int,vi,greater<int>>
#define sz(x)           (int)x.size()
#define all(x)          x.begin(),x.end()
#define allr(x)         x.rbegin(),x.rend()
#define gcd(x,y)        __gcd(x, y)
#define arrsz(x)        sizeof(x)/sizeof(x[0])
#define sp(x,y)         fixed<<setprecision(y)<<x
#define tc(x)           int x; cin>>x; while(x--)
#define loopf(i,x,y)    for(int i=x;i<=y;i++)
#define loopb(i,x,y)    for(int i=x;i>=y;i--)
#define in(x,n)         int x[n];loopf(i,0,n-1) cin>>x[i];
#define out(x)          for(auto i:x) cout<<i<<" "; cout<<endl;
#define init(x,n,y)     int x[n];loopf(i,0,n-1) x[i]=y;

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

bool isPowerOfTwo(int x){
   return x&&(!(x&(x-1)));
}

int takemod(int x){ 
    return (x%mod + mod) % mod; 
}

int lcm(int x,int y) {
    return (x/gcd(x,y)) * y;
}

int fpow(int base,int power,int MOD) {
    int result = 1;
    base=base%MOD;
    while(power){
        if(power&1) 
            result = (result*base) % MOD;
        base = (base*base) % MOD;
        power = power>>1;
    }
    return result;
}

int modinv(int x){return fpow(x,mod-2,mod);}

void fastIO(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void solve(){  
}

int32_t main(){
    
    fastIO();

    //tc(t){
        solve();
    //}
    init(dp,3,0);
    int n; cin>>n;
    loopf(i,0,n-1){
        init(newdp,3,0); in(cost,3);
        loopf(k,0,2){
            loopf(l,0,2){
                if(l!=k){
                    newdp[l]=max(newdp[l],dp[k]+cost[l]);
                }
            }
        }
        loopf(m,0,2) dp[m]=newdp[m];
    }
    cout<<max(max(dp[0],dp[1]),dp[2]);
    return 0;
}

Measured memory_bytes: 256
import math
a,b,n = map(int,input().split())

temp = a * b // math.gcd(a, b) - 1
temp1 = n - (n % b + 1) if n%b != n else n
temp = min(temp, temp1)
#print(temp)
ans = (a * temp)//b - a * (temp//b)
print(ans)

Measured memory_bytes: 9188
import itertools
n = int(input())
l = list(map(int, input().split()))
l.sort()

if n <= 2:
    print(0)
else:
    cnt = 0
    c = list(itertools.combinations(l, 3))
    for i in range(len(c)):
        if c[i][0] != c[i][1] and c[i][0] != c[i][2] and c[i][1] != c[i][2]:
            if c[i][0] + c[i][1] > c[i][2] and c[i][0] + c[i][2] > c[i][1] and c[i][2] + c[i][1] > c[i][0]:
                cnt += 1
    print(cnt)

Measured memory_bytes: 87236
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	
	int h, w, n;
	cin >> h >> w >> n;
	vector<pii> a(n);
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		a[i] = make_pair(tmp, i+1);
	}

	sort(a.begin(), a.end(), greater<pii>());
	vector<vector<int>> c(h, vector<int>(w, 0));
	
	int p = 0;
	for (int i = 0; i < n;i++) {
		for (int j = 0;j < a[i].first;j++) {
			int h1 = p / w;
			int w1 = (p%w);
			if (h1 % 2 == 1) {
				w1 = w - 1 - w1;
			}

			c[h1][w1] = a[i].second;
			p++;

		}
	}

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


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

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	cout << (1000 - n % 1000) % 1000 << "\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}

int main() {

 string s;
 cin >> s;
 if( 'a' <= s[0] and s[0] <= 'z') {
 		cout <<'a' << endl;
 }
 else{
 	cout << 'A' << endl;
 }

}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N;
	cin >> N;
	int su = 0, fs = N *(N+1) / 2;
	int bp = 2;
	while (fs % bp)
		++bp;
	set<int> s;
	fore(i, 1, N)
		s.insert(i);
	vector<int> part(N+1, -1);
	int goal = fs / bp;
	forn(rund, bp)
	{
		int acts = 0;
		while (acts < goal)
		{
			int best = 0;
			for (auto sit : s)
			{
				if (sit + acts <= goal)
				{
					if (sit > best)
						best = sit;
				}
			}
			assert(best);
			part[best] = rund;
			s.erase(best);
			acts += best;
		}
	}

	vector<pair<int, int> > edges;
	fore(i,1,N)
	{
		fore(j,1, i-1)
		{
			if (part[i] != part[j])
			{
				edges.push_back(make_pair(i, j));
			}
		}
	}
	cout << edges.size() << endl;
	forn(i, edges.size())
		cout << edges[i].first << " " << edges[i].second << endl;


	return 0;
}


Measured memory_bytes: 384
#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(){
  string s;
  cin >> s;
  int ans = 1000;
  REP(i, 26){
    char c = 'a' + i;
    int cnt = 0;
    int pre = s.size();
    REPR(i, s.size()-1){
      if(c == s[i]){
        pre = i;
      }
      cnt = max(cnt, pre - i);
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0; 
}

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

#define INF INT_MAX
#define ll long long

#define MAX_SIZE 1100000	//??????????????§???+10???

using namespace std;

bool is_prime[MAX_SIZE];	//true:?´???°???false:?´???°??\???

//n??\???????´???°?????°????±???????
int sieve(int n){
	for(int i = 0;i <= n;i++)is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;	//0??¨1????´???°??§?????????
	for(int i = 2;i <= n;i++){
		if(is_prime[i]){
			//n??\??????n?????°?????????false?????????
			for(int j = 2*i; j <= n;j+=i){
				is_prime[j] = false;
			}
		}
	}
}

//?????????a,?????????d???????????°??????n????????????????´???°????????????
int getNPrimeForProgression(int a,int d,int n){
	int c = 0,i = 1;
	while(c < n){
		if(is_prime[a+d*(i++-1)])c++;
	}
	i--;
	return a+d*(i-1);
}

int main(){
	int a,d,n;
	sieve(MAX_SIZE);	//MAX_SIZE?????§????´???°????±???????
	while(scanf("%d %d %d",&a,&d,&n) != EOF){
		if(a == 0 || d == 0 || n == 0)break;
		cout << getNPrimeForProgression(a,d,n) << endl;
	}

	return 0;
}

Measured memory_bytes: 4200
/*



Question






*/




#include <bits/stdc++.h>
using namespace std;
#define int                  long long int
#define ff                   first
#define ss                   second
#define pb                   push_back
#define mp                   make_pair
#define pii                  pair<int,int>
#define vi                   vector<int>
#define mi                   map<int,int>
#define pqb                  priority_queue<int>
#define pqs                  priority_queue<int,vi,greater<int>>
#define setbits(x)           __builtin_popcountll(x)
#define zrobits(x)           __builtin_ctzll(x)
#define mod                  1000000007
#define inf                  1e18
#define precise(x,y)         fixed<<setprecision(y)<<x
#define w(x)                 int x;cin>>x;while(x--)
#define endl                 "\n"
#define no_of_digit(n)       floor(log10(n))+1
#define copyarr(a,b,n)       copy_n(a,n,b)

bool vowelcheck(char c) {
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
		return true;

	return false;
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//*****************Enter the code here*******************//
	string s, t;
	cin >> s >> t;
	int c = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i])
			c++;
	}

	cout << c;

	return 0;
}


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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    i64 N = input();

    queue< i64 > q;
    q.push(3);
    q.push(5);
    q.push(7);

    i64 ans = 0;
    while (!q.empty()) {
        i64 a = q.front();
        q.pop();

        string s = to_string(a);
        if (s.find('3') != -1 and s.find('5') != -1 and s.find('7') != -1) ans++;

        if (10 * a + 3 <= N) q.push(10 * a + 3);
        if (10 * a + 5 <= N) q.push(10 * a + 5);
        if (10 * a + 7 <= N) q.push(10 * a + 7);
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

int main() {
	int N, K, a = 0;
	string S;
	cin >> N >> K >> S;
	for (int i = 1; i < N; i++) {
		if (S[i - 1] == S[i]) a++;
	}
	cout << min(2 * K + a, N - 1);
}

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

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {

            int n, a, b, p1, p2, x;

            var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);

            p1 = n * a;
            p2 = b;

            if (p1 <= p2)
                 x = p1;
            else x = p2;

            Console.WriteLine(x);

            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 13140
N = gets.to_i

def get_divider(n)
	(2..n).each{|i|
		if n % i == 0
			return i
		end
	}
end

def divide(i, s)
	list = []
	items = (1..i).to_a
	
	while n = items.pop
		sum = n
		l = [n]
		while sum < s
			j = items.length - 1
			while j >= 0
				if items[j] <= s - sum
					break
				end
				j -= 1
			end
			if j >= 0
				item = items[j]
				sum += item
				l << item
				items.delete_at(j)
			else
				puts "error"
				exit
			end
		end
		list << l
	end
	return list
end


sum = (N + 1) * N / 2
n = get_divider(sum)
s = sum / n
list = divide(N, s)

#p list
vs = []

if list.length > 2
	n.times{|i|
		l1 = list[i - 1]
		l2 = list[i]
		
		l1.each{|v1|
			l2.each{|v2|
				vs << [v1, v2]
			}
		}
	}
else
	l1 = list[0]
	l2 = list[1]
	
	l1.each{|v1|
		l2.each{|v2|
			vs << [v1, v2]
		}
	}
end
puts vs.length
vs.each{|v1, v2|
	puts "#{v1} #{v2}"
}


Measured memory_bytes: 2172
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
// #define int long long
#define mod (int)(1e9 + 7)
#define pb push_back
#define ll long long int
using namespace std;
typedef pair<int,int> pii;


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

  if(n%2!=0){
    cout<<0<<endl;
    return 0;
  }

  ll res=0;
  ll f=10;
  while(f<=n){
    res+=n/f;
    f*=5;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var ang = Console.ReadLine().Split().Select(s => int.Parse(s)).GroupBy(x=>x).ToArray();
            var ans = 0;
            foreach(var ag in ang)
            {
                if(ag.Key!=ag.Count())
                {
                    if(ag.Key< ag.Count())
                    {
                        ans += ag.Count()- ag.Key;
                    }
                    else
                    {
                        ans += ag.Count();
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 32092
s = input()
a, b = s[:2], s[2:]
if '01' <= a <= '12':
    if '01' <= b <= '12':
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if '01' <= b <= '12':
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 9032
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define Max zhi5968
typedef long long ll;
using namespace std;
const int maxn=100000+10;
set <int> st[100000+20];  
int a[maxn];   
int p[maxn];
int find(int x){  
    return x==p[x]?x:p[x]=find(p[x]);
}  
int main(){ 
	int n,m,i;
	cin>>n>>m;
    for(int i=0;i<n;i++)  
   		p[i]=i;  
   	for(i=1;i<=n;i++)
   		cin>>a[i];
   	for(i=0;i<m;i++)
   	{
   		int t1,t2;
		cin>>t1>>t2;
		int x=find(t1),y=find(t2);
		if(x!=y) p[y]=x;			
	}
	for(i=0;i<maxn;i++)
		find(i);
	int ans=0;
	for(i=1;i<=n;i++)
		if(p[i]==p[a[i]])
			ans++;
	cout<<ans<<endl;
    return 0;  
}  


Measured memory_bytes: 3576
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200'005)
#define MOD (1'000'000'007ll)
#define OO (1'050'000'000)
#define OOL (1'100'000'000'000'000'000ll)

//global


int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	rep(i,0,n+1){
		string res = s+t.substr(n-i,i);
		if(res.substr(0,n) == s && res.substr(i,n) == t){
			cout << n+i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < 100; ++i)
        for (int j = 0; j < 100; ++j)
            if (i * 4 + j * 7 == n)
                return cout << "Yes", 0;
    cout << "No";
}


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

#define mp make_pair
#define pb push_back
#define int long long

using namespace std;
const int inf = 1e18;
const double EPS = 0.00000001;
const int mod = 1000000007;

signed main(){
    double n;
    cin >> n;
    cout << fixed << setprecision(10) << ((int)(n+1)/2)/n << endl;
}


Measured memory_bytes: 3736
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Number of Multiples
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int l, r, d;
  scanf("%d%d%d", &l, &r, &d);

  printf("%d\n", r / d - (l - 1) / d);
  return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main() {

    zoom;
    ll N, i;
    cin >> N;
    vector<vector<ll> > A(3, vector<ll>(N)), dp(3, vector<ll>(N));
    for(i = 0; i < N; i += 1)
        cin >> A[0][i] >> A[1][i] >> A[2][i];
    dp[0][0] = A[0][0];
    dp[1][0] = A[1][0];
    dp[2][0] = A[2][0];
    for(i = 1; i < N; i += 1) {
        dp[0][i] = A[0][i] + (ll)max(dp[1][i - 1], dp[2][i - 1]);
        dp[1][i] = A[1][i] + (ll)max(dp[2][i - 1], dp[0][i - 1]);
        dp[2][i] = A[2][i] + (ll)max(dp[0][i - 1], dp[1][i - 1]);
    }
    cout << (ll)max(dp[0][N - 1], (ll)max(dp[1][N - 1], dp[2][N - 1]));
    return 0;
}

Measured memory_bytes: 5752
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    double res = 0;
    double sum = 0;

    int[] x = new int[n];
    int[] y = new int[n];
    int[] route = new int[n];

    for (int i = 0; i < n; i++) {
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
      route[i] = i;
    }

    do {
      for (int i = 0; i < n - 1; i++) {
        sum += Math.sqrt(Math.pow(x[route[i + 1]] - x[route[i]], 2) + Math.pow(y[route[i + 1]] - y[route[i]], 2));
      }
    } while ((route = nextPermutation(route)) != null);

    res = sum / factorial(n);

    System.out.println(res);

  }

  static int[] nextPermutation(int[] array) {
    int i = Integer.MAX_VALUE;
    int j = 0;
    int[] returnarray = new int[array.length];

    for (int l = array.length - 2; l >= 0; l--) {
      if (array[l] < array[l + 1]) {
        i = l;
        break;
      }
    }

    if (i == Integer.MAX_VALUE) {
      return null;
    }

    for (int l = array.length - 1; l >= 0; l--) {
      if (array[i] < array[l]) {
        j = l;
        break;
      }
    }

    int temp = array[i];
    array[i] = array[j];
    array[j] = temp;
    i++;

    for (int l = 0; l < i; l++) {
      returnarray[l] = array[l];
    }
    for (int l = 0; l < array.length - i; l++) {
      returnarray[l + i] = array[array.length - l - 1];
    }

    return returnarray;

  }

  static int factorial(int n) {
    if (n == 0) {
      return 1;
    }
    return n * factorial(n - 1);
  }

}

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

int WA[100001];
bool AC[100001];

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> p(m+1);
  vector<string> s(m+1);
  for(int i=1;i<=m;i++){
    cin >> p[i] >> s[i];
  }
  for(int i=1;i<=n;i++){
    WA[i]=0;
    AC[i]=false;
  }
  int sumwa=0;
  int sumac=0;
  
  for(int i=1;i<=m;i++){
    if(AC[p[i]]){
      continue;
    }
    if(s[i]=="AC"){
      AC[p[i]]=true;
      sumac++;
      sumwa+=WA[p[i]];
    }else if(s[i]=="WA"){
      WA[p[i]]++;
    }
  }    
  cout << sumac << " " << sumwa << endl;
}


Measured memory_bytes: 6656
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]


max_magic = 0
for a, _ in magic:
    max_magic = max(max_magic, a)

amount = H + 1
dp = [0] * (amount + max_magic)
dp[0] = 0

ret = float('inf')

for amt in range(1, amount + max_magic):
    t = [dp[amt - a] + b for a, b in magic]
    dp[amt] = min(t)

    if amt >= H:
        ret = min(dp[amt], ret)

print(ret)


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

int main()
{
  long int time=0;
  int N,M,K,max=0,j,A,B;
  long int *A_s,*B_s;
  
  cin>>N>>M>>K;
  A_s=new long int[N+1];
  B_s=new long int[M+1];
  A_s[0]=0;
  B_s[0]=0;
  for(int i=0;i<N;i++)
  {
    cin>>A;
    A_s[i+1]=A_s[i]+A;
  }
  for(int i=0;i<M;i++)
  {
    cin>>B;
    B_s[i+1]=B_s[i]+B;
  }
  
  j=0;
  for(int i=0;i<=N;i++)
  {
    do
    {
      time=A_s[i]+B_s[M-j];
      if(time<=K)
      {
        if(max<i+M-j)
	      	max=i+M-j;
        break;
      }
      if(M-j-1<0)
      	break;
      j++;
    }while(time>K);
  }
  cout<<max;
}

Measured memory_bytes: 6272
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<algorithm>
#include<numeric>
#include<iomanip>
#include<stack>
#include<map>
#include<set>
#include<random>
#include<cstring>
#include<cassert>
using namespace std;
#define ll long long int
#define ld long double
const ll Mod = (ll)1e9+7;
ll CaseN=1;
const ld PI = 22/7.0;
#define INF (ll)1e18 

ll tst()
{
ll ans=0;
		
return ans;
}


void solve()
{
	ll n;
	cin>>n;
	bool ans=false;
	if(n>=30)
	{
	ans = true;	
	}
	
	
	if(ans)
  {
  cout<<"Yes"<<endl; 
  }
  else
   {
  cout<<"No"<<endl;
  }

	//cout<<"Case #"<<CaseN<<": ";
	CaseN++;
	// print your ans below;

return ;
}


signed main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
//	cin>>t;
	while(t-->0)
	{
	solve();
	}
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

// I want to delete this stupid solution ;(
#define sandwich(x) [](auto a, auto b){return (x)(a, b);}

template <typename T>
using F2 = std::function<T(T,T)>;

template <typename T, int N, typename F = std::plus<T> >
struct SegmentTree{
    SegmentTree(T u, F f = F()){
        size = 1;
        while(size < N){
            size <<= 1;
        }

        unit = u;
        func = f;

        init();
    }
    void init(){
        for(int i=0;i<size;++i){
            data[i+size] = unit;
        }

        for(int i=size-1;i>0;--i){
            data[i] = func(data[i*2], data[i*2+1]);
        }
    }
    void update(int k, T v){
        k += size;
        data[k] = v;

        while(k > 1){
            k >>= 1;
            data[k] = func(data[k*2], data[k*2+1]);
        }
    }
    inline T query(int l, int r){
        return _query(l, r, 1, 0, size);
    }
    T _query(int a, int b, int k, int l, int r){
        if(b <= l || r <= a){return unit;}
        if(a <= l && r <= b){return data[k];}
        int mid = (l + r) >> 1;
        return func(_query(a, b,   2*k,   l, mid),
                    _query(a, b, 2*k+1, mid, r  ));
    }

    T unit, data[N*4];
    int size;
    F func;
};

vector<int> v[26];
SegmentTree<int, 200100> w(0), w2(0);
int cnt[26];

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

    string S;
    std::cin >> S;

    int L = S.size();
    
    for(int i=0;i<L;++i){
        v[S[i]-'a'].emplace_back(i);
    }

    int odd_n = 0;
    for(int i=0;i<26;++i){
        if(v[i].size() % 2 == 1){++odd_n;}
    }

    if(odd_n > 1){
        std::cout << -1 << std::endl;
        return 0;
    }

    ll res = 0ll;
    int decided = 0;
    while(decided < L){
        int nxt = -1, cost = 0;
        
        for(int i=0;i<26;++i){
            if(cnt[i] == (v[i].size() + 1) / 2){continue;}

            int a = v[i][cnt[i]], b = v[i][v[i].size() - 1 - cnt[i]];
            int first = a - (w.query(0, a) + w2.query(0, a)),
                last = L - 1 - b - (w.query(b, L) + w2.query(b, L));
            if(nxt == -1 || cost > first + last){
                nxt = i;
                cost = first + last;
                // std::cout << (char)('a' + i) << ", " << a << ", " << b << ", " << first << ", " << last << std::endl;
            }
        }

        // std::cout << (char)('a' + nxt) << ", " << cost << std::endl;
        res += cost;
        w.update(v[nxt][cnt[nxt]], 1);
        w2.update(v[nxt][v[nxt].size() - 1 - cnt[nxt]], 1);
        ++cnt[nxt];
        decided += 2;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 7952
import sys,bisect
input = sys.stdin.readline

n,p = map(int,input().split())
s = list(input())
for i in range(n):
    s[i] = int(s[i])
    
if p == 2 or p == 5:
    res = 0
    for i in range(n):
        if s[i]%p == 0:
            res += i+1
    print(res)
else:
    d = 1
    q = [0]
    for i in range(n-1,-1,-1):
        q.append((q[-1]+s[i]*d)%p)
        d = d*10%p
    q.sort()
    res = 0
    q.append(-1)
    f = 1
    for i in range(n+1):
        if q[i]==q[i+1]:
            f += 1
        else:
            res += f*(f-1)//2
            f=1
    print(res)


Measured memory_bytes: 75224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
int main (){
    ll n,m;
    cin>>n>>m;
    vector<ll>x(n+1),y(m+1);
    cin>>x[n]>>y[m];
    rep(i,0,n)cin>>x[i];
    rep(i,0,m)cin>>y[i];
    ll min=*min_element(y.begin(),y.end()),max=*max_element(x.begin(),x.end());
    if(max<min)cout<<"No ";
    cout<<"War\n";
}

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

struct Team {
	char name;
	int wins;
	int loss;
};
bool operator > (const Team& t1, const Team& t2) {
	if (t1.wins > t2.wins) return true;
	else if (t1.wins < t2.wins) return false;
	else return t1.loss < t2.loss;
}

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n == 0) break;
		Team* teams = new Team[n];
		for (int i=0; i<n; i++) {
			char c; std::cin >> c;
			teams[i].name = c;
			int wins = 0;
			int loss = 0;
			for (int j=0; j<n-1; j++) {
				int x; std::cin >> x;
				if (x==0) wins++;
				else if (x==1) loss++;
			}
			teams[i].wins = wins;
			teams[i].loss = loss;
		}
		std::sort(teams, teams + n, std::greater<Team>());
		for (int i=0; i<n; i++) std::cout << teams[i].name << std::endl;
		delete[] teams;
	}
	return 0;
}



Measured memory_bytes: 3112
#include "bits/stdc++.h"
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define int long long int
#define tc int t; cin>>t; while(t--)
#define fora(i,n) for(int i=0;i<n;i++)
#define forb(i,a,n) for(int i=a;i<n;i++)
#define mod 1000000007

template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}

int32_t main()
{
    

 	int n,q;
 	cin>>n;
 	map<int,int> mp;
 	int arr[n];
 	int sum=0;
 	fora(i,n) {
 		cin>>arr[i];
 		sum+=arr[i];
 	 mp[arr[i]]++;
}
 	cin>>q;	
 	while(q--) {
 		int b,c;
 		cin>>b>>c;
 		if(mp[b]==0) {
 			cout<<sum<<"\n";
 			continue;
 		}
 		else {

 			sum-=b*mp[b];
 			sum+=c*mp[b];
 			mp[c]+=mp[b];
 			mp[b]=0;
 			cout<<sum<<"\n";
 		}


 	}

    return 0;


}

Measured memory_bytes: 10072
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>

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

using namespace std;

int main() {

	int n, l;
	
	cin >> n >> l;
	vector<string>word(n);
	


	rep(i, 0, n) {
		cin >> word[i];
	}

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


	rep(i, 0, n)cout << word[i];
	cout << endl;




	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#define F first
#define S second
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-10
using namespace std;
struct P{
  int x,y;
  P (int x=0,int y=0):x(x),y(y){}
  P operator + (P p){return P(x+p.x,y+p.y);}
  P operator - (P p){return P(x-p.x,y-p.y);}
  P operator * (P p){return P(x*p.x,y*p.y);}
  P operator / (P p){return P(x/p.x,y/p.y);}

};

typedef pair<int,P> info;
int s,g;
double cost[1100][1100];
int n,m;
static const int INF = 1<<25;
void Init(){
  rep(i,1100){
    rep(j,1100){
      cost[j][i] = i==j?0:INF;
    }
  }
}

double norm(P p){
  return p.x*p.x+p.y*p.y;
}

double abs(P p){
  return sqrt(norm(p));
}

int prev[1100];
int d[1100];
bool used[1100];

void display(int num){
  for(int i=1;i<=num;i++){
    for(int j=1;j<=num;j++){
      printf("%4.0f ",cost[i][j]);
    }
    cout << endl;
  }
}


void dijkstra(){
  for(int i=0;i<1100;i++){
    d[i] = INF;
    used[i] = false;
    prev[i] = -1;
  }
  d[s] = 0;

  while(true){
    int v = -1;
    for(int i=1;i<=n;i++){
      if(!used[i]&&(v == -1 || d[v]>d[i]))v = i;
    }

    if(v == -1)break;
    used[v] = true;
    for(int i=1;i<=n;i++){
      if(d[i] > d[v]+cost[v][i]){
	d[i] = d[v]+cost[v][i];
	prev[i] = v;
      }
    }
  }
}

vector<int> get_path(int t){
  vector<int> path;
  for(;t!=-1;t=prev[t])path.push_back(t);
  reverse(path.begin(),path.end());
  return path;
}

int main(){

  vector<info> vec;
  vector<int> _path;
  int b,x,y;
  info insert;
  while(cin >> n && n){
  Init();
    vec.clear();
    rep(i,n){
      cin >> b >> x >> y;
      insert.F = b;
      insert.S.x = x;insert.S.y = y;      
      vec.push_back(insert);
    }
    rep(i,n){
      rep(j,n){
	if(i == j)continue;
	double val = abs(vec[i].S-vec[j].S);
	if(val < 50+EPS){
	  cost[vec[i].F][vec[j].F] = cost[vec[j].F][vec[i].F] = val;
	}
      }
    }  

    cin >> m;
    rep(i,m){
      _path.clear();
      cin >> s >> g;
      dijkstra();
      _path = get_path(g);
      if(_path.size() == 1)cout << "NA" << endl;
      else{
	for(int i=0;i<_path.size();i++){
	  cout << _path[i];
	  i==_path.size()-1?cout << endl:cout << " ";
	}
      }
     
    }


  }



  return 0;
}

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

int f(int n){
    int ret = 0;
    while(n > 0){
        bitset<32> b = n;
        n = n % b.count();
        ret++;
    }
    return ret;
}

int modpow(int a, int n, int m = MOD){
    ll ret = 1;
    while(n>0){
        if(n&1) ret = (ret*a) % m;
        a = (a*a) % m;
        n >>= 1;
    }
    return ret % m;
}

signed main(){
    int n; string x;
    cin >> n >> x;
    
    vi memo(n+5);
    memo[0] = 0;
    reps(i,1,n+4){
        memo[i] = f(i);
    }
    
    int popcount = 0;
    for(char c : x){
        if(c == '1') popcount++;
    }
    
    vi calc(2,0);
    rep(i, 2){
        if(i) popcount += 2;
        else popcount--;
        if(popcount <= 0) continue;
        
        int d = 1;
        for(int j = n-1; j >= 0; j--){
            if(x[j] == '1'){
                calc[i] = mod(calc[i] + d, popcount);
            }
            d = (d * 2) % popcount;
        }
    }
    popcount--;
    
    rep(i,n){
        int t;
        if(x[i] == '1'){
            if(popcount-1 <= 0){
                cout << 0 << endl;
                continue;
            }
            t = mod(calc[0] - modpow(2, n-i-1, popcount-1), popcount-1);
        }else{
            t = mod(calc[1] + modpow(2, n-i-1, popcount+1), popcount+1);
        }
        cout << 1 + memo[t] << endl;
    }
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 10e17;
int findLowerBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{

    auto low = lower_bound(arr.begin(),
                           arr.end(), p);

    return low - arr.begin();
}
int findUpperBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{
    auto up = upper_bound(arr.begin(),
                          arr.end(), p);

    return up - arr.begin();
}
bool vis[200005];
vector<int> vec[100005];
int child[100005];
void dfs(int node)
{
    vis[node] = 1;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            child[node] += child[vec[node][i]];
        }
    }
}
void belman(int n, int m, vector<pair<int, pair<int, int>>> vec, int dis[])
{
    for (int i = 0; i <= n + m - 1; i++)
    {
        for (int j = 0; j < vec.size(); j++)
        {
            int u = vec[j].second.first;
            int v = vec[j].second.second;
            int w = vec[j].first;

            if (dis[u] + w < dis[v])
            {
                dis[v] = dis[u] + w;
            }
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string str;
    int n;
    cin >> n;
    int m;
    cin >> m;
    int dis[n + 1];
    int dis1[n + 1];
    vector<pair<int, pair<int, int>>> vec, vec1;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        // vec.push_back({c, {a, b}});
        vec1.push_back({-c, {a, b}});
        // dis[i + 1] = inf;
        //dis1[i + 1] = inf;
    }
    for (int i = 1; i <= n; i++)
        dis[i] = inf;

    dis[1] = 0;
    belman(n, m, vec1, dis);
    for (int i = 0; i < n; i++)
        dis1[i + 1] = dis[i + 1];
    belman(n, m, vec1, dis);
    bool flag = 0;
    //    // for (int i = 1; i <= n; i++)
    //     {
    //         cout << dis[i] << " " << dis1[i] << "\n";
    //     }
    if (dis[n] != dis1[n])
    {
        cout << "inf"
             << "\n";
        return 0;
    }
    for (int i = 1; i <= n; i++)
        dis[i] = inf;
    dis[1] = 0;

    belman(n, m, vec1, dis);
    cout << -1 * dis[n] << "\n";

    return 0;
}


Measured memory_bytes: 6040