akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=2000+19;
const int p=924844033;

int vis[N],cnt[N],fac[N],f[N];
int n,k,res;

void dp(){
	static int g[N][N][2],h[N][N],c;
	g[0][0][0]=1;
	For(i,1,n+1){
		For(j,0,i+1){
			g[i][j][0]=(g[i-1][j][0]+g[i-1][j][1])%p;
			if (j) g[i][j][1]=g[i-1][j-1][0];
		}
	}
	h[0][0]=1;
	For(i,1,n+1)
		For(j,1,cnt[i]+1){
			c++;
			For(k,0,n+1){
				for (int x=0;x<=i&&x<=k;x++){
					h[c][k]=(h[c][k]+1ll*h[c-1][k-x]*(g[i][x][0]+g[i][x][1]))%p;
				}
			}
		}
	For(i,0,n+1) f[i]=h[c][i];
}

int main(){
	n=IN(),k=IN();
	For(i,1,n+1)
		if (!vis[i]){
			int tmp=0;
			for (int x=i-k;x>=1;x-=k) tmp++;
			for (int x=i+k,y=0;x<=n;x+=k,y^=1){
				tmp++;
				if (y) vis[x]=1;
			}
			cnt[tmp]++;
		}
	dp();
	fac[0]=1;
	For(i,1,N) fac[i]=1ll*fac[i-1]*i%p;
	For(i,0,n+1){
		int tmp=1ll*f[i]*fac[n-i]%p;
		if (i&1) res=(res-tmp+p)%p;else res=(res+tmp)%p;
	}
	printf("%d\n",res);
}

Measured memory_bytes: 35072
from fractions import gcd

def lcm(x, y):
    return x * y // gcd(x, y)

a, b, c, d = list(map(int, input().split()))
print((b-a+1)-(b//c - (a-1)//c)-(b//d - (a-1)//d)+(b//lcm(c, d) - (a-1)//lcm(c, d)))

Measured memory_bytes: 5688
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    int N;
    cin >> N;

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

    double mul = 1.0;
    for(int i = 0; i < N; i++){
        mul *= v[i];
    }

    double div = 0;
    for(int i = 0; i < N; i++){
        div += (mul / v[i]);
    }

    cout << setprecision(10) << mul / div << endl;

}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    string s;cin >> s;
    if (s.find("AC") != string::npos) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> Vi;
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 dp[394][394];

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

    int n,m,dum; cin>>n; int w[n],v[n];
    for (int i = 0; i < n; i++)cin>>w[i]>>dum>>v[i];
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= 393; j++){
            if(j<w[i])chmax(dp[i+1][j],dp[i][j]);
            else chmax(dp[i+1][j],max(dp[i][j],max(dp[i][j-w[i]]+v[i],dp[i+1][j-w[i]]+v[i])));
        }
    }
    cin>>m; Vi ans;
    for (int i = 0; i < m; i++){
        int q; cin>>q;
        if(!dp[n][q]){cout<<-1<<'\n'; return 0;}
        else ans.push_back(dp[n][q]);
    }
    for (int i = 0; i < m; i++)cout<<ans[i]<<'\n';
}


Measured memory_bytes: 3728
#include <stdio.h>

#define LEN 3

int main(void) {

    int i[3];

    scanf("%d %d %d", &i[0], &i[1], &i[2]);

    int j, k;
    for (j = 0; j < LEN; ++j) {
        for (k = 0; k < LEN - j - 1; ++k) {
            if (i[k] > i[k + 1]) {
                int tmp = i[k];
                i[k] = i[k + 1];
                i[k + 1] = tmp;
            }
        }
    }

    for (j = 0; j < LEN - 1; ++j) {
        printf("%d ", i[j]);
    }
    printf("%d\n", i[LEN - 1]);

    return 0;
}

Measured memory_bytes: 596
n = int(input())
a,b = map(int,input().split())
p = list(map(int,input().split()))
count1 = 0
count2 = 0
count3 = 0

for i in range(n):
    if p[i] <= a:
        count1 +=1
    elif a+1 <= p[i] <= b:
        count2 +=1
    elif b+1 <= p[i]:
        count3 +=1
print(min(count1,count2,count3))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<stdio.h>
using namespace std;
int main() {
	int i, j, k,l, b, f, r, v, n, ans[4][3][10] = {};
	cin >> n;
	for (l = 0; l < n; l++) {
		cin >> b >> f >> r >> v;
		ans[b-1][f-1][r-1] += v;
	}
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				cout << " " << ans[i][j][k];

			}
			cout << endl;
		}
		if (i != 3) {
			cout << "####################" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
using LL = long long; using ll = LL;
using PLL = pair<LL, LL>; using pll = PLL;
using PII = pair<int, int>; using pii = PII;
const int INF = 1e9; const LL LINF = 1e18;
#define SZ(a) (int)a.size()
#define FOR(i,s,t) for(int i= s; i<t;i++)
#define ALL(a) a.begin(),a.end()
using VL = vector<LL>; using VLL = vector<VL>;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) { init(size); }
	void init(int size) { data.clear(); data.resize(size, -1); }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

