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

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

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

int N,A,B,C;
vector<int> l(N);

int rec(int i,int a, int b, int c) {
  if (i==N) {
    if (!a||!b||!c) return 10000000;
    return abs(a-A) + abs(b-B) + abs(c-C);
  }
  int res = rec(i+1,a,b,c);
  chmin(res, rec(i+1,a+l[i],b,c)+(a?10:0));
  chmin(res, rec(i+1,a,b+l[i],c)+(b?10:0));
  chmin(res, rec(i+1,a,b,c+l[i])+(c?10:0));

  return res;
}

int main() {
  cin >> N >> A >> B >> C;
  l.resize(N);
  rep(i,N) cin >> l[i];
  cout << rec(0,0,0,0) << endl;
}

Measured memory_bytes: 256
program abc142
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: a,b,g,div,divmax,cnt,ans

    read*, a,b
    g = gcd(a,b)
    divmax = ceiling(sqrt(dble(g)))
    ans=1
    do div=2,divmax
        cnt=1
        if (mod(g,div) == 0) ans=ans+1
        do while(mod(g,div)==0)
            g=g/div
            cnt=cnt+1
        end do
    end do
    if (g>1)ans=ans+1
    print'(i0)', ans
contains
    function lcm(x,y) result(ret)
        integer(int64):: x,y,ret
        ret=x*y/gcd(x,y)
    end function
    recursive function gcd(x,y) result(ret)
        integer(int64):: x,y,ret
    
        if (mod(x,y) == 0) then
            ret = y
            return
        end if
    
        ret = gcd(y,mod(x,y))
    end function
end program abc142

Measured memory_bytes: 256
/*
Problem :
Algorithm :
Status :
*/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define DEBUG printf("Passing Line %d in Function [%s].\n",__LINE__,__FUNCTION__);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 505;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};

int n,ans;
int dis[MAXN][MAXN],w[MAXN][MAXN];
deque<pii> q;

bool check(int x,int y){
    return x >= 1 && x <= n && y >= 1 && y <= n;
}

void bfs(int x,int y){
    ans += --dis[x][y];
    w[x][y] = 0;
    while(!q.empty())
        q.pop_back();
    q.push_back(make_pair(x,y));
    while(!q.empty()){
        int x = q.front().first;
        int y = q.front().second;
        q.pop_front();
        for(int i = 0;i < 4;i++){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(!check(nx,ny))
                continue;
            if(dis[nx][ny] > dis[x][y] + w[nx][ny]){
                dis[nx][ny] = dis[x][y] + w[nx][ny];
                if(w[nx][ny])
                    q.push_back(make_pair(nx,ny));
                else
                    q.push_front(make_pair(nx,ny));
            }
        }
    }
}

int main(){
    // freopen("data.in","r",stdin);
    // freopen("data.out","w",stdout);
    scanf("%d",&n);
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            dis[i][j] = min(min(i,n - i + 1),min(j,n - j + 1));
            w[i][j] = 1;
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            int pos;
            scanf("%d",&pos);
            int x = (pos - 1) / n + 1;
            int y = (pos - 1) % n + 1;
            bfs(x,y);
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

int main(void){
    string s;
    cin >> s;
    int n = (int)s.size();

    int n0 = 0, n1 = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='0') n0++;
        else n1++;
    }
    cout << n - abs(n0-n1) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<#x<<": "<<x<<endl;ll
#define Nmax 400005
#define OFF 100001
using namespace std;

ll n,A[Nmax],B[Nmax],x;

int main()
{
    cin >> n;
    for (int i=1;i<=n;i++){
        A[i] = n * i;
        B[i] = n * (n-i+1);
    }
    for (int i=1,nr = n-1;i<=n;i++,nr--){
        cin >> x;
        B[x] -= nr;
    }
    for (int i=1;i<=n;i++) cout << A[i] << ' ';
    cout << '\n';
    for (int i=1;i<=n;i++) cout << B[i] << ' ';

    return 0;
}


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

const int MAXN = 2e5 + 10, MOD = 1e9 + 7;
inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline int sub(int x, int y) { return x < y ? x - y + MOD : x - y; }
inline int mul(int x, int y) { return 1LL * x * y - 1LL * x * y / MOD * MOD; }
inline int Qpow(int a, int b) { int ans = 1; for (; b; a = mul(a, a), b >>= 1) if (b & 1) ans = mul(ans, a); return ans; }
inline int inv(int a) { return Qpow(a, MOD - 2); }

int n;
int a[MAXN], b[MAXN], fac[10010], ifac[10010], dp[4100][4100];

inline void init() {
	fac[0] = 1;
	for (int i = 1; i <= 10000; ++i) fac[i] = mul(fac[i - 1], i);
	ifac[10000] = inv(fac[10000]);
	for (int i = 9999; ~i; --i) ifac[i] = mul(ifac[i + 1], i + 1);
}
inline int binom(int n, int m) { return mul(fac[n], mul(ifac[m], ifac[n - m])); }

