akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 998244353LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back
#define MAX_N 1000000

long long extgcd(long long a, long long b, long long& x, long long& y) {
	long long d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}
long long mod_inverse(long long a, long long m) {
	long long x, y;
	if(extgcd(a, m, x, y) == 1) return (m + x % m) % m;
	else return -1;
}
vector<long long> fact(MAX_N+1, INF);
long long mod_fact(long long n, long long& e) {
	if(fact[0] == INF) {
		fact[0]=1;
		if(MAX_N != 0) fact[1]=1;
		for(ll i = 2; i <= MAX_N; ++i) {
			fact[i] = (fact[i-1] * i) % MOD;
		}
	}
	e = 0;
	if(n == 0) return 1;
	long long res = mod_fact(n / MOD, e);
	e += n / MOD;
	if((n / MOD) % 2 != 0) return (res * (MOD - fact[n % MOD])) % MOD;
	return (res * fact[n % MOD]) % MOD;
}
// return nCk
long long mod_comb(long long n, long long k) {
	if(n < 0 || k < 0 || n < k) return 0;
	long long e1, e2, e3;
	long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2), a3 = mod_fact(n - k, e3);
	if(e1 > e2 + e3) return 0;
	return (a1 * mod_inverse((a2 * a3) % MOD, MOD)) % MOD;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = (int)s.size();
	vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
	dp[0][0] = 1;
	REP(i, n) REP(j, n + 1) {
		ll b = j, r = 2 * i - j - i;
		if(s[i] == '0') r += 2;
		else if(s[i] == '1') {
			r += 1; b += 1;
		} else {
			b += 2;
		}
		if(b > 0) {
			dp[i + 1][b - 1] += dp[i][j];
			dp[i + 1][b - 1] %= MOD;
		}
		if(r > 0) {
			dp[i + 1][b] += dp[i][j];
			dp[i + 1][b] %= MOD;
		}
	}
	ll ans = 0;
	REP(i, n + 1) {
		ans += dp[n][i] * mod_comb(n, i);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

/* --------------------------------------- */


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

using namespace std;

int u[100001];
int pos = -1;
vector <int> g[100001], ans, ans1;	

void dfs (int v) {
	u[v] = 1;
	ans.push_back (v);
	for (auto to : g[v]) {
		if (u[to]) continue;	
		dfs (to);
		break;
	}
}

void dfs1 (int v) {
	u[v] = 1;
	if (v != pos)
		ans1.push_back (v);
	for (auto to : g[v]) {
		if (u[to]) continue;
		dfs1 (to);
		break;
	}      
}

int main () {
   int n, m;
   cin >> n >> m;
   for (int i = 1;i <= m;i ++) {
   	int x, y;
   	cin >> x >> y;
		g[x].push_back (y);
   	g[y].push_back (x);
   }
   pos = -1;
   for (int i = 1;i <= n;i ++) {
		if (g[i].size () == 1) {
			pos = i;
			break;
		}
   }
	if (pos == -1) pos = 1;    
	dfs (pos);
	dfs1 (pos);
	cout << ans.size () + ans1.size () << endl;
	reverse (ans1.begin (), ans1.end ());
	for (auto to : ans1) cout << to << ' ';
	for (auto to : ans) cout << to << ' ';
	return 0;
}

Measured memory_bytes: 10360
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;
using vi = vector<int>;

int cc(int n) {
    int cnt = 0;
    while (n % 2 == 0) n/=2, ++cnt;
    return cnt;
}

int main()
{
    cin.tie(0), ios::sync_with_stdio(false);
    int N;
    ll a[100010];

    int none = 0;
    int t = 0;
    int f=0;

    cin >> N;

    rep(i, N) {
        cin >> a[i];
        if (cc(a[i]) > 1) {
            ++f;
        } else if (cc(a[i]) == 1) {
            ++t;
        } else {
            ++none;
        }
    }

    if (none <= f + (t ? 0 : 1)) {
        outl("Yes");
    } else {
        outl("No");
    }
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	vector<int> a(4);
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]){
		vector<int> b(4);
		cin>>b[0]>>b[1]>>b[2]>>b[3];
		int h=0,bl=0;
		for(int i=0;i<4;++i){
			if(b[i]==a[i]) ++h;
			else if(find(a.begin(),a.end(),b[i])!=a.end()) ++bl;
		}
		cout << h << " " << bl << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cerrno>
#include <cfenv>
#include <cstring>
#include <bitset>
#include <queue>
#include <iomanip>

using namespace std;
double L;
int amari;
double H, W, D;
double ans = 0;

int main()
{
	cin >> L;
	H = L / 3;
	W = H;
	D = H;
	ans = pow(H, 3);
	cout << setprecision(14) << ans;


}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define MAN 10000
#define GOSEN 5000
#define SEN 1000

using namespace std;

int main() {
	int n, y;
	int i, j, q;

	cin >> n >> y;

	rep(i, 0, n) {
		rep(j, 0, n - i) {
			if (y == MAN * i + GOSEN * j + SEN * (n - i - j)) {
				cout << i << " " << j << " " << n - i - j;
				return 0;
			}
		}
	}

	cout << -1 << " " << -1 << " " << -1;

	return 0;
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b == 0) return 0;
    ll r = a % b;
    if(r == 0) return b;
    else return gcd(b, r);

}