void solve() {
	int N, M;
	while (cin >> N >> M, N) {
		UnionFind uf(N);
		FOR(i, 0, M) {
			int a, b;
			cin >> a >> b;
			a--, b--;
			uf.unite(a, b);
		}
		VL used(N, 0);
		int isgroup = 0;
		int cnt = 0;
		FOR(i, 0, N) {
			int root = uf.root(i);
			if (used[root])continue;
			cnt++;
			if (uf.size(root) != 1)isgroup=1;
			used[root] = 1;
		}
		LL nene = 1;
		const LL mod = 1e9 + 7;

		FOR(i, 0, cnt) {
			nene *= 2;
			nene %= mod;
		}
		nene += isgroup;
		nene %= mod;
		cout << nene << endl;
	}

}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	solve();
	return 0;
}


Measured memory_bytes: 4288
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	string s;
	cin >> s;
	cin >> s;
	cout << "A" << s[0] << "C" << endl;

}

Measured memory_bytes: 256
(defn count-flip
  "start-with could be \\0 or \\1
   pattern a seq of characters"
  [start-with pattern]
  (loop [expecting start-with
         [c & r] pattern
         flip-count 0]
    (if (not c)
      flip-count
      (recur (case expecting \0 \1 \1 \0)
             r
             (if (= expecting c) flip-count (inc flip-count))))))
(defn abc124-C [pattern]
  (min (count-flip \0 pattern)
       (count-flip \1 pattern)))
(defn main-abc124-C []
  (let [pattern (read-line)]
    (println (abc124-C pattern))))
(main-abc124-C)

Measured memory_bytes: 78456
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

#define rad(x) (x*atan(1.0)*4.0/180.0)
int n;

void koch( double x1, double y1, double x4, double y4, int d ){
	if( d == n ){
		printf("%.5lf %.5lf\n", x4, y4);
		return;
	}
	double x2 = (x4-x1) / 3.0 + x1;
	double y2 = (y4-y1) / 3.0 + y1;
	double x3 = (x4-x1) * 2.0 / 3.0 + x1;
	double y3 = (y4-y1) * 2.0 / 3.0 + y1;
	double x = (x3-x2)*cos(rad(60.0)) - (y3-y2)*sin(rad(60.0)) + x2;
	double y = (x3-x2)*sin(rad(60.0)) + (y3-y2)*cos(rad(60.0)) + y2;
	koch( x1, y1, x2, y2, d+1 );
	koch( x2, y2, x,  y,  d+1 );
	koch( x,  y,  x3, y3, d+1 );
	koch( x3, y3, x4, y4, d+1 );
}