int main() {
	scanf("%d", &n), init();
	for (int i = 1; i <= n; ++i) scanf("%d%d", a + i, b + i), ++dp[2003 - a[i]][2003 - b[i]];
	for (int i = 1; i <= 4010; ++i)
		for (int j  = 1; j <= 4010; ++j) dp[i][j] = add(add(dp[i - 1][j], dp[i][j - 1]), dp[i][j]);
	int ans = 0;
	for (int i = 1; i <= n; ++i) ans = add(ans, dp[2003 + a[i]][2003 + b[i]]);
	for (int i = 1; i <= n; ++i) ans = sub(ans, binom(a[i] + a[i] + b[i] + b[i], a[i] + a[i]));
	printf("%d\n", mul(ans, inv(2)));
	return 0;
}

Measured memory_bytes: 69684
import math
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    k=INT()
    s=STR()
    ls=len(s)
    if ls<=k:
        print(s)
    else:
        print(s[0:k]+'...')
if __name__ == '__main__':
    do()

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

using namespace std;

int a[12][12];
int c[12];
int n,m,x;

bool check(vector<int>count){
    for(int i: count){
        if(i < x){
            return false;
        }
    }
    return true;
}

long long solve(int i,vector<int>count){
    if(i == n){
        if(check(count)){
            return 0;
        }
        else{
            return 1e9;
        }
    }
    long long ans = 1e9;
    auto changed = count;
    for(int j = 0;j < count.size();j++){
        changed[j] += a[i][j];
    }
    ans = min(ans, min(solve(i+1,count),c[i]+solve(i+1,changed)));
    return ans;
}

int main(){
    cin >> n >> m >> x;
    for(int i = 0;i < n;i++){
        cin >> c[i];
        for(int j = 0;j < m;j++){
            cin >> a[i][j];
        }
    }
    int ans = solve(0,vector<int>(m,0));
    if(ans == 1e9){
        cout << -1;
    }
    else
    {
        cout << ans;
    }
    
}

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

int main(){
  int N;
  cin >> N;
  double x[10];
  string u[10];

  double sum = 0;
  for(int i = 0; i < N; i++){
    cin >> x[i] >> u[i];

    if(u[i] == "JPY"){
      sum += x[i];
    }else{
      sum += x[i] * 380000;
    }
  }

  cout << sum;

  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int win = 0;
    int lose = 0;
    if(s.size() < 8){
        cout << "YES" << endl;
    }
    else{
        for(int i=0;i<s.size();i++){
            if(s[i] == 'o'){
                win++;
            }
            else{
                lose++;
            }
        }
        if(lose >= 8){
            cout << "NO" << endl;
        }
        else{
            cout << "YES" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char S[(int)1e5 + 2] = {};
    intmax_t Q;
    struct query {
        intmax_t T;
        intmax_t F;
        char C;
    } query[(int)2e5];

    char head[(int)2e5 + 2] = {}, foot[(int)2e5 + 2] = {};
    char *sp, *hp = head + 1, *fp = foot + 1;
    intmax_t reverse = 0;

    scanf("%s", &S[1]);
    scanf("%jd", &Q);
    for (size_t i = 0; i < Q; i++) {
        scanf("%jd", &query[i].T);
        if (query[i].T == 2) {
            scanf("%jd %c", &query[i].F, &query[i].C);
        }
    }

    for (size_t i = 0; i < Q; i++) {
        if (query[i].T == 1) {
            reverse++;
        } else {
            if (query[i].F == 1) {
                if (reverse % 2 == 0) {
                    *hp++ = query[i].C;
                } else {
                    *fp++ = query[i].C;
                }
            } else {
                if (reverse % 2 == 0) {
                    *fp++ = query[i].C;
                } else {
                    *hp++ = query[i].C;
                }
            }
        }
    }

    sp = S + strlen(&S[1]) + 1;
    if (reverse % 2 == 0) {
        while (*--hp) {
            putchar(*hp);
        }
        printf("%s", &S[1]);
        printf("%s", &foot[1]);
    } else {
        while (*--fp) {
            putchar(*fp);
        }
        while (*--sp) {
            putchar(*sp);
        }
        printf("%s", &head[1]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 5632
n = gets.to_i
m = gets.split.map(&:to_i)
even = Hash.new(0)
odd = Hash.new(0)
n.times do |i|
  i % 2 == 0 ? even[m[i]] += 1 : odd[m[i]] += 1
end
max = 0
odd = odd.sort{|(k1, v1), (k2, v2)| v2 <=> v1 }
odd_max = odd[0][1]
odd_second = (odd.size == 1) ? 0 : odd[1][1]
even.sort{|(k1, v1), (k2, v2)| v2 <=> v1 }.each do |k, v|
  break if v + odd_max < max
  count = (k == odd[0][0]) ? v + odd_second : v + odd[0][1]
  max = count if max < count
end
puts n - max


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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int d; cin>>d;
	if (d==25) cout<<"Christmas";
	else if (d==24) cout<<"Christmas Eve";
	else if (d==23) cout<<"Christmas Eve Eve";
	else if (d==22) cout<<"Christmas Eve Eve Eve"<<endl;
	return 0;
}


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

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        if (n % 2 == 0) {
            System.out.println(n);
        } else {
            System.out.println(n * 2);
        }
    }
}

Measured memory_bytes: 23092
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        
        int output = 0;
        
        for (int i = 0; i < n; i ++) {
            int h = s.nextInt();
            if (h >= k)
                output ++;
        }
        
        System.out.println(output);
        
    }
    
}


