akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<vector>
using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    vector<int> l, r;
    for(int i = 0; i < n; i++){
        if(s[i] == 'L') l.push_back(i);
        else            r.push_back(i);
    }
    vector<int> v(n, 0);
    for(int i = 0; i < n; i++){
        if(s[i] == 'L'){
            int j = r[lower_bound(r.begin(),r.end(),i)-r.begin()-1];
            if((i-j)%2) v[j+1]++;
            else        v[j]++;
        }else{
            int j = l[lower_bound(l.begin(),l.end(),i)-l.begin()];
            if((j-i)%2) v[j-1]++;
            else        v[j]++;
        }
    }
    for(int i = 0; i < n; i++)  cout << v[i] << " \n"[i+1==n];
    return 0;
}

Measured memory_bytes: 1532
#include <stdio.h>

int main(){

    int angka1;
    int angka2;

    scanf("%d",&angka1);
    scanf("%d",&angka2);

    if (angka1>8 || angka2>8){
        printf(":(");
    }else{
        printf("Yay!");
        }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int s,w;cin>>s>>w;
	if(w>=s) cout<<"unsafe"<<"\n";
	else cout<<"safe"<<"\n";
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

template<class T>
long long lis(T& arr)
{
        const long long _inf = 1LL << 60;
        long long arrsize = static_cast<long long>(arr.size());
        std::vector<long long> dp(arrsize, _inf);
        for (long long i = 0; i < arrsize; ++i) {
                 *std::lower_bound(all(dp), arr[i]) = arr[i];               
        }
        return static_cast<long long>(dp.size()) - count(all(dp), _inf);
}

int main()
{
        ll n;
        cin >> n;
        vll a(n);
        rep(i, 0, n) cin >> a[i];
        ll ans = lis(a);
        cout << ans << endl;
}


Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
typedef long long ll;

int main() {
  ll A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
  if(abs(A-B)<=(V-W)*T){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int dp[100010];
int pre[100010];

int main() {
  int n,m;
  while(cin>>n>>m) {
    string s;
    cin >> s;

    memset(dp,0x3f,sizeof(dp));
    dp[0] = 0;
    pre[0] = -1;
    map<int, deque<int>> min_mp;
    min_mp[0].push_back(0);
    for (int i=1; i<=n; i++) {
      if (s[i] != '1' && min_mp.size() != 0)
      {
        dp[i] = min_mp.begin()->first;
        pre[i] = *min_mp.begin()->second.begin();
      }
      min_mp[dp[i]].push_back(i);
      // cout << tpl(i,dp[i],pre[i]) << endl;
      if (i-m >= 0) {
        min_mp[dp[i-m]].pop_front();
        if (min_mp[dp[i-m]].size() == 0) {
          min_mp.erase(dp[i-m]);
        }
      }

    }
    if (dp[n] > 10000000) {
      cout << -1 << endl;
      continue;
    }

    vector<int> ans;
    int p = n;
    while(1) {
      if (pre[p] == -1) break;
      ans.push_back(p - pre[p]);
      p = pre[p];
    }

    reverse(ALL(ans));
    int as = ans.size();
    REP(i,as)
      printf("%d%c",ans[i], i!=as-1?' ':'\n');
  }
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;

    if (n%1000==0){
        cout << 0 << endl;
    }else{
        n %= 1000;
        cout << 1000 - n << endl;
    }
}

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

#define endl '\n'
#define sz(x) ((int)(x.size()))

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

	long long x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	if(x - ((__int128) (k)) * d < 0) {
		k -= x / d;
		if(k&1) cout << d - x%d << endl;
		else cout << x%d << endl;
	}
	else {
		cout << x - k * d << endl;
	}

	return 0;
}

Measured memory_bytes: 3560
N, M = map(int, input().split())
X = list(map(int, input().split()))
X = sorted(X)
diff = []

# 地点間の距離をdiffに記憶
for i in range(M - 1):
    diff.append(abs(X[i] - X[i + 1]))

# N個の区間でM個の地点を覆う
# すると、N-1個の覆われていない区間ができる
# これを最大にすると覆う区間を最小にできる

diff = sorted(diff, reverse=True)
#print(diff)
# diffの中で大きい順にN-1個の総和をとる
#数直線の長さ - 覆わなくて良い範囲の総和
ans = (X[-1] - X[0]) - sum(diff[:N - 1])
# ans = sum(diff[:N-1]) でもOK、どうしても覆う必要がある区間の和
print(ans)


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

int main() {	

	ll l, r; cin >> l >> r;
	ll ans = 9223372036854775807LL;
	if (2019LL <= r - l) {
		ans = 0;
	}
	else {
		for (ll i = l; i < r; i++) {
			for (ll j = i + 1;  j <= r; j++) {
				ll tmp = (i * j) % 2019LL;
				ans = min(ans, tmp);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    else:
        ans += a[i]
        nxt = min(a[i+1], b[i]-a[i])
        ans += nxt
        a[i+1] -= nxt
print(ans)

Measured memory_bytes: 19116
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5,M=2e5+5;
int n,m,U[M],V[M];
vector<int>e[N];
int mp[N][N];
int vis1[N],vis2[N];
void dfs1(int u,int k)
{
    vis1[u]=k;
    for(int i=0;i<e[u].size();i++)
    {
        int v=e[u][i];if(vis1[v]) continue;
        dfs1(v,k);
    }
}
void dfs2(int u,int k)
{
    vis2[u]=k;
    for(int i=0;i<e[u].size();i++)
    {
        int v=e[u][i];if(vis2[v]) continue;
        dfs2(v,k);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&U[i],&V[i]);
        e[U[i]].push_back(V[i]);
    }
    for(int i=1;i<=n;i++)
    {
        memset(vis1,0,sizeof(vis1));
        memset(vis2,0,sizeof(vis2));
        vis1[i]=vis2[i]=666;
        int up=e[i].size();
        for(int j=0;j<up;j++)
            if(!vis1[e[i][j]])
            dfs1(e[i][j],j+1);
        for(int j=up-1;j>=0;j--)
            if(!vis2[e[i][j]])
            dfs2(e[i][j],j+1);
        for(int j=1;j<=n;j++)
            if(vis1[j]&&j!=i)
        {
            if(vis1[j]==vis2[j]) mp[i][j]=1;
            else mp[i][j]=2;
        }
    }
    for(int i=1;i<=m;i++)
    {
        if(mp[U[i]][V[i]]&&mp[V[i]][U[i]])
        {
            if(mp[U[i]][V[i]]==2) printf("same\n");
            else printf("diff\n");
        }
        else
        {
            if(mp[U[i]][V[i]]==1) printf("same\n");
            else printf("diff\n");
        }
    }
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
// #define mp make_pair
#define nt _int128 
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define inf 0x3f3f3f3f
 
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 5;
const ll mxi = 2e3 + 5;

int main()
{
    fast_as_levi;
    string s1,s2;
    cin>>s1>>s2;
    ll i,j;
    ll n = s1.length();
    ll m = s2.length();
    ll dp[n+1][m+1];
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j] = 0;
            }
            else if(s1[i-1]==s2[j-1])
            {
                dp[i][j] = dp[i-1][j-1] + 1; 
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string ans = "";
    i=n,j=m;
    while(i>0 && j>0)
    {
        if(s1[i-1] == s2[j-1])
        {
            ans += s1[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}

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

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n);
    rep(i,n)rep(j,d) {
        int x_;
        cin >> x_;
        x[i].push_back(x_);
    }
    vector<double> distance;
    for (int i = 0; i < (n-1); i++) {
        for (int j = i+1; j < n; j++) {
            double sum = 0;
            rep(k,d) {
                sum += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
            }
            distance.push_back(sqrt(sum));
        }
    }
    int ct = 0;
    rep(i,distance.size()) {
        if (distance[i] == (int)distance[i]) ct++;
    }
    cout << ct << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define D(a) cout<<#a<<": ";for(auto i:a)cout<<i<<' ';cout<<endl;
using namespace std;
int main()
{
    int N; cin >> N;
    vector<int> A(N+1);
    for (int i = 0; i < N; i++) cin >> A[i];
    long long ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        if (A[i] > i) goto FAIL;
        if (A[i] < A[i+1] - 1) goto FAIL;
        if (A[i] != A[i+1] - 1) {
            ans += A[i];
        }
    }
    cout << ans << endl;
    return 0;
FAIL:
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=j;i<=k;++i)
#define Forr(i,j,k) for (int i=j;i>=k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;
 
template<typename T>bool chkmax(T& a,T b) {return a<b?a=b,1:0;}
template<typename T>bool chkmin(T& a,T b) {return a>b?a=b,1:0;}
 
ll a,b,c,x,y,ans=1e15;
 
inline void file() {
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
}
 
int main() {
//	file();
	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y);
	ll z=min(x,y); c*=2;
	chkmin(ans,a*x+b*y);
	chkmin(ans,a*(x-z)+b*(y-z)+c*z);
	chkmin(ans,c*max(x,y));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
int n,m,c[100050];
int main() {
	scanf("%d%d",&n,&m);
	int i,l,r;
	while(n--) {
		scanf("%d%d",&l,&r);l--;
		int lim=l,lst=0;
		for(i=1;i<=lim;i=lst+1) {
			lst=min(l/(l/i),r/(r/i));
			if(r/i-1>=l/i)c[i]++,c[lst+1]--;
		}
		c[lst+1]++,c[r+1]--;
	}for(i=1;i<=m;i++)c[i]+=c[i-1],printf("%d\n",c[i]);
}


Measured memory_bytes: 1280
/******************************************
 * Author : sinon.su96@gmail.com
 * Or : ahafid96@gmail.com
 * Username : SINON
 * Date : April 2020
 * Civil and Structural engineering student
 * at Ecole des Ponts ParisTech
 * ***************************************/

//Import usefull library :
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
using namespace std;

//usefull abreviation
#define fi first
#define se second
#define pb push_back
#define sqr(x) (x)*(x)
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef vector<int> vi;


int main()
{
  int n, m, ai, sum,selected;
  cin >> n >> m;
  vector<int> a;
  string y;
  sum = 0;
  selected = 0;
  for (int i=0; i<n; i++){
    cin >> ai;
    a.push_back(ai);
    sum += ai;
  }
  for (auto i:a){
    if (4*m*i>=sum) selected +=1;
  }
  if (selected >= m) y = "Yes";
  else y = "No";
  cout << y <<"\n";
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val buildingNum = 4
    val floorNum = 3
    val roomNum = 10
    var information = Array(buildingNum) {Array(floorNum) {Array(roomNum) {0}}}

    repeat(readLine()!!.toInt()) {
        val (b, f, r, n) = readLine()!!.split(" ").map(String::toInt)
        information[b - 1][f - 1][r - 1] += n
    }

    information.forEachIndexed {
        building, infoBuilding -> infoBuilding.forEachIndexed {
            _, infoFloor -> infoFloor.forEach { print(" $it") }
            println()
        }
        if (building != buildingNum - 1) {println("#".repeat(20))}
    }
}



Measured memory_bytes: 31520
#include<cstdio>
#include<memory.h>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
int main() {
	ll N, K, a, b;
	cin >> N >> K;
	ll ans = 0;
	for (b = K + 1; b <= N; b++) {
		ll x;
		a = (b - K)*(N / b);
		x = N%b; 
		if (x > 0) {
			x -= K;
			if (K) x++;
			if (x > 0) a += x;
		}
		ans += a;
	}
	cout << ans;
}

Measured memory_bytes: 768
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	int a, b;
	cin >> a >> b;
	cout << a / b << " " << a % b << " ";
	printf("%.15f\n", (double)a / b);
	return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,ans,sum=0,a[5010];
    cin>>n>>k;
    ans=n;
    for(i=0; i<n; i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    for(i=n-1; i>=0; i--)
    {
        if(sum+a[i]<k) sum+=a[i];
        else ans=i;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

void chmin(ll &x, ll y) {
  x = min(x, y);
}

int main() { initio();
  int N; cin >> N;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  vector<vector<int>> G(N);
  rep(i, N-1) {
    int u, v; cin >> u >> v; u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  constexpr ll inf = 1e18;
  vector<vector<ll>> dp0(N); // all positive
  vector<vector<ll>> dp1(N); // some negative
  auto merge = [&](vector<ll> a0, vector<ll> a1, vector<ll> b0, vector<ll> b1) -> pair<vector<ll>, vector<ll>> {
    const int n = a0.size();
    const int m = b0.size();
    vector<ll> c0(n + m - 1, inf);
    vector<ll> c1(n + m - 1, inf);
    repe(i, 1, n) repe(j, 1, m) {
      if (b0[j] != inf) {
        if (a0[i] != inf) chmin(c0[i + j - 1], a0[i] + b0[j]);
        if (a1[i] != inf) chmin(c1[i + j - 1], a1[i] + b0[j]);
        if (a0[i] != inf) chmin(c0[i + j], a0[i]);
        if (a1[i] != inf) chmin(c1[i + j], a1[i]);
      }
      if (b1[j] != inf) {
        if (a0[i] != inf) chmin(c1[i + j - 1], a0[i] + b1[j]);
        if (a1[i] != inf) chmin(c1[i + j - 1], a1[i] + b1[j]);
        if (b1[j] < 0) {
          if (a0[i] != inf) chmin(c0[i + j], a0[i]);
          if (a1[i] != inf) chmin(c1[i + j], a1[i]);
        }
      }
    }
    return {c0, c1};
  };
  auto dfs = [&](auto dfs, int u, int p) -> void {
    if (A[u] > 0) {
      dp0[u] = {inf, A[u]};
      dp1[u] = {inf, inf};
    } else {
      dp1[u] = {inf, A[u]};
      dp0[u] = {inf, inf};
    }
    for (int v : G[u]) if (v != p) {
      dfs(dfs, v, u);
      auto p = merge(dp0[u], dp1[u], dp0[v], dp1[v]);
      tie(dp0[u], dp1[u]) = p;
    }
  };
  dfs(dfs, 0, -1);
  repe(i, 1, N + 1) {
    if (dp0[0][i] != inf || dp1[0][i] < 0) {
      cout << i - 1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 165536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define SZ(x) (long long)x.size()
#define endl '\n'
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007

int32_t main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("output.txt", "w", stderr);
#endif
  int n, q, b, c;
  cin >> n;
  vector<int> v(n);
  REP(i, 0, n) cin >> v[i];
  unordered_map<int, int> mp;
  REP(i, 0, n) mp[v[i]]++;
  int ss = 0;
  REP(i, 0, n) ss += v[i];
  cin >> q;
  while (q--) {
    cin >> b >> c;
    int freq = mp[b];
    ss -= mp[b] * b;
    ss += freq * c;
    mp[c] = mp[c] + freq;
    mp[b] = 0;
    cout << ss << endl;
  }
  return 0;
}

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

int main()
{
    long long  ans=0,i,j,n,t,b,c;
    string s,s1,s2;
    cin>>t;
    int ara[t];
    for(i=0;i<t;i++)
    {
        cin>>ara[i];

    }
    int ret=ara[0];
     for(i=1;i<t;i++)
    {
       if(ara[i]>=ret)
        ret=ara[i];
       else
       {
           ans+=(ret-ara[i]);

       }
    }
    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
int n,num[200010];


int main()
{
	int i,j;
	int mul2=0,mul4=0,germ=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
		if(num[i] % 2 == 0)
		{
			mul2++;
			if(num[i] % 4 == 0)
			{
				mul4++;
				mul2--;
			}
		}
		else if(num[i] % 2 == 1)
		{
			germ++;
		}
	}
//	printf("germ=%d		mul2=%d		mul4=%d\n",germ,mul2,mul4);
	
	if(germ==0) printf("Yes\n");
	else if(germ>0)
	{
		if(mul2==0)
		{
			if(germ<=mul4+1)
			{
				printf("Yes\n");
			}
			else printf("No\n");
		}
		else if(mul2>0)
		{
			if(germ<=mul4) printf("Yes\n");
			else printf("No\n");
		}
	}
	else printf("No\n");
	
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  long long N;
  cin >> N;
  string res = "";
  while (N)
  {
    N--;
    res += (char)('a' + (N % 26));
    N /= 26;
  }
  reverse(res.begin(), res.end());
  cout << res << endl;
}

Measured memory_bytes: 3632
import Data.List
import Data.Ord
main = do
  t <- readLn :: IO Int
  xs <- fmap (map read . words) getLine :: IO [Int]
  print $ solve3 xs
solve3 = maximum . map length . group . sort . foldl (\acc x -> (x - 1) : x : (x + 1) : acc) []


Measured memory_bytes: 63868
import math


class Solution:

    def solve(self, N: int, K: int, S):

        num_change = 0
        hapiness = 0

        prev = ""

        for s in S:
            if prev == s:
                hapiness += 1
            elif prev != "":
                num_change += 1

            prev = s

        return hapiness + min(num_change, 2 * K)


if __name__ == '__main__':

    # standard input
    N, K = map(int, input().split())
    S = input()

    # solve
    solution = Solution()
    print(solution.solve(N, K, S))


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
void InsertionSort(int N, vector<int>& A) {
	for (int i = 1; i < N; i++) {
		if (A.at(i - 1) > A.at(i)) {
			int tmp = A.at(i);
			int j = i - 1;
			while (j >= 0) {
				if (A.at(j) <= tmp) break;
				A.at(j + 1) = A.at(j);
				j--;
			}
			A.at(j) = tmp;
		}
		for (int k = 0; k < N; k++) {
			cout << A.at(k);
			if (k != N - 1) cout << ' ';
		}
		cout << endl;
	}
}
long long GCD(long long A, long long B) {
	if (B == 0) return A;
	else return GCD(B, A % B);
}
bool Prime_Num(long long N) {
	for (long long i = 2; i <= sqrt(N); i++) {
		if (N % i == 0) {
			return false;
		}
	}
	return true;
}
int main() {
	long long N;
	cin >> N;
	vector<long long>A(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	long long MIN = A.at(0), MAX = -999999999999;
	for (long long i = 1; i < N; i++) {
		MAX = max(MAX, A.at(i) - MIN);
		MIN = min(MIN, A.at(i));
	}
	cout << MAX << endl;
}


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

int main(void){
    int A,B,M;
    cin >> A >> B >> M;
    int a[A],b[B];
    rep(i,A){
        cin >> a[i];
    }
    rep(i,B){
        cin >> b[i];
    }
    int x[M],y[M],c[M],d[M];
    rep(i,M){
        cin >> x[i] >> y[i] >> c[i];
        d[i] = a[x[i]-1] + b[y[i]-1] - c[i];
    }
    int small = 10000000;
    rep(i,M){
        if(small>d[i]) small = d[i];
    }
    int as = 100000,bs = 1000000;
    rep(i,A){
        if(as > a[i]) as = a[i];
    }
    rep(i,B){
        if(bs > b[i]) bs = b[i];
    }
    if(as+bs < small) small = as+bs;
    cout << small << endl;
    return 0;
}

Measured memory_bytes: 2560
H = []
W = []
for _ in range(300):
  _h, _w = map(int, input().split())
  if _h == 0 and _w == 0:
    break
  else:
    H.append(_h)
    W.append(_w)

for i in range(len(H)):
    for j in range(H[i]):
        dash = ""
        for k in range(W[i]):
            if j%2 == 0 and k%2 ==0 or j%2 == 1 and k%2 ==1:
                dash = dash + '#'
            else:
                dash = dash + "."
        print(dash)
    print('')



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

int main()
{
    float n, sum=0.0;
    cin >> n;
    vector<float> v(n);
    for (int i = 0; i < n;i++){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    sum = (v.at(0) + v.at(1)) / 2;
    for (int i = 2; i < n;i++){
        sum=(sum+v.at(i))/2;
     //   cout << sum << endl;
    }
    cout << sum << endl;
}

Measured memory_bytes: 384
class UnionFindTree:
    def __init__(self, V):
        self.parent = [i for i in range(V)]

    def root(self, x):
        if self.parent[x] == x:
            return x
        self.parent[x] = self.root(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        self.parent[rx] = ry
        return

    def find(self, x, y):
        return self.root(x) == self.root(y)

class Edge:
    def __init__(self, s, t, w):
        self.s = s
        self.t = t
        self.w = w

    def __lt__(self, right):
        return self.w < right.w

def Kruscal(edges, V):
    utf = UnionFindTree(V)
    res = 0
    edges.sort()
    for e in edges:
        s = e.s
        t = e.t
        if not utf.find(e.s, e.t):
            res += e.w
            utf.unite(e.s, e.t)
    return res

def main():
    [V, E] = map(int, (raw_input()).split(" "))
    edges = [None]*E
    for i in range(E):
        [s,t,w] = map(int, (raw_input()).split(" "))
        edges[i] = Edge(s,t,w)

    print Kruscal(edges, V)

if __name__ == "__main__":
    main()

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define pb push_back
#define all(a) (a).begin(),(a).end()

using namespace std;

using triple = tuple<int, int, int>;

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> S(N), T(N), X(N), D(Q);
    REP(i, N) cin >> S[i] >> T[i] >> X[i];
    REP(i, Q) cin >> D[i];

    vector<triple> v;
    REP(i, N) {
        v.pb(triple(S[i] - X[i], 0, i));
        v.pb(triple(T[i] - X[i], 1, i));
    }
    REP(i, Q) {
        v.pb(triple(D[i], 2, i));
    }
    sort(all(v));
    multiset<int> roadworks;
    vector<int> result(Q, -1);
    for (triple t: v) {
        if (get<1>(t) == 0) {
            roadworks.insert(X[get<2>(t)]);
        } else if (get<1>(t) == 1) {
            roadworks.erase(roadworks.find(X[get<2>(t)]));
        } else if (get<1>(t) == 2) {
            if (!roadworks.empty()) {
                result[get<2>(t)] = *roadworks.lower_bound(0);
            }
        }
    }
    REP(i, Q) cout << result[i] << endl;
    return 0;
}

Measured memory_bytes: 21736
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)              cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)              cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)          cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

string s;

int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    ll n=s.size();
    ll x,y;
    for(ll i=0; i<n; i++){
        if(s[i]=='A'){
            x=i+1;
            break;
        }
    }
    for(ll i=n-1; i>=0; i--){
        if(s[i]=='Z'){
            y=i+1;
            break;
        }
    }
    cout << y-x+1;
    return 0;
}
/* The judge is never wrong! Your code is buggy 
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    vector<ll> sum(2000, 0);
    for(int i = 1; i <= 2000; i++) {
        for(int j = 0; j < n; j++) {
            if(a[j] < i) {
                sum[i - 1]++;
            }
        }
    }
    
    vector<ll> sum2(n, 0);
    for(int i = 0; i < n; i++) {
        for(int j = i + 1; j < n; j++) {
            if(a[i] > a[j]) {
                sum2[i]++;
            }
        }
    }
    
    ll ans = 0;
    ll num = k;
    num *= k - 1;
    num /= 2;
    num %= MOD;
    for(int i = 0; i < n; i++) {
        ans += (sum[a[i] - 1] * num) % MOD;
        ans %= MOD;
        ans += (k * sum2[i]) % MOD;
        ans %= MOD;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}

int main(){
    //std::stack<int> stack;
    long a,b,v,w,t;
    cin >> a >> v >> b >> w >> t;
    string ans = "NO";
    if(v <= w){
        cout << ans << endl;
        return 0;
    }else{
        long dis = abs(a-b);
        long sec = v - w;
        
        if(sec * t >= dis){
            ans = "YES";
        }
    }
    
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {

int N; cin >> N ;

if(N==7||N==5||N==3) cout << "YES" << endl;

else cout << "NO" << endl;


return 0;
}

Measured memory_bytes: 256
while true
    n = gets.to_i
    break if n == 0
    card = [[], []]
    n.times{card[0] << gets.to_i}
    card[0].sort!
    card[1] = (1..(2*n)).to_a - card[0]
    player, ba = 0, 0
    until card[0].empty? || card[1].empty?
        ba = card[player].find{|x| x > ba}
        if ba
            card[player].delete(ba)
        else
            ba = 0
        end
        player = 1 - player
    end
    puts card[1].length
    puts card[0].length
end


Measured memory_bytes: 6880
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer a = sc.nextInt();
		Integer b = sc.nextInt();
		Integer c = sc.nextInt();
		Integer k = sc.nextInt();
		
		Integer result = 0;
		if(k <= a) {
			result = k;
		} 
		else if(k <= a+b) {
			result = a;
		}
		else{
			result = a - (k - a - b);
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 35840
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}
// cf IO: I64d
// atcoder IO: ｌｌｄ
const int Maxn=4005;
char ans[Maxn];
char ask(int x,int y){
	printf("? %d %d\n",x,y);
	fflush(stdout);
	char c;
	scanf("\n%c",&c);
	return c;
}
vector<int> now;
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if (b>=a){
		printf("Impossible\n");
		fflush(stdout);
		return 0;
	}
	now.push_back(0);
	for (int i=1;i<a+b;i++){
		if (now.empty()){
			now.push_back(i);
			continue;
		}
		int x=now.back();
		char c=ask(x,i);
		if (c=='N'){
			now.pop_back();
			//cerr<<123<<endl;
		}
		else{
			now.push_back(i);
		}
	}
	int t=now.back();
	for (int i=0;i<a+b;i++){
		char c=ask(t,i);
		if (c=='N') ans[i]='0'; else ans[i]='1';
	}
	ans[a+b]='\0';
	printf("! %s\n",ans);
	fflush(stdout);
	return 0;
}


Measured memory_bytes: 724
n = int(input())
a = list(map(int,input().strip().split()))
a.sort()
# print(a)
ans=1;
for i in a:
    ans*=i
    if(ans>1000000000000000000):
        break
if(ans>1000000000000000000):
    print(-1)
if(ans<=1000000000000000000):
    print(ans)


Measured memory_bytes: 21656
#include<stdio.h>
int main(void){
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0)break;
		if(x<y){
			printf("%d %d\n",x,y);
		}else{
			printf("%d %d\n",y,x);
		}
	
	}
	return 0;
}
 

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

int main(){
    int n,x; cin>>n>>x;
    int m[n];
    for(int i=0;i<n;i++) cin>>m[i];

    for(int i=0;i<n;i++){
        x-=m[i];
    }
    sort(m,m+n);
    // cout<<m[0];
    int count = n;
    // for(int i=0;i<n;i++){
    //     if(x<0) break;
    //     count++;
    //     x-=m[0];
    // }
    count = count + x /m[0];

    cout << count<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
const int mod=1e9+7;
void exgcd(int a,int b,int& d,int& x,int& y){
    if(!b) { d = a;x=1;y=0;}
    else{ exgcd(b, a%b, d, y, x); y -= x*(a/b); }
}
int inv(int a,int p){
    int d,x,y;
    exgcd(a,p,d,x,y);
    return d == 1 ? (x+p)%p : -1;
}
int ac[10000][10000]={0};
int calc(int n,int m){
	if(m==0||m==n)
		return 1;
	if(ac[n][m]!=0)
		return ac[n][m];
	return ac[n][m]=calc(n-1,m)+calc(n-1,m-1)%mod;
}

signed main(){
	int s;
	cin>>s;
	int sum=0;
	for(int i=1;i<=s/3;i++){
		sum+=calc(s-2*i-1,i-1);
		sum%=mod;
	}
	sum%=mod;
	cout<<sum<<endl;
}
//acacacacacacacacacacacacacacacacacacducatiakioi

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

using namespace std;

int main(){
	int N; cin >> N;
	vector<int> A(N), B(N), C(N-1);
	int cnt = 0;

	for(int i = 0; i < N; ++i) { cin >> A[i]; A[i]--; }
	for(int i = 0; i < N; ++i) cin >> B[i];
	for(int i = 0; i < N-1; ++i) cin >> C[i];

	for(int i = 0; i < N; ++i) cnt += B[i];

	for(int i = 0; i < N-1; ++i){
		if(A[i+1]-A[i] == 1) cnt += C[A[i]];
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    agc023a()
}

fun agc023a() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()

    val cumulativeSum = LongArray(n + 1)
    for (i in aList.indices) cumulativeSum[i + 1] = cumulativeSum[i] + aList[i]

    val answer = cumulativeSum.groupBy { it }.map { it.value.size.toLong() }
        .map { it * (it - 1) / 2 }.sum()

    println(answer)
}


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

typedef long long ll;
using namespace std;

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    auto get_price = [&](int ab) {
        int p_ab = c * ab;
        int p_a = a * max(x - ab / 2, 0);
        int p_b = b * max(y - ab / 2, 0);
        return p_ab + p_a + p_b;
    };

    int ans = min({
       get_price(0),
       get_price(x * 2),
       get_price(y * 2),
    });

    cout << ans;

    return 0;
}


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

using namespace std;
using ll = long long;
int main() {
	int n, h, w;
	cin>>n>>h>>w;
	vector<pair<ll, ll>>a(n);
	for(auto &e:a)cin>>e.first>>e.second;

	int ans=0;
	for(auto e:a)if(e.first>=h&&e.second>=w)++ans;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
typedef pair<int, int> P;
const int MAX_N = 1000000000;
const int MAX_L = 100000000;
const int MAX_SQRT_B = 10000;
const int INF = 1000000000;
typedef int64_t ll;
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 N;
vector<int> a(100005);
vector<bool> b(100005);

int cnt = 0;

int solve(int x) {

	b.at(1) = true;
	
	if (x == 2) {
		cnt++;
		return cnt;
	}

	if (!(b.at(x))) {
		b.at(x) = true;
		cnt++;
		return solve(a.at(x));
	}
	else {
		return -1;
	}
}


int main() {
	cin >> N;
	for (int i = 1; i <= N ; i++)
	{
		cin >> a.at(i);
		b.at(i) = false;
	}
	cout << solve(a.at(1)) << endl;
}

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

const int maxn =2e6+5;

int main()
{
    ios::sync_with_stdio(false);

    string s;cin>>s;
    if(s=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;



    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    
    int counter,divisor_num = 0;
    for(counter = a; counter <= b; counter++){
        if(c%counter == 0) divisor_num++;
    }
    printf("%d\n", divisor_num);
}



Measured memory_bytes: 2052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

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 <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

double culc(int xi, int xj, int yi, int yj){
    int bs = (xi - xj) * (xi - xj) + (yi - yj) * (yi - yj);
    double distance = sqrt(bs);
    return distance;
}

int main(){
    int n;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1) cin >> b[i];
    int a[n];
    int sum = 0;
    for (int i = n - 2; i >= 0; i--){
        if (i == n - 2)
            a[i + 1] = a[i] = b[i];
        else
            a[i] = b[i];
            if (b[i] <= a[i + 1])
                a[i + 1] = b[i];
    }
    rep(i, n) sum += a[i];
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int q,q1,d,q2;;
    cin >> q;
    std::deque<int> deq;
    for (int i=0;i<q;i++) {
        cin >> q1;
        if ( q1==0 ) {
            cin >> d >> q2;
            if ( d==0 ) {
                deq.insert(deq.begin(),q2);
            } else if ( d==1 ) {
                deq.emplace_back(q2);
            }
        } else if ( q1==1 ) {
            cin >> d;
            cout << deq[d] << endl;
        } else if ( q1==2 ) {
            cin >> d;
            if ( d==0 ) {
                deq.erase(deq.begin());
            } else if ( d==1 ) {
                deq.pop_back();
            }
        }
    }
}



Measured memory_bytes: 4604
n=int(input())
p=[int(i) for i in input().split()]
count=0
for t in range(1,n-1):
    if p[t-1]<p[t]<p[t+1] or p[t-1]>p[t]>p[t+1]:
        count+=1
    else:
        continue
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int N;
    cin >> N;
    map<string, ll> mp;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }

    ll cnt=0;
    for(auto x: mp){
        cnt += x.second*(x.second-1)/2;
    }
    cout << cnt;
}

Measured memory_bytes: 11136
h,w = map(int,input().split())
a,b = map(int,input().split())
c,d = map(int,input().split())
a -= 1
b -= 1
c -= 1
d -= 1

g = []
for _ in range(h):
    s = list(input())
    tmp = []
    for i in s:
        tmp.append(i)
    g.append(tmp)
if g[c][d] =='#':print(-1);exit()
from collections import deque
q = deque([])
p  =deque([])
dp = [[float('inf')]*w for _ in range(h)]

q.append((a,b,0))
dist = [(1,0),(0,1),(0,-1),(-1,0)]
seen = [[False]*w for _ in range(h)]

dp[a][b] = 0
seen[a][b] = True

while p or q:
    while q:
        x,y,cnt = q.popleft()
        p.append((x,y,cnt+1))
        for dx,dy in dist:
            X = x+dx
            Y = y + dy
            if 0<=X<h and 0<=Y<w and not seen[X][Y] and g[X][Y]=='.':
                if dp[X][Y]>cnt:
                    dp[X][Y] = min(dp[X][Y],cnt)
                    seen[X][Y] = True
                    q.append((X,Y,cnt))
                    p.append((X,Y,cnt+1))
    while p:
        x,y,cnt = p.popleft()
        for dx in range(-2,3,1):
            for dy in range(-2,3,1):
                X = x+dx
                Y = y + dy
                if 0<=X<h and 0<=Y<w and not seen[X][Y] and g[X][Y]=='.':
                    if dp[X][Y]>cnt:
                        dp[X][Y] = min(dp[X][Y],cnt)
                        seen[X][Y] = True
                        q.append((X,Y,cnt))
    # print(dp)
print(dp[c][d] if dp[c][d]!=float('inf') else -1)

Measured memory_bytes: 169348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

vector<ll> lc(90, -1);

ll Lucas(ll n) {
  ll a, b;
  if (lc.at(n - 1) == -1) lc.at(n - 1) = Lucas(n - 1);
  if (lc.at(n - 2) == -1) lc.at(n - 2) = Lucas(n - 2);
  a = lc.at(n - 1);
  b = lc.at(n - 2);
  return a + b;
}

int main() {
  lc.at(0) = 2;
  lc.at(1) = 1;
  ll n,ans;
  cin >> n;
  if (n == 1) ans = 1;
  else ans = Lucas(n);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256