int main(){
	cin >> n;
	cout << "0.00000 0.00000" << endl;
	koch(0.0,0.0,100.0,0.0,0);
	return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>

int main(){

	int a,s,m,h;
	
	scanf("%d",&a);
	
	h=a/3600;
	m=a%3600/60;
	s=a%3600%60;
	
	printf("%d:%d:%d\n",h,m,s);

	return 0;
}

Measured memory_bytes: 592
import math


def is_prime(n):
    """return True if n is a prime number

    >>> is_prime(1)
    False
    >>> is_prime(7)
    True
    >>> is_prime(81)
    False
    """
    if n == 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False

    for i in range(3, int(math.sqrt(n))+1, 2):
        if n % i == 0:
            return False

    return True


def run():
    count = int(input())
    nums = []
    for i in range(count):
        nums.append(int(input()))

    print('{}'.format(len(list(filter(is_prime, nums)))))


if __name__ == '__main__':
    run()



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

using namespace std;

int main() {
	int a, b;	cin >> a >> b;
	double ave = (a + b) / 2.0;

	if (ave > (a + b) / 2) {
		cout << (a + b) / 2 + 1 << endl;
	}
	else {
		cout << (a + b) / 2 << endl;
	}

	return 0;
}

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

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

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll N;
    cin >> N;
    set<ll> exist;
    map<ll, ll> counter;
    for (ll i = 2, end = sqrt(N); i < end; ++i) {
        while (N % i == 0) {
            N /= i;
            if (exist.find(i) == exist.end()) {
                exist.emplace(i);
                counter.emplace(i, 1);
            } else {
                ++counter[i];
            }
        }
    }

    if (N != 1) counter.emplace(N, 1);

    ll ans = 0;
    for (auto x : counter) {
        ll cnt = x.second;
        for (int i = 2;; ++i) {
            if (i * (i + 1) / 2 > cnt) {
                ans += i - 1;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  int n, quantum;
  string name;
  int time;
  queue<pair<string, int> > Q;

  cin >> n >> quantum;
  for (int i = 0; i < n; i++)
  {
    cin >> name >> time;
    Q.push(make_pair(name, time));
  }

  pair<string, int> u;
  int elaps = 0;
  int duration;

  while (!Q.empty())
  {
    u = Q.front();
    Q.pop();
    duration = min(u.second, quantum);
    u.second -= duration;
    elaps += duration;
    if (u.second > 0)
    {
      Q.push(u);
    }
    else
    {
      cout << u.first << " " << elaps << endl;
    }
  }

  return 0;
}


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

int main(){
  int n;
  cin>>n;
  int k=n%10;
  if(k==3){
  cout<<"bon"<<endl;
  }
  else if(k==0||k==1||k==6||k==8){
  cout<<"pon"<<endl;
  }
  else{
  cout<<"hon"<<endl;
  }
}

Measured memory_bytes: 3640
parseInt(x) = parse(Int64,x)
function main()
n = parse(Int64, readline())
  a = map(parseInt, split(readline()))
gl = zeros(Int64 , n)
gr = zeros(Int64 , n)
for i in 1:n-1
    gl[i+1] = gcd(gl[i],a[i])
    gr[i+1] = gcd(gr[i],a[n - i + 1])
end
g = zeros(Int,n)
for i in 1 : n
    g[i] = gcd(gl[i],gr[end - i + 1])
end
  println(Int64(maximum(g)))
end
main()



Measured memory_bytes: 134128
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAX_N = 100005;

int n;
ll a[MAX_N][3];
ll dp[MAX_N][3];

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i][0] >> a[i][1] >> a[i][2];

	for (int i = 0; i < n; i++)
		for (int j = 0; j < 3; j++)
			for (int k = 0; k < 3; k++)
				if (j != k)
					dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]);
				
	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}

Measured memory_bytes: 4992
def fuct(n:int)->int:
    if n<=1:
        return 1
    else:
        return n * fuct(n-1)

def main():
    n,a,b = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v, reverse=True)
    print(sum(v[:a])/a)
    res = 0

    if v[0]==v[a-1]:
        vn = v.count(v[0])
        for r in range(a,b+1):
            res += fuct(vn)//(fuct(vn-r) * fuct(r))
    else:
        vn = v.count(v[a-1])
        r = v[:a].count(v[a-1])
        res += fuct(vn)//(fuct(vn-r) * fuct(r))

    print(res)

if __name__ == '__main__':
    main()

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

int main() {
	string S;
	cin >> S;
	int cnt = 0;
	long times = 0;
	for (int i=0; i<S.size(); i++) {
		if (S[i]=='W') {
			times += i-cnt;
			cnt++;
		}
	}
	cout << times << endl;

	return 0;
}

Measured memory_bytes: 640
//2019年12月8日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

namespace {
    // printElms(&a[0], a[n]);　みたいな感じで使う。
    void printElems(const int* begin, const int* end)
    {
        for (const int* p = begin; p != end; ++p) {
            std::cout << *p << ' ';
        }
        std::cout << std::endl;
    }
}

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari rep1(i,n-1)rep(j,i)
#define souatari1 for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 10000000000000000;


int a[1000005];
int dp[1000005][2];

int main(){
	string s;
	cin >> s;
	int n = s.size();
	rep1(i,n){
		a[i] = int(s[i-1] - '0');
	}
	dp[n+1][0] = 10;
	repr1(i,n){
		dp[i][0] = min(dp[i+1][0]+(9-a[i]),dp[i+1][1]+(10-a[i]));
		dp[i][1] = min(dp[i+1][0]+a[i]+1,dp[i+1][1]+a[i]);
	}
	prints(min(dp[1][0]+1,dp[1][1]));


    return 0;
}



Measured memory_bytes: 13060
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9,
        2, 4, 6, 8, 10, 12, 14, 16, 18,
        3, 6, 9, 12, 15, 18, 21, 24, 27,
        4, 8, 12, 16, 20, 24, 28, 32, 36,
        5, 10, 15, 20, 25, 30, 35, 40, 45,
        6, 12, 18, 24, 30, 36, 42, 48, 54,
        7, 14, 21, 28, 35, 42, 49, 56, 63,
        8, 16, 24, 32, 40, 48, 56, 64, 72,
        9, 18, 27, 36, 45, 54, 63, 72, 81]

if int(input()) in nums:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, int>;
const ll MOD = 1000000007;

