akhauriyash/Code-Regression huggingface dataset:
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

int n;
vi a, b;

signed main() {
  cin >> n;
  a = b = vi(n);

  rep(i, n) cin >> a[i] >> b[i];
  lint res = 0;
  rrep(i, n - 1, 0) {
    if ((a[i] + res) % b[i] == 0) continue;
    res += ((a[i] + res) / b[i] + 1) * b[i] - (a[i] + res);
  }

  print(res);
}


Measured memory_bytes: 1024
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 410, mod = 1e9 + 7;
int dp[maxn][maxn], n, c, l[maxn], r[maxn], ps[maxn][maxn];
void add(int &a, int b) {
	a += b;
	if(a >= mod) a -= mod;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> c;
	for(int i = 0; i < n; i++) cin >> l[i], l[i]--;
	for(int i = 0; i < n; i++) cin >> r[i];
	for(int i = 1; i < maxn; i++) {
		for(int t = 1, j = 0; j < maxn; j++) {
			ps[i][j] = (ps[i-1][j] + t)%mod;
			t = t * 1ll * i % mod;
		}
	}
	dp[0][0] = 1;
	for(int i = 0; i <= n; i++) {
		for(int d = 0; d <= c; d++) {
			int u = 1;
			for(int j = 0; d+j <= c; j++) {
				add(dp[i+1][d+j], dp[i][d]*1ll*(mod + ps[r[i]][j] - ps[l[i]][j])%mod);
			}
		}
	}
	cout << dp[n][c];
}


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

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

    int M[n][n];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; ++i) {
        int u, k;
        std::cin >> u >> k;
        int v;
        for (int j = 0; j < k; ++j) {
            std::cin >> v;
            M[u-1][v-1] = 1;
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            std::cout << M[i][j];
            if (j != (n-1)) {
                std::cout << " ";
            }
        }
        std::cout << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int main() {
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=(c+b-1)/b;
  int y=(a+d-1)/d;
  if(x<=y)cout<<"Yes\n";
  else cout<<"No\n";
 	return 0;
}

Measured memory_bytes: 3600
#!/mnt/c/Users/moiki/bash/env/bin/python

N = int(input())
inp_list = [ list(map(int , input().split()))  for i in range(N)]


ans = 0
for e,t in enumerate(sorted(inp_list, key=lambda x : x[0] + x[1], reverse = True)):
    if e % 2 == 0:
        ans += t[0]
    else:
        ans -= t[1]
print(ans)

    


Measured memory_bytes: 32992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll maxn = 200005;
const ll N = 500005;
char s[200005];
ll dp[10005],n,p,ans=0;
int main(){  
	cin.tie(0); 
    ios::sync_with_stdio(false);
    cin>>n>>p>>(s+1);
    if(p==2||p==5){
        for(int i=1;i<=n;i++){
            if((s[i]-'0')%p==0){
                ans+=i;
            }
        }
    }
    else {
        ll tmp=0,base=1;
        for(int i=n;i>=1;i--){
            tmp=(tmp+(s[i]-'0')*base)%p;
            base=(base*10)%p;
            dp[tmp]++;  
        }
        ans+=dp[0]+1ll*dp[0]*(dp[0]-1)/2;
        for(int i=1;i<=p-1;i++) ans+=(dp[i]-1)*dp[i]/2;
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<llint,vector<llint>,greater<llint>> que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint n,m,x;
llint a[105];

void solve(){
	cin >> n >> m >> x;
	for(int i=0;i<m;i++)cin >> a[i];
	llint mp[105];
	for(int i=1;i<=n;i++)mp[i]=0;
	for(int i=0;i<m;i++)mp[a[i]]=1;
	llint a1=0,a2=0;
	for(int i=1;i<x;i++)a1+=mp[i];
	for(int i=x+1;i<=n;i++)a2+=mp[i];
	cout << min(a1,a2) << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
	PrintWriter out;
    StringTokenizer st;
    BufferedReader br;
 	
 	class Pair implements Comparable<Pair>
	{
	    int f;
	    int s;
 
	    Pair(int t, int r) {
	       f = t;
	       s = r;
	    }
	    public int compareTo(Pair p)
	    {
	    	if(this.f!=p.f)
	    		return this.f-p.f;
 
	    	return this.s-p.s;
	    }
 	}
 // 	class Sort implements Comparator<String> 
	// { 
	//     public int compare(String a, String b) 
	//     { 
	//     	return (a+b).compareTo(b+a);
	//     } 
	// }
 
	String ns() {
        while (st == null || !st.hasMoreElements()) {
 
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    String nextLine() throws Exception {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            throw new Exception(e.toString());
        }
        return str;
    }
 
    int nextInt() {
        return Integer.parseInt(ns());
    }
 
    long nextLong() {
        return Long.parseLong(ns());
    }
 
    double nextDouble() {
        return Double.parseDouble(ns());
    }
	
	int upperBound(long a[],long key)
	{
		int l=0,r=a.length-1;
		int i=-1;
 
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid]<key)
				l=mid+1;
 
			else{
				i=mid;	
				r=mid-1;
			}
			
		}
		return i;
	}
	int lowerBound(Pair[] a , long key)
	{
		int l = 0, r = a.length- 1;
		int i = -1;
 	
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid].f<key)
			{
				i=mid;
				l=mid+1;	
			}
 
			else
				r=mid-1;
			
		}
		return i;
	}
 
	long power(long x,long y)
	{
	    long ans=1;
	    
	    while(y!=0)
	    {
	        if(y%2==1) ans=(ans*x)%mod;
	        x=(x*x)%mod;
	        y/=2;
	    }
	    return ans%mod;
	}
	
 
	int mod= 1000000007;
	long gcd(long x ,long y)
	{
		if(y==0)
			return x;
		return gcd(y,x%y);
	}
 
	// ArrayList<Integer> a[];
	// TreeMap<Integer, Long> map;
	// int vis[];
	// long d[];
	// void dfs(int ver, int m)
	// {
	// 	map.put(ver, d[m % 3]);
	// 	for(int v : a[ver])
	// 	{
	// 		if(vis[v] == 0){
	// 			vis[v] = vis[ver] + 1;
	// 			dfs(v, m + 1);
	// 		}
	// 	}
	// }
 
 	int countSetBits(long n) 
    { 
        int count = 0; 
        while (n > 0) { 
            n &= (n - 1); 
            count++; 
        } 
        return count; 
    }

	void solve() throws IOException{
		int n = nextInt();
		int k = nextInt();
		int a[] = new int[n];

		for(int i = 0; i < n; i++)
			a[i] = nextInt();

		int f = 0;
		for(int s = k; s < n; s++)
		{
			if(a[s] > a[f++])
				out.println("Yes");
			else
				out.println("No");
		}		
	}
	
    void run() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
		solve();
		out.flush();
 
		out.close();
	}
 
	public static void main(String args[]) throws IOException {
		new Main().run();
	}
}



