akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

// Begin Template IO/Utility
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
void dbg_out(){
	cerr<<endl;
}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){
	cerr<<' '<< H; 
	dbg_out(T...);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &V){
	os<<'[';
	for(int i=0;i<(int)V.size();i++)
		os<<V[i]<<",]"[i==(int)V.size()-1];
	return os;
}
template<typename T> istream& operator>>(istream &is, vector<T> &V){
	for(T &x:V)
		is>>x;
	return is;
}
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T,U> &p){
	os<<'{'<<p.first<<','<<p.second<<'}';
	return os;
}
template<typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){
	is>>p.first>>p.second;
	return is;
}
template<typename T> void minself(T &a, T &b){
	a=min(a,b);
}
template<typename T> void maxself(T &a, T &b){
	a=max(a,b);
}
// End Template IO/Utility
int main(){
	cin.tie(0),cin.sync_with_stdio(0),cout.tie(0),cout.sync_with_stdio(0);
	int n, m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int tmp;
		cin>>tmp;
		n-=tmp;
	}
	cout<<(n>=0?n:-1);
}
	


Measured memory_bytes: 3656
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  const long long mod = 1e9 + 7;
  int n;
  cin >> n;
  long long a[1001] = {};
  for (int i = 2; i <= n; i++) {
    int x = i;
    for (int j = 2; j * j <= x; j++) {
      int cnt = 0;
      while (x % j == 0) {
        cnt++;
        x /= j;
      }
      a[j] += cnt;
    }
    if (x > 1) a[x]++;
  }
  long long ans = 1;
  for (int i = 0; i < 1001; i++) {
    if (a[i] == 0) continue;
    ans *= (a[i] + 1);
    ans %= mod;
  }
  cout << ans << endl;
  return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    unsigned long int n = 0, a = 0, b = 0, units = 0, blues = 0, rest = 0;
    string S;
    
    cin >> n >> a >> b;
    units = n / (a + b);
    blues = units * a;
    rest = n - (a + b) * units;
    if(rest >= a){
        blues += a;
    }else{
        blues += rest;
    }
    cout << blues << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
  public static void main(String []args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();

    int sum = 0;
    int[] arr = new int[n];
    for(int i = 0; i < n; i++) {
        arr[i] = sc.nextInt();
        sum += arr[i];
    }
    double thres = (sum/(4.0*k));
    //System.out.println(thres);
    int c = 0;
    for(int i = 0; i < n; i++) {
        if(arr[i] >= thres) {
            c++;
        }
    }
    if(c >= k) {
        System.out.println("Yes");
    }
    else {
        System.out.println("No");
    }
  }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

// 0-indexed
struct BIT {
    vector<int> data;
    int size;
    BIT(int n): size(n + 1), data(n + 1, 0) {}
    void add(int i, int x) {
        i++;
        while (i <= size) {
            data[i] += x;
            i += i & -i;
        }
    }
    int sum(int i) {
        i++;
        int ret = 0;
        while (i > 0) {
            ret += data[i];
            i -= i & -i;
        }
        return ret;
    }
};

signed main() {
    int N;
    cin >> N;
    vi idxw(N), idxb(N);
    REP(i, N * 2) {
        char c; int a;
        cin >> c >> a;
        if (c == 'W') idxw[a - 1] = i;
        else idxb[a - 1] = i;
    }

    vector<vi> costw(N, vi(N + 1)), costb(N + 1, vi(N));
    
    BIT bit(2 * N);
    REP(i, N * 2) bit.add(i, 1);
    REP(w, N + 1) {
        REP(b, N) {
            costb[w][b] = bit.sum(idxb[b] - 1);
            bit.add(idxb[b], -1);
        }
        REP(b, N) bit.add(idxb[b], 1);
        if (w < N) bit.add(idxw[w], -1);
    }

    bit = BIT(2 * N);
    REP(i, N * 2) bit.add(i, 1);
    REP(b, N + 1) {
        REP(w, N) {
            costw[w][b] = bit.sum(idxw[w] - 1);
            bit.add(idxw[w], -1);
        }
        REP(w, N) bit.add(idxw[w], 1);
        if (b < N) bit.add(idxb[b], -1);
    }

    vector<vi> dp(N + 1, vi(N + 1, INF));
    dp[0][0] = 0;
    REP(w, N + 1) {
        REP(b, N + 1) {
            if (w < N) chmin(dp[w + 1][b], dp[w][b] + costw[w][b]);
            if (b < N) chmin(dp[w][b + 1], dp[w][b] + costb[w][b]);
        }
    }
    cout << dp[N][N] << endl;
    return (0^_^0);
}



Measured memory_bytes: 94336
n=int(input())
a={}
for i in range(n):
  a[i]=int(input())

max1id,max1val=max(a,key=a.get),max(a.values())
a.pop(max1id)
max2id,max2val=max(a,key=a.get),max(a.values())
a[max1id]=max2val
for i in range(n):
  if i==max1id:
    print(max2val)
  else:
    print(max1val)
  
  

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

#define pb push_back
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

int const N = 3e3;

double dp[N][N] = {};