// 0-origin BIT
template <typename T>
class BIT{
public:
    vector<T> data;
    int n;
    BIT(){}
    BIT(int n_){
        n = n_;
        data.assign(n, T(0));
    }
    // v[a] += w
    void add(int a, T w){
        for (int x = a; x < n; x |= x + 1) data[x] = max(data[x], w);
    }
    // sum of v[i] for i in [0, a)
    T bmax(int a){
        T ret = 0;
        for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
            ret = max(ret, data[x]);
        }
        return ret;
    }
};

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

    vector<int> x(n);
    ll total = 0;
    for(int i=0;i<n;i++){
        cin >> x[i];
        total += x[i];
    }

    BIT<ll> bit(n+1);
    for(int i=0;i<n;i++){
        ll c = bit.bmax(x[i]) + x[i];
        bit.add(x[i], c);
    }
    cout << total - bit.bmax(n+1) << endl;

    return 0;
}

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

def calcScore(t, s, c):
    scores = [0]*26
    lasts = [0]*26
    for i in range(1, len(t)):
        scores[t[i]] += s[i][t[i]]
        dif = i - lasts[t[i]]
        scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2
        lasts[t[i]] = i
    for i in range(26):
        dif = len(t) - lasts[i]
        scores[i] -= c[i] * dif * (dif-1) // 2
    return scores

def update(socre, day, t, q):
    p = t[day]
    t[day] = q
    scores[p] = 0
    scores[q] = 0
    lasts = [0]*26
    for i in range(1, len(t)):
        if t[i] == p or t[i] == q:
            scores[t[i]] += s[i][t[i]]
            dif = i - lasts[t[i]]
            scores[t[i]] -= c[t[i]] * dif * (dif-1) // 2
            lasts[t[i]] = i
    for i in [p, q]:
        dif = len(t) - lasts[i]
        scores[i] -= c[i] * dif * (dif-1) // 2
    return scores

D = int(input())
c = list(map(int, input().split()))
s = [[0]*26 for _ in range(D+1)]
for i in range(1, D+1):
    s[i] = list(map(int, input().split()))
t = [-1]*(D+1)
for i in range(1, D+1):
    t[i] = int(input()) - 1
M = int(input())

scores = calcScore(t, s, c)

ans = [None]*M
for i in range(M):
    d, q = map(int, input().split())
    t[d] = q-1
    ans[i] = sum(calcScore(t, s, c))

for v in ans:
    print(v)

