akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());
//int randt(int l, int r){ return (rando() % (r - l + 1) + l); }

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5;
int mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7;
ll infll = 1e18 + 7;



signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int x; cin >> x; x %= 1000; if (x == 0) cout << x; else cout << 1000 - x;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

class BinaryIndexedTree {
    vector<int64_t> container;

public:
    BinaryIndexedTree(size_t size)
        : container(size + 1)
    {
        fill(container.begin(), container.end(), 0);
    }
    void add(size_t i, int64_t v)
    {
        size_t idx = i + 1;
        while (idx < container.size()) {
            container[idx] += v;
            idx += idx & -idx;
        }
    }
    int64_t find(size_t i)
    {
        size_t idx = i;

        int64_t result = 0;
        while (idx != 0) {
            result = container[idx] + result;
            idx -= idx & -idx;
        }
        return result;
    }
    size_t lower_bound(int64_t v)
    {
        if (v == 0) {
            return 0;
        }
        int64_t w = v;
        size_t x = 0;
        for (size_t k = msb(container.size() - 1); k > 0; k >>= 1) {
            if (x + k < container.size() && container[x + k] < w) {
                w -= container[x + k];
                x += k;
            }
        }
        return x + 1;
    }

private:
    size_t msb(size_t x)
    {
        x |= x >> 1;
        x |= x >> 2;
        x |= x >> 4;
        x |= x >> 8;
        x |= x >> 16;
        return (x + 1) >> 1;
    }
};

int main()
{
    int n;
    int64_t k;
    cin >> n >> k;

    vector<int64_t> a(n);
    rep(i, n)
    {
        cin >> a[i];
        a[i] -= k;
    }

    vector<int64_t> b(n + 1);
    irep(i, n)
    {
        if (i == 0) {
            b[i] = 0;
        } else {
            b[i] = b[i - 1] + a[i - 1];
        }
    }

    auto c = b;
    sort(c.begin(), c.end());

    BinaryIndexedTree bit(c.size());
    int64_t result = 0;
    irep(i, n)
    {
        size_t idx = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
        result += bit.find(idx + 1);
        bit.add(idx, 1);
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 6528
h, w, k = map(int,input().split())
maze = []
res = []
for _ in range(h):
    l = list(input())
    maze.append(l)
    res.append([None] * w)
wrote = False
colornum = 0
for i in range(h):
    if maze[i].count("#") == 0:
        if wrote is False:
            continue
        else:
            for j in range(w):
                res[i][j] = res[i-1][j]
            continue
    wrote = True
    colornum += 1
    passFirst = False
    for j in range(w):
        if maze[i][j] == "#":
            if passFirst is True:
                colornum += 1
                res[i][j] = colornum
            else:
                res[i][j] = colornum
                passFirst = True
        else:
            res[i][j] = colornum

from pprint import pprint

for i in range(1, h):
    if res[h-1-i].count(None) == w:
        for j in range(w):
            res[h-1-i][j] = res[h-1-i+1][j]

if res[h-1].count(None) == w:
    for j in range(w):
        res[h-1][j] = res[h-2][j]


for i in range(h):
    print(" ".join(list(map(str, res[i]))))


Measured memory_bytes: 46956
n = int(input())
S = input()

w, e = 0, S.count('E')
ans = n

for s in S:
    if s == 'W':
        ans = min(ans, (w+e))
        w += 1
    else:
        e -= 1
        ans = min(ans, (w+e))

print(ans)


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
vector<char>a;
char s[11];
int main()
{
    while(~scanf("%s",s))
    {
        int j=0;
        for(int i=0;i<strlen(s);i++)
        {
            if(s[i]=='0'||s[i]=='1')
                a.push_back(s[i]);
            else
            {
                if(a.size()==0)
                    continue;
                a.pop_back();
            }
        }
        for(int i=0;i<a.size();i++)
            printf("%c",a[i]);
        printf("\n");
    }
}


Measured memory_bytes: 256
//ABC 154 F Many Many Paths 
//leaf1415 
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#define llint long long
#define mod 1000000007

using namespace std;

llint sx, sy, tx, ty;
const int FACT_MAX = 3000005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	make_fact();
	
	cin >> sx >> sy >> tx >> ty;
	
	llint ans = 0;
	for(int i = sx; i <= tx; i++){
		ans += comb(i+ty+1, ty), ans %= mod;
		ans += mod - comb(i+(sy-1)+1, sy-1), ans %= mod;
	}
	
	cout << ans << endl;
	
	return 0;
}




Measured memory_bytes: 47104
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n:u32 = sc.read();
    let mut a:Vec<u32> = (0..n).map(|_|sc.read()).collect();
    a.reverse();
    for i in 0..a.len(){
        if i > 0 {
            print!(" ");
        }
        print!("{}",a[i]);
    }
    println!("");
}

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
 
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}



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

