akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int[] reads() { return readln.split.to!(int[]); }

int f(int x) {
    int t;
    while(x%2 == 0) x/=2, t++;
    return t;
}

void main() {
    readln;
    writeln(reads.map!(f).sum);
}

Measured memory_bytes: 2556
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }
 
    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
 
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int x_max = x;
        int y_min = y;
 
        int tmp = 0;
        for (int i=0;i<n;i++) {
        	tmp = scanner.nextInt();
        	if(tmp>x_max) {
        		x_max = tmp;
        	}
        }
        for (int j=0;j<m;j++) {
        	tmp = scanner.nextInt();
        	if(tmp<y_min) {
        		y_min = tmp;
        	}
        }
 
        if(x_max>=y_min){
        	System.out.println("War");
        }else if((x_max == x)&&(y_min==y)) {
        	System.out.println("War");
        }else {
        	System.out.println("No War");
        }
 
 
    }
 
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
 
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
 
    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 22740
#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 mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
   ll a[3][3];
   
   ll i,j;
   for(i=0;i<3;i++)
   {
       for(j=0;j<3;j++)cin>>a[i][j];
   }
   ll n;
   cin>>n;
   mll m;
   for(i=0;i<n;i++)
   {
       ll x;
       cin>>x;
       m[x]++;
   }
   ll b[3][3];
   clr(b);
   for(i=0;i<3;i++)
   {
       for(j=0;j<3;j++)
       {
           if(m[a[i][j]]>0)
           {
               b[i][j]=1;
           }
       }
   }
   ll f=0;
   for(i=0;i<3;i++)
   {
      ll ff=0;
      for(j=0;j<3;j++)
      {
         if(b[i][j]==0)
         {
             ff=1;
         }
      }

      if(!ff)
      {
          f=1;
      }
      ff=0;
        for(j=0;j<3;j++)
      {
         if(b[j][i]==0)
         {
             ff=1;
             break;
         }
      }
      if(!ff)
      {
          f=1;
      }
   }

   if(b[0][0]==1&&b[1][1]&&b[2][2])
   {
       f=1;
   }
   if(b[2][0]&&b[1][1]&&b[0][2])
   {
       f=1;
   }
   if(f)
   {
       cout<<"Yes\n";
       return;
   }
   cout<<"No\n";
   


}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}


Measured memory_bytes: 3672
#include <iostream>