Measured memory_bytes: 73044
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{

    static long M=(long)1e9+7;
    public static void main(String[] args) {
        FastReader fs=new FastReader();
        long h=fs.nextLong();
        long count=0;
        long i=1;
        while(h!=1){
            h/=2;
            count+=i;
            i<<=1;
        }
        count+=i;
        System.out.println(count);
    }
    
    public static long min(long a, long mod){
        return pow(a, mod-2,mod);
    }
    public static long mul(long a,long b,long mod){
        long res=0;
        while(b!=0){
            if ((b & 1) == 1){ res = (res + a) % mod;}
            a = (a + a) % mod;
            b >>= 1;
        }
        return res;
    }
    
    public static long pow(long a, long n, long mod){
        long res=1;
        while(n != 0){
            if ((n & 1) == 1) res = mul(res, a, mod)%mod;
            a = mul(a , a, mod)%mod;
            n >>= 1;
        }
        return res;
    }
    
    public static long gcd(long a, long b){
        if(a == 0) return b;
        return b == 0 ? a: gcd(b, a % b);
    }

    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int W, a, b; cin >> W >> a >> b;

    if(a+W < b){
        cout << b-a-W << endl;
    }
    else if(b+W < a){
        cout << a-b-W << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <vector>
using namespace std;

int main() {
	int a;
	int L;

	while(cin >> a >> L, a | L) {
		vector<int> v;
		int ans_i = 0, ans_j = 0;
		for(bool flag = true; flag;) {
			stringstream sstr, sstr1, sstr2;
			string str, rev;

			sstr << a;
			sstr >> str;

			v.push_back(a);
			ans_i++;

			sort(str.begin(), str.end());
			rev = str;
			reverse(rev.begin(), rev.end());

			int M, m;
			sstr1 << str; sstr2 << rev;
			sstr1 >> m; sstr2 >> M;

			for(int i = 0; i < L - rev.size(); i++) {
				M *= 10;
			}

			a = M - m;

			for(int i = 0; i < v.size(); i++) {
				if(v[i] == a) {
					ans_j = i;
					flag = false;
					break;
				}
			}
		}

		cout << ans_j << " " << v[ans_j] << " " << ans_i - ans_j << endl;
	}
}

Measured memory_bytes: 1252
n = input().split()
a=0
b=0
l="x"
m="x"
for i in range(len(n)):
    if n.count(n[i])>a:
        a=n.count(n[i])
        l=n[i]
for i in range(len(n)):
    if len(n[i])>b:
        b=len(n[i])
        m=n[i]
print(l,m)


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

auto GCD(auto a,auto b){ //ユークリッドの互助法で最大公約数
    if (a%b == 0){
        return b;
    }
    else {
        return GCD(b,a%b);
    }
}

auto LCM(auto a,auto b){ //GCDを使って最小公倍数を求める
    auto g = GCD(a,b);
    return (a/g)*b;  // (a*b)/GCD(a,b) なんだけど、こうしないとa,b=INFとかだとはみ出しちゃう
}

int main(){
    LL A,B;cin >> A >> B;
    LL ans = 0;
    ans = LCM(A,B);
    cout << ans << endl;
}


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

int main() {
	// your code goes here
    int d, g;
    cin >> d >> g;
    vector <int> p(d), c(d);
    for(int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
    }
    vector <int> vec(d);
    for(int i = 0; i < d; i++) vec[i] = i;
    int ans = INT_MAX;
    do{
       int g1 = g;
       int ans1 = 0;
       for(int i = 0; i < d; i++){
           int i1 = vec[i];
           if(g1 > (100*(i1+1)*(p[i1]))){
              g1 -= (100*(i1+1)*(p[i1]));
              g1 -= c[i1];
              ans1 += p[i1];
           }
           else{
              ans1 += (g1/(100*(i1+1)));
              if((g1%(100*(i1+1)))) ans1++;
              break;
           }
           if(g1 <= 0) break;
       }
       ans = min(ans1, ans);
         
    }while(next_permutation(vec.begin(), vec.end()));
    cout << ans;
	return 0;
}


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

#define INF 1LL << 60
#define pb push_back
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)

int N;
int C[25], V[25];

int main() {
    cin >> N;
    REP(i, N) cin >> V[i];
    REP(i, N) cin >> C[i];

    int x = 0, y = 0;
    REP(i, N) {
        double cp = (double)V[i]/C[i];
        if (cp > 1.0) {
            x += V[i];
            y += C[i];
        }
    }

    cout << x - y << endl;

    return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll X;

struct exam {
	ll b, lo, hi;
	ll score(ll k) {
		if (k < b) return lo*k;
		else return lo*b + hi*(k-b);
	}
	bool operator<(exam e) { return score(X) > e.score(X); }
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;
	cin >> n >> X;
	
	vector<exam> e(n);
	FOR(i,0,n) {
		ll b, lo, hi;
		cin >> b >> lo >> hi;
		e[i] = {b,lo,hi};
	}
	sort(all(e));

	ll score = 0;
	FOR(i,0,n) score += e[i].score(e[i].b);
	
	ll kmin = -1, kmax = n*X;
	while (kmax-kmin > 1) {
		ll k = (kmin+kmax)/2;
		
		ll sum = 0;
		FOR(i,0,k/X) sum += e[i].score(X);
		
		ll best = -oo;
		FOR(i,0,k/X) {
			ll cur = sum - e[i].score(X) + e[i].score(k%X) + e[k/X].score(X);
			best = max(best,cur);
		}
		FOR(i,k/X,n) {
			ll cur = sum + e[i].score(k%X);
			best = max(best, cur);
		}
		
		if (best >= score) kmax = k;
		else kmin = k;	
	}

	cout << kmax << endl;


}



Measured memory_bytes: 2560
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());

            string str = Console.ReadLine();
            if(str[0]=='7' || str[1] == '7' || str[2] == '7')
            {
                Console.WriteLine("Yes");
            }
            else { Console.WriteLine("No"); }



            //ここまで
        }
    }

}


Measured memory_bytes: 25884
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Set<Integer> set = new HashSet<>();
		int n = sc.nextInt();
		int k = sc.nextInt();
		for (int i = 0; i < k; i++) {
			int d = sc.nextInt();
			for (int j = 0; j < d; j++) {
				set.add(sc.nextInt());
			}
		}
		sc.close();
		System.out.println(n - set.size());
	}
}


Measured memory_bytes: 37676
import string
n = int(input())
a = input()
b = input()
c = input()
cnt = 0
for x, y, z in zip(a, b, c):
    wl = [0]*26
    wl[string.ascii_lowercase.index(x)] += 1
    wl[string.ascii_lowercase.index(y)] += 1
    wl[string.ascii_lowercase.index(z)] += 1
    cnt += 3 - max(wl)
print(cnt)

Measured memory_bytes: 3768
N, K  = map(int,input().split())
L = list(map(int,input().split()))
dp = [10**10 for _ in range(N+2)]
dp[0] = L[0]
for i in range(N-1):
    for k in range(1,1+K):
        try:
            dp[i+k] = min(dp[i]+abs(L[i]-L[i+k]),dp[i+k])
        except:
            pass