void solve();

int main(void){
    ll A, B;
    cin >> A >> B;
    ll gcd_ab = gcd(A, B);
    ll lim = (ll) sqrtl(gcd_ab) + 1;
    int ans = 1;
    ll idx = 2;
    bool add = false;
    while(idx <= lim){
        if(gcd_ab % idx != 0){
            if(add) ans++;
            idx++;
            add = false;
        }
        else{
            gcd_ab /= idx;
            add = true;
        }
    }
    if(add) ans++;
    if(idx <= gcd_ab) ans++; 
    cout << ans << endl;

    return 0;
}

void solve(){}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int n;
   string s;
   cin >> n;
   vector<int> v(n);
   int ans = 1e9;
   rep(i,n) {
      cin >> v[i];
      int cnt = 0;
      while(v[i]%2 == 0){
         v[i]/=2;
         cnt++;
      }
      v[i] = cnt;
      ans = min(ans,v[i]);
   }
   cout << ans << endl;

   return 0;
}


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

int main() {
	int k, a, b;
	std::cin >> k >> a >> b;

	std::cout << (a % k == 0 || (a / k != b / k) ? "OK" : "NG") << std::endl;
}

Measured memory_bytes: 3624
program main
    integer(8) :: answer = 1
    integer(8) :: m = 1000000007
    integer :: num
    character (52) :: s1, s2
    character :: s(52) = '_'
    integer :: a = 0, start = 1
    logical :: flag = .true.

    read *, num
    read *, s1
    read *, s2
    s1 = trim(s1)
    s2 = trim(s2)

    if(s1(1:1) /= s2(1:1)) then
        answer = 6
        start = 3
        flag = .true.
    else
        answer = 3
        start = 2
        flag = .false.
    end if

    do i=start,num
        if (i+a > num) then
            exit
        end if

        if (flag) then
            if (s1(i + a:i + a) /= s2(i+a:i+a)) then
                a = a + 1
                answer = answer*3
                answer = mod(answer, m)
                flag = .true.
            else
                flag = .false.
            end if
        else
            if (s1(i + a:i + a) /= s2(i+a:i+a)) then
                a = a + 1
                answer = answer*2
                answer = mod(answer, m)
                flag = .true.
            else
                answer = answer*2
                answer = mod(answer, m)
                flag = .false.
            end if
        end if
    end do

    print *, answer
end program main

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
void countingSort(int k, int size,int A[],int B[]);
int findmax(int size, int A[]);
int main(int argc, char** argv) {
    int size;
    scanf("%d",&size);
    int arrayA[size];
    
    for(int i= 1; i<size+1;i++)
    {
        scanf("%d", &arrayA[i]);
    }
    
    int k = findmax(size, arrayA);
    int arrayB[size+1];
    countingSort( k, size,arrayA, arrayB);
    for(int i= 1; i<size+1;i++)
    {
        if(i<size)
            printf("%d ", arrayB[i]);
        if(i==size)
            printf("%d\n",arrayB[i]);
    }
    return (EXIT_SUCCESS);
}
int findmax(int size, int A[])
{
    int max=0;
    for(int i=1; i<size+1; i++)
    {
        if(A[i]>max)
        {
            max = A[i];
        }
    }
    return max;
}
void countingSort(int k, int size,int A[],int B[])
{
    int C[k+1];
    for(int i=0;i<=k;i++)
    {
        C[i] = 0;    
    }
    for(int j=1;j<=size;j++)
    {
        C[A[j]]=C[A[j]]+1;
    }
    for(int i=1;i<=k;i++)
    {
        C[i]=C[i] + C[i-1];
    }
    for(int j=size; j>=1; j--)
    {
        B[C[A[j]]] = A[j];
        C[A[j]] = C[A[j]]-1;
    }    
}