Measured memory_bytes: 48660
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define INF 1e12
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	vector<int> app1(26,0),app2(26,0);
	string a,b; cin>>a>>b;
	For(i,0,sz(a)-1)
	{
		app1[a[i]-'a']++;
		app2[b[i]-'a']++;
	}
	sort(all(app1));
	sort(all(app2));
	For(i,0,25)
	{
		if(app1[i]!=app2[i])
		{
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 916
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;
#define EXEC(...) void exec() { (__VA_ARGS__ - 1) ? multi() : solve(0); }

void exec();
void solve(int t);
void multi() { int TT; cin>>TT; REP1(t,TT) solve(t); }
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    exec();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 1234560
#endif

int N,M;
vector<int> A(SIZE);

pair<int,int> count(string s) {
    pair<int,int> ret = {0,0};
    for (char c:s) {
        if (c=='(') {
            ret.first++;
        } else if (ret.first) {
            ret.first--;
        } else {
            ret.second++;
        }
    }
    return ret;
}

void solve(int _t) {
    cin>>N;
    string s;
    map<int,vector<pair<int,int>>> B;
    vector<pair<int,int>> S,E;
    REP(i,N) {
        cin>>s;
        auto r = count(s);
        if (!r.second) {
            S.push_back(r);
        }
        else if (!r.first) {
            E.push_back(r);
        }
        else {
            B[r.second-r.first].push_back(r);
        }
    }
    int cnt=0;
    for (auto q:S) {
        cnt += q.first;
    }
    for (auto p:B) {
        for (auto q:p.second) {
            cnt -= q.second;
            if (cnt < 0) {
                _PN("No");
                return;
            }
            cnt += q.first;
        }
    }
    for (auto q:E) {
        cnt -= q.second;
    }
    string ans = (!cnt ? "Yes" : "No");
    _PN(ans);
}
EXEC(1)



Measured memory_bytes: 28624
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
  Comb(){
    fac = new ll[1000001];
    finv = new ll[1000001];
    inv = new ll[1000001];
    fac[0] = 1;
    for(int i=1;i<1000001;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000001;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000001;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  int choco[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      char c;
      cin >> c;
      choco[i][j] = c-'0';
    }
  }
  ll ans = MOD;
  for(int state=0;state<(1<<(h-1));state++){
    ll temp = 0;
    vector<int> a;
    a.push_back(0);
    for(int i=0;i<h-1;i++){
      if(state&(1 << i)){
        a.push_back(i+1);
        temp++;
      }
    }
    bool impossible = false;
    a.push_back(h);
    int n = a.size()-1;
    ll able = 0;
    for(int i=0;i<w;i++){
      for(int j=0;j<n;j++){
        able = 0;
        for(int l=a[j];l<a[j+1];l++) able += choco[l][i];
        if(able > k) impossible = true;
      }
    }
    if(impossible) continue;
    vector<int> count(n);
    for(int i=0;i<n;i++) count[i] = 0;
    bool flag = false;
    for(int i=0;i<w;i++){
      for(int j=0;j<n;j++){
        for(int l=a[j];l<a[j+1];l++) count[j] += choco[l][i];
        if(count[j] > k) flag = true;
      }
      if(flag){
        temp++;
        for(int j=0;j<n;j++) count[j] = 0;
        for(int j=0;j<n;j++){
          for(int l=a[j];l<a[j+1];l++) count[j] += choco[l][i];
        }
        flag = false;
      }
    }
    ans = min(ans,temp);
  }
  if(ans == MOD) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		
		//中間試験m、期末試験f、再試験rの点数を受け取る
		while(true){
			String s1 = sc.next();
			int m = Integer.parseInt(s1);
			String s2 = sc.next();
			int f = Integer.parseInt(s2);
			String s3 = sc.next();
			int r = Integer.parseInt(s3);
			//全て-1が入力されたときプログラムを終了する
			if(m == -1 && f == -1){
				if(r == -1){
					break;
				}
			}
			//中間、期末のどちらか休んだ場合はFと表示
			if(m == -1 || f == -1){
				System.out.println("F");
			}
			//80点以上はA
			else if(80 <= m + f){
				System.out.println("A");
			}
			//65点以上はB
			else if(65 <= m + f && m + f < 80){
				System.out.println("B");
			}
			//50点以上はC
			else if(50 <= m + f && m + f < 65){
				System.out.println("C");
			}
			//30点以上はD（ただし再試験が50点以上ならC）
			else if(30 <= m + f && m + f < 50){
				if(50 <= r){
					System.out.println("C");
				}
				else{
					System.out.println("D");
				}
			}
			//30点未満はF
			else{
				System.out.println("F");
			}
		}
	}

}

Measured memory_bytes: 17176
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import math
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#############
# Main Code #
#############

N,M = map(int,input().split())
found = 0

check_list = []
for j in range(M):
  check_list.append(tuple(map(int,input().split())))

if N > 1:
  for i in range(pow(10,N-1),pow(10,N)):
    if not found:
      is_ok = 1
      for item in check_list:
        s,c = item[0], item[1]
        ss = str(i)
        if ss[s-1] != str(c):
          is_ok = 0
      if is_ok:
        print(i)
        found = 1
        break
      
else:
  for i in range(10):
    if not found:
      is_ok = 1
      for item in check_list:
        s,c = item[0], item[1]
        ss = str(i)
        if ss[s-1] != str(c):
          is_ok = 0
      if is_ok:
        print(i)
        found = 1
        break


if not found:
  print(-1)
        

Measured memory_bytes: 40304
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
template <typename T = int>
T in() {
    T temp; cin >> temp; return temp;
}

template <typename VType = int>
list<VType> const LR(VType start, VType end) {
    list<VType> ret; for (VType i = start; i < end; i++) ret.push_back(i); return move(ret);
}

int main() {
    int N(in());
    char S[N];

    int bmax = 0, wmax = 0;
    
    for (char& c : S) {
        cin >> c;
        if (c == '#') bmax++;
        else wmax++;
    }
    S[N] = 0;
    int bcount = 0, wcount = wmax;
    int ret = bcount + wcount;
    for (char c : S) {
        if (c == '#') bcount++;
        else wcount--;
        ret = min(ret, bcount + wcount);
    }
    cout << ret << endl;
    return 0;
}




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

def solve(N: int, S: "List[str]"):
    a=collections.Counter(S)
    c=a.most_common()[0][1]
    ans=[]
    for i in a:
        if a[i]==c:
            ans.append(i)
    ans.sort()

    for i in range(len(ans)):
        print(ans[i])
    
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 45116
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5 + 10;


int main(){
	ios_base::sync_with_stdio(NULL);cin.tie(nullptr);cout.tie(nullptr);
        int a , b , c , k;
        cin >> a >> b >> c >> k;
        int ans = min(k , a);
        k -= min(k , a);
        k -= min(k , b);
        ans -= min(k , c);
        cout  << ans << '\n';
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line
int h , w ;
vector<string> field;

const int mod = 1e9+7;
int dy[4] = {0,0,1,-1};
int dx[4] = {1,-1,0,0};
int main()
{
	//BFSで最短手数を求める。白の数-(最短ゴール手数+1)が答え。()の中は、白の数から使う白の数を引いたものと捉えられる。
	cin >> h >> w ;
	field.resize(h);
	rep(i,h) cin >> field[i] ;//xとyの添字に注意
	int gy = h - 1 , gx = w - 1 ;
	//count[gy][gx]が最短手数になるよう幅優先探索を施す
	bool seen[55][55] ;
	int count[55][55];
	rep(i,55)rep(j,55) seen[i][j] = false , count[i][j] = 0 ;
	queue<pair<int,int>> que;
	que.push(make_pair(0,0));
	seen[0][0] = true; 
	while(!que.empty()){
		auto point = que.front();
		que.pop();
		int ry =point.first;
		int rx = point.second;
		int move = count[ry][rx];
		for(int dir = 0 ; dir < 4 ; dir ++){
			int ny = ry + dy[dir];
			int nx = rx + dx[dir];
			if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if(field[ny][nx] == '#') continue;
			if(seen[ny][nx]) continue;
			seen[ny][nx] =  true ;
			que.push(make_pair(ny,nx));
			count[ny][nx] = move + 1 ;
		}
	}
	int mini = count[gy][gx]; //ゴールまでの最短点数
	//TODO 最短手数に1足すのを忘れずに
	mini ++ ; //必要な白の個数

	//マップに白が何個あるかを数える
	int white = 0 ;
	rep(i,h){
		rep(j,w){
			if(field[i][j] == '.'){
				white ++ ;
			}
		}
	}
	if(seen[gy][gx]){
		cout << white - mini << endl;
	}else cout << -1 << endl;

}


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

using System.Collections;

class Program
{
    static void Main()
    {
        var a = int.Parse(Console.ReadLine());
        var b = int.Parse(Console.ReadLine());
        var c = int.Parse(Console.ReadLine());
        var d = int.Parse(Console.ReadLine());
        var e = int.Parse(Console.ReadLine());
        
        var dishList = new[] { a, b, c, d, e };

        int time = 0;

        foreach(var dish in dishList.OrderByDescending(n => (n - 1) % 10))
        {
            //10の倍数分じゃないと出来ないので時間調整する
            if (time % 10 != 0)
            {
                time = time / 10 * 10 + 10;
            }

            //注文して届くまでの時間を加算する
            time += dish;
        }

        Console.WriteLine(time);

    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <string.h>

int main(){
  char s[101];
  char t[101];
  scanf("%s\n%s",s,t);
  int len = strlen(s);

  int i = 0;
  int j = 0;
  int yes = 0;
  for(i = 0; i < len; i++){
    for(j = 0; j < len; j++){
      if(s[j] == t[(j+i) % len]){
        if(j == len - 1){
          yes = 1;
          break;
        }
        continue;
      }else{
        break;
      }
    }
    if(yes == 1){
      break;
    }
  }
  if(yes == 1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


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

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

#define INF 1e9



int main(){
  int N;
  string S;
  cin >> N >> S;
  int cnt = S.size();
  REP(i, S.size()-1){
    if(S[i] == S[i+1]){
      cnt--;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;


int main(void){
  
  string s;
  cin>>s;
  
  bool isgood=true;
  if(s[0]==s[1]) isgood=false;
  if(s[1]==s[2]) isgood=false;
  if(s[2]==s[3]) isgood=false;
  
  if(isgood){
    cout<<"Good";
  }
  else{
    cout<<"Bad";
  }
  return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		

int n, m, s, t;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int vis[101010];
void dijkstra(int s, vector<vector<pair<int, int>>> &E, vector<ll> &D) {
	REP(i, n) D[i] = INFL;
	REP(i, n) vis[i] = 0;

	min_priority_queue<pair<ll, int>> que;

	D[s] = 0;
	que.push({ 0, s });

	while (!que.empty()) {
		auto q = que.top();
		que.pop();

		ll cst = q.first;
		int cu = q.second;

		if (vis[cu]) continue;
		vis[cu] = 1;

		fore(p, E[cu]) {
			ll cst2 = cst + p.second;
			int to = p.first;

			if (chmin(D[to], cst2)) que.push({ D[to], to });
		}
	}
}



int main() {
	
	
	cin >> n >> m >> s >> t;
	s--; t--;

	vector<vector<pair<int, int>>> c(n), d(n);

	VLL da(n), db(n);

	REP(i, m) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--; v--;

		c[u].push_back({ v,a });
		c[v].push_back({ u,a });
		d[u].push_back({ v,b });
		d[v].push_back({ u,b });
	}

	dijkstra(s, c, da);
	dijkstra(t, d, db);

	VLL ans(n);

	REP(i, n)ans[i] = da[i] + db[i];

	for (int i = n - 2; i >= 0; i--) {
		chmin(ans[i], ans[i + 1]);
	}
	

	REP(i, n)cout << 1000000000000000 - ans[i] << endl;


	return 0;
}

Measured memory_bytes: 16508
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=100002;
ll dp[N];
ll h[N];

ll  calc(ll n){ if(n==1) return 0;
     if(dp[n]!=-1)
     return dp[n];
    dp[n]=min(abs(abs(h[n]-h[n-1])+calc(n-1)),abs(abs(h[n]-h[n-2])+calc(n-2)));
    return dp[n];
}



signed main(){

memset(dp,-1,sizeof(dp));
ll n;
cin>>n;
for(ll i=1;i<=n;i++)
cin>>h[i];
dp[1]=h[1];
dp[2]=abs(h[2]-h[1]);
 ll ans =calc(n);

cout<<ans;

return 0;
}

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

#define ll long long
#define vi vector<int>
#define pi pair<int, int>

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	string s;
	cin >> s;
	if(s == "SAT"){
		cout << 1;
		return 0;
	}
	else if(s == "FRI") cout << 2;
	else if(s == "THU") cout << 3;
	else if(s == "WED") cout << 4;
	else if(s == "TUE") cout << 5;
	else if(s == "MON") cout << 6;
	else if(s == "SUN") cout << 7;
	return 0;
}

Measured memory_bytes: 256
def main():
    MOD = 10**9 + 7
    n, k = map(int, input().split())
    ans = 0
    for x in range(k, n+2):
        ans +=  (n+2)*(n+1)//2 - (n-x+2)*(n-x+1)//2 - (x+1)*x//2 + 1
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9168
#include <iostream>

using namespace std;

int main() {
    int r,g,b;
    cin >> r;
    cin >> g;
    cin >> b;
    if ((r>0 && r<10) && (g>0 && g<10) && (b>0 && b<10)) {
        int answer = 100*r + 10*g + b;
        if (answer % 4 ==0) {
            cout << "YES";
        }
        else
            cout << "NO";
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){

  int n,a[10000],i,j,count=0;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }

  for(i = 0; i < n; i++){      
    for(j = sqrt(a[i]);j > 2; j--){
      if(a[i] % j == 0)break;
    }
    if(a[i] % j != 0 || a[i] == 2 || a[i] == 3)count++;
  }

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

  return 0;
}



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

typedef long long ll;

ll f(ll A, ll B) {
    if (A == 0 || B == 0) return 0;

    ll ret = 0;
    if (A < B) {
        ret = 2*A*(B/A) + f(A, B%A);
    } else {
        ret = 2*B*(A/B) + f(A%B, B);
    }
    return ret;
}

int main(void) {

    ll N, X; cin >> N >> X;
    ll ans = N + f(X, N-X) - __gcd(N, X);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long lli;

const int NMAX = 900000;
#define int long long
vector <vector <int>> adj(NMAX, vector <int>());
vector <pii> t(NMAX);
int res[NMAX];
int glo_time;
int n, q;

void dfs(int i, int par){
	
	t[i].fi = ++glo_time;
	for(int chi: adj[i]){
		if(chi == par) continue;
		dfs(chi, i);
	}
	t[i].sc = ++glo_time;

}

signed main(){
	ios_base::sync_with_stdio(false);
	cin >> n >> q;
	for(int i=0; i<n-1; i++){
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}

	dfs(1, -1);

	while(q--){
		int p, x;
		cin >> p >> x;
		res[t[p].fi] += x;
		res[t[p].sc] -= x;
	}

	for(int i=1; i<NMAX; i++) res[i] += res[i-1];

	for(int i=1; i<=n; i++){
		cout << res[t[i].fi] << " ";
	}

	return 0;
}

Measured memory_bytes: 60288
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

ll a[10000];
int main(){
    ll n,k,ans=0,cnt=0,cnt2=0,mod=pow(10,9)+7;
    cin>>n>>k;
    rep(i,0,n)cin>>a[i];
    ll tmp=a[0];
    rep(i,0,n){
        rep(j,i+1,n){
            if(a[i]>a[j])cnt++;
        }
    }
    rep(i,0,n){
        rep(j,0,n){
            if(a[i]>a[j])cnt2++;
        }
    }
    ans+=(k*cnt)%mod;
    if(k%2==0)ans+=(((k/2)*(k-1))%mod)*cnt2;
    else ans+=((k*(k-1)/2)%mod)*cnt2;
    cout<<ans%mod;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
int main()
{
    long N;
    std::cin >> N;
    long A[20],B[20],C[20];
    for(long i=0; i<N; i++){
        std::cin >> A[i];
    }
    for(long i=0; i<N; i++){
        std::cin >> B[i];
    }
    for(long i=0; i<N; i++){
        std::cin >> C[i];
    }
    long value=0;
    long mae=10000;
    for(long i=0; i<N; i++){
        if(A[i]==mae+1){
            value+=C[mae-1];
        }
        mae=A[i];
        value+=B[A[i]-1];
    }
    std::cout << value << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(v) v.begin(),v.end()
#define vi vector<int> 
#define mod 1000000007
#define inf 1e17
#define fs first
#define ss second

template <typename T> 
void amax(T& x, T y) 
{ 
    if( x < y) x = y;
} 

template <typename T> 
void amin(T& x, T y) 
{ 
    if( x > y) x = y;
} 



int main(){
  
  ll a,b;
  cin >> a >> b;
  
  auto ans = (a*b)/__gcd(a,b);
      
  cout << ans << endl;

}


Measured memory_bytes: 256
a,b = map(int,input().split())
def xor(X):
  if X%2== 0:
    i = 0 if (X//2)%2==0 else 1
    return X ^ i
  else:
    i = 0 if ((X+1)//2)%2==0 else 1
    return i
A = xor(a-1)
B = xor(b)
print(A ^ B)
    

Measured memory_bytes: 38516
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
using pl = pair<ll,ll>;
signed main(){
	ll n,t; cin>>n>>t;
	vector<pl> vec(n);
	ll ans=MOD;
	rep(i,0,n)cin>>vec[i].second>>vec[i].first;
	sort(all(vec));
	rep(i,0,n){
		if(vec[i].first>t)break;
		chmin(ans,vec[i].second);
	}
	if(ans==MOD)cout <<  "TLE" << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    char c; read(c);
    print(char(c + 1));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  int a,b;
  cin >>a>>b;
  
  cout << (500*a>=b?"Yes":"No") << endl; 
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],n;
long long sum[N];
map<long long,int> mp;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;++i){
		sum[i]=sum[i-1]+a[i];
		++mp[sum[i]];
	}
	mp[0]++;
	long long ans=0;
	for(map<long long,int>::iterator i=mp.begin();i!=mp.end();++i)
		ans+=(long long)i->second*(i->second-1)>>1;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 15104
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 10000
#define Infinit 1e+10
#define White 0
#define Black 1
#define Red 2
int n;
vector<pair<int, int> >Relate[MAX];
struct Node{
	int id;
	int weight;

	Node(int inputted_id, int inputted_weight){
		id = inputted_id;
		weight = inputted_weight;
	}
	bool operator<(const Node& another) const{
		return weight < another.weight;
	};
	//2つのconstを付けないとコンパイルエラーになるので注意!!
};
void search() {
	int color[MAX],d[MAX],pointer;
	priority_queue<Node> path;
	for (int i = 0; i < n; i++) {
		if (i == 0) d[i] = 0;
		else d[i] = Infinit;
		color[i] = White;
	}
	path.push(Node(0, 0));
	while (!path.empty()) {
		Node x = path.top();
		pointer=x.id;
		color[pointer] = Black;
		for (int i = 0; i < Relate[pointer].size(); i++) {
			int v = Relate[pointer][i].first;
			if (d[pointer] + Relate[pointer][i].second < d[v] && color[v] != Black) {
				d[v] = d[pointer] + Relate[pointer][i].second;
				color[v] = Red;
				path.push(Node(v,d[v]*(-1)));

			}
		}
		path.pop();
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}
}
int main() {
	int u, k, v, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			Relate[u].push_back(make_pair(v, c));

		}
	}
	search();

}


Measured memory_bytes: 7980
// 2つの数の交換

#include <iostream>
using namespace std;

int main()
{
    int x, y;

    while (1) {
    cin >> x >> y;
    if (!(x+y))
        break;

    if (x > y)
        cout << y << ' ' << x << endl;
    else
        cout << x << ' ' << y << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
i=62,f[],y,m,s;main(c){for(;s?++f[y*12+*f+"=>?2J13IK<@V&"[--s]]:~scanf("%d,%d,%d",f,&y,&s)?s=s*4+1:++i<180?i%12>1?m=fmax(m,y=f[i]),y||++c:1:!printf("%d\n%d\n",c,m););}

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

void print_array(int a[],int n){
    for(int i=0;i<n;i++){
        if(i != 0) cout<<' ';
        cout<<a[i];
    }
    cout<<'\n';
}

void bubble_sort(int a[],int n){
    int start = 0;
    int flag = 1;
    int count = 0;
    while (flag){
        flag = 0;
        for (int j=n-1;j>start;j--){
            if (a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                flag = 1;
                count += 1;
            }
        }
        start++;
    }
    print_array(a,n);
    cout<<count<<'\n';
}

int main(){
    int A[100],N;
    cin>>N;
    for(int i=0 ;i<N;i++){
        cin>>A[i];
    }
    bubble_sort(A,N);   
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
ll cn[100005];
int main() {
	// your code goes here
	
	ll i,j,k,n,m,t;
	cin>>n;
	ll sum = 0;
	for(int i=0;i<n;i++) {
	    cin>>j;
	    sum += j;
	    cn[j]+=1;
	}
	
	cin>>t;
	while(t--){
	    ll p,q;
	    cin>>p>>q;
	    ll c1 = cn[p];
	    sum = sum + c1*(q-p);
	    cn[p] = 0;
	    cn[q] += c1;
	    cout<<sum<<"\n";
	}
	
	return 0;
}


Measured memory_bytes: 4324
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(N-1):
    minj = i
    for j in range(i+1,N):
        if A[j] < A[minj]:
            minj = j
    if A[i] != A[minj]:
        cnt +=1
    temp = A[i]
    A[i] = A[minj]
    A[minj] = temp

print(*A)
print(cnt)


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

const int N = 1e5 + 10;

int valid[N], pr[N];
long long a[N], sqr[N];
map <long long, int> rec;
map <long long, long long> sav;

int main(){
	int tot = 0;
	for (int i = 2; i <= 100000; i++) valid[i] = 1;
	for (int i = 2; i <= 100000; i++){
		if (valid[i]){
			pr[++tot] = i;
			for (int j = i * 2; j <= 100000; j += i) valid[j] = 0;
		}
	}
	for (int i = 1; i <= tot; i++) sqr[i] = 1LL * pr[i] * pr[i];
	int n, flag, sign, cnt, d, ans;
	long long temp, num, prod;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%lld",&a[i]);
	ans = 0; flag = 0;
	for (int i = 1; i <= n; i++){
		num = prod = 1; temp = a[i]; sign = 0;
		for (int j = 1; pr[j] < 3000; j++){
			cnt = 0;
			while (temp % pr[j] == 0){
				cnt++;
				temp /= pr[j];
			}
			cnt %= 3;
			if (cnt == 1){
				num *= pr[j];
				prod *= pr[j] * pr[j];
			}
			else if (cnt == 2){
				num *= pr[j] * pr[j];
				prod *= pr[j];
			}
			if (prod > 10000000000LL){
				sign = 1;
				break;
			}
		}
		if (sign){
			ans++;
			continue;
		}
		if (temp > 1){
			d = lower_bound(sqr + 1, sqr + tot + 1, temp) - sqr;
			if (sqr[d] == temp){
				num *= temp;
				prod *= pr[d];
				rec[num]++;
				sav[num] = prod;
			}
			else{
				if (10000000000LL / prod < temp * temp) ans++;
				else{
					num *= temp;
					prod *= temp * temp;
					rec[num]++;
					sav[num] = prod;
				}
			}
		}
		else{
			if (prod == 1) flag = 1;
			else{
				rec[num]++;
				sav[num] = prod;
			}
		}
	}
	for (auto it : sav){
		ans += max(rec[it.first], rec[it.second]);
		rec[it.first] = 0;
		rec[it.second] = 0;
	}
	ans += flag;
	printf("%d\n", ans);
	return 0;
} 


Measured memory_bytes: 17024
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vvp g;
vvi a;

bool dfs(int v,int p,int ds,int id){
	if(v==ds) return 1;
	bool B=0;
	for(auto t:g[v]){
		int u=t.first;
		if(u!=p){
			if(dfs(u,v,ds,id)){
				a[id][t.second]++;
				B=1;
				break;
			}
		}
	}
	return B;
}

int main(){
	cin>>n;
	g=vvp(n);
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back({v,i});
		g[v].push_back({u,i});
	}
	cin>>m;
	a=vvi(m,vi(n-1));
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		dfs(u,-1,v,i);
	}
	ll res=0;
	for(int i=0;i<1<<m;i++){
		int t=0;
		vi b(n-1);
		for(int j=0;j<m;j++) if(i&1<<j){
			t++;
			for(int k=0;k<n-1;k++) if(a[j][k]) b[k]=1;
		}
		ll x=1;
		for(int j=0;j<n-1;j++) if(!b[j]) x<<=1;
		if(t%2==1) x*=-1;
		res+=x;
	}
/*	for(int i=0;i<m;i++){
		for(auto j:a[i]) cout<<j;
		cout<<endl;
	}*/
	cout<<res<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
int main()
{
	long int s=0;
	int d,c=1;
	while(scanf("%d",&d)!=EOF)
	{
		while(d*c<600)
		{
			s+=pow(d*c,2)*d;
			c++;
		}
		printf("%d\n",s);
		c=s=0;
	}
}

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

namespace ABC130A
{
    class Program
    {
        static void Main(string[] args)
        {
            var xa = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var x = xa[0];
            var a = xa[1];
            if (x < a)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("10");
            }
        }
    }
}


Measured memory_bytes: 13396
import math

def main():
  a, b, x = map(int, input().split())
  box = a * a * b
  fill_rate = x / box
#  print("fill_rate:",fill_rate)
  if fill_rate > 0.5:
    height = b * (1 - fill_rate)
#    print("height:",height)
    width = a / 2
#    print("width:",width) 
  else:
    area_size = a * b * fill_rate
    width = area_size / b * 2
    height = b
  result_radian = math.atan(height/width)
  result = result_radian / math.pi * 180
  return result

print(main())

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//mint型にキャスト
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(int n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
int main(){
    int n,m;
    cin>>n>>m;
    V<ll> a(n),b(m);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
    sort(all(a),greater<ll>());
    sort(all(b),greater<ll>());
    ll a_ind=0,b_ind=0;
    mint ans=1;
    for(ll i=n*m;i>=1;i--){
      if((a_ind<n&&a[a_ind]>i)||(b_ind<m&&b[b_ind]>i))ans=0;
      mint tmp=1;
      if(a_ind<n&&b_ind<m&&a[a_ind]==i&&b[b_ind]==i){
          a_ind++;b_ind++;
      }else if(a_ind<n&&a[a_ind]==i){
        a_ind++;
        tmp=mint(b_ind);
      }else if(b_ind<m&&b[b_ind]==i){
        b_ind++;
        tmp=mint(a_ind);
      }else{
        ll c=a_ind*b_ind-(n*m-i);
        if(c<=0)ans=0;
        else tmp=mint(c);
      }
      ans*=tmp;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256