using namespace std;

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main(){
long long x,y;
cin>>x>>y;
long long ans=0;
if((4*x-y)%2==0&&(4*x-y>=0)&&(y-2*x)>=0){
    ans=1;
}
if(ans==1){
    cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}

    return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>

#define true 1
#define false -1
int solve(int,int);

int A[2005],n;
int main(){
  int q,m,i,a;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    a=solve(0,m);
    if(a==true){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }
  return 0;
}

int solve(int i,int m){
  int res;
  if(m==0){
    return true;
  }
  if(i>=n){
    return false;
  }
  if(solve(i+1,m)==true){
    res=solve(i+1,m);
    return res;
  }
  else if(solve(i+1,m-A[i])==true){
    res = solve(i+1,m-A[i]);
    return res;
  }
  return false;
}



Measured memory_bytes: 2048
n ,m ,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
 
sa = [0]
sb = [0]
 
 
for i in range(n):
    sa.append(sa[i]+a[i])
 
for i in range(m):
    sb.append(sb[i]+b[i])
 
ans = 0
 
for i in range(n+1):
    if sa[i] > k:
        break
    mb = 0
    lb = m+1
    for j in range(100):
        mid = (mb+lb)//2
        if sb[mid] + sa[i] <= k:
            mb = mid
        else:
            lb = mid
    ans = max(ans, i + mb)
 
print(ans)

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    string str;
    cin>>str;
    ll sum=0;
    fr(i,0,SZ(str))
    {
        sum+=(str[i]-'0');
    }
    if(sum%9==0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin >> n >> m;
  vi l(m),r(m);
  REP(i,m) cin >> l[i] >> r[i];
  vi ans(n+1,0);
  REP(i,m) ans[l[i]-1]++,ans[r[i]]--;
  REP(i,n) ans[i+1] += ans[i];
  int res = 0;
  REP(i,n) if(ans[i]==m) res++;
  cout << res << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define MOD (long long)(1e9+7)
typedef long long int ll;
typedef unsigned long long int ull;

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

bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll T=1;
  // cin>>T;
  for(int _case=0;_case<T;_case++){
    double n, m, sum=0, a;
    cin>>n>>m;
    for(int i=0;i<m;i++){
      cin>>a;
      sum+=a;
    }
    if(sum>n) cout<<-1<<endl;
    else cout<<n-sum<<endl;
  }
  return 0;
}


Measured memory_bytes: 3792
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          fozubaoyou    no BUGs alive
*/
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define MINF -999999999
using namespace std;

int main(){
    int n; cin >> n;
    int mir, mar = MINF;
    cin >> mir;
    REP(i, n-1) {
        int x; cin >> x;
        mar = max(mar, x-mir);
        mir = min(mir, x);}
    cout << mar << endl;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    string S[H];
    REP(i, H) cin >> S[i];

    int cake[H][W];
    int str = 1;

    REP(i, H) REP(j, W) cake[i][j] = -1;
    REP(i, H) REP(j, W) if (S[i][j] == '#') cake[i][j] = str++;

    REP(i, H) REP(j, W)
    {
        if (S[i][j] != '#') continue;

        for (int jl=j-1; jl>=0; --jl)
            if (cake[i][jl] == -1) cake[i][jl] = cake[i][j];
            else break;

        for (int jr=j+1; jr<W; ++jr)
            if (cake[i][jr] == -1) cake[i][jr] = cake[i][j];
            else break;
    }

    FOR(i, 1, H) REP(j, W)
    {
        if (cake[i][j] == -1) cake[i][j] = cake[i-1][j];
    }

    for(int i=H-1; i>=0; --i) REP(j, W)
    {
        if (cake[i][j] == -1) cake[i][j] = cake[i+1][j];
    }

    FOR(i, 1, H) REP(j, W)
    {
        if (cake[i][j] == -1) cake[i][j] = cake[i-1][j];
    }

    REP(i, H)
    {
        REP(j, W)
        {
            if (j != 0) cout << " ";
            cout << cake[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#!/usr/bin/env python
# coding: utf-8

# In[14]:


N,K,Q = map(int, input().split())
point = [0]*N
for _ in range(Q):
    A = int(input())
    point[A-1] += 1 
ans = [print("Yes") if point[i] > Q-K else print("No") for i in range(len(point))]


# In[ ]:






Measured memory_bytes: 5724
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int K = 38;
	int N = K * (K - 1) + 1;


	vector<int> kotae[2000];
	int tmp = 2;
	rep(i, K) {
		kotae[1].pb(N - i);
		rep(j, K - 1) kotae[tmp++].pb(N - i);
	}

	int kazu = 1;
	rep1(i, (K - 1)*(K - 1)) {
		kotae[(i - 1) / (K - 1) + 2].pb(i);
		tmp = (i - 1) % (K - 1);
		int tasu = (i - 1) / (K - 1);
		rep1(k, K) {
			kotae[tmp + k * (K - 1) + 2].pb(i);
			tmp = (tmp + tasu) % (K - 1);
		}
	}

	cosp(N);
	co(K);
	rep1(i, N) {
		rep(j, kotae[i].size() - 1) {
			cosp(kotae[i][j]);
		}
		co(kotae[i].back());
	}





	Would you please return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin>>n>>m;
    vector<int> rew(m);
    vector<int> d(n),r(n);
    for(int i =0; i<n; i++){
        cin>>d.at(i)>>r.at(i);
    }
    vector<vector<int> > days(m);
    for(int i =0; i<n; i++){
        if(m-d[i] <0) continue;
        else days[m-d[i] ].push_back(r[i]);
    }
    priority_queue<int> q;
    long long ans =0;
    for(int i =m-1 ; i>=0; i--){
        for(int j =0; j<days[i].size() ; j++){
            q.push(days.at(i).at(j));
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6784
n = int(input())

def cnt_divisor(n):
    cnt = 0
    for i in range(1, n+1):
        if n % i == 0:
            cnt += 1
    return cnt

cnt = 0
for j in range(1, n+1):
    if j % 2 == 0:
        continue
    if cnt_divisor(j) == 8:
        cnt += 1

print(cnt)


Measured memory_bytes: 2940
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

using namespace std;

int main() {
	int i, j;
	string str;
	map<char, string> mp;
	
	cin >> str;

	//for (i = 0; i < str.size(); i++) {
	mp.insert(pair<char, string>('a', str));
	//}

	cin >> str;
	mp.insert(pair<char, string>('b', str));

	cin >> str;
	mp.insert(pair<char, string>('c', str));

	string str2;
	str = mp['a'];
	for (; ; ) {
		if (mp[str[0]].size() == 0) {
			transform(str.begin(), str.end(), str.begin(), ::toupper);
			cout << str[0] << endl;
			break;
		}
		str2 = mp[str[0]];

		mp[str[0]].erase(mp[str[0]].begin() );

		/*
		cout << endl;
		cout << "a->" << mp['a'] << endl;
		cout << "b->" << mp['b'] << endl;
		cout << "c->" << mp['c'] << endl;
		*/
		//if (str2.size() == 0) {
		if( mp[str2[0]].size() == 0){
			transform(str2.begin(), str2.end(), str2.begin(), ::toupper);
			cout << str2[0] << endl;
			break;
		}
		str = mp[str2[0]];

		mp[str2[0]].erase(mp[str2[0]].begin());
		/*
		cout << endl;
		cout << "a->" << mp['a'] << endl;
		cout << "b->" << mp['b'] << endl;
		cout << "c->" << mp['c'] << endl;
		*/
	}




	return 0;
}


Measured memory_bytes: 256
h,w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

l = [[] for _ in range(h)]
x = 0
y = 0
for i in range(n):
  for _ in range(a[i]):
    l[y].append(i+1)
    x += 1
    if x == w:
      x = 0
      y += 1
for i in range(h):
  if i%2 == 0: print(*l[i])
  else: print(*reversed(l[i]))


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

namespace ABC119C
{
    class Program
    {
        static int N;
        static int A;
        static int B;
        static int C;
        static int[] data;
        static int INF = (int)Math.Pow(10, 9);
        static int[] bmp;

        static int Solve(int current, int a, int b, int c)
        {

            if (current == N)
            {
                List<int> tmp = new List<int>();

                tmp.Add(a);
                tmp.Add(b);
                tmp.Add(c);

                tmp.Sort();

                if (tmp.First() > 0)
                {
                    return Math.Abs(A - a) + Math.Abs(B - b) + Math.Abs(C - c) - 30;
                }
                else
                {
                    return INF;
                }

            }

            List<int> list = new List<int>();

            list.Add(Solve(current + 1, a, b, c));
            list.Add(Solve(current + 1, a + bmp[current], b, c) + 10);
            list.Add(Solve(current + 1, a, b + bmp[current], c) + 10);
            list.Add(Solve(current + 1, a, b, c + bmp[current]) + 10);

            list.Sort();

            return list.First();

        }

        static void Main(string[] args)
        {
            string[] temp = System.Console.ReadLine().Split(' ');
            N = int.Parse(temp[0]);
            A = int.Parse(temp[1]);
            B = int.Parse(temp[2]);
            C = int.Parse(temp[3]);
            bmp = new int[N];
            for (int i = 0; i < N; i++)
            {
                bmp[i]=(int.Parse(System.Console.ReadLine()));
            }



            Console.WriteLine(Solve(0, 0, 0, 0));
        }
    }
}


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

int main(){
    int n;
    int o=0, t=0, f=0;
    scanf("%d", &n);
    rep(i, 0, n){
        int x;
        scanf("%d", &x);
        if(x%4 == 0){
            f++;
        }else if(x%2 == 0){
            t++;
        }else{
            o++;
        }
    }
    if(t>0){
        o++;
    }
    if(o-1 <= f){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define lli long long int
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,a,n) for(int i = a; i < n; i++)
#define s(n) cin >> n
#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define rsz(x,n) x.clear(); x.resize(n)
#define rrsz(x,a,n) x.clear(); x.resize(n,a)
#define wt while(true)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ls(x) ((2*(x)) + 1)
#define rs(x) ((ls(x)) + 1)
#define md(a,b) (((a) + (b))/2)
#define INF (1e9 + 7)
using namespace std;
lli m=1e9+7;
int main()
{
    lli n;
    s(n);
    bool a[n][n];
    rep(i,n){
        rep(j,n){
            s(a[i][j]);
        }
    }
    lli dp[8388608]={0};
    dp[0]=1;
    lli t[8388608];
    rep(i,1<<n){
        lli sum=0;
        rep(j,n){
            if(i&(1<<j))sum++;
        }
        t[i]=sum;
    }
    rep(i,1<<n)
    {
      lli x=t[i];
      rep(k,n){
          if((!(i&(1<<k)))&&a[x][k])
          {
              dp[i]%=m;
              dp[i|(1<<k)]+=dp[i];
              dp[i|(1<<k)]%=m;
          }
      }
    }
    cout<<dp[(1<<n)-1]%m;
    return 0;
}

Measured memory_bytes: 83840
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

int main() {
    cin>>N>>M>>K;
    vec a(N + 1, 0), b(M + 1, 0);
    rep(i,N) cin>>a[i + 1];
    rep(i,M) cin>>b[i + 1];
    rep(i,N) a[i+1] += a[i];
    rep(i,M) b[i+1] += b[i];
    ll res = 0;
    rep(i,N + 1){
        ll can_use = K - a[i];
        if(can_use < 0) break;
        ll num = upper_bound(ALL(b), can_use) - b.begin();
        --num;
        //cout<<i<<' '<<num<<endl;
        chmax(res, i + num);
    }
    cout<<res<<endl;
}


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

int main() {
  int x;
  int a;
  int b;
  int c;
  int d;
  int e;
  
  
  cin >> x >> a >> b;
  
  c = x - a;
  d = c / b;
  e = c - b * d;
  
  cout << e << endl;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>


using namespace std;

int main()
{  
    int n,a,ans;
    //int count=0;
        
    cin>>n>>a;
    
    ans = n*n-a;
    
    cout<<ans<<endl;
    
    
    //cout<<n<<endl;
    
         
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t a, b, n; cin >> a >> b >> n;
	if(b == 1) {
		cout << 0 << '\n';
		return 0;
	}
	int64_t t = n / b * b - 1;
	int64_t ans = a * t / b - a * (t / b);
	ans = max(ans, a * n / b - a * (n / b));
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define reset(x,n) memset((x),(n),sizeof(x))
#define all(n) (n).begin(),(n).end()
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0);
ll dp[100005];
int main(){
	ll n,w,tw,tv;
	cin>>n>>w;
	
	for(int i=0;i<n;i++){
		cin>>tw>>tv;
		for(int j=w;j>=tw;j--){
			dp[j]=max(dp[j],dp[j-tw]+tv);
		}
	}
	cout<<dp[w]<<'\n';
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

//Salary for a Plumber
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int[] q = new int[n-1];
			long sum = 0;
			for(int i=0;i<n;i++)sum+=sc.nextInt();
			for(int i=0;i<n-1;i++)q[i]=sc.nextInt();
			Arrays.sort(q);
			long res = sum*n;
			for(int i=n-2;i>=0;i--){
				sum+=q[i];
				res = Math.max(res, sum*(i+1));
			}
			System.out.println(res);
		}
	}
	
	void debug(Object...o){
		System.out.println(Arrays.deepToString(o));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 95544
#include <cstdio>

using namespace std;

int a[100],mp[101] = {0};

signed main()
{
    int key, j = 0;
    while ( scanf("%d\n", &key ) != EOF)
    {
        a[j] = key;
        mp[ key ]++;
        j++;
    }
    int mode_value = 0;
    for( int i = 1; i <= 100; i++ )
    {
        if( mode_value < mp[i] )
        {
            mode_value = mp[i];
        }
    }
    
    for( int i = 1; i <= 100; i++ )
    {
        if( mp[i] == mode_value )
        {
            printf( "%d\n", i );
        }
    }
    return 0;
}


Measured memory_bytes: 2744
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

template<class T>
struct Point2D {
	T x, y;
	constexpr Point2D(T x = 0, T y = 0) noexcept : x(x), y(y) {};
	constexpr Point2D(pair<T, T>& p) noexcept : x(p.first), y(p.second) {};
	constexpr bool operator==(const Point2D& rhs) const noexcept { return x == rhs.x && y == rhs.y; }
	constexpr bool operator!=(const Point2D& rhs) const noexcept { return !((*this) == rhs); }
	constexpr bool operator< (const Point2D& rhs) const noexcept { return x < rhs.x || (x == rhs.x && y < rhs.y); }
	constexpr bool operator> (const Point2D& rhs) const noexcept { return rhs < (*this); }
	constexpr bool operator<=(const Point2D& rhs) const noexcept { return !((*this) > rhs); }
	constexpr bool operator>=(const Point2D& rhs) const noexcept { return !((*this) < rhs); }
	constexpr Point2D  operator+ (const Point2D& rhs) const noexcept { return { x + rhs.x, y + rhs.y }; }
	constexpr Point2D  operator- (const Point2D& rhs) const noexcept { return { x - rhs.x, y - rhs.y }; }
	constexpr Point2D  operator* (const T& k) const noexcept { return { k * x, k * y }; }
	constexpr Point2D  operator/ (const T& k) const noexcept { return { x / k, y / k }; }
	constexpr Point2D& operator+=(const Point2D& rhs) noexcept { return ((*this) = (*this) + rhs); }
	constexpr Point2D& operator-=(const Point2D& rhs) noexcept { return ((*this) = (*this) - rhs); }
	constexpr Point2D& operator*=(const T& k) noexcept { return ((*this) = (*this) * k); }
	constexpr Point2D& operator/=(const T& k) noexcept { return ((*this) = (*this) / k); }
	constexpr Point2D  operator- () const noexcept { return { -x, -y }; }
	constexpr T operator* (const Point2D& rhs) const noexcept { return x * rhs.x + y * rhs.y; }
	constexpr Point2D nor() const noexcept { return { y, -x }; }
	constexpr long double hypot() const noexcept { return ::hypotl(x, y); }
	friend istream& operator>>(istream& is, Point2D& p) { return is >> p.x >> p.y; }
	friend ostream& operator<<(ostream& os, const Point2D& p) { return os << p.x << " " << p.y << "\n"; }
	template<class U> U& operator[](vector<vector<U>>& v) { return v[x][y]; }
};

using pnt = Point2D<lint>;


int main() {

	lint N, D;
	cin >> N >> D;

	vector<pnt> xy(N);
	for (int i = 0; i < N; i++) cin >> xy[i];

	cout << count_if(xy.begin(), xy.end(), [&D](auto& p) { return p * p <= D * D; }) << "\n";

	return 0;
}



Measured memory_bytes: 6296
def main():
    N = str(input())
    result = ""

    for c in N:
        if c == '0':
            result = result + '0'
        elif c == '1':
            result = result + '1'
        elif c == 'B':
            result = result[0:len(result)-1]
    
    print(result)



if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for(int i = 0; i < t; i++)

int main()
{
    vector<int> group[2] = {
        {1, 3, 5, 7, 8, 10, 12},
        {4, 6, 9, 11}
    };
    string anss[2] = {"No", "Yes"};
    int x, y, ans;
    cin >> x >> y;
    ans = count_if(group[0].begin(), group[0].end(), [x, y](int i) { return i == x || i == y; }) / 2;
    ans = max((int)count_if(group[1].begin(), group[1].end(), [x, y](int i) { return i == x || i == y; }) / 2, (int)ans);
    cout << anss[ans] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int main() {
	string s;
   cin >> s;
   int N=0;
   if(s.at(0)=='1'){N++;}
   if(s.at(1)=='1'){N++;}
   if(s.at(2)=='1'){N++;}
   
   cout << N << endl;
 }
   


Measured memory_bytes: 256
N, L = (int(i) for i in input().split())
String = [input() for s in range(N)]

for i in range(N-1):
    start = N - 1
    #print("start " + str(start))
    for j in range(start-i):
        #print(str(start-j-1) + " " + str(start-j))
        Left = String[start-j-1]
        Right = String[start-j]
        if Left > Right:
            String[start-j-1] = Right 
            String[start-j] = Left

for s in String:
    print(s, end="")

Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(1000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
P = list(map(int, input().split()))

ans = 0
mi = 2 ** 60

for i in P:
    if i <= mi:
        ans += 1
    mi = min(mi, i)

print(ans)

Measured memory_bytes: 24744
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;

  vector<pair<int, int>> vec(m);
  int x,y;
  for(int i=0;i<m;i++){
    cin >> x >> y;
    vec[i] = make_pair(x, y);
  }
  sort(vec.begin(), vec.end(), [](const pair<int,int> &x, const pair<int,int> &y){return x.second < y.second;});
  int ans = 0;
  while(!vec.empty()){
    int e = vec[0].second;
    vec.erase(remove_if(vec.begin(),vec.end(), [e](const pair<int, int> &x){return x.first < e;}), vec.end());
    ans++;
    //cout << "e=" << e << endl;
    //for(auto& x: vec){
    //  cout << x.first << " " <<  x.second << endl;
    //}
    //cout << endl;
  }
  cout << ans << endl;
}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

ll MAX_V = 2e5 + 5;
vector<vector<ll>> G(MAX_V);//隣接リスト(添え字は始点、値は終点)
vector<ll>t(MAX_V);//訪問したかどうか
void dfs(ll k){
  t[k]=1;
  for(ll i=0;i<G[k].size();i++){
    if(t[G[k][i]]==0){
      dfs(G[k][i]); 
    }
  }
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  for(ll i=0;i<n;i++){
    ll k;cin>>k;
    rep(j,0,k){
      ll l;cin>>l;
      l--;
      G[l+n].push_back(i);
      G[i].push_back(l+n);
    }
  }
  dfs(0);
  rep(i,0,n)if(t[i]==0){
    judge=false;
  }
  ans2(judge);
  return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

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


bool comp(Pl x, Pl y) {
	return (x.first * (y.second+1) < y.first * (x.second+1));
}

void Main() {
	ll N, T; cin >> N >> T;
	vector<Pl> dat(N); cin >> dat;
	sort(rbegin(dat), rend(dat), comp);
	vll A, B;
	vll zs;
	
	zs.push_back(0);
	for (int i = 0; i < N; i++) {
		if (dat[i].first > 0) {
			A.push_back(dat[i].first);
			B.push_back(dat[i].second);
		} else {
			zs.push_back(dat[i].second+1);
		}
	}
	
	sort(begin(zs), end(zs));
	for (int i = 1; i < zs.size(); i++) {
		zs[i] += zs[i-1];
	}

	int n = A.size();
	vvll dp(31, vll(n+1, LLINF));
	dp[0][0] = 0;
	int ans = 0;
	for (int c = 0; c < 31; c++) {
		ll minv = dp[c][0];
		for (int i = 1; i < n+1; i++) {
			chmin(dp[c][i], dp[c][i-1]);
			if (c > 0 && dp[c-1][i-1] <= T) {
				ll val = dp[c-1][i-1] + (dp[c-1][i-1] + 1) * A[i-1] + B[i-1] + 1;
				if (val <= T) chmin(dp[c][i], val);
			}
			chmin(minv, dp[c][i]);
		}
		if (minv > T) break;
		int num = --upper_bound(begin(zs), end(zs), T - minv) - begin(zs);
		chmax(ans, c + num);
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

int main() {
	string s;
	cin >> s;
	bool found = false;
	if (s.length() < 2)
		cout << "No" << endl;
	else {
		for (int i = 0; i <= (int)s.length() - 2; i++) {
			if (s.substr(i, 2).compare("AC") == 0) {
				cout << "Yes" << endl;
				found = true;
				break;
			}
		}
		if (!found)
			cout << "No" << endl;
	}

	return 0;
}


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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

void solve_abc_c() {
	ll n, m;
	ll k;
	ll h, w;
	//ll x;
	//ll a;
	//string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;

	cin >> n;
	V a(n);
	rep(i, n) cin >> a[i];

	rep(i, n) {
		while (1) {
			if (a[i] % 2 == 0) {
				l_ans++;
				a[i] /= 2;
			}
			else {
				break;
			}
		}
	}

	cout << l_ans << "\n";
}

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

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 3736
/** 
 
题意:给定长度为n的序列 给定n次操作 x y 表示x位置可以和y位置进行交换 求解a[i]=i 的最大数量; 
 
题解:建立领接表,对于每个节点我们对其进行访问,,对于存在边的,存在领接关系的,可以将其任意两个位置进行交换； 
将其可以交换的点压入集合中,找完以该节点为起始的边后,我们对该集合进行遍历，查询a[k]确定k是否存在于set中; 
  
 
*/  
  
#include<bits/stdc++.h>  
#define ll long long  
using namespace std;  
   
const int maxn=2e5+7;  
int a[maxn];  
bool vis[maxn];  
   
vector<int>v[maxn];  
set<int>s;  
   
void dfs(int pos){  
    vis[pos]=1;  
    s.insert(pos);  
    for(int k:v[pos]) if(!vis[k]) dfs(k);  
}  
   
int main (){  
    ios_base::sync_with_stdio(false);  
    int n,m;cin>>n>>m;  
    memset(vis,0,(n+3)*sizeof(bool));  
    for(int i=1;i<=n;i++) cin>>a[i];  
    for(int i=1;i<=m;i++){  
        int x,y;cin>>x>>y;  
        v[x].push_back(y);  
        v[y].push_back(x);  
    }  
    int ans=0;  
    for(int i=1;i<=n;i++){  
        if(!vis[i]) dfs(i);  
        for(int k:s) if(s.find(a[k])!=s.end()) ans++;  
        s.clear();  
    }  
    cout<<ans<<endl;  
    return 0;  
}  


Measured memory_bytes: 16256
package main

import (
  "fmt"
)

func main() {
  var s string
  fmt.Scan(&s)
  
  result := 0
  cnt := 0
  for _, char := range s{
    if char == 'A' || char == 'T' || char == 'G' || char == 'C' {
      cnt++
    } else {
      cnt = 0
    }
    if result < cnt {
      result = cnt
    }
  }
  fmt.Println(result)
}

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

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

using namespace std;

int n, k;

int main(){
	scanf("%d%d", &n, &k);
    printf("%s", 2 * k <= n + 1 ? "YES" : "NO");
    return 0;
}


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

int main() {
	int N, M;
	while( cin >> N, N ) {
		vector<vector<bool>>d( 21, vector<bool>( 21 ) );
		for( size_t i = 0; i < N; i++ ) {
			int a, b;
			cin >> a >> b;
			d[a][b] = 1;
		}
		cin >> M;
		int nowx = 10, nowy = 10;
		for( size_t i = 0; i < M; i++ ) {
			char c;
			cin >> c;
			int p;
			cin >> p;
			int nextx = 0, nexty = 0;
			switch( c ) {
			case 'N':
			{
				nexty++;
				break;
			}
			case 'S':
			{
				nexty--;
				break;
			}
			case 'E':
			{
				nextx++;
				break;
			}
			case 'W':
			{
				nextx--;
				break;
			}
			}
			for( size_t i = 0; i < p; i++ ) {
				nowx += nextx;
				nowy += nexty;
				if( d[nowx][nowy] ) {
					N--;
					d[nowx][nowy] = 0;
				}
			}
		}
		cout << (N == 0 ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 3088
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int v1[] = new int[n / 2];
		int v2[] = new int[n / 2];
		for (int i = 0; i < n / 2; i++) {
			v1[i] = sc.nextInt();
			v2[i] = sc.nextInt();
		}

		Arrays.sort(v1);
		Arrays.sort(v2);
		int p = 1;
		for (int i = 0; i < (n / 2) - 1; i++) {
			if (v1[i] != v1[i + 1]) {
				p++;
			}
		}
		int x1[] = new int[p];
		p = 1;
		for (int i = 0; i < (n / 2) - 1; i++) {
			if (v2[i] != v2[i + 1]) {
				p++;
			}
		}
		int x2[] = new int[p];
		Renzoku(v1, x1);
		Renzoku(v2, x2);

		Arrays.sort(x1);
		Arrays.sort(x2);
		int ans=n-x1[x1.length-1]-x2[x2.length-1];

		if(ans==0&&v1[0]==v2[0]){
		System.out.println(n/2);
		}else if(mode(v1)==mode(v2)){
			System.out.println(Math.min(n-x1[x1.length-2]-x2[x2.length-1],n-x1[x1.length-1]-x2[x2.length-2]));
		}else{

		System.out.println(ans);
	}}

	public static int mode(int x[]) {
		int mode = 0;
		Arrays.sort(x);
		int p = 1;
		for (int i = 0; i < x.length - 1; i++) {
			if (x[i] != x[i + 1]) {
				p++;
			}
		}
		int x1[] = new int[p];
		Renzoku(x, x1);
		int x1max = haimax(x1);
		int x1maxnum = 0;
		for (int i = 0; i < x1.length; i++) {
			if (x1[i] == x1max) {
				x1maxnum = i;
			}
		}
		p = 0;
		mode = x[0];
		for (int i = 0; i < x.length - 1; i++) {

			if (x[i] != x[i + 1]) {
				p++;
			}
			if (p == x1maxnum) {
				mode = x[i + 1];
				break;
			}
		}
		return mode;
	}

	public static int Renzoku(int c[], int x[]) {

		int mode = 0;
		int val = 0;

		for (int i = 0; i <= c.length - 2; i++) {
			if ((c[i] == c[i + 1]) && i != c.length - 2) {
				val++;
			} else {
				if ((c[i] == c[i + 1]) && i == c.length - 2) {
					val++;
				}
				val++;
				x[mode] = val;
				mode++;

				if ((c[i] != c[i + 1]) && i == c.length - 2) {
					x[mode] = 1;
					mode++;
				}

				val = 0;
			}

		}
		return mode;

	}

	public static int haimax(int a[]) {
		int d;
		d = a[0];
		for (int i = 0; i <= a.length - 1; i++) {
			if (d <= a[i]) {
				d = a[i];
			}

		}
		return d;
	}


}


Measured memory_bytes: 50136
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 1000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
bitset<maxx/2>vis;
vector<ll>prime;
void sieve(){
    ll x=maxx/2, y=sqrt(maxx)/2;
    for(ll i=1;i<=y;i++){
        if(vis[i]==0){
            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
                vis[j]=1;
        }
    }
    prime.push_back(2);
    for(ll i=3;i<maxx;i+=2)
        if(vis[i/2]==0)
        prime.push_back(i);
}
bool isprime(ll a)
{
    if(a==2){
        return true;
    }
    if(a%2==0){
        return false;
    }
    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++){
        if(a%prime[i]==0){
            return false;
        }
    }
    return true;
}
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
ll arr[100005];
ll freq[100005];
void Dufaux()
{
    ll n,q;
    ll b,c;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        freq[arr[i]]++;
        sum+=arr[i];
    }
    cin>>q;
    while(q--){
        cin>>b>>c;
        if(freq[b]>0){
            ll pp=freq[b];
            freq[b]=0;
            sum+=(c-b)*pp;
            freq[c]+=pp;
        }
        cout<<sum<<endl;
    }
    return;
}
int main()
{
	FastIO;
	///sieve();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 5128
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>
#include <map>
using program_type = std::pair<int32_t, int32_t>;
using programs_array_type = std::vector<program_type>;

void merge_consec_program(programs_array_type& per_ch, programs_array_type& global) {
    if (per_ch.empty()) return;

    std::sort(per_ch.begin(), per_ch.end());
    global.emplace_back(per_ch[0]);
    for (auto it = per_ch.begin()+1; it != per_ch.end(); it++) {
        //merge
        if (it->first == global.back().second) {
            (global.end() - 1) -> second = it->second;
        } else {
            global.emplace_back(*it);
        }
    }
}

int main(){
    int32_t N, C;
    std::cin >> N >> C;
    std::vector<programs_array_type> per_channel_program(C);
    programs_array_type global_program;
    
    for (int32_t i = 0; i < N; i++) {
        int32_t s, t, c;
        std::cin >> s >> t >> c;
        per_channel_program[c-1].push_back(std::make_pair(s,t));
    }

    //sort and merge
    for (int32_t c = 0; c < C; c++) {
        merge_consec_program(per_channel_program[c], global_program);
    }

    //sort global program
    std::sort(global_program.begin(), global_program.end());

    //Greedy
    std::vector<int32_t> last_program;
    for (auto program : global_program) {
        bool updated = false;
        for (int32_t i = 0; i < (int32_t)last_program.size(); i++) {
            if (last_program[i] < program.first) {
                last_program[i] = program.second;
                updated = true;
                break;
            }
        }
        if (!updated) last_program.push_back(program.second);
    }

    std::cout << last_program.size() << std::endl;
    return 0;
}


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

using namespace std;

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

int sum(int n) {
  int ans = 0;
  while(n > 0) {
    ans += (n % 10);
    n /= 10;
  }
  return ans;
}

int main() {
  int n; cin >> n;
  if((n % sum(n)) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

int main()
{
  int N;

  cin >> N;

  int charge = -N;

  while (charge < 0) {
    charge += 1000;
  }

  cout << charge << endl;

  return 0;
}


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

int main() {
  int64_t h,w,k;
  cin >> h >> w >> k;
  int64_t ans=0;
  vector<vector<int>> vec(h,vector<int>(w));
  rep(i,h)rep(j,w){
      char c;
      cin >> c;
      if(c=='.')vec[i][j]=0;
      else vec[i][j]=1;
  }
  for(int i=0; i<(1<<h); i++)for(int j=0;j<(1<<w);j++){
      bitset<7> bith(i);
      bitset<7> bitw(j);
      int now=0;
      rep(k,h)rep(l,w){
          if(vec[k][l]==1&&bith.test(k)&&bitw.test(l)) now++;
      }
      if(now==k) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
import string
from sys import stdin
H, W = [int(_) for _ in stdin.readline().rstrip().split()]
S = [stdin.readline().rstrip().split(' ') for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == 'snuke': 
            print(string.ascii_uppercase[j]+str(i+1))

Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define LL long long 
using namespace std;
LL n,h,w;
LL getlcm(LL a,LL b)
{
	return a/__gcd(a,b)*b;
}
LL getans(LL n,LL h,LL b)
{
	LL lcm=getlcm(n,h);
	LL up=lcm/n*4-lcm/h;
if(up<=0) return -1;
	LL down=lcm;
	
	LL g=__gcd(up,down);
	up=up/g; down=down/g;
	
	lcm=getlcm(down,b);
	up=lcm/down*up-lcm/b;
	down=lcm;
if(up<=0) return -1;
    
    g=__gcd(up,down);
	up=up/g; down=down/g;
	if(up==1)
	 return down;
	else return -1;
}
int main()
{
	scanf("%d",&n);
	for(LL i=1;i<=3501;++i)
	 for(LL j=1;j<=3501;++j)
	{
	    LL zhi=getans(n,i,j);
	    if(zhi!=-1)
	    {
	    	printf("%lld %lld %lld\n",i,j,zhi);
	    	return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256