Measured memory_bytes: 17368
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF 1000000000
#define mod 1000000007


int main() {
    int N; cin >> N;
    vector<int> A(N);
    int S = 0;
    for(int &a:A){
        cin >> a;
        S += a;
    }
    
    P mn = P(INF, INF);
    for(int i=0; i<N; i++){
        int x = abs(S - N * A[i]);
        mn = min(mn, P(x, i));
    }
    
    cout << mn.second << endl;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    vector<vector<ll>> g(n);
    rep(i, m){
        ll u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
    }

    ll s, t;
    cin >> s >> t;
    s--, t--;

    // ３の倍数という制約のため，u_0, u_1, u_2のように扱う（_以降があまり）．
    vector<vector<ll>> dist(n, vector<ll>(3, -1));
    dist[s][0] = 0;

    queue<pll> que;
    que.push(make_pair(s, 0));

    while(!que.empty()){
        pll crr = que.front();
        ll v = crr.first;
        ll p = crr.second;
        que.pop();

        ll next_p = (p+1) % 3;

        for(ll vi : g[v]){
            if(dist[vi][next_p] >= 0)continue;

            dist[vi][next_p] = dist[v][p] + 1;
            que.push(make_pair(vi, next_p));
        }
    }

    if(dist[t][0] < 0)cout << -1 << endl;
    else cout << dist[t][0] / 3 << endl;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int A,B,C,ans0,ans1;
  A=0;
  B=0;
  C=0;
  ans0=0;
  ans1=0;
  cin >> A >> B;
  C=B*2;
  ans0=A-C;
 if(ans0>=0){
 cout << ans0 <<endl;
 }
 else if(ans0<0){
 cout << ans1 << endl;
 }
}

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

int main(){
  int N, P;
  cin >> N >> P;
  
  vector<int> A(N);
  int kisu = 0, gusu = 0;
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
    if (A.at(i) % 2 == 0){
      gusu++;
    }
    else{
      kisu++;
    }
  }
  
  vector<vector<int>> pascal(N + 1, vector<int>(N + 1));
  pascal.at(0).at(0) = 1;
  for (int i = 1; i < N + 1; i++){
    pascal.at(i).at(0) = 1;
    pascal.at(i).at(i) = 1;
    for (int j = 1; j < i; j++){
      pascal.at(i).at(j) = pascal.at(i - 1).at(j - 1) + pascal.at(i - 1).at(j);
    }
  }
  
  long long int ans, ans_kisu = 0, ans_gusu;
  
  ans_gusu = pow(2, gusu);
  
  int num = P;
  while (num <= kisu){
    ans_kisu += pascal.at(kisu).at(num);
    num += 2;
  }
  
  ans = ans_kisu * ans_gusu;
  cout << ans << endl;

}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s; cin >> s;
    int n = s.size();
    if(s[n-1] == '?'){
        s[n-1] = 'D';
    }
    for(int i=n-2; i>=0; i--){
        if(s[i] != '?') continue;
        if(i && s[i-1] == 'P') s[i] = 'D';
        else if(s[i+1] == 'D') s[i] = 'P';
        else s[i] = 'D';
    }
    cout << s;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxM = 1e5+7;
const int maxV = 90010;
 
const int MOD = 1e9+7;
 
int T;
const int maxN = 1e5+8;
const ll INF = 1000000000000000010LL;
const int K = 15;
ll a[maxN];
ll b[maxN];
int n;

string s[maxN];

