akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, T; cin >> K >> T;
    int a[T];
    rep(i, T) cin >> a[i];
    sort(a, a+T);
    int ans = a[T-1] - 1;
    rep(i, T-1) ans -= a[i];
    cout << max(0, ans) << endl;


    return 0;
}


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

string a[110];

int main(){
	int k,b; scanf("%d%d",&k,&b);
	for(int i=1;i<=k;i++)
		cin>>a[i];
	sort(a+1,a+k+1);
	for(int i=1;i<=k;i++)
		cout<<a[i];
	cout<<endl;
	return 0;
}

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

int main() {
  string  num;
  string one;
  cin >> num;
  
  one = num.substr(num.size()-1,1);
  
  if(one == "3") cout << "bon";
  else if(one == "0" || one == "1" || one == "6" || one == "8") cout << "pon";
  else cout << "hon";
}


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

using namespace std;
using ll = long long int;

int main()
{
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++)
  {
    for(int j = i; j < s.size() - 1; j++)
    {
      string temp = s.substr(0, i + 1);
      temp += s.substr(j + 1, s.size());
      if(temp == "keyence")
      {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}


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

typedef long long ll;
const int N = 200233, inf = 1100000007;
int n, L, a[N], lf[N], rf[N], lp[N], rp[N];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> s;
ll ans = 0;

int main() {
  scanf("%d%d", &n, &L);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    lf[i] = rf[i] = 1;
    lp[i] = i - 1;
    rp[i] = i + 1;
    s.push(make_pair(a[i], i));
  }
  rf[0] = 1;
  lf[n + 1] = n;
  while (1) {
    int x = s.top().second;
    s.pop();
    if (a[x] == inf) break;
    int y = x, cnt = 1;
    vector<int> v(1, x);
    while (a[rp[y]] == a[y]) {
      cnt++;
      y = rp[y];
      v.push_back(y);
      s.pop();
    }
    for (int i = 0, sum = 0; i < cnt; i++) {
      ans += (ll) lf[v[i]] * rf[v[i]];
      if (i - L + 1 >= 0) {
        sum += lf[v[i - L + 1]];
      }
      ans += (ll) sum * rf[v[i]];
    }
    int lt = lp[x], rt = rp[y];
    if (lt == 0 && rt == n + 1) {
      break;
    }
    int cnt2 = cnt / L;
    vector<int> nlf(cnt2, 0), nrf(cnt2, 0);
    for (int i = 0; i < cnt; i++) {
      if (cnt - i >= L) {
        nlf[cnt2 - 1 - (cnt - i - L) / L] += lf[v[i]];
      }
      if (i + 1 >= L) {
        nrf[(i + 1 - L) / L] += rf[v[i]];
      }
    }
    for (int i = 0, sum = 0; i < cnt2; i++) {
      ans -= (ll) nlf[i] * nrf[i];
      if (i - L + 1 >= 0) {
        sum += nlf[i - L + 1];
      }
      ans -= (ll) sum * nrf[i];
    }
    if (!cnt2) {
      ++cnt2;
      a[v[0]] = inf - 1;
      nlf.assign(1, 0);
      nrf.assign(1, 0);
    }
    for (int i = 0; i < cnt2; i++) {
      a[v[i]]++;
      s.push(make_pair(a[v[i]], v[i]));
      lf[v[i]] = nlf[i];
      rf[v[i]] = nrf[i];
    }
    lp[v[0]] = lt;
    rp[v[cnt2 - 1]] = rt;
    rp[lt] = v[0];
    lp[rt] = v[cnt2 - 1];
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 6640
N=int(input())
A=list(map(int,input().split()))

def all_devided_2(A):
#	print(A)
	for i in range(len(A)):
		if A[i] % 2 != 0:
			return False
	return True

res = 0
while all_devided_2(A) == True:
	res += 1
	for i in range(len(A)):
		A[i] //= 2;

print(res)

Measured memory_bytes: 3060
count = int(input())
li = list(map(int, input().split()))

sli = sorted(li)

default_median_index = int((len(sli) + 1) / 2)
default_median = sli[default_median_index]

for i in range(len(li)):
    r = li[i]
    if r < default_median:
        print(default_median)
    else:
        print(sli[default_median_index - 1])



Measured memory_bytes: 25472
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int a[6], b[6];
bool saiki(int x, int y,int min,int max,bool z) {
	if (x == 0)return true;
	if (y == 0)return false;
	if (z) {
		bool P = false;
		bool n = true;
		for (int i = 0; i < 6; i++) {
			if (a[i] + 1 == min) {
				n = false;
				P=P||saiki(x - 1, y, min - 1, max, false);
			}
			else if (a[i] - 1 == max) {
				n = false;
				P=P||saiki(x - 1, y, min, max+1, false);
			}
		}
		if (n)P=P||saiki(x, y, min, max, false);
		return P;
	}
	else {
		bool Q = true;
		bool m = true;
		for (int i = 0; i < 6; i++) {
			if (b[i] + 1 == min) {
				m = false;
				Q=Q&&saiki(x, y-1, min - 1, max, true);
			}
			else if (b[i] - 1 == max) {
				m = false;
				Q = Q&&saiki(x, y-1, min, max + 1, true);
			}
		}
		if (m)Q = Q&&saiki(x, y, min, max, true);
		return Q;
	}
	return true;
}
int main() {
	int e; cin >> e;
	for (int f = 0; f < e; f++) {
		for (int g = 0; g < 6; g++) {
			cin >> a[g];
		}
		int sum = 0;
		for (int h = 1; h < 14; h++) {
			if (h != 7) {
				bool k = true;
				for (int i = 0; i < 6; i++) {
					if (a[i] == h)k = false;
				}
				if (k) {
					b[sum] = h;
					sum++;
				}
			}
		}
		if (saiki(6, 6, 7, 7, true))puts("yes");
		else puts("no");
	}
}

Measured memory_bytes: 3068
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int array[] = new int[n];
        for(int i=0; i<n; i++){
            array[i] = sc.nextInt();
        }
        Arrays.sort(array);
        int min = array[n-1];
        for(int i=0; i<=n-k; i++){
            if(min > array[i+k-1] - array[i]) min = array[i+k-1] - array[i];
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 51020
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next(),b = scanner.next(),c = scanner.next();
		int cta = 0,ctb = 0,ctc = 0;
		cta++;
		String pos = String.valueOf(a.charAt(0));
		boolean check = true;
		while(check){
			switch(pos){
			case "a":
				if(cta == a.length()){
					check = false;
				}else{
					pos = String.valueOf(a.charAt(cta));
					cta++;
				}
				break;
			case "b":
				if(ctb == b.length()){
					check = false;
				}else{
					pos = String.valueOf(b.charAt(ctb));
					ctb++;
				}
				break;
			case "c":
				if(ctc == c.length()){
					check = false;
				}else{
					pos = String.valueOf(c.charAt(ctc));
					ctc++;
				}
				break;
			}
		}
		switch(pos){
		case "a":
			System.out.println("A");
			break;
		case "b":
			System.out.println("B");
			break;
		case "c":
			System.out.println("C");
			break;
		}
	}
}




Measured memory_bytes: 20820
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef SHUBHAM107
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD) {
	a %= m; ll res = 1; while (b) {if (b & 1)res = res * a % m; a = a * a % m; b >>= 1;}
	return res;
}
ll bpow(ll a, ll b) {ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a) {return modpow(a, MOD - 2, MOD);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}

const int mxN = 2e5 + 5;
void solve() {
	int n;
	cin >> n;
	vi heights(n);
	forn(i, n) cin >> heights[i];
	map<int,int> mp;
	rforn(i, n) mp[i-heights[i]]++;
	ll ans = 0;
	forn(i, n-1){
		mp[i-heights[i]]--;
		if(mp.count(i+heights[i])){
			ans += mp[i+heights[i]];
		}
	}
	cout << ans;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef SHUBHAM107
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}


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

int main() {
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for (size_t i = 0; i < S.size(); i++) {
        if (S.at(i) != T.at(i))
            cnt++;
    }
    std::cout << cnt;
    return 0;
}


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int D;
  cin >> D;
  if (D == 25)
    cout << "Christmas" << endl;
  else if (D == 24)
    cout << "Christmas Eve" << endl;
  else if (D == 23)
    cout << "Christmas Eve Eve" << endl;
  else
    cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

// 1次元 vector
template <class T>
ostream &operator<<(ostream &s, vector<T> vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        if (i > 0) {
            s << " ";
        }
        s << vec[i];
    }
    return s << endl;
}
template <class T>  // 2次元 vector
ostream &operator<<(ostream &s, vector<vector<T>> vec2) {
    for (int i = 0; i < (int)vec2.size(); ++i) {
        s << vec2[i];
    }
    return s;
}
int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }

    vector<vector<int>> dp = make_vec<int>(N + 1, H + 1);
    for (int i = 0; i < N + 1; i++) {
        for (int j = 1; j < H + 1; j++) {
            dp[i][j] = INF;
        }
    }

    for (int n = 0; n < N; n++) {
        for (int h = 0; h <= H; h++) {
            chmin(dp[n][min(h + A[n], H)], dp[n][h] + B[n]);
            chmin(dp[n + 1][h], dp[n][h]);
        }
    }

    cout << dp[N - 1][H] << endl;
}


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