int main()
{
	fastio;

	dp[0][0] = 1;

	int n;
	cin >> n;

	double p;
	double res = 0;
	for (int i = 1; i <= n; ++i)
	{
		cin >> p;
		for (int j = 0; j <= i; ++j)
		{
			dp[i-j][j] = (i-j-1 < 0 ? 0 : dp[i-j-1][j] * p) + 
						 (j-1 < 0 ? 0 : dp[i-j][j-1] * (1-p));

			if (i == n && i-j > j)
				res += dp[i-j][j];
		}
	}
	cout << fixed << setprecision(10) << res << '\n';

	return 0;
}


Measured memory_bytes: 49848
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
#include<vector>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

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



int main() {

	int n, ans = 0;
	int a[100000] = {};

	cin >> n;
	rep(i, 0, n)cin >> a[i];
	sort(a, a + n);
	rep(i, 0, n) {
		int cnt = 1;
		for (int j = i - 1; j >= 0; j--) {
			if (a[j] + 1 == a[i] || a[j] == a[i])cnt++;
			else break;
		}
		for (int j = i + 1; j < n; j++) {
			if (a[j] - 1 == a[i] || a[j] == a[i])cnt++;
			else break;
		}
		ans = max(ans, cnt);
		while (1) {
			if (i == n || (a[i + 1] != a[i]))break;
			else i++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define int ll
int cnt[100005]={0};
signed main(){
  ll n,k;
  cin>>n>>k;
  vector<P> vec;
  for(int i=0;i<n;i++){
    ll t,d;
    cin>>t>>d;
    vec.push_back(P(d,t));
  }
  sort(vec.begin(),vec.end(),greater<P>());
  ll ans=0;
  ll val=0;
  for(int i=0;i<k;i++) {
    if(cnt[vec[i].second]==0) val++;
    cnt[vec[i].second]++;
    ans+=vec[i].first;
  }
  ans+=val*val;

  ll nxt_ans=ans;
  ll over=k-1,under=k;
  while(1){
    while(under<n&&cnt[vec[under].second]!=0) under++;
    while(over>=0&&cnt[vec[over].second]<=1) over--;
    if(under>=n||over<0) break;
    cnt[vec[under].second]++;
    cnt[vec[over].second]--;
    ll kans=nxt_ans;
    kans-=vec[over].first;
    kans-=val*val;
    val++;
    kans+=vec[under].first;
    kans+=val*val;
    ans=max(ans,kans);
    nxt_ans=kans;
    over--;
    under++;
  }
  cout<<max(nxt_ans,ans)<<endl;
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define bit(n) (1LL<<(n))

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

    vector<lint> a(n);
    for(auto& elem : a)  cin >> elem;

    vector<lint> b(n);
    for(auto& elem : b)  cin >> elem;

    auto next_combination = [](lint sub) {
        lint x = sub & -sub;
        lint y = sub + x;
        return (((sub & ~y) / x) >> 1) | y;
    };

    // 1. 偶数番目(0, 2, ...)に使うカードで全探索
    lint k = (n+1)/2;
    lint ans = 1e18;
    for(lint mask = bit(k)-1; mask < bit(n); mask = next_combination(mask)) {
        bitset<30> bs(mask);
        vector<pair<lint, lint>> seq;
        vector<pair<lint, lint>> odd, even;
        for(lint i=0; i<n; i++) {
            if(bs.test(i)) {
                seq.emplace_back(i%2 ? b[i] : a[i], i);
                even.emplace_back(i%2 ? b[i] : a[i], i);
            } else {
                seq.emplace_back(i%2 ? a[i] : b[i], i);
                odd.emplace_back(i%2 ? a[i] : b[i], i);
            }
        }

        // 2. 目標とする並び順を決める
        sort(even.begin(), even.end());
        sort(odd.begin(), odd.end());

        vector<lint> vec(n);
        map<pair<lint,lint>, lint> mp;
        for(lint i=0; i<n; i++) {
            vec[i] = (i%2 ? odd[(i-1)/2] : even[i/2]).first;
            mp[(i%2 ? odd[(i-1)/2] : even[i/2])] = i;
        }
        if(!is_sorted(vec.begin(), vec.end()))  continue;

        vector<lint> ind;
        for(auto elem : seq)  ind.push_back(mp[elem]);

        // 3. バブルソートのswap回数
        lint counter = 0;
        for(lint i=0; i<n; i++)
        for(lint j=i+1; j<n; j++) {
            if(ind[i] > ind[j])  counter++;
        }
        ans = min(ans, counter);
    }

    cout << (ans == 1e18 ? -1 : ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  n,W,i,j;
    cin>>n>>W;
    long long  w[n+1],v[n+1];
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    long long k[n+1][W+1];
    for(i=0;i<=n;i++)
    {
        k[i][0]=0;
    }
    for(i=0;i<=W;i++)
    {
        k[0][i]=0;
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=W;j++)
        {
            if(j>=w[i-1])
            {
                k[i][j]=max(v[i-1]+k[i-1][j-w[i-1]],k[i-1][j]);
            }
            else
            k[i][j]=k[i-1][j];
        }
    }
    cout<<k[n][W];
    return 0;
    
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,d,e=0,f=0,j,i;
cin>>a>>b;
vector<ll>v;
    if(a+b<=9)cout<<a+b<<endl;
        else cout<<"error\n";

}

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


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


Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))
fl = False
for i in range(1,200):
    task = 0
    if fl == True:
        break
    for a in li:
        task += a
        if task >= i:
            task -= i
        else:
            print(i-1)
            fl = True
            break
            


Measured memory_bytes: 5588
n = int(input())
s = []
for i in range(0, n):
    s.append(input())
count_AC = 0
count_WA = 0
count_TLE = 0
count_RE = 0
for j in s:
    if j == 'AC':
        count_AC += 1
    elif j == 'WA':
        count_WA += 1
    elif j == 'TLE':
        count_TLE += 1
    elif j == 'RE':
        count_RE += 1
print("AC" + " x " + str(count_AC))
print("WA" + " x " + str(count_WA))
print("TLE" + " x " + str(count_TLE))
print("RE" + " x " + str(count_RE))

Measured memory_bytes: 16180
a = list(map(int,list(input())))
c = 1
co = 0
p = a[0]
pp = []
for i in range(len(a)-1):
	if a[(i+1)] == p:
		c += 1
	else:
		pp.append(c)
		c = 1
		p = a[i+1]
pp.append(c)
if len(pp) != 1:
	ppp = pp[0]
	for i in range(len(pp)-1):
		if pp[i] >= 0:
			co += 2*(max(pp[i],pp[i+1]) - abs(pp[i] - pp[i+1]))
			pp[i+1] = pp[i+1] - pp[i]
		else:
			pp[i+1] = pp[i+1] - pp[i]
print(co)


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

int main()
{
    int n;
    cin >> n;
    int a[n];
    int count = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(a[i] != i + 1)
            count++;
    }
    
    if(count <= 2)
        cout << "YES";
    else
        cout << "NO";
    
    
    
}

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

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pll;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fir first
#define sec second
#define gc getchar
#define pc putchar