int main() {
	int n;
	scanf("%d",&n);
	map<string,int> mp;
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
		string x;
		cin>>x;
		sort(x.begin(),x.end());
		int cnt = mp[x];
		ans += cnt;
		mp[x]++;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11904
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else if(s == "Rainy") cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
const int MAXN = 1e5;
int main()
{
	int N, i, F = -1;
	int D[MAXN];
	scanf("%d", &N);
	for(i=0; i<N; ++i)
		scanf("%d", D+i);
	std::sort(D, D+N);
	long long sum = 0;
	for(i=0; i+1<N; ++i)
		if((sum+=D[i])<<1 < D[i+1])
			F = i;
	printf("%d\n", N-F-1);
}

Measured memory_bytes: 512
import math

N = int(input())
Prime = []
ans = 0

def func(n):
    while n % 2 == 0:
        n = n // 2
        Prime.append(2)
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        while n % i == 0:
            n = n //i
            Prime.append(i)
    if n > 2:
        Prime.append(n)

func(N)

for i in set(Prime):
    c = i
    while N % c == 0:
        N = N // c
        ans += 1
        c = c * i

print(ans)

Measured memory_bytes: 9232
def c_exam_and_wizard(N, A, B):
    ans = 0
    sum_of_shortage_for_passing_mark = 0
    campensation_for_shortage = []
    for a, b in zip(A, B):
        if a < b:
            ans += 1
            sum_of_shortage_for_passing_mark += b - a
        elif a > b:
            campensation_for_shortage.append(a - b)

    if sum_of_shortage_for_passing_mark == 0:
        return 0  # 準備度を変更するまでもない

    campensation_for_shortage.sort(reverse=True)  # A_i-B_iが大きなiから分けていく
    for pts in campensation_for_shortage:
        if pts >= sum_of_shortage_for_passing_mark:
            ans += 1
            break

        sum_of_shortage_for_passing_mark -= pts
        ans += 1
    else:
        ans = -1
    return ans

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
print(c_exam_and_wizard(N, A, B))

Measured memory_bytes: 18356
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int a[m];
    rep(i, m) cin >> a[i];
    vector<int> use = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    vector<pii> digit(10020, MP(-INF, -INF)); //i本のマッチ棒を使ってできる最大の桁数と最高位の数字
    digit[0] = MP(0, 0);

    rep(i, 10010) {

        rep(j, m) {
            if (digit[i + use[a[j]]].first < digit[i].first + 1
                    || (digit[i + use[a[j]]].first == digit[i].first + 1
                    && digit[i + use[a[j]]].second < a[j])) { //更新
                digit[i + use[a[j]]].first = digit[i].first + 1;
                digit[i + use[a[j]]].second = a[j];
            }
        }
    }

    int match = n;
    while (match > 0) {
        cout << digit[match].second;
        match -= use[digit[match].second];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
while True:
  min_A = min(A)
  A = list(map(lambda x: x % min_A, A))
  A = [x for x in A if x != 0]
  A.append(min_A)
  if len(A)==1:
    break

print(min_A)

Measured memory_bytes: 14224
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>>to(N);
	for (int i = 0; i < M; ++i) {
		int s, t;
		cin >> s >> t;
		s--;
		t--;
		to[s].push_back(t);
	}
	vector<double>dp(N);
	dp[N - 1] = 0;
	for (int i = N - 2; i >= 0; --i) {
		double  now = 0;
		for (auto j : to[i]) {
			now += dp[j];
		}
		now /= to[i].size();
		now += 1;
		dp[i] = now;
	}
	double ans = dp[0];
	
	for (int i = 0;i<N-1;++i) {
		if (1 == to[i].size()) {
			continue;
		}
		int nu = to[i][0];
		for (auto j : to[i]) {
			if (dp[nu] < dp[j]) {
				nu = j;
			}
		}
		vector<double>dp0(N);
		dp0[N - 1] = 0;
		for (int j = N - 2; j >= 0; --j) {
			double  now = 0;
			for (auto k : to[j]) {
				if (j == i && k == nu) {
					continue;
				}
				now += dp0[k];
			}
			int deg = to[j].size();
			if (j == i) {
				deg--;
			}
			now /= deg;
			now += 1;
			dp0[j] = now;
		}
		ans = min(ans, dp0[0]);
	}
	printf("%.10f\n", ans);
	return 0;
}



Measured memory_bytes: 5056
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};
const main=()=>{
  let n=tn()
  let ar=tnn(n)
  let m=ar.reduce((a,b)=>a>b?a:b)
  let m2=0
  let c=0
  for(let i=0;i<n;i++){
    if(m==ar[i])c++
    else m2=max(m2,ar[i])
    if(c==2){
      m2=m
      break
    }
  }
  for(let i=0;i<n;i++){
    to(ar[i]!=m?m:m2)
  }
}
main()


Measured memory_bytes: 56744
//*
#include <bits/stdc++.h>
//*/
/*
#include <iostream>
#include <vector>
#include <string.h>
//*/
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;
const ll LLINF = LLONG_MAX / 10;
typedef pair<int, int> P;
//typedef pair<double, double> P;

int N;
int A[310][310];
bool vis[310][310];