struct info{
	string name;
	int point;
	int id; // 1-indexed
};

bool comp(info& a, info& b){
	if(a.name != b.name) return a.name < b.name;
	if(a.point != b.point) return a.point > b.point;
	return a.id < b.id;
}

int main(){
    
    int n;
    cin >> n;
    
	
	vector<info> infos(n);
	rep(i,n){
		string s;
		int p;
		cin >> s >> p;
		infos[i] = {s, p, i+1};
	}
	sort(infos.begin(), infos.end(), comp);
	rep(i,n) cout << infos[i].id << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n, w[3010], K, D[110][101000], Mod = 1000000007, S[101000];
int main() {
	int i, j, k, a;
	scanf("%d%d", &n,&K);
	D[0][0] = 1;
	for (i = 1; i <= n; i++) {
		scanf("%d", &a);
		for (j = 0; j <= K; j++) {
			S[j + 1] = (S[j] + D[i - 1][j]) % Mod;
		}
		for (j = 0; j <= K; j++) {
			D[i][j] = (S[j + 1] - S[max(0, j - a)] + Mod) % Mod;
		}
	}
	printf("%d\n", D[n][K]);
}

Measured memory_bytes: 40704
N, x = map(int, input().split())
a = list(map(int, input().split()))

a = sorted(a)
ans = 0

for i in range(N):
    if sum(a[:i + 1]) <= x:
        ans = i+1
    else:
        print(i)
        exit()

if sum(a[:ans]) == x:
    print(ans)
else:
    print(ans-1)


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

int main(){
  
  int N;
  cin >> N;
  long long A[N],B[N-1];
  
  for (int i = 0; i < N+1; i++){
    cin >> A[i];
  }
  
  for (int i = 0; i < N; i++){
    cin >> B[i];
  }
  
  long long counter = 0;
  
  for (int i = 0; i < N; i++){
    if (B[i] <= A[i]){
      counter += B[i];
    }else if(B[i] <= A[i] + A[i+1]){
      counter += B[i];
      A[i+1] -= B[i] - A[i];
    }else{
      counter += A[i] + A[i+1];
      A[i+1] = 0;
    }
  }
  
  cout << counter << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int mod[4] = {};
    int n;
    cin >> n;
    rep(i, n)
    {
        int a;
        cin >> a;
        mod[a % 4]++;
    }

    if (mod[1] + mod[3] <= mod[0] || (mod[1] + mod[3] == mod[0] + 1 && mod[2] == 0))
        OP("Yes");
    else
        OP("No");

    return 0;
}

Measured memory_bytes: 256
l = int(input())
s = input()
r = set()
cx = set(s)
for x in range(0, l - 2):
    if not cx:
        break
    if s[x] not in cx:
        continue
    cx.remove(s[x])
    cy = set(s[x+1:])
    for y in range(x + 1, l - 1):
        if not cy:
            break
        if s[y] not in cy:
            continue
        cy.remove(s[y])
        cz = set(s[y+1:])
        for z in range(y + 1, l):
            if not cz:
                break
            if s[z] not in cz:
                continue
            cz.remove(s[z])
            r.add(s[x] + s[y] + s[z])

print(len(r))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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 main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto &&i : A) {
        cin >> i;
    }
    auto b = A;
    SORT(b);
    int mx  = b[b.size() - 1];
    int cnt = upper_bound(ALL(b), mx) - lower_bound(ALL(b), mx);
    for (auto &&i : A) {
        if (cnt == 1 && i == mx) {
            std::cout << b[b.size() - 2] << '\n';
        } else {
            std::cout << mx << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K = inputValue();
    int ans = a[K-1];
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(void){
    int n,m,d;cin>>n>>m>>d;
    vector<string>Grid(n);
    int count=0;
    rep(i,n){
        cin>>Grid.at(i);
        for(int j=0;j+d<=m;j++){
            rep(k,d){
                if(Grid.at(i).at(k+j)=='#')break;
                if(k==d-1)count++;
            }
        }
    }
    rep(i,m){
        for(int j=0;j+d<=n;j++){
            rep(k,d){
                if(Grid.at(k+j).at(i)=='#')break;
                if(k==d-1)count++;
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1e9+7;
const int INF=1001001001;
int64_t dp[55][5000];
int main() {
  int N,A;
  cin>>N>>A;
  vector<int>x(N);
  for(int i=0;i<N;i++){
    cin>>x[i];
    x[i]-=A;
  }
  for(int i=0;i<55;i++){
    for(int j=0;j<5000;j++){
        dp[i][j]=0;
    }
  }
  dp[0][2500]=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<5000;j++){
        if(dp[i][j]==0){continue;}
        dp[i+1][j]+=dp[i][j];
        dp[i+1][j+x[i]]+=dp[i][j];
    }
  }
  
  cout<<dp[N][2500]-1<<endl;
  return 0;  
}

Measured memory_bytes: 5752
import java.util.*;

public class Main {

	int[][] graph;
	int W, H;
	static final int[] dx = {0,0,-1,1};
	static final int[] dy = {1,-1,0,0};

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			W = in.nextInt();
			H = in.nextInt();
			if(W==0 && H==0) return ;
			graph = new int[H][W];
			for(int i=0; i<H; i++){
				for(int j=0; j<W-1; j++){
					int a = in.nextInt();
					if(a == 0){
						graph[i][j] |= 1<<3;
						graph[i][j+1] |= 1<<2;
					}
				}
				if(i<H-1){
					for(int j=0; j<W; j++){
						int a = in.nextInt();
						if(a==0){
							graph[i][j] |= 1<<0;
							graph[i+1][j] |= 1<<1;
						}
					}
				}
			}
			System.out.println(solve());
		}
	}

	class Pair{
		int y, x, dist;
		Pair(int _y, int _x, int _d){
			this.y = _y;
			this.x = _x;
			this.dist = _d;
		}
	}

	int solve(){
		Queue<Pair> Q = new LinkedList<Pair>();
		Q.add(new Pair(0,0,1));
		boolean[][] visited = new boolean[H][W];
		visited[0][0] = true;
		while(!Q.isEmpty()){
			Pair tp = Q.poll();
			if(tp.x == W-1 && tp.y == H-1) return tp.dist;
			for(int k=0; k<4; k++){
				if(((graph[tp.y][tp.x] >> k)&1) == 1 && !visited[tp.y + dy[k]][tp.x + dx[k]]){
					visited[tp.y + dy[k]][tp.x + dx[k]] = true;
					Q.add(new Pair(tp.y + dy[k], tp.x + dx[k], tp.dist+1));
				}
			}
		}
		return 0;
	}

	public static void main(String args[]){
		new Main().run();
	}
}

Measured memory_bytes: 12000
let () = Scanf.scanf "%d %d %d" @@ fun n m d ->
  if n - d < 1 then
    print_endline "0.0"
  else if d = 0 then
    Printf.printf "%.10f\n" @@ float_of_int (n - d) /. float_of_int (n * n) *. float_of_int (m - 1)
  else
    Printf.printf "%.10f\n" @@ 2. *. float_of_int (n - d) /. float_of_int (n * n) *. float_of_int (m - 1)


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {
	static int[][] diamond = null;
	static int[][] max = null;
	static int[] tmpMax = null;
	static int height = -1;
	static int width = -1;
	
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> array = new ArrayList<String>();

		try {
			String str = null;
			while ((str = br.readLine()) != null && !str.equals("")) {
				array.add(str);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		width = array.size() / 2 + 1;
		height = array.size();
		diamond = new int[height][width];

		max = new int[height][width];
		
		for(int i = 0; i < height; i++) {
			String s = array.get(i);
			String[] data = s.split(",");
			for(int j = 0; j < data.length; j++) {
				diamond[i][j] = Integer.parseInt(data[j]);
			}
		}
		bfs();

		System.out.println(max[height-1][0]);

	}
	
	private static void bfs() {
		int k = 0;
		int l = 1;
		max[0][0] = diamond[0][0];
		for (int i = 1; i < height; i++) {
			for (int j = 0; j <= i + k; j++) {
				if(j == 0 && (width > i))
					max[i][j] = diamond[i][j] + max[i - 1][j];
				else if(j == i && (width > i)) 
					max[i][j] = diamond[i][j] + max[i -1][j - 1];
				else {
					max[i][j] = diamond[i][j] + Math.max(max[i - 1][j], max[i -1][j - l]);
				}
			}
			
			if(width - 1 <= i) {
				k -= 2;
				l = -1;
			}
		}
	}

}

Measured memory_bytes: 19592
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <algorithm>
#include <tuple>
#include <numeric>

int main()
{
	long N, A[5];
	long ret;

	std::cin >> N;
	for (int i = 0; i < 5; ++i) {
		std::cin >> A[i];
	}

	std::sort(std::begin(A), std::end(A));
	ret = (N + A[0] - 1) / A[0] + 4;
	std::cout << ret << "\n";
}


Measured memory_bytes: 256
S = input()
l = set(S)

res = 10 ** 9
# 使われている文字列を全探索
for x in l:
    # tmp: xでない文字の連続する長さの数え上げ用
    # chk: xでない文字の連続する長さのmax
    tmp, chk = 0, 0
    # 文字列を見ていく
    for s in S:
        # xでない文字の連続する長さのmaxをとっていく
        if s != x:
            tmp += 1
        else:
            chk = max(chk, tmp)
            tmp = 0
    # 文字列の終わり部分
    chk = max(chk, tmp)
    # 連続する長さのmin
    res = min(chk, res)
print(res)

Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int N = read(), ans0 = 0, ans1 = 0, dot = 0, number = 0;
    char c=getchar();
    while (c<'!' || c>'~') c = getchar();
    for (int i = 0; i<N; i++) {
        if (c == '#') {
            if (dot != 0) {
                ans0 = min(ans0, ans1)+dot;
                ans1 += number;
                dot = number = 0;
            }
            number++;
        }
        else if(number != 0) dot++;
        c = getchar();
    }
    if (dot != 0) {
        ans0 = min(ans0, ans1)+dot;
        ans1 += number;
        dot = number = 0;
    }
    printf("%d\n", min(ans0, ans1));
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

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

using namespace std;

struct task{
  int a, b;
  bool operator<( const task& right ) const {
    return (b == right.b) ? (a > right.a) : (b < right.b);
    // return (b == right.b) ? (a > right.a) : (b < right.b);
  };
};

int main() {
    int n;


    scanf("%d", &n);
    vector<task> v(n);
    int a, b;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &v[i].a, &v[i].b);
    }

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

    int t = 0;
    int i;
    for (i = 0; i < n; i++) {
      t += v[i].a;
      if ( t > v[i].b ) break;
      // printf("%d %d\n", v[i].a, v[i].b);
    }
    printf("%s\n", (i==n) ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 1792
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	ll x, a;
	cin >> x >> a;
	if (a > x) cout << 0;
	else cout << 10;
	return 0;
}

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

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int main()
{
  int N, K, L;

  cin >> N >> K >> L;
  UnionFind uf1(N), uf2(N);
  for(int i = 0; i < K; i++) {
    int p, q;
    cin >> p >> q;
    uf1.unite(--p, --q);
  }
  for(int i = 0; i < L; i++) {
    int p, q;
    cin >> p >> q;
    uf2.unite(--p, --q);
  }
  vector< int > v1[N], v2[N];
  for(int i = 0; i < N; i++) {
    v1[uf1.find(i)].push_back(i);
    v2[uf2.find(i)].push_back(i);
  }

  int ret[200000];

  for(int i = 0; i < N; i++) {
    if(i != uf1.find(i)) continue;
    map< int, int > nots;
    for(auto &to : v1[i]) nots[uf2.find(to)]++;
    for(auto &to : v1[i]) ret[to] = nots[uf2.find(to)];
  }
  for(int i = 0; i < N; i++) {
    if(i > 0) cout << " ";
    cout << ret[i];
  }
  cout << endl;
}

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

int main() {
    int N, K, sum = 0;
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        int x; cin >> x;
        sum += min(x, abs(x - K)) * 2;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, i; cin >> N; int A[N]={}, B[N]={};
for(i=0; i<N; i++){ cin >> A[i]; B[A[i]-1]++; }
for(i=0; i<N; i++){ cout << B[i] << " "; }
cout << "\n";
}

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

bool S( string a , string  b )
{
    if( a < b )
        return 1 ;
    else
        return 0 ;
}

int main()
{
    int n;
    cin>>n;
    map<string , int> mp;
    for(int i=0 ; i<n ; i++)
    {
        string x;
        cin>>x;
        mp[x]++;
    }
    int mx=0;
    for( auto it : mp )
    {
        mx=max( mx  , it.second );
    }
    vector<string> a;
    for( auto it : mp)
    {
        if( it.second == mx )
            a.push_back( it.first );
    }
    sort( a.begin() , a.end() , S );
    for(int i=0 ; i<a.size() ; i++)
    {
        cout<<a[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 28788
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <math.h>
#include <typeinfo>
#include <numeric>
using namespace std;

int main()
{
	int N;
	cin >> N;
 
	vector<int> A(N + 1);
	vector<int> B(N);
 
	for (int i = 0; i <= N; i++)
	{
		cin >> A[i];
	}
 
	for (int i = 0; i < N; i++)
	{
		cin >> B[i];
	}
 
	long long ans = 0;
	for (int i = N - 1; i >= 0; i--)
	{
		if (B[i] >= A[i + 1])
		{
			ans += A[i + 1];
			if (A[i] <= (B[i] - A[i + 1]))
			{
				ans += A[i];
				A[i] = 0;
			}
			else
			{
				ans += B[i] - A[i + 1];
				A[i] = A[i] - (B[i] - A[i + 1]);
			}
		}
		else
		{
			ans += B[i];
		}
 	}
 
	cout << ans << endl;
 
	return 0;
 
}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	
	string s;
	int count = 0;
	int point;

	cin >> s;

	FOR(i, 0, s.size() - 1) {
		if (s[i] == '0') {
			count++;
		}
	}

	point = s.size() - count;

	cout << min(count, point) * 2 << endl;

	return 0;
}

Measured memory_bytes: 512
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()

# int(input())
# map(int, input().split())

from bisect import bisect_left

n = int(input())
a = tuple(sorted(map(int, input().split())))

ans = 0
for i in range(n):
    # 最大辺i
    for j in range(i):
        # 長さ中間の辺j
        min_k = a[i] - a[j] + 1
        # 最小辺が満たすべき最低限の長さ
        ans += max(0, j - bisect_left(a, min_k))
print(ans)


Measured memory_bytes: 42972
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        Program pg = new Program();
        pg.Exe();
    }
    public void Exe()
    {
        string before = Console.ReadLine();
        string after = Console.ReadLine();
        int ans = 0;

        if(string.Compare(before, after) != 0)
        {
            int len = before.Length;
            for(int i = 0; i < len; i++)
            {
                if(before[i] != after[i])
                {
                    ans++;
                }
            }
        }

        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 27744
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

AB = [tuple(map(int, input().split())) for _ in range(M)]

AB.sort(key = lambda x: x[1]) #右側が小さい順にソート
AB.sort(key = lambda x: x[0]) #左側が小さい順にソート

ans = 0

right = N + 1
for a, b in AB:
    if a < right:
        right = min(right, b)
    else:
        ans += 1
        right = b

print (ans + 1)



Measured memory_bytes: 18208
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

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

  return 0;
}

// EOF


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

static const int MAX = 50;
int h, w, white[MAX][MAX];

int bfs(){
    P p[MAX][MAX];
    rep(i, h) rep(j, w){
        p[i][j] = P(-1, -1);
    }
    queue<P> q;
    q.push(P(0, 0));
    bool flag = false;
    while(!q.empty()){
        int r = q.front().first;
        int c = q.front().second;
        q.pop();
        if(r == h-1 && c == w-1){
            flag = true;
            break;
        }
        auto check = [&](int i, int j){
            if(i < 0 || h <= i) return;
            if(j < 0 || w <= j) return;
            if(!white[i][j]) return;
            if(p[i][j] != P(-1, -1)) return;
            q.push(P(i, j));
            p[i][j] = P(r, c);
            return;
        };
        check(r+1, c);
        check(r-1, c);
        check(r, c+1);
        check(r, c-1);
    }
    int ans = 1;
    if(flag){
        P pos(h-1, w-1);
        while(pos != P(0, 0)){
            pos = p[pos.first][pos.second];
            ans++;
        }
    }
    return flag ? ans : -1;
}

int main(){
    int black = 0;
    cin >> h >> w;
    rep(i, h) rep(j, w){
        char ch;
        cin >> ch;
        if(ch == '#'){
            black++;
            white[i][j] = 0;
        } else {
            white[i][j] = 1;
        }
    }
    int res = bfs();
    if(res == -1) cout << -1 << endl;
    else cout << h * w - black - res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int isPrime(int);
 
int main(){
 
  int n,data[100000],i,c=0;
 
  scanf("%d",&n);
 
  for(i=0 ; i<n ; i++){
    scanf("%d",&data[i]);
    if(isPrime(data[i])==0) c++;
  }
 
printf("%d\n",c);
 
return 0;
 
}
 
 
int isPrime(int x){
 
  int i,sq;
 
  sq=(int)sqrt(x);
 
  if(x==2) return 0;
  else if(x<2) return 1;
  else if(x%2==0) return 1;
 
  else{
    i=3;
    while(i<=sq){
      if(x%i==0) return 1;
      i+=2;
    }
  }
 
  return 0;
}

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long N = in.nextLong();

			for (long n = 1; n <= 3500; n++) {
				for (long h = 1; h <= 3500; h++) {
					if ((4*h*n - N*n - N*h) != 0 && N*h*n % (4*h*n - N*n - N*h) == 0) {
						long w = N*h*n / (4*h*n - N*n - N*h);
						if (w >= 1) {
							out.println(h +" " + n + " " + w);
							return;
						}
					}
				}
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 23124
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct Node
{
	int t,x,y;
}p[100010];
bool cmp(Node a,Node b)
{
	return a.t <b.t ;
}
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int f=1;
		memset(p,0,sizeof(p));
		for(int i = 1; i <= n; i++)
		{
			scanf("%d%d%d",&p[i].t ,&p[i].x,&p[i].y);
		}
		sort(p+1,p+n+1,cmp);
		for(int i = 1; i <= n; i++)
		{
			int ans=(p[i].x+p[i].y)-(p[i-1].x+p[i-1].y);
			if((p[i].t-p[i-1].t-ans)%2!=0||(p[i].t-p[i-1].t)<ans)
			f=0;
		}
		if(f)
		printf("Yes\n");
		else
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll s,w;
  cin >> s >> w;
  if(w>=s) pr("unsafe");
  else pr("safe");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
using namespace std;
// typedef vector<vector<ll> > matrix;
// const ll S = 3e5 + 20;
// const ll N = 1e6 + 1;
// const ll PRIME = 1e9 + 7;
const ll MAX = 1e6;

void solve()
{
    int x, y;
    cin >> x >> y;
    if (y & 1)
    {
        cout << "No"
             << "\n";
        return;
    }
    if ((1.0 * y / x) > 4)
    {
        cout << "No"
             << "\n";
        return;
    }
    if ((y / x) == 4 || (y / x) == 2)
    {
        cout << "Yes"
             << "\n";
        return;
    }
    if ((y / x) < 4 && (y / x) > 2)
    {
        cout << "Yes"
             << "\n";
        return;
    }
    cout << "No"
         << "\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    // cin >> t;
    t = 1;
    while (t--)
    {
        solve();
    }
}


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

int A[1000];

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int baisu=a;
    while(!A[baisu]){
        A[baisu]=1;
        baisu+=a;
        int amari=baisu%b;
        baisu=amari;
        if(amari==c){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_parityll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

ll powa(ll a, ll b, ll c)
{
    a%=c;
    if(a<0)
	a+=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}
 
#define N 2000005
 
ll fact[N];
ll ifact[N];
 
ll ncr(ll n, ll r)
{
    if(r>n)
        return 0;
    ll ans = fact[n];
    ans*=ifact[r];
    ans%=mod;
    ans*=ifact[n-r];
    ans%=mod;
    return ans;
}

int main()
{
   FAST/**/
   
   fact[0] = 1;
   for(ll i=1;i<N;i++)
        fact[i] = fact[i-1]*i, fact[i]%=mod;
   for(ll i=0;i<N;i++)
        ifact[i] = powa(fact[i],mod-2,mod);
  
   ll ans = 0;
   ll k;
   cin>>k;
   string s;
   cin>>s;
   
   ll n = s.length();
   ll dp[n+k+1];
   memset(dp,0,sizeof(dp));
   dp[n] = powa(26,k,mod);
   ans+=dp[n];
   for(ll i=n+1;i<=n+k;i++)
   {
       dp[i] = powa(25,i-1-(n-1),mod)*powa(26,n+k-i,mod);
       dp[i]%=mod;
       dp[i]*=(ncr(i-1,n-1));
       dp[i]%=mod;
       ans+=dp[i];
       ans%=mod;
   }
   //cout<<dp[4]<<"\n";
   cout<<ans;
   
   
   
   return 0;        
}  
   

Measured memory_bytes: 51084
//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    double n,x,t;
    cin >> n >> x >> t;
    int kekka = ceil(n/x) * t;
    cout << kekka << endl;
}

Measured memory_bytes: 3724
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
a = arrIN()
if len(set(a))==2:
    print('Yes')
else:
    print('No')

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i, N) cin >> p[i];

    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, K)
    {
        ans += p[i];
    }
    cout << ans << endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int N, Q;
	cin >> N;
	map<int, ll> K;
	ll sum = 0;
	
	fx(N) {
		int a;
		cin >> a;
		sum += a;
		K[a]++;
	}
	cin >> Q;
	fx(Q) {
		int b, c;
		cin >> b >> c;
		sum += (c - b) * K[b];
		K[c] += K[b];
		K[b] = 0;
		ce(sum)
	}
    return 0;
}



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

using namespace std;

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

	// AからBかA+K-1の内小さいほうまでを出力
	for (int i = A; i <= min(B, A + K -1); i++) { 
		cout << i << '\n';
	}	
	// B-K+1からA+Kのうち小さいほうから(一回目AについてのループでBに到達した場合、確実にA+K>Bとなるのでこのループは実行されない)
	for (int i = max(B - K + 1, A + K); i <= B; i++) {
		cout << i << '\n';
	}
}

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

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	i64 n, m;
	cin >> n >> m;
	set<i64> a1;
	int i = 2;
	i64 t = n;
	while(n>1){
		if (n % i == 0) {
			if (m % i == 0) {
				a1.insert(i);
			}
		}
		while (n % i == 0) {
			n /= i;
		}
		if (i > sqrt(t)) {
			if (m % n == 0) {
				a1.insert(n);
			}
          n=1;
		}
		i++;
	}
	cout << a1.size() + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int count = 0;
	for (int i = 0; i < A + 1; i++) {
		for (int j = 0; j < B + 1; j++) {
			for (int k = 0; k < C + 1; k++) {
				if (500 * i + 100 * j + 50 * k == X) {
					count++;
				}
			}
		}
	}

	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll p[mx],a[mx],b[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
void solve()
{
    char c;
    cin>>c;
    char ans=c+1;
    cout<<ans<<endl;

}
int main()
{
    faster();
    int tc;
    tc=1;
    while(tc--)
        solve();
    return  0;
}


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

int main(){
    int x;
    cin >> x;

    int c500 = x / 500;
    int r500 = x % 500;
    int c5 = r500 / 5;

    cout << c500 * 1000 + c5 * 5 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int x,y,z,n;
  scanf("%d",&x);
  if(x<500){
    y=(x/5)*5;
    printf("%d",y);
  }else{
    y=x/500;
    z=x-(y*500);
    n=(z/5)*5;
    y=y*1000;
    printf("%d",y+n);
  }
  return 0;
}
  

Measured memory_bytes: 1716
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	int n;cin>>n;
	multiset<int>s;
	rep(i,n){
		int d;scanf("%d",&d);
		s.insert(d);
	}
	int m;cin>>m;
	rep(i,m){
		int d;scanf("%d",&d);
		if(!s.count(d)){
			puts("NO");return 0;
		}
		s.erase(s.find(d));
	}
	puts("YES");
}

Measured memory_bytes: 9600
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//long.Parseはstringをlongに変換。
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long answer = 0;
    long memo = 0;
    Array.Sort(nums);
    while(true)
    {
      answer += nums[3*n-2-2*memo];
      memo++;
      if(memo == n) break;
    }
    
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 40012