#define fo0(i,a,b) for(int i=(a);i<(b);i++)
#define fo1(i,a,b) for(int i=(a);i<=(b);i++)
#define fd0(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define fd1(i,a,b) for(int i=(a);i>=(b);i--)
#define mset(a,b) memset(a,(b),sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))

template<typename T> inline T gcd(T a, T b){T t;if(a>b){while(b){
t=b;b=a%b;a=t;}return a;}else{while(a){t=a;a=b%a;b=t;}return b;}}
template<typename T> inline T lcm(T a, T b){return a/gcd(a,b)*b;}

template<typename T> inline void QR(T &x){x=0;int fl=1;char ch=gc();while(ch<'0'||ch>'9')
{if(ch=='-')fl=-1;ch=gc();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=gc();}x*=fl;}
void Read(int &x){QR(x);} void Read(LL &x){QR(x);}
void Read(double &x){scanf("%lf", &x);} void Read(char &x){x=gc();}
template<typename T> void QW(T x){if(x<0){pc('-');x=-x;}if(x/10)QW(x/10);pc(x%10+'0');}
void Write(int &x){QW(x);} void Write(LL &x){QW(x);}
void Write(double &x){printf("%f", &x);} void Write(char &x){pc(x);}
void in(){} template<class T1,class...T2> void in(T1 &head,T2 &...tail){Read(head);in(tail...);}
void out(){} template<class T1,class...T2> void out(T1 head,T2 ...tail){Write(head);out(tail...);}

const int N = 100005;

int n, m;

struct City{
	int year, p, id, num;
}c[N];
bool cmp1(City x, City y){
	return x.id < y.id;
}
bool cmp2(City x, City y){
	if(x.p != y.p)
		return x.p < y.p;
	else
		return x.year < y.year;
}

int cnt(int x){
	int res = 0;
	while(x){
		res++;
		x /= 10;
	}
	return res;
}

int main(){
	in(n, m);
	fo1(i, 1, m){
		in(c[i].p, c[i].year);
		c[i].id = i;
	}
	sort(c+1, c+m+1, cmp2);
	int lst = 0;
	fo1(i, 1, m){
		if(c[i].p == c[i-1].p)
			c[i].num = i - lst;
		else	c[i].num = 1, lst = i-1;
	}
	sort(c+1, c+m+1, cmp1);
	fo1(i, 1, m){
		int t = cnt(c[i].p);
		fo1(j, 1, 6-t)	putchar('0');
		out(c[i].p);
		t = cnt(c[i].num);
		fo1(j, 1, 6-t)	putchar('0');
		out(c[i].num, '\n');
	}
	return 0;
}

Measured memory_bytes: 3072
H, W, K = map(int, input().split())
ans = []
c = 1
v = 0

for _ in range(H):
    s = input()
    m = [-1]*W

    for i, j in enumerate(s):
        if j=="#":
            v += 1
            for k in range(i+1):
                if m[k]==-1:
                    m[k] = v
    if m[0]==-1:
        if ans:
            ans.append(ans[-1])
        else:
            c += 1
    else:
        for i in range(W):
            if m[i]==-1:
                m[i] = m[i-1]
        
        for _ in range(c):
            ans.append(m)
        c = 1

for i in ans:
    print(*i)