signed main()
{
    cin >> N;

    int sum = 0;
    REP(i,N) {
        REP(j,N) {
            cin >> A[i][j];
            sum += A[i][j];
        }
    }

    sum /= 2;

    memset(vis, 0, sizeof(vis));
    REP(k,N) REP(i,N) REP(j,N) {
        if (vis[i][j] || vis[j][i] || i == j || i == k || j == k) continue;
        if (A[i][k] + A[k][j] < A[i][j]) {
            cout << -1 << endl;
            return 0;
        } else if (A[i][k] + A[k][j] == A[i][j]) {
            vis[i][j] = true;
            sum -= A[i][j];
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(10000007);
// c(5, 2) → 10
// c.p(5, 2) → 20

int main() {
  int X, Y;
  cin >> X >> Y;
  if ((X+Y) % 3 != 0) {
    cout << 0 << '\n';
    return 0;
  }
  int time = (X+Y) / 3;
  int diff = abs(X - Y);
  int xTime = (time+diff) / 2;
  mint ans = c(time, xTime);
  cout << ans << '\n';
  return 0;
}

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

#define FILE_IN freopen("kotlin.in", "r", stdin);
#define FILE_OUT freopen("kotlin.out", "w", stdout);

#define fr(i,n) for(int i=0;i<n;i++)
#define frr(i,a,b) for(int i =a;i<=b;i++)
// for(auto it : g[i].nb)

typedef long long ll;
typedef long double ld;

#define pb push_back

#define all(a) a.begin(),a.end() 

#define fi first
#define se second
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> t3ll;

#define mt make_tuple
#define get(a,id) get<id>(a)

const long double PI = acos(-1.0l);
const ll MOD = 1e9+7;

//LONG_LONG_MAX
//-DBL_MAX

bool debug = 1;
#define printa(a) cout << #a << " = " << (a) << endl
#define prin(a) if(debug) cout << #a << " = " << (a) << endl
#define soprin(a) if(debug) cout << (a)
#define ppal(a)  if(debug) cout << #a << endl
#define prinsep if(debug) cout << "------" << endl
#define cendl if(debug) cout << endl
#define prinpar(p) if(debug) cout << #p << ".fi=" << (p).fi << " " << #p << ".se=" << (p).se << endl
#define print(tup) if(debug) cout << #tup << " = {" << get(tup,0) << ", " << get(tup,1) << ", " << get(tup,2) << "}\n"
#define prinv(v) if(debug){ cout << #v << ":" << endl; for(auto it = (v).begin(); it!=(v).end();it++){ cout << *it << " ";} cout << endl;}

const int N = -1;

int main(){
	//FILE_IN FILE_OUT
	
	int n;
	cin >> n;
	
	int xa = 0,ya=0,ta=0, xn,yn,tn;
	//scanf("%d%d%d", &ta, &xa, &ya);
	
	fr(i,n){
		scanf("%d%d%d", &tn, &xn, &yn);
		int dt = tn-ta;
		int d = abs(xa-xn)+abs(ya-yn);
		
		if(dt<d or (dt-d)%2){
			cout << "No" << endl;
			return 0;
		}	
		
		ta = tn, xa = xn, ya = yn;
	}
	
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
string s,t;

void input() { 
  cin >> s >> t;
}

void solve() {
  ll a=0;
  rep(i,s.size()){
    if(s[i]==t[i]){a++;}
  }
  cout << s.size() - a << endl;
}

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


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000],arr1[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long long x,i,j,k,y,z,w;
    cin>>z;
    i=0;
    for (i=0;i<=1000;i++)
    {
    	arr[i]=i*i*i*i*i;
    	arr1[i]=i;
	}
    for (i=1001;i<=2000;i++)
    {
    	x=-(i-1000);
    	arr[i]=x*x*x*x*x;
    	arr1[i]=x;
	}	
    for (i=0;i<=2000;i++)
    {
    	for (j=0;j<=2000;j++)
    	{
    		if (arr[i]-arr[j]==z)
    		{
    			cout<<arr1[i]<<" "<<arr1[j]<<endl;
    			return 0;
			}
		}
	}
}

Measured memory_bytes: 3688
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>


using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T, typename F>
void chmax( T &a, F b) {
  if (b > a)a = b;
}

template<typename T, typename F>
void chmin( T &a, F b) {
  if (b < a)a = b;
}



ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;
  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }

  return ans;
}



ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}


string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}