int main(){
    int n;
    cin>>n;
    ll sum=0,cnt1=0,cnt2=0;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    sum=a[0];
    bool plus=false;
    if(sum>0)plus=true;
    if(!plus){
        cnt1+=abs(1-sum);
        sum=1;
    }
    for(int i=1; i<n; ++i){
        sum+=a[i];
        if(sum-a[i]>0&&sum>=0){
            cnt1+=abs(-1-sum);
            sum=-1;
        }
        else if(sum-a[i]<0&&sum<=0){
            cnt1+=abs(1-sum);
            sum=1;
        }
    }
    sum=a[0];
    bool minus=false;
    if(sum<0)minus=true;
    if(!minus){
        cnt2+=abs(-1-sum);
        sum=-1;
    }
    for(int i=1; i<n; ++i){
        sum+=a[i];
        if(sum-a[i]>0&&sum>=0){
            cnt2+=abs(-1-sum);
            sum=-1;
        }
        else if(sum-a[i]<0&&sum<=0){
            cnt2+=abs(1-sum);
            sum=1;
        }
    }
    cout<<min(cnt1,cnt2)<<endl;
    return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			(a).begin(),(a).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	int A[100][100];
	cin >> N;
	REP(i, 2) {
		REP(j, N) {
			cin >> A[i][j];
		}
	}

	int ans = 0;
	REP(i, N) {
		int sum = 0;
		for (int j = 0; j <= i; j++) {
			sum += A[0][j];
		}
		for (int j = i; j < N; j++) {
			sum += A[1][j];
		}
		ans = max(ans, sum);
	}

	cout << ans << endl;
	return 0;

}


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