Measured memory_bytes: 7436
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define endl '\n'
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int x,y,f=0;
    cin>>x>>y;
    vector<int>vec(x);
    ll ans=0;
    for(int i=0;i<x;i++){
        cin>>vec[i];
        ans+=vec[i];
    }
    vector<int>div;
    for(int i=1;i<=sqrt(ans);i++){
        if(ans%i==0){
            if((ans/i)==i)
                div.push_back(i);
            else{
                div.push_back(ans/i);
                div.push_back(i);
            }
        }
    }
    sort(div.rbegin(),div.rend());
    for(int i=0;i<div.size();i++){
        vector<int>a;
        int right=0,left=0,mid=0;
        for(int c=0;c<x;c++){
            if(vec[c]%div[i]!=0) {
                a.push_back(vec[c]%div[i]);
            }
        }
        sort(a.begin(),a.end());
        for(int c=0;c<a.size();c++)
            right+=div[i]-a[c];
        for(int c=0;c<a.size();c++){
            right-=div[i]-a[c];
            left+=a[c];
            if(right==left) {
                mid=left;
            }
        }
        if(mid<=y){
            cout<<div[i];
            break;
        }
    }
}


Measured memory_bytes: 256
def a_airport_bus(N, C, K, T):
    import bisect
    t = sorted(T)
    index = 0  # t[index]はまだバスに乗っていない人の内最も早い空港到着時刻
    ans = 0
    while index <= N - 1:
        # 時刻 t[index] にバスを出した場合乗り込める人数の候補
        num_take_bus = bisect.bisect_right(t, t[index] + K) - index
        if num_take_bus > C:
            index += C  # 定員分だけ乗せる
        else:
            index += num_take_bus  # 乗れるだけ乗せる
        ans += 1  # バスを1台出した
    return ans

N, C, K = [int(i) for i in input().split()]
T = [int(input()) for _ in range(N)]
print(a_airport_bus(N, C, K, T))

Measured memory_bytes: 8280
#include<iostream>

using namespace std;

int N, M;
static const int MOD = 1000000007;

int main(){
	cin >> N >> M;
	long long ans = 1;
	if(N + 1 == M || M + 1 == N){
		for(int i = 1; i <= N; i++){
			ans = (ans * i) % MOD;
		}
		for(int i = 1; i <= M; i++){
			ans = (ans * i) % MOD;
		}
	}else if(N == M){
		for(int i = 1; i <= N; i++){
			ans = (ans * i) % MOD;
		}
		for(int i = 1; i <= M; i++){
			ans = (ans * i) % MOD;
		}
		ans = (ans * 2) % MOD;
	}else{
		cout << 0 << endl;
		return 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] val = new int[r][c];
        int[] rsum = new int[r + 1];
        int[] csum = new int[c];
        int ans = 0;
        
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                val[i][j] = sc.nextInt();
                rsum[i] += val[i][j];
                rsum[r] += val[i][j];
            }
        }
        for (int j = 0; j < c; j++) {
            for (int i = 0; i < r; i++) {
                csum[j] += val[i][j];
            }
        }
        
        
        for (int i = 0; i < r + 1; i++) {
            for (int j = 0; j < c; j++) {
                if (i < r) {
                    System.out.print(val[i][j] + " ");
                } else {
                    System.out.print(csum[j] + " ");
                }
            }
            System.out.println(rsum[i]);
        }
    }
}



Measured memory_bytes: 42028
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

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