Measured memory_bytes: 56160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main (){
    ll h,res=0,quo=1;cin>>h;

    while(h){
            res+=quo;
            h/=2LL;
            quo*=2LL;
    }
    cout<<res;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M,sum=0,c=0;
    cin >> N >> M;
    int a[N];
    for(int i=0; i<N; i++){
        cin >> a[i];
        sum+=a[i];
    }
    for(int i=0; i<N; i++){
        if(4*M*a[i]>=sum) c++;
    }
    if(c>=M) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i];

    sort(v.rbegin(), v.rend());
    int ans = accumulate(v.begin(), v.begin() + k, 0);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = list(map(int,input().split()))

ans = 0
for i in range(N):
  A = list(map(int,input().split()))
  s = 0
  for i in range(M):
    s += A[i] * B[i]
  if s + C > 0:
    ans += 1
print(ans)

Measured memory_bytes: 3060
// Copyright 2019 zhouzhendong. All Rights Reserved.
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=1000005*2;
int n;
char s[N];
int a[N];
int pre[N],nxt[N];
int del[N];
int cnt[3];
void erase(int x){
	pre[nxt[x]]=pre[x];
	nxt[pre[x]]=nxt[x];
	del[x]=1;
	cnt[a[x]]--;
}
struct Node{
	int x,y,z;
	Node(){}
	Node(int _x,int _y,int _z){
		x=_x,y=_y,z=_z;
	}
};
queue <Node> q0[3],q1[3][3];
void Ins(int i){
	if (i==0||i==n+1)
		return;
	int x=pre[i],y=i,z=nxt[i];
	if (x==0||z==n+1||a[x]!=a[z])
		q0[a[y]].push(Node(x,y,z));
	else
		q1[a[y]][a[x]].push(Node(x,y,z));
}
int main(){
	cin>>(s+1);
	n=unique(s+1,s+1+strlen(s+1))-s-1;
	nxt[0]=1,pre[n+1]=n;
	a[n+1]=-1;
	For(i,1,n)
		nxt[i]=i+1,pre[i]=i-1;
	For(i,1,n)
		cnt[a[i]=s[i]-'A']++;
	for (int i=nxt[0];i!=n+1;i=nxt[i])
		Ins(i);
	while (1){
		int id[3]={0,1,2};
		sort(id,id+3,[&](int a,int b){return cnt[a]>cnt[b];});
		int c0=id[0],c1=id[1];
		if (cnt[0]==cnt[1]&&cnt[0]==cnt[2])
			break;
		if (!q0[c0].empty()){
			Node now=q0[c0].front();
			q0[c0].pop();
			if (del[now.x]||del[now.y]||del[now.z])
				continue;
			erase(now.y);
			Ins(now.x);
			Ins(now.z);
		}
		else {
			assert(!q1[c0][c1].empty());
			Node now=q1[c0][c1].front();
			q1[c0][c1].pop();
			if (del[now.x]||del[now.y]||del[now.z])
				continue;
			int w=pre[now.x];
			erase(now.x);
			erase(now.y);
			Ins(w);
			Ins(now.z);
		}
	}
    int cnt = 0;
	for (int i=nxt[0];i!=n+1;i=nxt[i])
		putchar('A'+a[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 48896
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
row = []
col = []
for i in range(n):
    k, *l = map(int, input().split())
    row += [i] * k
    col += [e + n - 1 for e in l]

cost = [1] * len(row)

graph = csr_matrix((cost, (row, col)), shape=(n + m, n + m))
_, labels = connected_components(graph)

bl = (labels[:n] == labels[0]).all()
print("YES" if bl else "NO")


Measured memory_bytes: 27976
#include <iostream>
#include <stdlib.h>
#include <math.h>

#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))

using namespace std;

int main(){
	int x[4] = {0,0,0,0};
	for (int i = 0; i < 3; i++) {
		int a, b;
		cin >> a >> b;
		x[a - 1]++;
		x[b - 1]++;
	}
	int count = 0;
	for (int i = 0; i < 4; i++) {
		if (x[i] == 0) { cout << "NO"; return 0; }
		if (x[i] % 2 != 0) {
			count++;
		}
	}
	if (count == 2) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 100000000000000000000
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define out(s) cout<<s
#define outs(s,a) cout<<s<<a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
void solve(){
	ll n,i;
	in(n);
	vll vec(n);
	nfl(i,n){
		in(vec[i]);
		if(vec[i]%2==0){
			if(vec[i]%3!=0 && vec[i]%5!=0){
				cout<<"DENIED\n";
				return;
			}
		}
	}
	cout<<"APPROVED\n";
}	
int main(){
	clock_t t1=clock();
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
	clock_t t2=clock();
	cerr<<"Time elapsed:- "<<(double)(t2-t1)/CLOCKS_PER_SEC<<'\n';
}	


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

    for(int j = 105 ; j <= n ; ++j){ 
      if(j%2!=0){
   	 for(int i = 1 ; i <= j ; ++i){ 
      if(j%i==0){
        count++;
      } 
     }
      }
     if(count == 8){
          ans++;
     }
     count = 0;
    }
    
    System.out.println(ans);
    
  }
}


Measured memory_bytes: 35868
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=20+10;
typedef pair<string,int>P;
map<string,int>save;
string s[MAX];
int d[5]={-1,1,-4,4};
void bfs(){
    queue<P>q;
    q.push(P("01234567",0));
    save["01234567"]=0;
    while(!q.empty()){
        P t=q.front();
        q.pop();
        int flag=t.second;
        for(int i=0;i<4;i++){
            if((flag==3&&d[i]==1||(flag==4&&d[i]==-1))||flag+d[i]<0||flag+d[i]>=8)
                continue;
            string str=t.first;
            swap(str[flag],str[flag+d[i]]);
            if(save.find(str)==save.end()){
                save[str]=save[t.first]+1;
                q.push(P(str,flag+d[i]));
            }
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    bfs();
    int a[10];
    while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7]){
        string siyu;
        char ch[10];
        for(int i=0;i<8;i++){
            ch[i]='0'+a[i];
        }
        ch[8]='\0';
        siyu=ch;
        cout<<save[siyu]<<endl;

    }
    return 0;
}

Measured memory_bytes: 5216
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

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

    int ans;

    // 緑の長方形が赤に触れているとき
    // b点
    if (a <= b && b <= a + W)
    {
        ans = 0;
    }
    // b + W 点
    else if (a <= b + W && b + W <= a + W)
    {
        ans = 0;
    }
    else if (a + W < b)
    {
        ans = abs(b - (a + W));
    }
    else if (b + W < a)
    {
        ans = abs(a - (b + W));
    }
    cout << ans << endl;
    return (0);
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

vector<bool> prime(){
    vector<bool> v(100050,true);
    for(int i=2;i*i<100050;++i)if(v[i]){
        for(int j=i*2;j<100050;j+=i)v[j] = false;
    }
    return v;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    auto v = prime();
    vector<int> a(100005);
    for(int i=2;i<=100000;++i)if(i%2==1){
        if(v[i] and v[(i+1)/2]) a[i] = 1; 
    }
    for(int i=1;i<=100000;++i)a[i] += a[i-1];
    int q;
    cin>>q;
    for(int i=0;i<q;++i){
        int l,r;
        cin>>l>>r;
        l--;
        cout << a[r] - a[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << (n) * (n - 1) / 2 + m * (m - 1) / 2 << "\n";
    return 0;
}

Measured memory_bytes: 256
import Foundation

let input = readLine()!
let inputArray = input.components(separatedBy: " ")
let A = Int(inputArray[0])!
let B = Int(inputArray[1])!
let C = Int(inputArray[2])!
let K = Int(inputArray[3])!

if A + B > K {
    print(K)
} else {
    var remain = K - A - B
    print(A - remain)
}


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

int main()
{
  string input;
  cin >> input;
  int s=0;
  for(int i = 0; i < (int)input.size(); ++i){
    char a = input[i];
    s+=a-'0';
  }
  if(stoi(input) % s == 0)printf("Yes\n");
  else printf("No\n");
  return 0;
}


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

using namespace std;

//void substring_dfs(vector < int, int > substring){
    
//}


int main(int argc, const char * argv[]) {
    // insert code here...
    
    int a,b;
    cin >> a >> b;
    
    if (b < a && a > 1) {
        a--; b = a;
    }
    
    cout << min(a,b) << endl;
    
    return 0;
}


Measured memory_bytes: 256
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim n As Integer = NextInt()
        Dim a As Integer = NextInt()
        Dim b As Integer = NextInt()

        WriteLine(Math.Max(0, CLng(b - a) * (n - 2) + 1))
    End Sub

    Function Contains(dic As List(Of Integer()), abc As Integer()) As Boolean
        For Each dic_i As Integer() In dic
            Dim flg As Boolean = False
            Dim j As Integer = 0
            For Each dic_ij As Integer In dic_i
                If dic_ij <> abc(j) Then
                    flg = True
                End If
                j += 1
            Next
            If Not flg Then Return True
        Next
        Return False
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module


Measured memory_bytes: 19920
def dfs(board,y,x):
    if not board[y][x]:
        return 0
    board[y][x]=0
    dx,dy=[0,1,0,-1],[1,0,-1,0]
    for i in xrange(4):
        dfs(board,y+dy[i],x+dx[i])
    return 1
while True:
    try:
        board=[[0]+map(int,raw_input()[:])+[0] for unused in xrange(12)]
        board.insert(13,[0]*14)
        board.insert(0,[0]*14)
        print sum([dfs(board,i/12+1,i%12+1) for i in xrange(12*12)])
        raw_input()
    except:
        break

Measured memory_bytes: 4316
n = int(input())
A = list(map(int, input().split()))
if A.count(0) != 0:
    print(0)
    exit()
for i, a in enumerate(A):
    if i == 0:
        ans = a
    elif ans > 10**18:
        print(-1)
        exit()
    else:
        ans = ans*a
if ans > 10**18:
    print(-1)
    exit()
print(ans)


Measured memory_bytes: 21612
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
  string s, t;
  cin >> s >> t;
  int count = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == t[i])
      ++count;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        if (n % k == 0) {
            System.out.println(0);
            return;
        }
        long mod = Math.abs(n % k - k);
        System.out.println(Math.min(n % k, mod));
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int cnt[100100];

int main() {
	int N;
	cin >> N;
	rep(i,N) {
		int a;
		cin >> a;
		cnt[a]++; cnt[a+1]++; cnt[a+2]++;
	}
	int res = 0;
	rep(i,100100) {
		res = max(res, cnt[i]);
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 640
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,i;cin>>n;
	vector<int>b(n);
	for(i=0;i<n;i++){cin>>b[i];}
	for(i=0;i<n;i++){
		if(i+1<b[i]){cout<<"-1"<<endl;return 0;}
	}
	vector<int>c;
	while(b.size()){
		for(i=b.size()-1;i>=0;i--){
				if(b[i]==i+1){c.pub(i+1);b.erase(b.begin()+i);break;}
		}
	}
	REV(c);
	for(auto it:c){cout<<it<<endl;}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		if(N < A) System.out.println("Broys");
		if((B - A) % 2 == 0) {
			System.out.println("Alice");
		}else {
			System.out.println("Borys");
		}
	}
}

Measured memory_bytes: 23124
N = int(input())
S = input()
dp = [[] for _ in range(N)]
white = black = 0
for i in range(N):
    if S[i] == '.':
        white += 1
    else:
        black += 1
    dp[i] = [white, black]
W = S.count('.')
B = N - W #黒石の数
answer = W
for i in range(N):
    # iの場所より左側を全て白、右側を黒にする
    change = dp[i][1] + (W - dp[i][0])
    if change < answer:
        answer = change
print(answer)

Measured memory_bytes: 30056
N, M = map(int, input().split())
X = list(map(int, input().split()))
if N < M:
    X.sort()
    XX = [X[i + 1] - X[i] for i in range(M - 1)]
    XX.sort()
    ans = sum(XX[:M - N])
else:
    ans = 0
print(ans)

Measured memory_bytes: 13968
import sys
readline = sys.stdin.readline

a = list(map(int,input().split()))
N = a[0]
M = a[1]
cnt = [0,]*(M+1)
ans = 0
for i in range(N):
    K, *like, = readline().split()
    K = int(K)
    like = [int(s) for s in like]
    for j in range(K):
        cnt[like[j]] += 1
for i in range(1, M+1):
    if cnt[i] == N:
        ans += 1
print(str(ans))


Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main(void)
{
    int x, h;
    double s;
while(1){
    scanf("%d", &x);
    scanf("%d", &h);
if(x==0&&h==0)
break;
    s = x*x + x * sqrt(x*x + 4.0*h*h);
    printf("%f\n", s);
}

    return 0;
}

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int mod = 1e9 + 7;

int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 25;

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

int n, m, d[MAXN][MAXN];
char c[MAXN][MAXN];

int solve(int x, int y){
  queue<point> Q; Q.push(point(x, y));
  memset(d, -1, sizeof(d));
  int ret = 0;
  d[x][y] = 0;

  while(!Q.empty()){
    auto kord = Q.front(); Q.pop();
    x = kord.first, y = kord.second;

    REP(i, 4){
      int nx = x + dx[i], ny = y + dy[i];
      if(nx < 0 || ny < 0 || nx >= n || ny >= m || d[nx][ny] != -1 || c[nx][ny] == '#') continue;
      d[nx][ny] = d[x][y] + 1;
      Q.push(point(nx, ny));
      ret = max(ret, d[nx][ny]);
    }
  }
  return ret;
}

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

  cin >> n >> m;
  REP(i, n) REP(j, m) cin >> c[i][j];

  int sol = 0;
  REP(i, n) REP(j, m)
    if(c[i][j] == '.')
      sol = max(sol, solve(i, j));
  cout << sol;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long 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 main() {
    int n;
    cin >> n;
    vector<int>a(n),b(n);
    rep(i,n) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(n%2==1) {
        int minv = a[n/2];
        int maxv = b[n/2];
        cout << maxv-minv+1 << endl;
        return 0;
    } else {
        int minv = (a[n/2-1]+a[n/2]);
        int maxv = (b[n/2-1]+b[n/2]);
        cout << (maxv-minv)+1 << endl;
    }

}

Measured memory_bytes: 4804
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <cmath>
using namespace std;

#define INF 1e18
#define int long long
static const int MAX = 110;
static const int NOTFIXED = 0;
static const int FIXED = 1;

int n, m[MAX][MAX];

void dijkstra() {
    int d[n], status[n];
    for(int i = 0; i < n; i++) {
        d[i] = INF;
        status[i] = NOTFIXED;
    }
    d[0] = 0;
    status[0] = NOTFIXED;

    while(true) {
        int u = -1;
        int minv = INF;
        for(int i = 0; i < n; i++) {
            if(minv > d[i] && status[i] != FIXED) {
                u = i;
                minv = d[i];
            }
        }

        if(u == -1) break;
        status[u] = FIXED;
        for(int v = 0; v < n; v++) {
            if(m[u][v] != INF && status[v] != FIXED) {
                if(d[v] > d[u] + m[u][v]) {
                    d[v] = d[u] + m[u][v];
                    status[v] = NOTFIXED;
                }
            }
        }
    }

    for(int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
    }
}

signed main() {
    cin >> n;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            m[i][j] = INF;
        }
    }

    for(int i = 0; i < n; i++) {
        int u, k; cin >> u >> k;
        for(int j = 0; j < k; j++) {
            int v, c; cin >> v >> c;
            m[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}



Measured memory_bytes: 3204
import java.util.Scanner;

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

        for(int i = 0; i < s.length(); i++) {
            if((i+1) % 2 != 0) {
                str.append(s.charAt(i));
            }
        }
        System.out.println(str.toString());
    }
}


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

ll solve(ll h) {
    if (h == 1) return 1;
    return 1 + (2 * solve(h / 2));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h;
    cin >> h;
    cout << solve(h);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

bool check(int n){
  string s = to_string(n);
  return s.size() % 2 == 1;
}

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

  int n;
  while(cin >> n){
    int ans = 0;

    FORE(i,1,n){
      if(check(i)){
        ++ans;
      }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

typedef pair<ll, int> pli;

struct node{
  pli val;
  int H, sum;
  node *L , *R;
  node(pli _val = pli(0,0)){
   val = _val;
   H = rand();
   L = R = null;
   sum = 1;
                           }
};

int get(node* vr){
  return vr ? vr->sum : 0;
}

void update(node* vr){
  if(vr){
    vr->sum = 1 + get(vr->L) + get(vr->R);
  }
}

void split(node* vr , const pli& on , node*& l , node*& r){
  if(!vr){
   l = r = null;
   return;
         }
  if(vr->val >= on){
   split(vr->L , on , l , vr->L);
   r = vr;
   update(r);
                   }
  else{
   split(vr->R , on , vr->R , r);
   l = vr;
   update(l);
      }
}

node* merge(node* l , node* r){
  if(!l || !r)return l ? l : r;
  if(l->H < r->H){
   l->R = merge(l->R , r);
   update(l);
   return l;
                 }
  else{
   r->L = merge(l , r->L);
   update(r);
   return r;
      }
}

int main(){
  int n, k;
  scanf("%d%d", &n, &k);
  vi in(n);
  for(int& e : in)
    scanf("%d", &e),
    e -= k;

  node* tree = new node(mp(0, -1));
  ll ps = 0;
  ll ans = 0;
  for(int i = 0;i < n;++i){
    ps += in[i];

    node *l, *r;
    split(tree, pli(ps, (int) 1E9), l, r);
    ans += get(l);
    tree = merge(l, r);

    split(tree, pli(ps, i), l, r);
    tree = merge(l, merge(new node(pli(ps, i)), r));
  }

  cout << ans << '\n';

  return 0;
}


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

int main(){
	int N,M; cin>>N>>M;
	vector<int> A(N);
	int tot = 0;
	rep(i, N){
		cin>>A[i];
		tot += A[i];
	}
	int c = 0;
	rep(i, N) if(tot <= A[i]*4*M) c++;
	puts(c >= M? "Yes":"No");
}

Measured memory_bytes: 256
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

/*-------------------------------------------------------------------------------------------------------------------------*/
#define ll long long                  // Short form for long long
#define ld long double                // Short form for long double
typedef pair<ll, ll> ii;              // Pair of long long
typedef vector<ll> vi;                // Vector of long long
typedef vector<vi> vvi;               // Vector of vector of long long
typedef vector<ii> vii;               // Vector of pairs
typedef vector<vii> vvii;             // Vector of vector of pairs
#define pq priority_queue             // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                      // For pairs
#define ss second                     // For pairs
#define pb push_back                  // Pushback to vector
#define mp make_pair                  // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end() // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
/*-------------------------------------------------------------------------------------------------------------------------*/

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, a, b;
    cin >> n >> a >> b;

    if (n < (a + b - 1) || n > (a * b))
    {
        cout << "-1\n";
        return 0;
    }

    for (int i = b; i >= 1; i--)
        cout << i << " ";

    n -= b;
    a--;

    if (a == 0)
        return 0;

    ll each = n / a;
    ll extra = n % a;

    ll curr = b;

    for (int i = 0; i < extra; i++)
    {
        for (int j = curr + each + 1; j > curr; j--)
            cout << j << " ";
        curr += each + 1;
    }

    a -= extra;
    for (int i = 0; i < a; i++)
    {
        for (int j = curr + each; j > curr; j--)
            cout << j << " ";
        curr += each;
    }
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <algorithm>

const int N = 2e5 + 10;

int n;
int a[N], pos[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    pos[x] = i;
  }
  int i = 1, ans = n;
  while (i <= n) {
    int j = i + 1, del = 1;
    while (j <= n && pos[j - 1] < pos[j]) {
      ++del;
      ++j;
    }
    ans = std::min(ans, n - del);
    i = j;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 896
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  long[char] cnt;
  foreach (_; 0..n) {
    cnt[readln.chomp[0]]++;
  }

  long sum;
  auto ini = ['M', 'A', 'R', 'C', 'H'];
  foreach (i; 0..ini.length) {
    if (!cnt.get(ini[i], 0)) continue;
    long ltmp = cnt[ini[i]];
    foreach (j; i+1..ini.length) {
      if (!cnt.get(ini[j], 0)) continue;
      ltmp *= cnt[ini[j]];
      foreach (k; j+1..ini.length) {
        if (!cnt.get(ini[k], 0)) continue;
        ltmp *= cnt[ini[k]];
        sum += ltmp;
        ltmp /= cnt[ini[k]];
      }
      ltmp /= cnt[ini[j]];
    }

  }

  sum.writeln;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll a,b;cin>>a>>b;
    cout << max(a+b,max(a-b,a*b)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b &&  b == c) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N=105;
 
int n, ans=0;
int a[N];
 
int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		while(a[i]>0)
		{
			int j;
			for(j=i;j<=n;j++)
			{
				if(a[j]==0)
					break;
			}
			for(int k=i;k<j;k++)
				a[k]--;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) (v).begin(),(v).end()
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
ll dp1[5001];
ll dp2[5000 * 5000 + 1];
int main() {
	int N;
	cin >> N;
	vector<int> A(3);
	vector<int> B(3);
	for (int i = 0; i < 3; i++) cin >> A[i];
	for (int i = 0; i < 3; i++) cin >> B[i];
	for (int i = 0; i < 3; i++) {
		for (int j = A[i]; j <= N; j++) {
			dp1[j] = max(dp1[j], dp1[j - A[i]] + (B[i] - A[i]));
		}
	}
	int M = N + dp1[N];
	for (int i = 0; i < 3; i++) {
		for (int j = B[i]; j <= M; j++) {
			dp2[j] = max(dp2[j], dp2[j - B[i]] + (A[i] - B[i]));
		}
	}
	cout << M + dp2[M] << endl;
}


Measured memory_bytes: 195584
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 100002;

int n;
ll L, t;

ll x[N_MAX];

int w[N_MAX];

vector <int> v1, v2;

int ans[N_MAX];

int last1 (int pos)
{
    int l = 0, r = (int)v1.size() - 1;
    while(l < r)
    {
        int mid = ((l + r + 1) >> 1);
        if(x[v1[mid]] > pos)
            r = mid - 1;
        else
            l = mid;
    }
    return l;
}

int last2 (int pos)
{
    int l = 0, r = (int)v2.size() - 1;
    while(l < r)
    {
        int mid = ((l + r + 1) >> 1);
        if(x[v2[mid]] > pos)
            r = mid - 1;
        else
            l = mid;
    }
    return l;
}

int cnt1 (int l, int r)
{
    l = (l % L + L) % L;
    r = (r % L + L) % L;
    if(l <= r)
        return last1(r) - last1(l - 1);
    else if(l - r > 1)
        return (int)v1.size() - 1 - cnt1(r + 1, l - 1);
    return 0;
}

int cnt2 (int l, int r)
{
    l = (l % L + L) % L;
    r = (r % L + L) % L;
    if(l <= r)
        return last2(r) - last2(l - 1);
    else if(l - r > 1)
        return (int)v2.size() - 1 - cnt2(r + 1, l - 1);
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> L >> t;
    v1.push_back(0);
    v2.push_back(0);
    for(int i = 1; i <= n; i++)
    {
        cin >> x[i] >> w[i];
        if(w[i] == 1)
            v1.push_back(i);
        else
            v2.push_back(i);
    }
    for(int i = 1; i <= n; i++)
        if(w[i] == 1)
        {
            int pos = (x[i] + 2LL * t) % L;
            int c = (cnt2(x[i], pos) + (2LL * t / L) * ((int)v2.size() - 1) % n) % n;
            int j = ((i - 1 + c) % n + n) % n + 1;
            ans[j] = ((pos - t) % L + L) % L;
        }
        else
        {
            int pos = ((x[i] - 2LL * t) % L + L) % L;
            int c = (cnt1(pos, x[i]) % n + (2LL * t / L) * ((int)v1.size() - 1) % n) % n;
            int j = ((i - 1 - c) % n + n) % n + 1;
            ans[j] = (pos + t) % L;
        }
    for(int i = 1; i <= n; i++)
        cout << ans[i] << "\n";
    return 0;
}


Measured memory_bytes: 5368
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int s=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		while(x%2==0){
			s++;
			x=x>>1;
		}
	}
	cout<<s<<endl;
	return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 2000005;

/* ...o(^-^)o... */

int main(){
    int a; cin >> a;
    out(a+a*a+a*a*a);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;

int n, Ma, Mb;
int dp[50][500][500];
vector<int> a(50, 0);
vector<int> b(50, 0);
vector<int> c(50, 0);

int main() {
    cin >> n >> Ma >> Mb;
    int amax = 0; int bmax = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a.at(i) >> b.at(i) >> c.at(i);
        amax += a.at(i);
        bmax += b.at(i);
    }

    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= amax; ++j) {
            for(int k = 0; k <= bmax; ++k) {
                dp[i][j][k] = INF;
            }
        }
    }

    dp[0][0][0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= amax; ++j) {
            for(int k = 0; k <= bmax; ++k) {
                chmin(dp[i+1][j+a.at(i)][k+b.at(i)], dp[i][j][k]+c.at(i));
                chmin(dp[i+1][j][k], dp[i][j][k]);
            }
        }
    }

    int ans = INF;
    for(int i = 1; i <= amax; ++i) {
        for(int j = 1; j <= bmax; ++j) {
            if(i % Ma == 0 && j % Mb == 0) {
                if((i / Ma) == (j / Mb)) {
                    chmin(ans, dp[n][i][j]);
                }
            }
        }
    }

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

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 40320
import sys
a, b, c, k = map(int, input().split())
r = 0
x = min(a, k)
k -= x
r += x
if k==0:
    print(r)
    sys.exit()
k -= b
if k <= 0:
    print(r)
    sys.exit()
x = min(k, c)
r -= x
print(r)


Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define FILE freopen("input.txt", "r", stdin)

using namespace std;

const int MAXN = 100001;
const int mod = 1000000007;

typedef long long ll;

int n, m;
vector<int> adj[MAXN];

ll dp1[MAXN];
ll dp2[MAXN];

void dfs1(int x, int p){
	dp1[x] = 1;
	for(int c : adj[x]){
		if(c != p){
			dfs1(c, x);
			dp1[x] = dp1[x] * (dp1[c]+1)%m;
		}
	}
}

void dfs2(int x, int p){

	vector<ll> sf;
	ll mul = 1;
	sf.push_back(mul);

	for(int i = adj[x].size()-1; i >= 0; --i){
		if(adj[x][i] != p){
			mul = (mul * (1+dp1[adj[x][i]]))%m;
			sf.push_back(mul);
		}
	}

	mul = 1;

	for(int c : adj[x]){
		if(c != p){
			ll tt = (mul * sf[sf.size()-2])%m;
			dp2[c] = (tt * dp2[x] + 1)%m;
			mul = mul * (1+dp1[c]) % m;
			sf.pop_back();
			dfs2(c, x);
		}
	}
}


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

	for(int i= 1; i < n; ++i){
		int u, v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dp2[1] = 1;

	dfs1(1, 0);
	dfs2(1, 0);

	for(int i = 1; i <= n; ++i){
		cout<< dp1[i] * dp2[i] %m << endl;
	}

}

Measured memory_bytes: 18432