int main() {
	
	const int q = 1000000007;
	int N;
	int64_t p = 1;
	cin >> N;
	for (int i=1; i<=N; i++)
		p = (p * i) % q;

	cout << p << endl;
	return 0;
	
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define mp make_pair
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcd(int a,int b){return a*b / gcd(a,b);}
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};
LL hako[200200];
LL q[200200];
int main(){
  LL n;
  cin >> n;
  rep(i,0,n){
    cin >> q[i];
    hako[q[i]]++;
  }
  LL base = 0;
  rep(i,0,n+1){
    base += hako[i] * (hako[i]-1) / 2;
  }
  rep(i,0,n){
    LL res =  base - (hako[q[i]] * (hako[q[i]]-1)/2) + ((hako[q[i]]-1) * (hako[q[i]]-2)/2);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 6272
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7
import heapq

N,M = I()
L = [l() for _ in range(N)]
A = deque([])
B = deque([])
L.sort()
ans = 0
for a,b in L:
    A.append(a)
    B.append(b)
q = []
heapq.heapify(q)
for i in range(1,M+1):
    for j in range(len(A)):
        if A[0] > i:
            break
        else:
            A.popleft()
            heapq.heappush(q,B.popleft()*-1)
    if q:
        ans += heapq.heappop(q)*-1
print(ans)

Measured memory_bytes: 104508
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans = 0;
  scanf("%lld", &n);
  ll a[n], las = 0, now = 0;
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  for(i = 0; i < n; ++i) {
    ll s = 1;
    while(1) {
      ll tmp = a[i] & now;
      s = 0;
      for(j = 0; j < 21; ++j) {
        if(tmp & 1 << j) {
          s = 1;
          break;
        }
      }
      if(s) {
       now -= a[las];
       las++;
      } else {
        now += a[i];
        break;
      }
    }
    ans += i - las + 1;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1664
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n; cin>>n;
    ll ans = 0;
    vector<ll> cnt(1e5 + 5);
    for(int i =0 ; i <n; i++){
        int k; cin>>k;
        cnt[k]++;
        ans += k;
    }
    int q; cin>>q;
    for(ll i = 0 ; i  < q; i++){
        ll pos, nw; 
        cin>>pos>>nw;
        ans-=pos*cnt[pos];
        ans+=nw*cnt[pos];
        cnt[nw]+=cnt[pos];
        cnt[pos] = 0;
        cout<<ans<<endl;
    }

    return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&b==c){
    cout << 1 << endl;
  } else if(a==b||b==c||a==c) {
    cout << 2 << endl;
  } else {
    cout << 3 << endl;
  }
}

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

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

int t[4][4];

int calc(){
  int res=0;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      int id=t[i][j]-1;
      if(id==-1)continue;
      int y=id/4, x=id%4;
      res+= abs(y-i) + abs(x-j);
    }
  }
  return res;
}

int R;

bool dfs(int py,int px,int depth,int prev){
  int h=calc();
  if(h==0)return true;
  if(depth+h>R)return false;
  for(int i=0;i<4;i++){
    if( (i+2)%4 == prev )continue;
    int ny=py+dy[i];
    int nx=px+dx[i];
    if(ny<0 || nx<0 || ny>=4 || nx>=4)continue;
    swap(t[ny][nx],t[py][px]);
    if( dfs(ny,nx,depth+1,i) )return true;
    swap(t[ny][nx],t[py][px]);
  }
  return false;
}

int main(){
  int sy=0,sx=0;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      cin>>t[i][j];
      if(t[i][j]==0){
        sy=i;
        sx=j;
      }
    }
  }
  for(R=0;R<=44;R++){
    if( dfs(sy,sx,0,-1) ){
      cout<<R<<endl;
      return 0;
    }
  }
  cout<<45<<endl;
  return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n, m,k;
	cin >> n >> m >> k;
	int paint = 0;
	REP(i, n){
		paint = i * m;
		REP(j, m+1) {
			if (paint == k) {
				cout << "Yes" << endl;
				return 0;
			}
			paint += n - (i * 2);
		}
	}
	cout << "No" << endl;
	return 0;
}



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