int main() {
    int n, x, t;
    cin >> n >> x >> t;

    int ans = (n + x - 1) / x * t;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3588
import sys
from collections import deque
import copy
def main():
    N, M = map(int, input().split())
    A = [int(i) for i in input().split()]
    count = 0
    for i in range(M):
        count += A[i]
    if N - count < 0:
        print(-1)
    else:
        print(N - count)


if __name__ == '__main__':
    main()


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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

using namespace std;

int main ()
{
  int H,W,K,res;
  vector<string> c;
  string b;
  int Hst,Wst,Hmax,Wmax,black;

  cin >> H >> W >> K;

  REPI (H)
  {
    cin >> b;
    c.push_back (b);
  }

  Hst = 0;
  Hmax = pow (2,H);
  Wmax = pow (2,W);
  res = 0;
  while (Hst < Hmax)
  {
    Wst = 0;
    while (Wst < Wmax)
    {
      black = 0;
      REPI (H)
      {
        REPJ (W)
        {
          if (((Hst >> i) % 2) == 0 && ((Wst >> j) % 2) == 0 && c[i][j] == '#' )
            black++;
        }
      }

      if (black == K)
        res++;      
      Wst++;
    }
    Hst++;
  }
  
  cout << res << endl;


  return 0;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int dp[1000];

int main() {
    int n; cin >> n;
    rep(i, 1000) dp[i] = 0;
    rep(i, n) {
        int s, l, p; cin >> s >> l >> p;
        Rep(j, s, l+1) rep(k, 400) chmax(dp[k+j], dp[k] + p);
    }
    int m; cin >> m;
    vector<int> me(m);
    rep(i, m) cin >> me[i];
    rep(i, m) if(dp[me[i]] == 0) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, m) cout << dp[me[i]] << endl;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[5],sum;
	for(int i=0;i<5;i++){
		cin >> a[i];
	}
	if(a[0]<=a[1] && a[0]<=a[2]){
		sum=a[0];
	}else if(a[1]<=a[0] && a[1]<=a[2]){
		sum=a[1];
	}else if(a[2]<=a[0] && a[2]<=a[1]){
		sum=a[2];
	}
	if(a[3]<a[4]){
		sum=sum+a[3];
	}else{
		sum=sum+a[4];
	}
	cout << sum-50 << endl;
}


Measured memory_bytes: 3096
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        sc.nextLine();
        int b = sc.nextInt();
        int c = sc.nextInt();
        sc.nextLine();
        int[] d = new int[a];
        for(int i = 0;i<a; i++){
            d[i] = sc.nextInt();
            sc.nextLine();
        }
        int count = c;
        for(int i = 0;i<a;i++){
            count += (b+d[i]-1)/d[i]; 
        }
        System.out.println(count);
    }
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    vector<ll> B(M);
    rep(i, N)
    {
        cin >> A[i];
    }
    rep(i, M)
    {
        cin >> B[i];
    }
    vector<ll> SA(N + 1, 0);
    vector<ll> SB(M + 1, 0);
    rep(i, N)
    {
        SA[i + 1] = SA[i] + A[i];
    }
    rep(i, M)
    {
        SB[i + 1] = SB[i] + B[i];
    }

    ll ans = 0;
    for (ll i = 0; SA[i] <= K && i <= N; i++) {
        ll b = (ll)(upper_bound(SB.begin(), SB.end(), K - SA[i]) - SB.begin());
        ans = max(b - 1 + i, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9592
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include<string.h>
#include <math.h>
#include <stack>
#define ll long long
using namespace std;
typedef struct Node {
	double x;
	char u[4];
};
Node a[11];
int main() {
	int n;
	long double res = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%lf %s", &a[i].x, &a[i].u);
	for (int i = 0; i < n; i++) {
		if (strcmp(a[i].u, "JPY") == 0) {
			res += a[i].x;
		}
		else {
			res += (a[i].x * 380000.0);
		}
	}
	printf("%Lf\n", res);
}

Measured memory_bytes: 128
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        double x = 0;
        double y = 0;
        double angle = 90;

        while(true){


            String line = sc.next();

            int a = 0;
            int b = 0;

            int index = 0;
            boolean minas = false;
            for(; index < line.length(); index++){
                if(line.charAt(index) == ','){
                    index++;
                    break;
                }else{
                    a *= 10;
                    a += Integer.parseInt("" + line.charAt(index));
                }
            }

            if(line.charAt(index) == '-'){
                minas = true;
                index++;
            }

            for(; index < line.length(); index++){
                b *= 10;
                b += Integer.parseInt("" + line.charAt(index));
            }

            if(minas){
                b *= -1;
            }


            int distance = a;
            int rot = b;
            if(distance == 0 && rot == 0){break;}

            x += Math.cos(Math.toRadians(angle)) * distance;
            y += Math.sin(Math.toRadians(angle)) * distance;
            angle -= (double)rot;

        }
        System.out.println((int)x);
        System.out.println((int)y);

    }
}

Measured memory_bytes: 17140
from collections import deque
k = int(input())

dq = deque(list(range(1, 10)))
rep = 0
while rep < k:
    now = dq.popleft()
    rep+=1
    for i in (-1, 0, 1):
        if 0<=now%10+i<10: dq.append(now*10+now%10+i)
print(now)

Measured memory_bytes: 11956
#include <iostream>
using namespace std;
using ll = long long;