print(dp[N-1]-dp[0])



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

int main() {
	int i,j,k,m,n,a,b,c,t,co[100][100],ti[100][100];
	while(cin >> n >> m) {
		if (n+m==0) break;
		for (i=0;i<m;i++) for (j=0;j<m;j++) { co[i][j]=ti[i][j]=999999;}
		for (i=0;i<n;i++) {
			cin >> a >> b >> c >> t; a--; b--;
            co[a][b]=co[b][a]=c; ti[a][b]=ti[b][a]=t;
		}
		for (k=0;k<m;k++) for (i=0;i<m;i++) for (j=0;j<m;j++) {
			co[i][j]=min(co[i][j],co[i][k]+co[k][j]);
			ti[i][j]=min(ti[i][j],ti[i][k]+ti[k][j]);
		}
		cin >> k;
		for (i=0;i<k;i++) {
			cin >> a >> b >> c; a--; b--;
			if (c==0) cout << co[a][b] << endl; else cout << ti[a][b] << endl;
		}
	}
	return 0;
} 

Measured memory_bytes: 1236
N, X = map(int, input().split())
L = list(map(int, input().split()))
d = 0
ans = 0
for i in range(N):
    if d > X:
        print(ans)
        exit()
    ans += 1
    d += int(L[i])
if d <= X:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

vector<ll> pickdiv(ll n){
    vector<ll> res;
    for(ll i=1; i*i <=n;i++){
        if(n%i)continue;
        res.emplace_back(i);
        ll q = n/i;
        if(q != i){
            res.emplace_back(q);
        }
    }
    return res;
}

ll ndigit(ll N){
    ll cnt = 0;
    while(N > 0){
        N /= 10;
        cnt++;
    }
    return cnt;
}