const ll N = 1e6 + 5;



int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif


  ll n, b;
  cin >> n ;

  b = 1000;

  vl a(n + 2);

  a[0] = M;
  a[n + 1] = -M;

  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }

  ll dollar = 0, rem = b, ans = rem;

  for (ll i = 1; i <= n; i++) {
    if (a[i] <= a[i - 1] && a[i] <= a[i + 1]) {
      dollar += rem / a[i];
      rem %= a[i];
    }  if (a[i] >= a[i - 1] && a[i] >= a[i + 1]) {
      rem += dollar * a[i];
      dollar = 0;
    }
    //d2(rem, dollar);
    chmax(ans, rem);
  }


  cout << ans;


  //end_routine();



  return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100005;
char s[MAXN];
int n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	int sta=0,score=0;
	for(int i=1;i<=n;++i){
		if(s[i]=='g'){
			if(sta>0)++score,--sta;
			else ++sta;
		}else{
			if(sta>0)--sta;
			else --score,++sta;
		}
	}
	cout<<score<<endl;
	return 0;
}

Measured memory_bytes: 384
MOD = 10**9 + 7
def comb(n, k, MOD):
    if n < k or n < 0 or k < 0:
        return 0
    if k == 0:
        return 1
    iinv = [1] * (k + 1)
    ans = n
    for i in range(2, k + 1):
        iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
        ans *= (n + 1 - i) * iinv[i] % MOD
        ans %= MOD
    return ans
N, K = map(int, input().split())
for i in range(1,K+1):
        print((comb(N-K+1,i,MOD)*comb(K-1,K-i,MOD))%MOD)

Measured memory_bytes: 43248
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
typedef long long ll;

ll n;
ll a;
ll b;