int main() {
  int N, K;
  cin >> N >> K;

  if (K % 2 == 0) {
    ll a = N / K;
    ll b = (N + (K / 2)) / K;
    cout << a * a * a + b * b * b << endl;
  } else {
    ll a = N / K;
    cout << a * a * a << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 1000000007;
ll H,W;

ll Cal(ll x,ll y) {
  ll res = (x * W) + y;
  return res;
}

int main() {
  int N;
  cin >> H >> W;
  cin >> N;
  ll a[N],b[N];
  ll ans[10];
  for (int i = 0; i < 10; i++) ans[i] = 0;
  ans[0] = (H-2) * (W-2);
  unordered_map<ll,bool> mat; 
  unordered_map<ll,ll> res;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    mat[Cal(a[i],b[i])] = true;
  }
  for (int i = 0; i < N; i++) {
    for (int x = -2; x <= 0; x++) {
      for (int y = -2; y <= 0; y++) {
        bool inside = true;
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
          for (int k = 0; k < 3; k++) {
            ll xx = a[i] + x + j;
            ll yy = b[i] + y + k;
            if (0 <= xx && xx < H && 0 <= yy && yy < W) {
              
            } else {
              inside = false;
            }
            if (mat[Cal(xx,yy)]) {
              cnt++;
            }
          }
        }
        if (inside) {
          if (res[Cal(a[i]+x,b[i]+y)] == 0) {
            res[Cal(a[i]+x,b[i]+y)] = cnt;
            ans[cnt]++;
            ans[0]--;
          }
        }
      }
    }
  }

  for (int i = 0; i < 10; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 154964
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

#define ll long long

ll MAX(ll a,ll b){

    if(a>b)return a;
    else return b;

}
int main(){

    string S;
    vector<string> V;
    int K;
    cin>>S>>K;

    for(int i=0;i<S.size();i++){

        V.push_back(S.substr(i,1));
        if(i>=1)V.push_back(S.substr(i-1,2));
        if(i>=2)V.push_back(S.substr(i-2,3));
        if(i>=3)V.push_back(S.substr(i-3,4));
        if(i>=4)V.push_back(S.substr(i-4,5));

    }
    sort(V.begin(),V.end());
    unique(V.begin(),V.end());
    cout<<V[K-1]<<endl;

    return 0;
}

Measured memory_bytes: 1660
n = int(input())

words = [input() for _ in range(n)]

spoken = {words[0]}

for x, y in zip(words, words[1:]):
    if y[0] != x[-1]:
        print("No")
        exit()
    if y in spoken:
        print("No")
        exit()
    spoken.add(y)
else:
    print("Yes")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)
 
int main() {
  static const double pi = acos(-1.0);
  double a,b,h,m,hk,mk,x,tmpans,ans;
  cin>>a>>b>>h>>m;
  hk=(h*30)+(m*0.5);
  mk=m*6;
  x=abs(hk-mk);
  if(x>180){x=360-x;}
  ans=sqrt((a*a)+(b*b)-(2*a*b*cos(x/180.0*pi)));
  
  cout<<fixed<<setprecision(20)<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int h, w;
   cin >> h >> w;
   vector<vector<char>> S(h, vector<char>(w));
   rep(i, h) rep(j, w) cin >> S[i][j];

   int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
   int ans = 0;
   rep(sy, h) rep(sx, w) {
      if (S[sy][sx] == '#')
         continue;
      vector<vector<int>> d(h, vector<int>(w, inf));
      queue<P> que;
      que.push(P(sx, sy));
      d[sy][sx] = 0;
      while (que.size()) {
         P Q = que.front();
         que.pop();
         int x = Q.first;
         int y = Q.second;
         for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && S[ny][nx] == '.' &&
                d[ny][nx] == inf) {
               d[ny][nx] = d[y][x] + 1;
               que.push(P(nx, ny));
            }
         }
      }
      rep(gy, h) rep(gx, w) {
         if (d[gy][gx] != inf)
            ans = max(ans, d[gy][gx]);
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
n = int(input())

cards = [[False for i in range(13)] for j in range(4)]
# 0: S
# 1: H
# 2: C
# 3: D
pattern = ["S","H","C","D"]
i = 1
while i <= n:    
    mark, rank = input().split()
    rank = int(rank)
    cards[pattern.index(mark)][rank-1] = True
    i+=1
for i in range(4):
    for j in range(13):
        if cards[i][j] == False:
            print(f"{pattern[i]} {j+1}") 




Measured memory_bytes: 5616
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
#define maxn 200010
#define pb push_back

int n,A[maxn],B[maxn];
vector<int> a,b;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	for(int i=1;i<=n;i++)scanf("%d",&B[i]);
	reverse(B+1,B+n+1);
	for(int i=1;i<=n;i++)if(A[i]==B[i])a.pb(i);
	if(a.size()){
		for(int i=1;i<=n;i++)if(A[i]!=A[a[0]]&&B[i]!=B[a[0]])b.pb(i);
		if(b.size()<a.size())return printf("No\n"),0;
		for(int i=0;i<a.size();i++)swap(B[b[i]],B[a[i]]);
	}
	printf("Yes\n");
	for(int i=1;i<=n;i++)printf("%d ",B[i]);
}

Measured memory_bytes: 5560
#include <iostream>                                                                              
#include <string>                                                                                
#include <cctype>                                                                                
                                                                                                 
using namespace std;                                                                             
                                                                                                 
int main (void) {                                                                                
  string str, right, left;                                                                       
  int h, m;                                                                                      
                                                                                                 
  while (true) {                                                                                 
    cin >> str;                                                                                  
    if (str == "-") {                                                                            
      break;                                                                                     
    }                                                                                            
    cin >> m;                                                                                    
    for (int i=0; i<m; i++) {                                                                    
      cin >> h;                                                                                  
      left = str.substr(0,h);                                                                    
      right = str.substr(h);                                                                     
      str = right+left;                                                                          
    }                                                                                            
    cout << str << endl;                                                                         
  }                                                                                              
}                                                                                                
                                                                                                 
                                                                                                 
                                               

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

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

int main(){

    int n; cin >> n;
    vector<int> a(3*n);
    for(int i = 0; i < 3*n; i++){
        cin >> a[i];
    }

    sort(a.begin(), a.end(), comp);
    

    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans += a[i*2 + 1];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

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

    int x=(A%B)*2;
    while (x != A%B){
	if (x%B == C){
	    cout << "YES" << endl;
	    return 0;
	}
	x=(x+A%B)%B;
    }
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    N, X = map(int, input().split())
    m = []
    for i in range(N):
        m.append(int(input()))
    m.sort()
    t = sum(m)
    q = len(m)
    while t <= X:
        t += m[0]
        q += 1
    print(q-1)
main()

Measured memory_bytes: 9024
N, K = map(int, input().split())
S = list(input())

flag = True
for i in range(1, N):
    if K != 0:
        if flag:
            if S[i-1] != S[i]:
                flag = False
        if not flag:
            S[i] = 'L' if S[i] == 'R' else 'R'
            if i < N - 1:
                if S[i] == S[i+1]:
                    flag = True
                    K -= 1

ans = 0
if S[0] == 'R' and S[1] == 'R':
    ans += 1
for i in range(1, N - 1):
    if S[i] == 'R' and S[i + 1] == 'R':
        ans += 1
    elif S[i] == 'L' and S[i - 1] == 'L':
        ans += 1
if N > 1:
    if S[-1] == 'L' and S[-2] == 'L':
        ans += 1

print(ans)

Measured memory_bytes: 4084
import java.util.* ;
class Main {
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
	int A = scan.nextInt();
   int B = scan.nextInt();
    int C = scan.nextInt();
    
    if(B-A == C-B){
      System.out.println("YES");
    }else{
		System.out.println("NO");
    }
    

  }
}


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

const ll MOD = 1e9+7;

int main(){
    int h,n; cin >> h >> n;
    vector<ll> a(n),b(n); rep(i,n) cin >> a[i] >> b[i];
    ll dp[n+1][20000];
    rep(i,n+1) rep(j,20000) dp[i][j] = 1000000000;
    rep(i,n+1) dp[i][0] = 0LL;
    rep(i,n) rep(j,20000){
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        if(j - a[i] >= 0) dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-a[i]] + b[i]);
    }
    ll ans = dp[n][h];
    for(int j = h; j < 20000; ++j){
        ans = min(ans, dp[n][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 156800
#include <stdio.h>
#include <vector>
#include <queue>

struct edge {
    int to;
    long long cost;
};
typedef std::pair<long long, int> P;
typedef std::vector<edge> node;

const int MAX_N = 100000;
const long long INF = 1e17;
const int mod = 1e9 + 7;
node G[MAX_N];
long long ds[MAX_N], dt[MAX_N];
int dp1[MAX_N], dp2[MAX_N];
int N, M, S, T;

void dijkstra(int s, long long *d, int *dp) {
    std::priority_queue<P, std::vector<P>, std::greater<P> > que;
    std::fill(d, d + N, INF);
    d[s] = 0;
    dp[s] = 1;
    que.push(std::make_pair(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        long long v = p.second;
        if (d[v] < p.first) continue;
        for (auto e: G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                dp[e.to] = dp[v];
                d[e.to] = d[v] + e.cost;
                que.push(std::make_pair(d[e.to], e.to));
            } else if (d[e.to] == d[v] + e.cost) {
                dp[e.to] += dp[v];
                dp[e.to] %= mod;
            }
        }
    }
}

int main() {
    scanf("%d %d %d %d", &N, &M, &S, &T);
    S--;
    T--;
    for (int i = 0; i < M; ++i) {
        int U, V, D;
        scanf("%d %d %d", &U, &V, &D);
        U--;
        V--;
        G[U].push_back((edge) {V, D});
        G[V].push_back((edge) {U, D});
    }

    dijkstra(S, ds, dp1);
    dijkstra(T, dt, dp2);

    long long ans = 1ll * dp1[T] * dp1[T] % mod;
    for (int v = 0; v < N; ++v) {
        //if (2 * ds[v] == ds[T]) {
        if (ds[v] == dt[v] && ds[v] + dt[v] == ds[T]) {
            ans -= 1ll * dp1[v] * dp1[v] % mod * dp2[v] % mod * dp2[v] % mod;
            ans += mod;
            ans %= mod;
        }
    }
    for (int u = 0; u < N; ++u) {
        for (auto e: G[u]) {
            int v = e.to;
            long long c = e.cost;
            //if (ds[v] == ds[u] + c && 2 * ds[u] < ds[T] && 2 * dt[v] < ds[T]) {
            if (std::max(ds[u], dt[v]) * 2 < ds[T] && ds[u] + c + dt[v] == ds[T]) {
                ans -= 1ll * dp1[u] * dp1[u] % mod * dp2[v] % mod * dp2[v] % mod;
                ans += mod;
                ans %= mod;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 18004
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.IO;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
		Console.SetOut(sw);

		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int N = input[0];
		int X = input[1];
		var x = Console.ReadLine().Split().Select(int.Parse).ToArray();

       for(var i = 0; i < N; i++)
		{
			x[i] = Math.Abs(x[i] - X);
		}
		Array.Sort(x);
		var c = new Calculation();
		int ans = c.GetGcdOfSortedArray(x);

		Console.WriteLine(ans);

		Console.Out.Flush();
	}
}

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
//入力用

public class Calculation //各種値の計算メソッド
{
	public int GetGcd(int a, int b) //最大公約数(２数)
	{

		if (a < b)
		{
			int c = a;
			a = b;
			b = c;
		}
		if (b == 0)
		{
			return a;
		}
		int r = a % b;
		while (r > 0)
		{
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}
	public int GetGcdOfSortedArray(int[] array) //最大公約数(ソート済み数列)
	{
		if (array.Length == 0) { return 1; }
		else if (array.Length == 1) { return array[0]; }
		else
		{
			int n = 0;
			int g = array[0];
			while (n <= array.Length - 2)
			{

				int a = array[n + 1];
				int b = g;
				int r = a % b;
				while (r > 0)
				{
					a = b;
					b = r;
					r = a % b;
				}
				g = b;
				
				n++;
			}

			return g;

		}
	}

	public long GetNCR(int n, int r) //二項係数(生の値)
	{
		if (n == 1) { return 1; }
		long[] nC = new long[n + 1];
		nC[0] = 1;
		for (var i = 0; i <= r - 1; i++)
		{
			nC[i + 1] = nC[i] * (n - i) / (i + 1);
		}
		return nC[r];
	}


}


Measured memory_bytes: 21728
#include <stdio.h>
int main()
{
	int W,H,x,y,r,flag=0;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if((0<=x-r && x-r<=W) && (0<=x+r && x+r<=W)){
		if((0<=y-r && y-r<=H) && (0<=y+r && y+r<=H)){
			printf("Yes\n");flag=1;
		}
	}
	if(flag==0){
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,p;
  cin>>n>>p;
  vector<Int> w(n),b(n);
  for(Int i=0;i<n;i++) cin>>w[i]>>b[i];

  Int s=0;
  for(Int i=0;i<n;i++) s+=b[i];
  s*=p;

  vector<Int> v;
  for(Int i=0;i<n;i++)
    v.emplace_back((100-p)*w[i]+p*b[i]);
  sort(v.rbegin(),v.rend());
  
  for(Int i=0;i<n;i++){
    s-=v[i];
    if(s<=0){
      cout<<i+1<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};


template<typename T>
struct Combination {
private:
  int sz;
  vector<T> F, F_;
public:
  Combination(int sz) : sz(sz), F(sz+1), F_(sz+1) {
    F[0] = 1;
    for(int i = 0; i < sz; ++i) F[i+1] = F[i]*(i+1);
    F_.back() = (T)1/F.back();
    for(int i = sz-1; i >= 0; --i) F_[i] = F_[i+1]*(i+1);
  }
  T C(int n, int k){
    assert(n <= sz);
    if(n < 0 or k > n) return (T)0;
    return F[n]*F_[k]*F_[n-k];
  }
};

int main(){
  using mint = modint<998244353>;
  int N, X;
  cin >> N >> X;

  int M = 1;
  while(M <= X) M *= 2;
  vector<vector<mint>> dp(N+1,vector<mint>(M));
  dp[0][0] = 1;
  for(int i = 0; i <= X; ++i){
    for(int j = N-1; j >= 0; --j){
      for(int k = 0; k < M; ++k){
        if((k^i) > M) continue;
        dp[j+1][k^i] += dp[j][k];
      }
    }
  }

  Combination<mint> comb(X+N+1);
  mint ans = 0;
  for(int i = 0; i <= N; ++i){
    if((N-i)%2) continue;
    int c = (N-i)/2;
    ans += dp[i][X]*comb.C(X+c,c);
  }
  cout << ans << endl;
}



Measured memory_bytes: 4912
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<double,double> pdd;
typedef pair<string,int> psi;
const int MOD = 1e9 + 7;

const int N = 200001;

string s1,s2;
int q,a,b,c,d;
int f1[N][2];
int f2[N][2];

int main() {
  //  freopen("input.txt","r",stdin);
   cin >> s1 >> s2;
   cin >> q;
   for (int i = 1; i <= s1.size(); ++i){
       if(s1[i-1] == 'A')
            f1[i][0]++;
        if(s1[i-1] =='B')
            f1[i][1]++;
        f1[i][1] += f1[i-1][1];
        f1[i][0] += f1[i-1][0];
   }
    for (int i = 1; i <= s2.size(); ++i){
       if(s2[i-1] == 'A')
            f2[i][0]++;
        if(s2[i-1] =='B')
            f2[i][1]++;
        f2[i][1] += f2[i-1][1];
        f2[i][0] += f2[i-1][0];
   }
   while(q--){
    scanf("%d%d%d%d",&a,&b,&c,&d);
        int rr = (f1[b][0]-f1[a-1][0])*2 + (f1[b][1]-f1[a-1][1]);
        int kk = (f2[d][0]-f2[c-1][0])*2 + (f2[d][1]-f2[c-1][1]);

        if(rr%3 == kk%3){
            puts("YES");
        }else{
            puts("NO");
        }
   }
    return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int len,ans=0,max1=0;
char s[101];
int main()
{
	scanf("%d%s",&len,s);
	for (int i=0;i<len;i++)
	  if (s[i]=='I')
	  {
	  	ans++;
	  	max1=max(max1,ans);
	  }
	  else ans--;
	printf("%d",max1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	#define PI 			acos(-1)
	#define mp			make_pair
	#define pb			push_back
	#define all(a)		(a).begin(), (a).end()
	#define srt(a)			sort(all(a))
	#define mem(a, h)	memset(a, (h), sizeof(a))
	#define f 			first
	#define s 			second
	#define MOD			1000000007
	int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

	using namespace std;

	typedef long long 		ll;
	typedef unsigned long long 		ull;
	typedef pair<int, int>  ii;
	typedef vector<int>     vi;
	typedef vector<ii>      vii;
	typedef vector<ll>      vll;
	int main()
	{
		//ios::sync_with_stdio(false); cin.tie(0);
		//freopen("", "r", stdin);
		//freopen("", "w", stdout);
		int a,b;
		cin>>a>>b;
		int n = b-a;
		cout<<(n*(n+1))/2-b<<endl;
		return 0;
	}

Measured memory_bytes: 256