int main(){
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for (int i = 0; i < N; i++){
        cin >> S.at(i);
    }
    sort(S.begin(), S.end());
    string ans;
    for (int i = 0; i < N; i++){
        ans += S.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	ll n;
	cin >> n;

	const ll MAX_N = 100000;

	set<ll> se;
	se.insert(1);
	for (int i = 6; i < MAX_N; i *= 6) {
		se.emplace(i);
	}
	for (int i = 9; i < MAX_N; i *= 9) {
		se.emplace(i);
	}

	vector<ll> dp(MAX_N + 1, INF);
	dp[0] = 0;
	for (int i = 0; i < MAX_N; i++) {
		for (auto v : se) {
			if (i + v > MAX_N) {
				continue;
			}

			dp[i + v] = min(dp[i + v], dp[i] + 1);
		}
	}

	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int p, q, visit[1000000];
int main() {
	while (cin >> p >> q) {
		for (int i = 0; i < q; i++) visit[i] = -1; visit[p] = 0;
		for (int i = 0; ; i++) {
			p *= 10, cout << p / q, p %= q;
			if (p == 0) {
				cout << endl; break;
			}
			if (visit[p] != -1) {
				cout << endl;
				for (int j = 0; j < visit[p]; j++) cout << ' ';
				for (int j = visit[p]; j <= i; j++) cout << '^';
				cout << endl; break;
			}
			visit[p] = i + 1;
		}
	}
}

Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;



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

    int len = n.size();

    // dp[k][l]: kは残り非0, lは1の時=状態
    int dp[4][2] = {0};
    dp[k][1] = 1;
    rep(i, len){
        int nextdp[4][2] = {0};
        int num = n[i] - '0'; //上位i+1桁目の数字をチェック
        //cout << num << endl;
        //l=0側からの更新
        rep(k_itr, k){
            nextdp[k_itr][0] += dp[k_itr+1][0] * 9;
        }
        rep(k_itr, k+1){
            nextdp[k_itr][0] += dp[k_itr][0];
        }
        //l=1側からの更新
        //l=1を維持
        if (num != 0){
            rep(k_itr, k) nextdp[k_itr][1] = dp[k_itr+1][1];
        } else{
            rep(k_itr, k+1) nextdp[k_itr][1] = dp[k_itr][1];
        }
        
        //l=0に推移
        rep(k_itr, k) nextdp[k_itr][0] += max(num - 1, 0) * dp[k_itr+1][1]; //1以上の数で推移
        if (num != 0) rep(k_itr, k+1) nextdp[k_itr][0] += dp[k_itr][1]; //0で推移
    
        memcpy(dp, nextdp, sizeof(nextdp));

    }


    cout << dp[0][0] + dp[0][1] << endl;
    

}



Measured memory_bytes: 256
A,B,C,D=list(input())
op="+-"
for i in range(2):
    for j in range(2):
        for k in range(2):
            if eval(A+op[i]+B+op[j]+C+op[k]+D) == 7:
                print(str(A+op[i]+B+op[j]+C+op[k]+D)+"=7")
                exit()


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int x;
	
	while(cin>>x)
	{
		if(x<=599)
			cout<<8<<endl;
		else if(x<=799)
			cout<<7<<endl;
		else if(x<=999)
			cout<<6<<endl;
		else if(x<=1199)
			cout<<5<<endl;
		else if(x<=1399)
			cout<<4<<endl;
		else if(x<=1599)
			cout<<3<<endl;
		else if(x<=1799)
			cout<<2<<endl;
		else if(x<=1999)
			cout<<1<<endl;	
		
	}
	
	return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}


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