int main() {
	cin >> n >> a >> b;
	ll c = a + b;
	ll k = n / c;
	ll t = n % c;
	ll ans = k * a + min(t, a);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
q=int(input())
num=np.zeros(100001)
for i in a:
  num[i]+=1
sum=a.sum()
for i in range(q):
  b,c=map(int,input().split())
  sum+=(c-b)*num[b]
  num[c]+=num[b]
  num[b]=0
  print(int(sum))

Measured memory_bytes: 38448
import java.util.Scanner;


class Main {
	public static void main(String args[]) {
		
		//スキャナーで整数を３つ読み取る
	    Scanner sc = new Scanner(System.in);
	    String s1 = sc.next();
	    int a = Integer.parseInt(s1);
	    String s2 = sc.next();
	    int b = Integer.parseInt(s2);
	    String s3 = sc.next();
	    int c = Integer.parseInt(s3);
	    int sum = 0;
	    
	    //整数a、b、cが条件（１から１００００）内かつ、a<=bであるか確認
	    if(1 <= a && a <= 10000){
	    	if(1 <= b && b <= 10000){
	    		if(1 <= c && c <= 10000){
	    			if(a <= b){
	    					
	    			    //c約数がaからbまでの中に何個あるか計算
	    				for(int i = a; i <= b; i++){
	    					if(c % i == 0){
	    					    sum++;
	    					}
	    				}
	    				
	    				//約数の数を表示
	    				System.out.println( sum );
	    			}
	    		}
	    	}
	    }
	}
}

Measured memory_bytes: 17308
def modpow(a, n, p):
    if n == 1:
        ans = a % p
    else:
        if n % 2 == 0:
            ans = (modpow(a, n // 2, p) ** 2) % p
        else: # n % 2 == 1
            ans = (a * (modpow(a, n // 2, p) ** 2)) % p

    return ans

p = 10 ** 9 + 7
n, a, b = [int(x) for x in input().split()]

tot = modpow(2, n, p)

Xa, Ya = 1, 1
for i in range(a):
    Xa = (Xa * (n - i)) % p
    Ya = (Ya * (i + 1)) % p
Za = modpow(Ya, p - 2, p)
nCa = (Xa * Za) % p

Xb, Yb = 1, 1
for i in range(b):
    Xb = (Xb * (n - i)) % p
    Yb = (Yb * (i + 1)) % p
Zb = modpow(Yb, p - 2, p)
nCb = (Xb * Zb) % p

ans = (tot - nCa -nCb - 1) % p

print(ans)

Measured memory_bytes: 9248
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        System.Text.StringBuilder ans = new System.Text.StringBuilder();
        while(true) {
			int inputCount = int.Parse(Reader.ReadLine());
            if(inputCount == 0) {
                break;
            }
			decimal[] score = Reader.ReadLine().Split(' ').Select(a => decimal.Parse(a)).ToArray();
            decimal avg = score.Average();
			decimal bunsan = score.Select(a => (a - avg) * (a - avg)).Sum() / inputCount;
            double hens = Math.Sqrt((double)bunsan);
            ans.AppendLine(hens.ToString());
		}
        Console.Write(ans.ToString()); 
    
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"






5
70 80 100 90 20
3
80 80 80
0



";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 9888
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int h1,h2,m1,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int lgt=(60*h2+m2)-(60*h1+m1);
    out(lgt-k);
}

Measured memory_bytes: 3632
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

procedure Sort0000(var AText: string);
var
  sw:char;
  i,j,min:Integer;
begin
  for i := 0 to Length(AText) do begin
    min := i;
    for j := i+1 to Length(AText) do begin
      if AText[j] < AText[min] then
      min := j;
    end;
    sw:=AText[i];
    AText[i]:=AText[min];
    AText[min]:=sw;
  end;
end;

var
  s,t,t2:string;
  i:Integer;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(s);
    Readln(t);
    Sort0000(s);
    Sort0000(t);

    t2:=t;
    for i := 1 to length(t) do
      t2[length(t)-i+1]:=t[i];

    if s<t2 then
      Writeln('Yes')
    else
      Writeln('No');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int H, W;
bool pic[52][52];
int main(int argc, char **argv) {
    cin >> H >> W;

    for(int i = 1; i <= H; ++i)
        for(int j = 1; j <= W; ++j) {
            char ch;
            cin >> ch;
            pic[i][j] = ch == '#';
        }
    
    bool res = true;
    for(int i = 1; i <= H; ++i)
        for(int j = 1; j <= W; ++j) {
            if(pic[i][j])
                if(!pic[i + 1][j] && !pic[i - 1][j] &&
                    !pic[i][j + 1] && !pic[i][j - 1]) {
                        res = false;
                        goto finish;
                    }
        }
finish:;

    cout << (res ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
var s:string; 
    i:integer;
    kt:boolean;
begin
  readln(s);
  for i:=1 to length(s) do 
    begin
      if (s[i] = 'D') or (s[i] = 'U') or (s[i] = 'R') or (s[i] = 'L') then
        begin
          if (i mod 2 = 0) and (s[i] <> 'L') and (s[i] <> 'D') and (s[i] <> 'U') then 
            begin
              write('No');
              exit;
            end
          else if (i mod 2 <> 0) and (s[i] <> 'R') and (s[i] <> 'D') and (s[i] <> 'U') then 
            begin
              write('No');
              exit;
            end;
        end
      else 
        begin
          write('No');
          exit;
        end; 
    end; 
  write('Yes')
end.

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

using namespace std;


template <class Abel>
class UnionFind{
    vector<int> par_, weight_;
public:
    UnionFind(size_t n){
        par_.assign(n, -1);
        weight_.assign(n, 0);
    }

    int root(int x){
        if (par_[x] < 0) {
            return x;
        }else{
            int res = root(par_[x]);
            weight_[x] += weight_[par_[x]];
            return par_[x] = res;
        }
    }

    int weight(int x){
        root(x);
        return weight_[x];
    }

    int weight(int x, int y){
        return weight(y) - weight(x);
    }

    int size(int x){
        return -par_[root(x)];
    }

    bool IsSame(int x, int y){
        return root(x) == root(y);
    }

    void Merge(int x, int y, Abel w){
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y)
            return;
        if (size(x) < size(y)) {
            w = -w;
            swap(x, y);
        }
        par_[x] += par_[y];
        par_[y] = x;
        weight_[y] = w;
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind<int> uf(n);
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        uf.Merge(--a, --b, 0);
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
        ans = max(ans, uf.size(i));

    cout << ans << endl;
}

Measured memory_bytes: 4832
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll c[10][10];

signed main()
{
	ll N;
	cin >> N;
	REP(i, 9){
		REP(j, 9){

		}
	}
	FOR(i, 1, N){
		ll dig=pow(10, (ll)(log10(i)));
		c[(int)(i/dig)][i%10]++;
	}
	ll ans=0;
	REP(i, 10){
		REP(j, 10){
			ans+=c[i][j]*c[j][i];
		}
	}
	cout << ans << endl;
}


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

int main() {
    ll X, Y, A, B, C, ans=0;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);

    for(int i=0; i<A; i++)
	cin >> p[i];
    for(int i=0; i<B; i++)
	cin >> q[i];
    for(int i=0; i<C; i++)
	cin >> r[i];

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    for(int i=0; i<X; i++)
	ans += p[i];    
    for(int i=0; i<Y; i++)
	ans += q[i];
    int x=X-1, y=Y-1, z=0;
    ll tmp;
    
    while(true){
	if(p[x]<q[y]){
	    if(x<0){
		tmp = q[y];
		y--;
	    }
	    else{
		tmp = p[x];
		x--;
	    } 
	}
	else{
	    if(y<0){
		tmp = p[x];
		x--;
	    }
	    else{
		tmp = q[y];
		y--;
	    }
	}
	if(tmp<r[z] && z<C){
	    ans -= tmp;
	    ans += r[z];
	    z++;
	}
	else{
	    break;
	}
	
    }
    cout << ans << endl;
} 




Measured memory_bytes: 2688
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int people = sc.nextInt();
    int point = sc.nextInt();
    int q_cnt = sc.nextInt();
    int[] correcter = new int[q_cnt];
    int[] points = new int[people];
    
    for(int i = 0; i < q_cnt; i++){
       correcter[i] = sc.nextInt();
    }
    
    for(int j = 0; j < q_cnt; j++){      
        points[correcter[j] - 1]++;
    }
    
    for(int i = 0; i < people; i++){
      if(points[i] + point - q_cnt >= 1){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 61712
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	AB = input[0].split(" ");

	var A = AB[0],
		B = AB[1],
		S = input[1];

	console.log(new RegExp('^\\d{' + A + '}-\\d{' + B + '}$').test(S) ? 'Yes' : 'No');
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

char grade(int m, int f, int r) {
	if(m == -1 || f == -1) return 'F';
	if(m + f >= 80) return 'A';
	if(m + f >= 65) return 'B';
	if(m + f >= 50) return 'C';
	if(m + f < 30) return 'F';
	if(r >= 50) return 'C';
	return 'D';
}

int main()
{
	while(true) {
		int m, f, r;
		cin >> m >> f >> r;
		if ((m & f & r) == -1) {
			break;
		}
		cout << grade(m,f,r) << endl;
	}
}



Measured memory_bytes: 3088
#include<iostream>
#include<math.h>
using namespace std;
int solve(int E){
    int ans=E;
    for (int z=0;z*z*z<=E;++z){
        for (int y=0;y*y<=E;++y){
            int x=E-y*y-z*z*z;
            if(x+y+z<ans&&x>=0)
                ans=x+y+z;
             }
    }
    return ans;
}
int main(){
    int E;
    while (cin>>E&&E>0){
        cout<<solve(E)<<endl;
    }
}

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int N, A;
        cin >> N >> A;
        if (N % 500 <= A)
        {
                cout << "Yes" << endl;
        }
        else
        {
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll A[100010];
ll cnt[100010];
ll S;
ll Q;

int main()
{
  std::cin >> N;

  rep( i, N )
    std::cin >> A[i], S += A[i], ++cnt[A[i]];

  std::cin >> Q;

  rep( q, Q ) {
    ll B, C;
    std::cin >> B >> C;

    S += -cnt[B]*B+cnt[B]*C;
    cnt[C] += cnt[B];
    cnt[B] = 0;

    std::cout << S << std::endl;
  }

  return 0;
}

Measured memory_bytes: 5176
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int X;
	cin >> X;

	if (X >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};




int main(){
  int a[3],k;
  rep(i,3)cin>>a[i];
  cin>>k;
  sort(a,a+3);
  rep(i,k)a[2]*=2;
  int ans=0;
  rep(i,3)ans+=a[i];
  cout<<ans<<endl;

  return 0;
  }

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

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    int k;
    cin>>k;
    deque<int>d;

    for(int i = 1;i<=9;i++) d.push_back(i);
    int cnt = 0;
    int t;
    while(true){
        t = d.front();
        d.pop_front();
        int t1 = t%10;
        if(t1 != 0){
            d.pb(10*t + t1 - 1);
            //if(cnt==k) break;
        }
        d.pb(10*t + t1);
        cnt++;
        if(cnt==k) break;
        if(t1 != 9){
            d.pb(10*t+t1+1);
            //if(cnt==k) break;
        }
    }
    cout<<t;
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

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


Measured memory_bytes: 4776