int main(){
    ll N;
    string S;
    cin >> N;
    auto v = pickdiv(N);
    ll ans = 1e18;
    rep(i,v.size()){
        ll t = v[i];
        cmin(ans, max(ndigit(t), ndigit(N/t)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  int x, y, s;
  while (cin >> x >> y >> s, x) {
    int res = 0;
    for (int i = 1; i < s; ++i) for (int j = 1; j < s; ++j) {
      if (i * (100 + x) / 100 + j * (100 + x) / 100 == s) {
        res = max(res, i * (100 + y) / 100 + j * (100 + y) / 100);
      }
    }
    cout << res << '\n';
  }
}


Measured memory_bytes: 3084
fun main(args: Array<String>)
{
    val (l, r)  =readNInts()

    if (r - l + 1 >= 2019)
    {
        println(0)
    }
    else
    {
        var ans = 10000L
        for (i in l until r) {
            for (k in i+1..r) {
                val rem = (i * k) % 2019
                ans = if (ans > rem) rem else ans
            }
        }

        println(ans)
    }
}


// Read an integer
// Usage: val a = readInt()
private fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
private fun readNInts() = readLine()!!.split(" ").map(String::toLong)

// Read a string
// Usage: val a = readString()
private fun readString() = readLine()!!


Measured memory_bytes: 37860
n,m = map(int,input().split())

flag = dict()
for i in range(m):
  q, s = input().split()
  if q not in flag:
    flag[q] = [0,0]
    if s == "AC":
      flag[q][0] += 1
    else:
      flag[q][1] += 1
  else:
    if flag[q][0] != 1:
      if s == "AC":
        flag[q][0] += 1
      else:
        flag[q][1] += 1
      
ans = [0,0]
for v in flag.values():
  if v[0]:
    ans[0] += 1
    ans[1] += v[1]

print(ans[0],ans[1])


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n+2);
    rep(i,n) cin>>a[i+1];
    int sum=0;
    rep(i,n+1) sum+=abs(a[i]-a[i+1]);
    FOR(i,1,n){
        cout<<sum-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,n;
  cin>>n>>k;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p.at(i);
  }
  sort(p.begin(), p.end());
  int result=0;
  for(int i=0;i<k;i++){
    result+=p.at(i);
  }
  cout<<result;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

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

  if (A == B) cout << "Draw" << endl;
  else if(A == 1) cout << "Alice" << endl;
  else if(B == 1) cout << "Bob" << endl;
  else if(A > B) cout << "Alice" << endl;
  else cout << "Bob" << endl;

  return 0;
}


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

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    
    vector<int> d;
    for(int i = 1; i <= min(a,b); i++){
        if(a%i == 0 && b%i == 0) d.push_back(i);
    }
    sort(d.rbegin(), d.rend());
    cout << d[k-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


int main(){
    ll x, a, b; cin >> x >> a >> b;
    if(abs(x-a) > abs(x-b)){
        cout << 'B' << endl;
    }
    else cout << 'A' << endl;
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  ll res = 1LL << 58;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      res = min(res, i + N / i - 2);
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <ctime>
#include <string>
#include <cstring>
#include <random>
#define mp make_pair
#define pb push_back
#define NAME ""
#define y1 y1_423
#define list lista

using namespace std;

typedef long long ll;
typedef long double ld;

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

template<typename T>
ostream& operator << (ostream& cout, const set<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T>
ostream& operator << (ostream& cout, const multiset<T> &a) {
	if ((int)a.size() == 0) {
		return (cout << "{}");
	}
	auto it = a.begin();
	cout << "{" << *it;
	++it;
	for (; it != a.end(); ++it) {
		cout << "; " << *it;
	}
	return (cout << "}");
}

template<typename T1, typename T2>
ostream& operator << (ostream& cout, const pair<T1, T2> &a) {
	return cout << "(" << a.first << "; " << a.second << ")";
}

random_device gen;
mt19937 rnd(gen());

const int nmax = 2000 * 1000;
const int inf = 2000 * 1000 * 1000;
const ll infl = 1000ll * 1000ll * 1000ll * 1000ll * 1000ll * 1000ll;
const int mod = 1000 * 1000 * 1000 + 7;
const ld pi = acos(-1.0);

ll n, a[nmax];

int main() {
	//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	//freopen(NAME".in", "r", stdin);freopen(NAME".out", "w", stdout);
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
	}
	sort(a, a + n);
	for (int i = 1; i < n; i++) {
		a[i] += a[i - 1];
	}
	int ans = 1;
	for (int i = n - 1; i >= 0; i--) {
		if (a[i + 1] - a[i] <= a[i] * 2) {
			ans = n - i;
		} else {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1e9 +7;
signed main(){
    int k,p,q;;
    cin >>k;
    p=k/50;q=k%50;
    cout <<50<<endl;
    for(int i=0;i<q;i++){
        cout <<50-i+p<<' ';
    }
    for(int i=q;i<50;i++){
        cout <<49-i+p<<' ';
    }




    return 0;
}

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

int main()
{
    int n, tmp, sum=0, prev=1000000;
    cin >> n;
    
    for(int i=0; i<n-1; i++){
        cin >> tmp;
        sum += min(prev, tmp);
        prev = tmp;
    }
    sum += prev;
    
    cout << sum;
    return 0;
}


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

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())
#define endl '\n'

#ifdef SANJU
    #define localsys 1
#else
    #define localsys 0
#endif

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;



void sanjeev(int kkkk)
{
    string a,b;
    cin>>a>>b;
    vector<vector<int>>dp(a.length()+1,vector<int>(b.length()+1,0));

    // string ans="";
 
    for(int i=1;i<=a.length();i++)
    {
        for(int j=1;j<=b.length();j++)
        {
            if(a[i-1]==b[j-1])
            {
                // ans+=a[i-1];
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                int p=dp[i-1][j];
                int q=dp[i][j-1];
                if(p>q)dp[i][j]=p;
                else dp[i][j]=q;
            }
        }
    }

    // for(int i=0;i<dp.size();i++)
    // {
    //     cout<<endl;
    //     for(int j=0;j<dp[i].size();j++)cout<<dp[i][j]<<" ";
    // }

string ans="";

int i=a.length();
    int j=b.length();
    while(i>0 && j>0)
    {
        if(dp[i][j]==dp[i][j-1])j-=1;
        else if(dp[i][j]==dp[i-1][j])i-=1;
        else
        {
            ans=a[i-1]+ans;
            i-=1;
            j-=1;
        }
    }

    cout<<ans;
    // cout<<dp[a.length()][b.length()];
}

int main()
{
    if(!localsys) ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { sanjeev(i+1); }
    if(localsys) system("pause");
}


Measured memory_bytes: 35584
import math
def c(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
A = list(map(int, input().split()))
for i in range(1, N):
    A[i] += A[i - 1]
A.append(0)
A.sort()
i = 1
ans = 0
cnt = 1
while True:
    if i == len(A):
        if cnt >= 2:
            ans += c(cnt, 2)
        break
    if A[i] != A[i - 1]:
        if cnt >= 2:
            ans += c(cnt, 2)
        cnt = 1
    else:
        cnt += 1
    i += 1
print(ans)


Measured memory_bytes: 27268
H, W = map(int, input().split())
Ss = [[j for j in input()] for i in range(H)]

mapping = {'.':0, '#':1}

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if ans == 'No':
          continue
        if Ss[i][j] == '#':
            counter = 0
            
            if j>0:
                counter += mapping[Ss[i][j-1]]
            if i>0:
                counter += mapping[Ss[i-1][j]]
            if i<H-1:
                counter += mapping[Ss[i+1][j]]
            if j<W-1:
                counter += mapping[Ss[i][j+1]]
      
            if counter == 0:
                ans = 'No'
            
print(ans)

Measured memory_bytes: 40176
#include <cstdio>

int main(){
  int n;
  int a[100000], f[100000] = {};

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

  int res = 0;
  for(int i = 0; i < n; i++){
    if(f[i] == 0 && i == a[a[i] - 1] - 1){
      res++;
      f[i] = 1; f[a[i] - 1] = 1;
    }
  }
  printf("%d\n", res);

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;

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

  int64_t N, M;
  cin >> N >> M;
  int64_t A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  priority_queue<int64_t> que;
  for(int i=0;i<N;i++){
    que.push(A[i]);
  }
  for(int i=0;i<M;i++){
    int64_t a = que.top() / 2;
    que.pop();
    que.push(a);
  }
  int64_t ans1 = 0;
  for(int i=0;i<N;i++){
    ans1 += que.top();
    que.pop();
  }
  cout << ans1 << endl;
}


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

int main(){
  int n,m,k,ans;
  bool h[1000001];
  bool f;

  for(int i=0;i<=1000000;i++)h[i] = false;
  h[1] = true;

  k = 2;
  f = true;
  while(f){
    f = false;
    for(int i=1;i<=1000000/k;i++){
      if(h[i]){
	if(!h[k*i]){
	  f = true;
	  h[k*i] = true;
	}
      }
    }
    k *= 2;
  }

  k = 3;
  f = true;
  while(f){
    f = false;
    for(int i=1;i<=1000000/k;i++){
      if(h[i]){
	if(!h[k*i]){
	  f = true;
	  h[k*i] = true;
	}
      }
    }
    k *= 3;
  }

  k = 5;
  f = true;
  while(f){
    f = false;
    for(int i=1;i<=1000000/k;i++){
      if(h[i]){
	if(!h[k*i]){
	  f = true;
	  h[k*i] = true;
	}
      }
    }
    k *= 5;
  }

  while(1){
    cin >> n;
    if(!n)break;
    cin >> m;

    ans = 0;
    for(int i=n;i<=m;i++){
      if(h[i])ans++;
    }
    cout << ans << endl;
  }
}

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

int main() {

	int n = 0, k = 0;
	cin >> n >> k;
	int ans = 0;
	int res = 0;
	if(n % k == 0){
		ans = 0;
	}else{
		ans = 1;
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

int pos;
string str;

int number() {

  // sentou digit
  int ret = 0;
  
  while(isdigit(str[pos])) {
    ret *= 10;
    ret += str[pos]-'0';
    pos ++;
  }
  // saigo not digit
  return ret;
}

vector<int> rec() {
  
  vector<int> ret;
  pos ++;
  
  if(isdigit(str[pos])) {
    ret.push_back(number()/2+1);
    return ret;
  }
  
  if(str[pos] == '[') {
    while(str[pos] == '[') {
      vector<int> r = rec();
      assert(str[pos] == ']');
      pos ++;
      assert(r.size() == 1);
      ret.push_back(r[0]);
    }
    
    sort(ret.begin(), ret.end());
    
    int sum = 0;
    for(int i=0; i<(int)ret.size()/2 + 1; i++) {
      sum += ret[i];
    }
    
    return vector<int>(1, sum);
  }
  pos ++;
  return ret;
}

int main() {
  
  int Tc; cin >> Tc;
  
  for(int Tcnt=1; Tcnt<=Tc; Tcnt++) {
    cin >> str;
    pos = -1;
    vector<int> ret = rec();
    assert(ret.size() == 1);
    cout << ret[0] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1276
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {
	static class Node {
		int pos;
		int year;
		int prefecture;
		public Node (int pos, int year, int prefecture) {
			this.pos = pos;
			this.year = year;
			this.prefecture = prefecture;
		}
	}
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int M = Integer.parseInt(st.nextToken());
		Node[] cities = new Node[M];
		for (int i = 0; i < M; i++) {
			st = new StringTokenizer(br.readLine());
			int p = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			cities[i] = new Node(i, y, p);
		}
		Arrays.sort(cities, new Comparator<Node>() {
			public int compare(Node node1, Node node2) {
				return node1.year - node2.year;
			}
		});
		int[] count = new int[N+1];
		for (int i = 0; i < M; i++) {
			cities[i].year = ++count[cities[i].prefecture];
		}
		Arrays.sort(cities, new Comparator<Node>() {
			public int compare(Node node1, Node node2) {
				return node1.pos - node2.pos;
			}
		});
		for (int i = 0; i < M; i++) {
			System.out.println(String.format("%06d", cities[i].prefecture) + String.format("%06d", cities[i].year));
		}
	}
}


Measured memory_bytes: 111140