Measured memory_bytes: 6432
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
int main(int argc, char *argv[])
{
  for(;;) {
    int n;
    cin >> n;
    if(n == 0) break;
    vector<pair<int,int>> abs;
    for(int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      abs.push_back(make_pair(a, b));
    }
    int best = 0;
    vector<int> cnt(100003, 0);
    cnt[0] = 1;
    cnt[n+2] = -1;
    for(int i = 0; i < n; i++) {  // differences of the histogram
      cnt[abs[i].first]++;
      cnt[abs[i].second+1]--;
    }
    for(int i = 1; i <= n + 1; i++) { // build the histogram
      cnt[i] += cnt[i-1];
    }
    for(int i = 1; i <= n + 1; i++) {
      if(cnt[i] >= i) best = i - 1;
    }
    
    /* This is a bit more efficient version.
    int s = 0;
    sort(abs.begin(), abs.end());
    std::priority_queue<int> heap;
    // heap = friends x s.t. abs[x].second >= k+1
    for(int k = 1; k <= n; k++) {
      while(s < n && abs[s].first <= k+1) {
        heap.push(-abs[s].second);
        s++;
      }
      while(heap.size() > 0 && -heap.top() <= k) heap.pop();
      if(heap.size() >= k) { best = k; }
    }
    */
    /* This is a naive version.
    int s = 0;
    sort(abs.begin(), abs.end());
    for(int k = 1; k <= n; k++) {
      while(s < n && abs[s].first <= k+1) s++;
      int c = k;
      for(int j = s - 1; c > 0 && j >= 0; j--) {
        if(abs[j].second >= k+1) c--;
      }
      if(c == 0) { best = k; }
    }
     */
    cout << best << endl;
    break;
  }
  return 0;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define crap ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846264338327950288419716939937510
#define pb(a) push_back(a)
#define pf(a) push_front(a)

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

ll fun(vector < vector <ll> > arr,ll k,ll n,ll m,ll row,ll col)
{
	// Wherever bit is set in row or col , change that respective row and col
	ll i,j,t ;
	ll x,y,z ;
	i = col ;
	y = 0;
	while(i)
	{
		z = (i%2) ;
		if(z==1)
		{
			f(t,0,n)
				arr[t][y] = 3 ;
		}
		i = i/2 ;
		y++ ;
	}
	i = row ;
	y = 0;
	while(i)
	{
		z = (i%2) ;
		if(z==1)
		{
			f(t,0,m)
				arr[y][t] = 3 ;
		}
		i = i/2 ;
		y++ ;
	}
	ll count = 0;
	f(i,0,n)
	{
		f(j,0,m)
		{
			if(!arr[i][j])
				count++ ;
		}
	}
	if(count==k)
		return 1;
	return 0 ;
}


int main()
{
	crap;
	ll i,j,k,n,m;
	cin >> n >> m >> k;
	vector < vector <ll> > mat(n) ;
	f(i,0,n)
	{
		f(j,0,m)
		{
			char ch;
			cin >> ch ;
			if(ch=='.')
				mat[i].pb(1) ;
			else
				mat[i].pb(0) ;
		}
	}
	ll ans = 0;
	ll x,y ;
	x = pow(2,n) ;
	y = pow(2,m) ;
	for(i=0;i<x;++i)
		for(j=0;j<y;++j)
			ans += fun(mat,k,n,m,i,j) ;
	cout << ans endl ;
	return 0;
}

Measured memory_bytes: 3956
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';
int P[10] = { 0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2 };
int Q[10] = { 1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3 };
int R[10] = { 2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4 };
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	ll m, a, r, c, h;
	m = 0; a = 0; r = 0; c = 0; h = 0;
	cin >> n;
	rep(i, n) {
		string s;
		cin >> s;
		if (s[0] == 'M') m++;
		if (s[0] == 'A') a++;
		if (s[0] == 'R') r++;
		if (s[0] == 'C') c++;
		if (s[0] == 'H') h++;
	}
	ll ans = 0;
	ll d[5] = {};
	d[0] = m; d[1] = a; d[2] = r; d[3] = c; d[4] = h;
	rep(i, 10) {
		ans += d[P[i]] * d[Q[i]] * d[R[i]];
	}
	cout << ans;

}



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

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<pair<string, int>> rest(n);
    map<int, int> restNum;
    for(int i=0;i<n;i++) cin >> rest[i].first >> rest[i].second;
    for(int i=0;i<n;i++) restNum[rest[i].second] = i+1;
    sort(rest.begin(), rest.end());
    for(int i=1;i<n;i++){
      while(rest[i].first == rest[i-1].first && rest[i].second > rest[i-1].second){
        pair<string, int> tmp;
        tmp = rest[i-1];
        rest[i-1] = rest[i];
        rest[i] = tmp;
        i--;
      }
    }
    for(int i=0;i<n;i++) cout << restNum[rest[i].second] << endl;
    return 0;
}

Measured memory_bytes: 3616
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();

        BigDecimal ans = null;
        BigDecimal bda = new BigDecimal(a);
        bda.setScale(0);
        BigDecimal bdb = new BigDecimal(b);
        bdb.setScale(2, RoundingMode.DOWN);
        ans = bda.multiply(bdb);
        System.out.println(ans.longValue());
    }
}

Measured memory_bytes: 35920
n, m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(n)]
c = [list(map(int, input().split())) for j in range(m)]
for k in range(n):
    x = abs(s[k][0] - c[0][0]) + abs(s[k][1] - c[0][1])
    ans = 1
    for l in range(1, m):
        y = abs(s[k][0] - c[l][0]) + abs(s[k][1] - c[l][1])
        if y < x:
            x = y
            ans = l + 1
        elif y == x:
            x = y
    print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
typedef long long ll;

int n;
int t[1010], a[1010];

void solve() {
  ll x = t[0], y = a[0];
  for (int i=1;i<n;i++) {
    while(x % t[i] != 0)x++;
    while(y % a[i] != 0)y++;
    ll baseX = x / t[i];
    ll baseY = y / a[i];
    if (baseX > baseY) {
      y = a[i] * baseX;
    } else {
      x = t[i] * baseY;
    }
  }
  cout << (x + y) << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
int main(void){
    int a,b;
    std::cin >> a >> b;
    
    if ((a-b)%2==0 && (b-a)%2==0){
        std::cout << (a+b)/2 << std::endl;
    }
    else {
        std::cout << "IMPOSSIBLE" << std::endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;

int a[3][105];
int sum[3][105];

int main()
{
	int n;
	cin>>n;
	long long max=0;
	for(int i=1;i<=2;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>a[i][j];
			sum[i][j]=sum[i][j-1]+a[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(sum[1][i]+sum[2][n]-sum[2][i-1]>max)
			max=sum[1][i]+sum[2][n]-sum[2][i-1];
	}
	cout<<max<<endl;
	return 0;
}

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF 10000000000
#define MOD 10007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

//#define DEBUG

int main_(){
  int N,Q;
  cin>>N>>Q;
  string S;
  cin>>S;
  vector<int>l(Q),r(Q);
  for(int i=0;i<Q;i++)cin>>l[i]>>r[i];

  vector<int>ac(N);
  ac[0]=0;
  char old=S[0];
  for(int i=1;i<N;i++){
    if(old=='A'&&S[i]=='C'){
      ac[i]=ac[i-1]+1;
    }
    else{
      ac[i]=ac[i-1];
    }
    old=S[i];
  }
  for(int i=0;i<Q;i++){
    int rr=r[i]-1;
    int ll=l[i]-1;
    cout<<ac[rr]-ac[ll]<<endl;
  }
  return 0;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  vector<string>test;
  /*
   * input for debug
   */
  for(int i=0;i<test.size();++i){
    stringbuf buf;
    streambuf*out=cout.rdbuf(&buf);
    cout<<test[i]<<flush;
    cout.rdbuf(out);
    streambuf*in=cin.rdbuf(&buf);
    main_();
    cin.rdbuf(in);
    cout<<endl;
  }
#else
  main_();
#endif

  return 0;
}


Measured memory_bytes: 2256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e5+5;

ll dp[105][N];

ll n,W;
ll wei[105],val[105];

int main() {
    scanf("%lld%lld",&n,&W);
    
    for(ll i=0;i<n;i++){
        scanf("%lld%lld",wei+i,val+i);
    }
    
    memset(dp, 0x3f, sizeof(dp));
    
    dp[0][0] = 0;
    
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<N;j++){
            if(j >= val[i-1])
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-val[i-1]]+wei[i-1]);
            else 
                dp[i][j] = dp[i-1][j];
        }
    }
    
    ll answer = 0;
    
    for(ll j=0;j<N;j++){
        if(dp[n][j] <= W) 
            answer = j;
    }
    
    printf("%lld",answer);
    
    return 0;
}

Measured memory_bytes: 85804
#B - 105
function main()
    N = parse(readline())
    ANSWER = 0
    for i in 1:N
        i < 105 && continue
        i%2 == 0 && continue
        divisor = 0
        
        for j in 1: i/2 + 0.5
            if i%(2j - 1) == 0
                divisor += 1
            end
        end
        
        if divisor == 8
            ANSWER += 1
        end
    end
    print(ANSWER)
end

main()

Measured memory_bytes: 117968
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int [][] List = new int[3][3];
        int a[]=new int[3];
        int b[]=new int[3];
        
        for(int i=0;i<3;i++){
            
            for(int j=0;j<3;j++){
                List[i][j] =sc.nextInt();
                
            }
        }
        a[0]=0;
        for(int i=0; i<3; i++) {
            
            b[i] = List[0][i] - a[0];
        }
        for(int i=0; i<3; i++) {
        
            a[i] = List[i][0] - b[0];
        }
        
        
        for(int i=0; i<3; i++) {
           for(int j=0; j<3; j++) {
                if(List[i][j] != a[i]+b[j]) {
                    System.out.println("No");
                    return;
                }
            }
        }
        
        System.out.println("Yes");
        
        
    }       
    
        
}


Measured memory_bytes: 35788
quiz_number = int(input())
time = list(map(int,input().split()))
drink = int(input())
quiz_time = [list(map(int,input().split())) for i in range(drink)]

for i in range(drink):
    sum = 0
    quiz = quiz_time[i][0]
    change_time = quiz_time[i][1]
    for j in range(quiz_number):
        sum += time[j]
    sum = sum - time[quiz-1] + change_time
    print(sum)


Measured memory_bytes: 3064
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val x = readInteger()
    val dp = BooleanArray(x + 1)
    dp[0] = true
    for (i in 0..x) {
        for (j in 100..105) {
            if (i + j <= x && dp[i]) {
                dp[i + j] = true
            }
        }
    }

    val ans = if (dp[x]) "1" else "0"
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 33560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.MessageFormat;
import java.text.ParseException;

public class Main {

	public static final String MASK = "X";

	public static void main(String[] args) throws IOException, ParseException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		MessageFormat format = new MessageFormat("{0}+{1}={2}");

		while ((line = br.readLine()) != null) {

			Object[] o = format.parse(line);
			String strl = (String) o[0];
			String strr = (String) o[1];
			String stra = (String) o[2];

			int startNum = 0;
			if (strl.length() > 1 && strl.indexOf(MASK) == 0)
				startNum = 1;

			if (strr.length() > 1 && strr.indexOf(MASK) == 0)
				startNum = 1;

			if (stra.length() > 1 && stra.indexOf(MASK) == 0)
				startNum = 1;

			strl = new StringBuilder(strl).reverse().toString();
			strr = new StringBuilder(strr).reverse().toString();
			stra = new StringBuilder(stra).reverse().toString();

			String _strl, _strr, _stra;
			int _numl, _numr, _numa;
			boolean isSolved = false;
			for (int i = startNum; i < 10; i++) {
				_strl = strl.replace(MASK, Integer.toString(i));
				_strr = strr.replace(MASK, Integer.toString(i));
				_stra = stra.replace(MASK, Integer.toString(i));

				int carry = 0; // 桁上がり
				for (int j = 0; j < stra.length(); j++) {
					//
					try {
						_numl = Integer
								.parseInt(String.valueOf(_strl.charAt(j)));
					} catch (IndexOutOfBoundsException e) {
						_numl = 0;
					}
					try {
						_numr = Integer
								.parseInt(String.valueOf(_strr.charAt(j)));
					} catch (IndexOutOfBoundsException e) {
						_numr = 0;
					}
					try {
						_numa = Integer
								.parseInt(String.valueOf(_stra.charAt(j)));
					} catch (IndexOutOfBoundsException e) {
						_numa = 0;
					}
					if ((_numl + _numr + carry) % 10 == _numa) {
						if (j == stra.length() - 1) {
							isSolved = true;
							break;
						}
						carry = (_numl + _numr + carry) / 10;
					} else {
						isSolved = false;
						break;
					}
				}
				if (isSolved) {
					System.out.println(i);
					break;
				}
			}
			if (!isSolved)
				System.out.println("NA");
		}
	}
}

Measured memory_bytes: 23012
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int sosu(int n){
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  sort(a, a+n);
  int c, min_ans;

  c = a[n-1];
  for(int k=0; k<c; k++){
    sort(a, a+n);
    if(a[n-2] == 0) return a[n-1];
    else{
      for(int i=0; i<n-1; i++){
        if(a[i] == 0) continue;
        else{
          for(int j=i+1; j<n; j++){
            a[j] = a[j]%a[i];
          }
          break;
        }

      }
      }

    }
}

int main(){
  int n;
  cin >>n;
  int ans;
  ans = sosu(n);
  cout << ans <<endl;
}

Measured memory_bytes: 768
N, M, *A = map(int, open(0).read().split())
ls = [0]*10
ls[1] = 2
ls[2] = 5
ls[3] = 5
ls[4] = 4
ls[5] = 5
ls[6] = 6
ls[7] = 3
ls[8] = 7
ls[9] = 6
A.sort(reverse=True)
cls = {ls[a] for a in A}
cls = sorted(list(cls))
dp = [-float('inf')]*(N+10)
dp[0] = 0
for i in range(1,N+1):
  dp[i] = max(dp[i-c]+1 for c in cls)
ans = 0
M = N
for i in range(dp[N]):
  for a in A:
    c = ls[a]
    if dp[M-c]+1 == dp[M]:
      ans += a*10**(dp[N]-1-i)
      M -= c
      break
print(ans)

Measured memory_bytes: 3404
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N;

int main() {
  cin >> N;
  int a;
  vector<int> A(N);
  int mod4 = 0;
  int mod1 = 0;
  for (int i=0; i<N; i++) {
    cin >> a;
    if (a%4 == 0) {
      mod4++;
    }
    if (a%2 == 1) {
      mod1++;
    }
  }
  int mod2 = N-mod1-mod4;
  
  bool ans = true;
  if (mod1 > mod4+1) {
    ans = false;
  }
  if (mod1 == mod4+1 && mod2 != 0) {
    ans = false;
  }
  cout << (ans ? "Yes" : "No")  << endl;
}


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

int N,x,pre,temp;
long long sum;

int main(void){
    cin>>N>>x;
    cin>>pre;
    if(pre>x){
        sum+=pre-x;
        pre=x;
    }
    for(int i=0;i<N-1;i++){
        cin>>temp;
        if(temp+pre>x){
            sum+=temp-(x-pre);
            temp=x-pre;
        }
        pre=temp;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 -O2 -Wall -Wl,--stack=268435456

#include <bits/stdc++.h>
using namespace std;

typedef vector<int>        vi;
typedef vector< vi >       vvi;
typedef pair<int, int>     pi;
typedef vector< pi >       vpi;

typedef long long          ll;
typedef vector<ll>         vl;
typedef vector< vl >      vvl;

typedef pair<ll, ll>       pl;
typedef vector< pl >       vpl;
typedef vector< vpl >      vvpl;

const int LARGE_INT = 1000000007;
const ll LARGE_LONG = 1L << 60;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = (int)(a); i < (int)(b); i++)


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, a, b, ans = LONG_MAX;
    cin >> n >> a >> b;
    ll x = min(a,b), y = max(a,b);
    if ((y-x)%2 == 0) {
        ans = (y-x)/2;
    } else {
        ans = min(x+(y-x-1)/2, (n-y+1)+(y-x-1)/2);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n,y = [int(i)  for i in input().split()]
for i in range(2001):
  for j in range(2001):
    if 10000*(i)+5000*(j)+1000*max(0,(n-i-j)) == y:
      if n-i-j >= 0:
        print(i,j,n-i-j)
        exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define mod 1000000007

int main(void){
  int N,M;
  int x,y;
  long long xsum = 0;
  long long ysum = 0;
  scanf("%d%d",&N,&M);

  for(long long  i = 1;i <= N;i++){
    scanf("%d",&x);
    xsum += (2*i-N-1)*x;
    xsum %= mod;
  }

  for(long long i = 1;i <= M;i++){
    scanf("%d",&y);
    ysum += (2*i-M-1)*y;
    ysum %= mod;
  }

  printf("%lld\n",(xsum*ysum)%mod);

  return 0;
}

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

int n=1;
double avg, sd;

int main() {
    while (n != 0){
    cin >> n;
    if (n==0) return 0;
    double a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
        avg+=a[i];
    }
    avg/=n;
    for (int i=0; i<n; i++) {
        sd+=(avg-a[i])*(avg-a[i]);
    }
    sd/=n;
    sd=sqrt(sd);
    cout << fixed << setprecision(9) << sd << endl;
    avg = 0; sd = 0;
    }
}


Measured memory_bytes: 3288
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

void solve(){
  int h, w, ans = 0; cin >> h >> w;
  char c[h][w];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> c[i][j];
    }
  }
  vector<vector<pair<int, int> > > hz(h), v(w);
  vector<vector<int> > hz2(h, vector<int>(w, 0)), v2(h, vector<int>(w, 0));
  for(int i = 0; i < h; i++){
    int s = 0;
    for(int j = 0; j < w; j++){
      if(c[i][j] == '#'){
        if(j != s){
          hz[i].push_back(make_pair(s, j - 1));
          for(int k = s; k <= j - 1; k++){
            hz2[i][k] = j - s;
          }
        }
        s = j + 1;
      }
    }
    if(s != w){
      hz[i].push_back(make_pair(s, w - 1));
      for(int k = s; k <= w - 1; k++){
        hz2[i][k] = w - s;
      }
    }
  }
  for(int i = 0; i < w; i++){
    int s = 0;
    for(int j = 0; j < h; j++){
      if(c[j][i] == '#'){
        if(j != s){
          v[i].push_back(make_pair(s, j - 1));
          for(int k = s; k <= j - 1; k++){
            v2[k][i] = j - s;
          }
        }
        s = j + 1;
      }
    }
    if(s != h){
      v[i].push_back(make_pair(s, h - 1));
      for(int k = s; k <= h - 1; k++){
        v2[k][i] = h - s;
      }
    }
  }
  /*for(int i = 0; i < h; i++){
    for(int j = 0; j < hz[i].size(); j++){
      cout << hz[i][j].first << " ~ " << hz[i][j].second << endl;
    }
  }
  for(int i = 0; i < w; i++){
    for(int j = 0; j < v[i].size(); j++){
      cout << v[i][j].first << " ~ " << v[i][j].second << endl;
    }
  }

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << hz2[i][j] << " ";
    }
    cout << endl;
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << v2[i][j] << " ";
    }
    cout << endl;
  }*/
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      ans = max(ans, hz2[i][j] + v2[i][j] - 1);
    }
  }
  cout << ans << endl;

  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 51712
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,i,j,k,ans;
bool f(int k){if (k%2==0) return false;int t=0;
	for (int i=1;i<=k;i++) if (k%i==0) t++;if (t==8) return true; else return false;
}
int main(){
	scanf("%d",&n);for (i=1;i<=n;i++) if (f(i)) ans++;printf("%d\n",ans);return 0;
}

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

using namespace std;


typedef long long ll;
ll val[105],v[105],dp[100025];

int main() {
    int n,V;ll ans = 0;scanf("%d%d",&n,&V);
    for(int i = 1;i<=n;++i) scanf("%lld%lld",&v[i],&val[i]);
    memset(dp,0x3f,sizeof(dp));
    dp[0] = 0;
    for(int i = 1;i<=n;++i)
    {
        for(int j = 100000;j>=val[i];j--)
            dp[j] = min(dp[j],dp[j-val[i]]+v[i]);
    }
    for(int i = 1;i<=1e5;++i) if(dp[i]<=V) ans = max(ans,1ll*i);
    printf("%lld\n",ans);
    return 0;

}

Measured memory_bytes: 1024
N,M = map(int,input().split())
if M == 1:
  print(0)
  exit()

X = sorted(list(map(int,input().split())))
difX = [0] + [X[i+1]-X[i] for i in range(M-1)]
difX.sort(reverse=True)
print(sum(difX)-sum(difX[:N-1]))

Measured memory_bytes: 58408