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

int main() {
  int S, h, m, s;
  cin >> S;

  h = S / 3600;
  m = (S % 3600) / 60;
  s = (S % 3600) % 60;

  cout << h << ':' << m << ':' << s << endl;

  return 0;
}



Measured memory_bytes: 3088
n,m,c=map(int,input().split())
B=list(map(int,input().split()))
A=[list(map(int,input().split())) for _ in range(n)]

res=0

for i in range(n):
	cnt=c
	for j in range(m):
		cnt+=A[i][j]*B[j]
	if cnt>0:
		res+=1
		
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

map<string, int> mp;
map<string, vector<string> > mp2;

int solve(string s) {
  if (mp2.count(s)) {
    int a = 0;
    FOR(it, mp2[s])
      a += solve(*it);
    return min(a, mp[s]);
  }
  return mp[s];
}

int main() {
  int n;
  while(cin>>n, n) {
    mp.clear();
    REP(i,n) {
      string s;
      int p;
      cin >> s >> p;
      mp[s] = p;
    }
    int m;
    cin >> m;
    mp2.clear();
    REP(i,m) {
      string s;
      int k;
      cin >> s >> k;
      vector<string> v;
      REP(j,k) {
        string t;
        cin >> t;
        v.push_back(t);
      }
      mp2[s] = v;
    }
    string s;
    cin >> s;
    cout << solve(s) << endl;
  }
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct bian{int nxt,to;}bi[4040];
int n,head[2020],num,ans=0x3f3f3f3f,dis[2020],dp[2020],tot[2020],siz[2020];
char s[2020];
inline void add(int from,int to){bi[++num]=bian{head[from],to};head[from]=num;}
void dfs(int v,int fa)
{
	dp[v]=tot[v]=0,siz[v]=s[v]=='1';
	for(int i=head[v],u;i;i=bi[i].nxt)
	{
		u=bi[i].to;
		if(u==fa)continue;
		dfs(u,v);
		if(!siz[u])continue;
		siz[v]+=siz[u],dp[u]+=siz[u],tot[u]+=siz[u];
		if(tot[v]<dp[u])dp[v]=dp[u]-tot[v];
		else if(tot[u]<dp[v])dp[v]=dp[v]-tot[u];
		else dp[v]=(tot[v]+tot[u])&1;
		tot[v]+=tot[u];
	}
//	printf("%d %d %d\n",v,dp[v],tot[v]);
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	int x,y;
	for(int i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	for(int i=1;i<=n;++i)
	{
	//	printf("%d:\n",i);
		dfs(i,0);
		if(dp[i]==0)/*printf("%d ",i),*/ans=min(ans,tot[i]/2);
	}
	if(ans==0x3f3f3f3f)printf("-1");
	else printf("%d",ans);
	return 0;
}


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

priority_queue<int> pq;

int main() {
	int n, m;
	cin >> n >>m;
	for(int i = 0; i < n; i++) {
		int x; cin >> x; pq.push(x);
	}
	for(int i = 0; i < m; i++) {
		int k = pq.top();
		pq.pop();
		k = k/2;
		pq.push(k);
	}
	long long res = 0;
	while(!pq.empty()) {
		res += (long long)pq.top();
		pq.pop();
	}
	cout << res << endl;
	return 0;

}


Measured memory_bytes: 892
// Need start
#include<iostream>
// Need end
#include<vector>
using namespace std;

// Copy start
template<typename T, long long modulus=1000000007>
class ModInt {
    private:
        T value_;
    public:
        ModInt() {}
        ModInt(const T& _value) {
            value_ = _value % modulus;
        }
        ModInt(const ModInt& x) {
            value_ = x.value_;
        }
        T getValue() const {
            return value_;
        }
        ModInt& operator=(const ModInt& x) {
            value_ = x.value_;
            return *this;
        }
        ModInt& operator+=(const ModInt& x)  {
            value_ += x.value_;
            if (value_ >= modulus) value_ -= modulus;
            return *this;
        }
        ModInt& operator-=(const ModInt& x) {
            if (value_ < x.value_) value_ += modulus;
            value_ -= x.value_;
            return *this;
        }
        ModInt& operator*=(const ModInt& x) {
            value_ = (value_ * x.value_) % modulus;
            return *this;
        }
        ModInt& operator/=(const ModInt& x) {
            T now_value = x.value_;
            long long cnt = modulus - 2;
            while (cnt > 0) {
                if (cnt & 1) {
                    value_ = (value_ * now_value) % modulus;
                }
                now_value = (now_value * now_value) % modulus;
                cnt /= 2;
            }
            return *this;
        }
        ModInt operator+(const ModInt& x) const {
            return ModInt(*this) += x;
        }
        ModInt operator-(const ModInt& x) const {
            return ModInt(*this) -= x;
        }
        ModInt operator*(const ModInt& x) const {
            return ModInt(*this) *= x;
        }
        ModInt operator/(const ModInt& x) const {
            return ModInt(*this) /= x;
        }
        ModInt operator++(int) {
            ModInt tmp(*this);
            value_ = (value_ + 1 == modulus ? 0 : value_ + 1);
            return tmp;
        }
        ModInt operator--(int) {
            ModInt tmp(*this);
            value_ = (value_ - 1 < 0 ? modulus - 1 : value_ - 1);
            return tmp;
        }
        friend std::istream& operator>>(std::istream& stream, ModInt& x) {
            stream >> x.value_;
            x.value_ %= modulus;
            return stream;
        }
        friend std::ostream& operator<<(std::ostream& stream, const ModInt& x) {
            stream << x.value_;
            return stream;
        }
};
// Copy end

using ll = long long;
using mint = ModInt<ll>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    mint K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    mint ans = 0;
    mint one(1), two(2);
    for (int i = 0; i < N; ++i) {
        mint prev(0), tail(0);
        for (int j = 0; j < i; ++j) {
            if (A[i] < A[j]) prev++;
        }
        for (int j = i; j < N; ++j) {
            if (A[i] < A[j]) tail++;
        }
        mint sum = K * (two * prev + (K - one) * (prev + tail)) / two;
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(min(a,min(b,c))==a)
		cout<<a+min(b,c);
	else
		if(min(a,min(b,c))==b)
			cout<<b+min(a,c);
		else
			cout<<c+min(a,b);
	return 0;
}

Measured memory_bytes: 256
/* Life is all about calculated risks.
    But man am I bad at math. */

#include <bits/stdc++.h> 
#define ll long long int
#define ld long double
#define INF (ll)1e12
#define MOD 1000000007

#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;

using namespace std;

ld f(ll a, ll b, ll c);

ll n;
ll a[310];
vector<vector<vector<ld>>> dp(310, vector<vector<ld>>(310, vector<ld>(310,-10)));

vector<ll> cnt(5,0);

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

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

    printf("%.10Lf", f(cnt[1],cnt[2],cnt[3]));

    return 0;
}

ld f(ll a, ll b, ll c)
{
  	if(a<0||b<0||c<0) return 0;
    if(dp[a][b][c] > -1)
    {
        return dp[a][b][c];
    }

    if(a==0 && b==0 && c==0)
    {
        return dp[a][b][c] = 0;
    }

    return dp[a][b][c] = (ld)n/(ld)(a+b+c) + ((ld)a/(ld)(a+b+c))*f(a-1,b,c) + ((ld)b/(ld)(a+b+c))*f(a+1,b-1,c) + ((ld)c/(ld)(a+b+c))*f(a,b+1,c-1); 
}


Measured memory_bytes: 471040
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll n,a;
    cin>>n;
    map<ll,ll> mp;
    rep(i,n){
        cin>>a;
        mp[a]++;
    }
    ll cnt=0;
    for(auto x:mp){
        if(x.second%2) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
int main(void){
int n,count=0;
  scanf("%d",&n);
  char s[n+1];
  scanf("%s",&s);
  int t[4];
  for(int  i=0;i<10;i++){
	for(int  j=0;j<10;j++){
      
	for(int k=0;k<10;k++){
       t[0]=i;
      t[1]=j;
      t[2]=k;
      int flag1=0;
      int flag2=0;
      int flag3=0;
     // printf("%d %d %d\n",i,j,k);
      	for(int l=0;l<n;l++){
		if(!flag1&&(s[l]-'0')==t[0]){
         // printf("1桁目は%d ",t[0]);
          flag1=1;
          flag2=1;
          continue;
        }
          if(flag2&&(s[l]-'0')==t[1]){
            flag3=1;
            flag2=0;
           //  printf("2桁目は%d ",t[1]);
            continue;
          }
          if(flag3&&(s[l]-'0')==t[2]){
          //   printf("%d %d %d\n",t[0],t[1],t[2]);
            count++;
            break;
          }
        }
    }}}
  printf("%d",count);
  return 0;
}

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

#define mp make_pair
#define pb push_back
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0)
#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout)
#define sz(x) ((int)((x).size()))
#define len(x) ((int)((x).length()))
#define x first
#define y second
#define foreach(it, v) for (auto it : v)
#define rep(it, n) for (int it = 0; it < n; ++it)
#define forin(it, l, r) for (int it = l; it < r; ++it)
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1 << 31) - 1;
const ll LINF = (1ll << 63) - 1;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
mt19937 mmtw(MOD);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }
template <class T> T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; }
template <class T> T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; }
////////////////////////////////////////////////////////////////////////////////////////////////

const int MAXN = 1e5 + 5;
int n;
int a[MAXN];
int res, t;

int main() {
    FAST_IO;
    cin >> n;
    rep(i, n) {
        cin >> t;
        if (a != 0) {
            a[t - 1]++;
        }
        a[t]++;
        a[t + 1]++;
    }
    cout << arr_max(a, 1e5 + 2) << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	int n; cin >> n;
	int count = 0; string s; bool f = true;
	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s == "A")count++;
		else count--;
		if (count < 0)f = false;
	}
	if (f&&count==0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 3164
#include<iostream>

using namespace std;

int main(){

 int n;

 while(cin >> n,n){

  int a,b=0;

  for(int i=1;i<=n;i++){

    for(int t=2;t<=n;t++){

      a=i*t+(t*(t-1)/2);

      if(a==n){

    b=b+1;

      }

    }

    

  }

  cout << b<<endl;

 }

  return 0;

}

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

signed main(){
    long long a , b , x , y ,ans = 1;
    int gcd[1000005] = {};
    cin >> a >> b;
    x = a , y = b;
    for(int i=2 ; (long long)i*i<=y && a>1 ;i++){
        if(a%i == 0){
            while(a%i == 0){
                a/=i;
            }
            gcd[i] = 1;
        }
    }
    for(int i=2 ; (long long)i*i<=y && b>1 ;i++ ){
        if(b%i == 0){
            while(b%i == 0){
                b/=i;
            }
            ans += gcd[i];
        }
    }
    
    if(a > 1 && b > 1 && (a%b == 0 || b%a == 0)){
        ans++;
    }
    cout << ans << endl;
    return(0);
}


Measured memory_bytes: 4096
N,M = map(int,input().split())
a = set(int(input()) for x in range(M))
A = [0]*(N+1)
mod = 1000000007
A[0] = 1
if not(1 in a):
  A[1] = 1
for i in range(2,N+1):
    if i in a:
      A[i] = 0
    else:
      A[i] = (A[i-2] + A[i-1]) % mod
print(A[N])


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl







void relax(int &x, int y) {
    x=min(x,y);
}



const int N = 18;
const int inf = 1e9 + 10;


int n;
int dp[1<<N][N]; // # of swaps if mask of cards placed, last card placed is i
int a[N], b[N];


// Build cards into prefix. The contribution total swaps will be count of inversions at time of swap.
// Use parity of distance to determine whether top/bottom of card is used.

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }
    for (int i=0; i<n; i++) {
	cin>>b[i];
    }

    for (int mask=0; mask<1<<n; mask++) {
	for (int i=0; i<n; i++) {
	    dp[mask][i]=inf;    
	}
    }
    
    for (int i=0; i<n; i++) {
	dp[1<<i][i]=0;
    }

    for (int mask=1; mask<1<<n; mask++) {
	for (int i=0; i<n; i++) {
	    int pre = __builtin_popcount(mask);
	    // odd distance means card is flipped, even vice versa
	    int x = (i%2==(pre-1)%2 ? a[i] : b[i]);

	    for (int j=0; j<n; j++) {
		if (mask>>j&1) continue;
		int y = (j%2==pre%2 ? a[j] : b[j]);
		if (y<x) continue;
		
		// # of inversions with j: # of elems < y that have idx > j.
		int cost = dp[mask][i] + __builtin_popcount(mask>>j);
		relax(dp[mask|(1<<j)][j], cost);
	    }
	}
    }

    int res=inf;
    for (int i=0; i<n; i++) {
	relax(res, dp[(1<<n)-1][i]);
    }

    if (res==inf) res=-1;
    cout<<res<<endl;
    
    return 0;
}


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

int main(){

	unordered_map<string,int> f;

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		string s;
		cin>>s;
		f[s]++;
	}

	vector<pair<int,string>> ans;

	for(auto i:f){
		ans.push_back({i.second,i.first});
	}
	sort(ans.begin(),ans.end());

	n = ans.size();

	int m = ans[n-1].first;
	int j = 0;

	for(int i = 0; i < n; i++){
		if(ans[i].first == m){
			j = i;
			break;
		}
	}

	for(; j < n; j++)
		cout<<ans[j].second<<"\n";
	return 0;
}

Measured memory_bytes: 29252
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

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

  ArrayList<timeData> stock = new ArrayList<timeData>();
  ArrayList<timeData> result = new ArrayList<timeData>();
  ArrayList<timeData> under2 = new ArrayList<timeData>();

  void doIt(){
    for(int i=0;i<3;i++) {
      octetRead();
      // b_arrdisp("Data Read");
      toGrandStage();
    }
    toGrandStage(under2);
    // b_arrdisp("Grand Final");
    // System.out.println();

    for(timeData k : result){
      System.out.printf("%d %.2f%n",k.number,k.time);
    }
  }

  private timeData readData(){
    return new timeData(sc.nextInt(),sc.nextDouble());
  }

  private void octetRead(){
    for(int i=0;i<8;i++) stock.add(readData());
  }

  private void cropTimeTop2(){
    Collections.sort(stock);
    // b_arrdisp("Sorted");
    result.add(stock.get(0));
    result.add(stock.get(1));
    stock.remove(0);
    stock.remove(0);
  }

  private void toGrandStage(){
    cropTimeTop2();
    under2.addAll(stock);
    stock.clear();
  }

  private void toGrandStage(ArrayList<timeData> datainpt){
    stock.addAll(datainpt);
    toGrandStage();
  }

  private class timeData implements Comparable<timeData>{
    int number;
    double time;

    public timeData(int number,double time){
      this.number = number;
      this.time = time;
    }

    public int compareTo(timeData left){
      if(left.time < this.time) return 1;
      else return -1;
    }

    @Override
    public String toString(){
      return this.number + " " + this.time;
    }
  }

  private void b_arrdisp(String com){
    System.out.println(com);
    System.out.println("stock");
    System.out.println(stock);
    System.out.println("under2");
    System.out.println(under2);
    System.out.println("result");
    System.out.println(result);
  }
}

Measured memory_bytes: 28500
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(X: int):

    # 和で表現される場合
    upper = 160
    for a in range(-upper, upper+1):
        for b in range(-upper, upper+1):
            if X == a**5-b**5:
                print(a, b)
                return
    # # 差で表現される場合
    # upper = 120
    # for a in range(upper+1):
    #     for b in range(a, upper+1):
    #         if X == a**5-b**5:
    #             print(a, b)
                # return
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)


if __name__ == '__main__':
    main()


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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  rep(i, m) cin >> b[i];
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) rep(j, m) cin >> a[i][j];
  
  int ans = 0;
  rep(i, n) {
    int d = c;
    rep(j, m) d += a[i][j] * b[j];
    if (d > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int W,H;
bool inrange(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define MP make_pair
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class Dinic{//max flow
public:
    int n;
    vector<vector<edge> >G;//[MAX];
    vi level,iter;//[MAX];
    Dinic(int size){
        n=size;
        G=vector<vector<edge> >(n);
    }
    void add_edge(int from, int to, int cap){
        edge q={to,cap,int(G[to].size())};
        G[from].push_back(q);
        q={from,0,int(G[from].size()-1)};
        G[to].push_back(q);
    }
    int getmaxflow(int s,int t) {//from s to t,ford_fulkerson
        int flow=0;
        while(1){
            bfs(s);
            if(level[t]<0)return flow;
            iter=vi(n);
            int f;
            while((f=dfs(s,t,INF))>0)flow+=f;
        }
    }
private:
    void bfs(int s){
        level=vi(n,-1);
        queue<int>q;
        level[s]=0;
        q.push(s);
        while(!q.empty()){
            int v=q.front();q.pop();
            for(int i=0;i<G[v].size();i++){
                edge &e=G[v][i];
                if(e.cap>0&&level[e.to]<0){
                    level[e.to]=level[v]+1;
                    q.push(e.to);
                }
            }
        }
    }
    int dfs(int v,int t, int f) {
        if(v==t)return f;
        for(int &i=iter[v];i<G[v].size();i++){
            edge &e=G[v][i];
            if(level[v]>=level[e.to]||e.cap<=0) continue;
            int d =dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }
};

signed main(){
    int x,y,e;
    cin>>x>>y>>e;
    Dinic yebi(x+y+3);
    int s=x+y+1;
    int t=x+y+2;
    map<pii,int>mp;
    rep(i,e){
        int a,b; cin>>a>>b;
        yebi.add_edge(a,b+x,1);
        if(mp[pii(s,a)]++==0)yebi.add_edge(s,a,1);
        if(mp[pii(b+x,t)]++==0)yebi.add_edge(b+x,t,1);
    }
    cout<<yebi.getmaxflow(s, t)<<endl;
}



Measured memory_bytes: 3584
N = int(input())

def dfs(s):
  if int(s) > N:
    return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0
  for c in '753':
    ret += dfs(s+c)
  return ret

print(dfs('0'))
  
  

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

int main() {
  int n, a, maximum;
  cin>>n;
  long sum=0;
  for(int i=0; i<n; i++){
    if(i==0){
      cin>>maximum;
    } else {
      cin>>a;
      if(maximum<a){
        maximum=a;
      } else if(maximum>a) {
        sum+=maximum-a;
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3460
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
int inputs[200000];
long long cnt[3] = {};
int main(){
	iostream::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(i, n) {
		cin >> inputs[i];
	}
	long long ans = 1;
	REP(i, n) {
		long long cnter = 0;
		REP(q, 3) {
			if (cnt[q] == inputs[i]) cnter++;
		}
		ans *= cnter;
		ans %= MAX_MOD;
		REP(q, 3) {
			if (cnt[q] == inputs[i]) {
				cnt[q]++;
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int idx=0, idx2=0;
		boolean a=false;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='A' && !a) {
				a=true;
				idx=i;
			}
			if(s.charAt(i)=='Z' && a) {
				idx2=i;
			}
		}
		System.out.println(idx2-idx+1);
		
	}

}


Measured memory_bytes: 26320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,ans;
  cin >>n;
  if(n%2!=0)cout << 0 <<endl; 
  else {
    ans=0;
    n/=2;
    while(n>0){
      ans+=n/5;
      n/=5;
    }
    cout << ans<<endl;
  }
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

int n;

void make_koch(double px,double py,double qx,double qy,int t){
  if(t==n) return;
  double sx=(2*px+qx)/3;
  double sy=(2*py+qy)/3;
  double tx=(px+2*qx)/3;
  double ty=(py+2*qy)/3;
  double ux=sx+(tx-sx)/2-(ty-sy)*sqrt(3)/2;
  double uy=sy+(ty-sy)/2+(tx-sx)*sqrt(3)/2;
  make_koch(px,py,sx,sy,t+1);
  printf("%f %f\n",sx,sy);
  make_koch(sx,sy,ux,uy,t+1);
  printf("%f %f\n",ux,uy);
  make_koch(ux,uy,tx,ty,t+1);
  printf("%f %f\n",tx,ty);
  make_koch(tx,ty,qx,qy,t+1);
}
int main(){
  scanf("%d",&n);
  printf("%f %f\n",0.0,0.0);
  make_koch(0.0,0.0,100.0,0,0);
  printf("%f %f\n",100.0,0.0);
}

Measured memory_bytes: 2732
#include <stdio.h>

int main(void) {
	int r=0,i,j,c,n,p[128];
	scanf("%d",&n);
	for(i = 1;i <= n;i++){scanf("%d",&p[i]);}
	for(i = 1;i <= n;i++){
		c = 0;
		for(j = 1;j <= n;j++){
			if(p[j] >= i){c++;}
		}
		if(c >= i){r = i;}else{break;}
	}
	printf("%d\n",r);
	return 0;
}

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

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

    for (int i = 0; i < n; i++)
    {
        string X, Y;
        cin >> X >> Y;
        vector<vector<int>> dp(X.size() + 1);
        for (int j = 0; j < dp.size(); j++)
        {
            dp[j].resize(Y.size() + 1, 0);
        }

        int res = 0;
        for (int j = 0; j < X.size(); j++)
        {
            for (int k = 0; k < Y.size(); k++)
            {
                if (X[j] == Y[k])
                {
                    dp[j + 1][k + 1] = dp[j][k] + 1;
                    res = max(res, dp[j + 1][k + 1]);
                }
                else
                {
                    dp[j + 1][k + 1] = max(dp[j][k + 1], dp[j + 1][k]);
                }

                // cout << "########## (" << j << ", " << k << ") ##########" << endl;
                // cout << dp[j + 1][k + 1] << endl;
            }
        }

        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 6892
//#include <limits.h>
//#include <math.h>
#include <stdio.h>

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

  int start=-1;
  for (int i = 0; i<n; i++){
    if(a[i]==1){
      start=i;
      break;
    }

  }

  int lenga_num = 1;
  for (; start < n; start++)
  {
    if(start==-1)break;
      if(a[start] == lenga_num){
        count++;
        lenga_num++;
      }

  }
  int ans=n-count;

  if(start== -1)ans=start;
  if(ans == n)ans=0;
  printf("%d\n",ans);
  
  
  

  return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	R r1,r2;
	cin >> r1 >> r2;

	cout.precision(20);
	cout << fixed << 1.0*(r1*r2)/(r1+r2) << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    int h[30];
    int ans = 0;
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < n; i++){
        int counter = 0;
        if(h[0] <= h[i]){
            for(int j = 0; j < i; j++){
                if(h[j] <= h[i]) counter++;
                }
                if(counter == i) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
from heapq import *
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
num = min(k, n)
for a in range(num + 1):
    for b in range(num + 1 - a):
        trash = k - (a + b)
        get = v[:a] + v[-b:] if b != 0 else v[:a]
        heapify(get)
        for _ in range(min(trash, a + b)):
            temp = heappop(get)
            if temp > 0:
                heappush(get, temp)
                break
        SUM = sum(get)
        if ans < SUM:ans = SUM
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);


int main() {
    class BIT{
            ll n;
      		vector<ll> bitree;
        public:
        	BIT(unsigned long _n) : bitree(_n + 1, 0){
              n = _n;
            }
        	void add(ll id, ll x){
              while(id <= n){
                bitree[id] += x;
                id += id & -id;
              }
              return;
            }
        	ll sum(ll id){
              ll temp = 0;
              while(id > 0){
                temp += bitree[id];
                id -= id & -id;
              }
              return temp;
            }
      };
    cin>>N>>Q;
    BIT bit(N);
    rep(i, N){
        scanf("%lld", &A);
        bit.add(i + 1, A);
    }
    rep(i, Q){
        int t, u, v;
        scanf("%d%d%d", &t, &u, &v);
        if(t == 0){
            bit.add(u + 1, v);
        }else{
            printf("%lld\n", bit.sum(v) - bit.sum(u));
        }
    }
}


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

int main() {
  int ans;
  int n,r;
  cin >> n >> r;
  if(n<11)
    ans = r + 100*(10-n);
  else
    ans = r;
  cout << ans << endl;
}




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

int main(){
  int n;
  cin >> n;
  int a = 0;
  for (int i = 0; i<n;i++){
    string s;
    cin >> s;
    if (s == "Y"){
      a ++;
      break;
    }
  }
  if (a == 1)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;





int main(void) {

    int n, m; cin >> n >> m;
    vi H(n); rep(i, n) cin >> H[i];
    vector<vi> AB(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        AB[a].push_back(b);
        AB[b].push_back(a);
    }
    int ans = 0;
    rep(x, n) {
        bool flg = true;
        for(int y : AB[x]) {
            if (H[y] >= H[x]) flg = false;
        }
        if (flg) ans++;
    }

    cout << ans << endl;



    return 0;
}

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

int main(void){
    string s; cin >> s;
    int n, ans;
    if (s.find("RRR") != string::npos){
        cout << 3;
    }else if (s.find("RR") != string::npos){
        cout << 2;
    }else if (s.find("R") != string::npos){
        cout << 1;
    }else{
        cout << 0;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include<cstdio>
#define ll long long
using namespace std;
int n,m,k;
ll a[2000010],b[2000010];
int main()
{

    ll sum=0,maxs=0,i,j;
    cin>>n>>m>>k;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<m;i++)
        {cin>>b[i];sum+=b[i];}
        j=m;
      for(i=0;i<=n;i++)
      {
          while(j>0&&sum>k)
          {
              j--;sum-=b[j];
          }
          if(sum>k) break;
          maxs=max(maxs,i+j);
            if(i==n) break;
          sum+=a[i];
      }
      cout<<maxs<<endl;



}


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


int main(){
    int n;
    while(true){
        cin >> n;
        if(n == 0) break;
        string s[n];
        for(int i = 0; i < n; i++){
            cin >> s[i];
        }
        for(int i = 1; i < n; i++){
            for(int j = 1; j < s[i].size(); j++){
                if(s[i][j] != '.'){
                    s[i][j-1] = '+';
                    break;
                }
            }
        }
        for(int i = n-1; i >= 0; i--){
            for(int j = 0; j < s[i].size(); j++){
                if(s[i][j] == '+'){
                    int num = i-1;
                    while(s[num][j] == '.'){
                        s[num][j] = '|';
                        num--;
                    }
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < s[i].size(); j++){
                if(s[i][j] == '.') s[i][j] = ' ';
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < s[i].size(); j++){
                cout << s[i][j];
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3764
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
n = len(s)
for i in range(n//2+1):
    if s[i] == s[n-i-1]:
        continue
    print('No')
    quit()
for i in range((n//2)//2+1):
    if s[i] == s[n//2-i-1]:
        continue
    print('No')
    quit() 
s = s[(n+3)//2-1:]
for i in range((n//2)//2+1):
    if s[i] == s[n//2-i-1]:
        continue
    print('No')
    quit() 
print('Yes')

Measured memory_bytes: 5296
package main

import (
  "fmt"
)

func main() {
  var a, b, c, x int 
  fmt.Scan(&a, &b, &c, &x)
  x /= 50
  cnt := 0
  for i := 0; i < a + 1; i++ {
    for j := 0; j < b + 1; j++ {
      k := x - 10*i - 2*j
      if k >= 0 && k <= c {cnt++}
    }
  }
  fmt.Println(cnt)


}

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

int main() {
  int h, w, n;
  cin >> h >> w;
  char str[h+2][w+2];
  for (int n=0; n<w+2; n++) {
    str[0][n] = '.' ;
    str[h+1][n] = '.';
  }
  for (int j=1; j<h+1; j++) {
    str[j][0] = '.';  
    scanf("%s", &str[j][1]);
    str[j][w+1] = '.';
  }
  int x, y, now;
  bool f;
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  for (int i=1; i<h+1; i++) {
    for (int j=1; j<w+1; j++) {
      now = str[i][j];
      f = true;
      if (now == '.')
        continue;
      for (int k=0; k<4; k++) {
        y = i + dy[k];
        x = j + dx[k];
        if (now==str[y][x])
          f = false;
      }
      if (f) {
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");
  return 0;
}

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

typedef long long ll;

const int MAXN = 5e3 + 5;
const ll INF = 1e18;

int N, A, B;
int perm[MAXN], inv[MAXN];
ll dp[MAXN][MAXN];

void load() {
	scanf("%d%d%d", &N, &A, &B);
	for (int i = 1; i <= N; i++) {
		scanf("%d", perm + i);
		inv[perm[i]] = i;
	}
}

ll rec(int num, int mx) {
	ll &ref = dp[num][mx];
	if (ref != INF)
		return ref;
	if (num > N)
		return ref = 0;
	if (mx > inv[num]) 
		return ref = rec(num + 1, mx) + A;
	return ref = min(rec(num + 1, inv[num]), rec(num + 1, mx) + B);
}

ll solve() {
	for (int i = 0; i < MAXN; i++)
		for (int j = 0; j < MAXN; j++)
			dp[i][j] = INF;
			
	return rec(1, 0);
}

int main() {
	load();
	printf("%lld\n", solve());
	return 0;
}

Measured memory_bytes: 196224
import java.util.Scanner;
class Main{
    public static void main(String[] av){
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt(), y = sc.nextInt();
	int tmp;
	if(y > x){
	    tmp = x;
	    x = y;
	    y = tmp;
	}
	while((tmp = x % y)!= 0){
	    x = y;
	    y = tmp;
	}
	System.out.println(y);
    }
}


Measured memory_bytes: 26216
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


map<int, char>mp;
int check(vector<vector<int>>&sts) {
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < sts[i].size(); ++j) {
			cout << mp[sts[i][j]];
		}
		cout << endl;
	}
	fflush(stdout);
	string ans;
	cin >> ans;
	if (ans == "T")return 1;
	else if (ans == "F")return 0;
	else {
		exit(0);
		return -1;
	}
}
int main() {
	mp[0] = '.';
	mp[1] = '#';
	int N; cin >> N;
	vector<vector<int>>sts(2);
	for (int i = 0; i < 4; ++i) {
		sts[0] = vector<int>(1, i % 2);
		sts[1] = vector<int>(1, i / 2);
		int ok = check(sts);
		if (ok == 1) {
			break;
		}
		else if (ok == 0)continue;
		else {
			return 0;
		}
	}
	bool isleft = true;
	int num = 0;
	bool flag = false;
	while (1) {
		for (int i = 0; i < 2; ++i) {
			auto it = isleft ? sts[i].begin() : sts[i].end();
			const int val = i ? num % 2 : num / 2;
			sts[i].insert(it, val);
		}
		int ok = check(sts);
		if (ok == 1) {
			num = 0;
			flag = false;
		}
		else if (ok == 0) {
			for (int i = 0; i < 2; ++i) {
				auto it = isleft ? sts[i].begin() : sts[i].end()-1;
				sts[i].erase(it);
			}
			num++;
			if (num == 4) {
				isleft = false;
				num = 0;
			}
		}
		else {
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 596
n=int(input())
p=list(map(int,input().split()))

a=0
for i in range(1,n-1):
 if min(p[i-1],p[i+1])<p[i]<max(p[i-1],p[i+1]):
    a+=1

 else:
    a=a

print(a)

Measured memory_bytes: 2940
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

int main(){
    ll a[200005],b[200005];
    ll x=1000000007;
    ll n;
    cin>>n;
    cin>>a[0];
    b[0]=a[0];
    ll ans=0;
    for(ll i=1;i<n;i++){
        cin>>a[i];
        b[i]=a[i]+b[i-1];
        b[i]%=x;
        ans+=(a[i]%x)*(b[i-1]%x);
        ans%=x;
    }
    cout<<ans%x<<endl;
}

Measured memory_bytes: 6748
#include <bits/stdc++.h>
#define N 1805
using namespace std;

const int fx[] = { 0, 1, 0,-1};
const int fy[] = { 1, 0,-1, 0};

int n,m,k,sx,sy;
char s[N];
bool vis[N][N],mp[N][N],flag;
queue<int> qx,qy,qs;
int main() {
    scanf("%d%d%d",&n,&m,&k);
    for (int i=1;i<=n;i++) {
        scanf("%s",s+1);
        for (int j=1;j<=m;j++) mp[i][j] = s[j]!='#';
        for (int j=1;j<=m;j++) if (s[j]=='S') sx=i, sy=j;
    }

    if (sx == 1 || sx == n || sy == 1 || sy == m) return puts("0"), 0;

    vis[sx][sy] = 1;
    qx.push(sx), qy.push(sy), qs.push(0);
    while (!qx.empty()) {
        int ux = qx.front(); qx.pop();
        int uy = qy.front(); qy.pop();
        int us = qs.front(); qs.pop();
        if (us == k) continue;
        if (ux == 1 || ux == n || uy == 1 || uy == m) flag = 1;

        for (int i=0;i<4;i++) {
            int vx = ux + fx[i], vy = uy + fy[i];
            if (vx<1 || vx>n || vy<1 || vy>m) continue;
            if (!vis[vx][vy] && mp[vx][vy]) {
                vis[vx][vy] = 1;
                qx.push(vx), qy.push(vy), qs.push(us+1);
            }
        }
    }

    if (flag) return puts("1"), 0;

    int ans = 2147483647;   
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) if (vis[i][j]) {
            int t = min( min(i-1,j-1) , min(n-i,m-j) );
            int cur = (t+k-1) / k;
            ans = min(ans, cur+1);
        }
    cout << ans << endl;
    return 0;
}

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

template <typename T, typename _ = void>
struct is_container : std::false_type {};
template <typename T>
struct is_container<T, std::void_t<decltype(std::declval<T>().begin()),
                                   decltype(std::declval<T>().end())>>
    : std::true_type {};
template <typename T, typename _ = void>
struct is_pair : std::false_type {};
template <typename T>
struct is_pair<T, std::void_t<decltype(std::declval<T>().first),
                              decltype(std::declval<T>().second)>>
    : std::true_type {};
template <typename T>
void debug(const T& v) {
  if constexpr (is_pair<T>::value) {
    std::cerr << "{";
    debug(v.first);
    std::cerr << ", ";
    debug(v.second);
    std::cerr << "}";
  } else if constexpr (is_container<T>::value) {
    std::cerr << "{";
    for (auto it = v.begin(); it != v.end(); ++it) {
      if (it != v.begin()) std::cerr << ", ";
      debug(*it);
    }
    std::cerr << "}";
  } else {
    std::cerr << v;
  }
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
#if DEBUG
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  if constexpr (std::is_same<T, bool>::value) {
    std::cout << (value ? "Yes" : "No");
  } else {
    std::cout << value;
  }
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  write_to_cout(value);
  std::cout << ' ';
  write_to_cout(args...);
}
#define wt(...)                 \
  do {                          \
    write_to_cout(__VA_ARGS__); \
    cout << '\n';               \
  } while (0)

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

template <typename T, typename U>
bool chmax(T& a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T, typename U>
bool chmin(T& a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#include <boost/hana/functional/fix.hpp>
auto Fix = boost::hana::fix;

using ll = long long;

template <typename T>
using low_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(int, n, a);
  wt(n % 500 <= a);
}


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

const int MAXN = 8002;
const ll M = 1e9+7;

ll powm(ll p, ll b) {
  if (p<=0) return 1;
  ll ans = powm(p/2, b);
  ans = ans*ans%M;
  if (p%2) ans = ans*b%M;
  return ans;
}

ll fact[MAXN], inv[MAXN];

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  fact[0] = inv[0] = 1;
  for(int i=1;i<MAXN;i++) {
    fact[i]= fact[i-1]*i%M;
    inv[i] = powm(M-2, fact[i]);
    //cerr << fact[i] << " " << inv[i] <<endl;
  }
  int s;
  cin >> s;

  ll ans = 0;
  if (s>=3) {
    for(int k=1;s/k>=3;k++) {
      int t = s-3*k;
      int d = k-1;
      ll add = fact[t+d]*inv[t]%M*inv[d]%M;
      //cerr << t << " " << d << " " << fact[t+d]*inv[t]%M*inv[d]%M <<endl;
      ans = (ans+add)%M;
    }
  }

  cout << ans <<endl;
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define Pll pair<ll,ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll,ll>

const ll inf=1e18;
const ll maxs = 100005;
const ll mod = 1e9+7;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line cout<<endl;
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mst(x,a) memset(x,a,sizeof(x))

ll n;
double dp[3000][3000];
double p[3000];

double go(ll pos,ll h,ll t)
{
    if(pos==n)return h>t;
    if(dp[pos][h]!=-1)
        return dp[pos][h];
    
    double ans=0;
    ans += p[pos]*go(pos+1,h+1,t);
    ans += (1-p[pos])*go(pos+1,h,t+1);
    return dp[pos][h]=ans;    
}


int main() 
{
    fastio();
    cout.precision(20);
	cout<<fixed;
	ll t=1;
    //cin>>t;
    while(t--)
	{
	  for(ll i=0;i<3000;i++)
	  {
	      for(ll j=0;j<3000;j++)
	        dp[i][j]=-1;
	  }
	  
	   cin>>n;
	   for(ll i=0;i<n;i++)
          cin>>p[i];
         
        cout<<go(0,0,0);  
    }
	
	return 0;
}

Measured memory_bytes: 70784
s = input()
i = 0
count = 0
one_flag = False
while i < len(s):
	if one_flag == False:
		one_flag = True
		i += 1
		count += 1
	else:
		if s[i] == s[i - 1]:
			if i == len(s) - 1:
				break
			else:
				one_flag = False
				i += 2
				count += 1
		else:
			i += 1
			count += 1
print(count)

Measured memory_bytes: 40304
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int a,b,c,k; cin >> a >> b >> c >> k;
    if(a>=k) cout << k << endl;
    else if (a+b >= k) cout << a << endl;
    else cout << -k+2*a+b << endl;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N, M, X;
    cin >> N >> M >> X;

    vector<int> as(M);
    for (int i = 0; i < M; i++) {
        cin >> as[i];
    }

    auto it = lower_bound(as.begin(), as.end(), X);
    int l_cnt = distance(as.begin(), it);
    int r_cnt = distance(it, as.end());

    cout << min(l_cnt, r_cnt) << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#define int long long
using namespace std;

const int DEPTH = 17;

struct SegTree {
	int lazySum[1 << DEPTH + 1];
	int segSum[1 << DEPTH + 1];
	
	SegTree() {
		for (int i = 0; i < 1 << DEPTH + 1; i++) {
			lazySum[i] = 0;
			segSum[i] = 0;
		}
	}
	
	void lazy_evaluate(int id) {
		if (lazySum[id] == 0) return;
		segSum[id] += lazySum[id];
		
		if (id < (1 << DEPTH) - 1) {
			lazySum[id * 2 + 1] += lazySum[id] / 2;
			lazySum[id * 2 + 2] += lazySum[id] / 2;
		}
		lazySum[id] = 0;
	}
	
	void add(int l, int r, int x, int a = 0, int b = (1 << DEPTH), int id = 0) {
		lazy_evaluate(id);
		
		if (a >= r || b <= l) return;
		if (l <= a && b <= r) {
			lazySum[id] += x * (b - a);
			lazy_evaluate(id);
			return;
		}
		add(l, r, x, a, (a + b) / 2, id * 2 + 1);
		add(l, r, x, (a + b) / 2, b, id * 2 + 2);
		segSum[id] = segSum[id * 2 + 1] + segSum[id * 2 + 2];
	}
	
	int getSum(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return 0;
		
		lazy_evaluate(id);
		if (l <= a && b <= r) {
			return segSum[id];
		}
		
		int res1 = getSum(l, r, a, (a + b) / 2, id * 2 + 1);
		int res2 = getSum(l, r, (a + b) / 2, b, id * 2 + 2);
		return res1 + res2;
	}
};

SegTree seg;

signed main() {
	int n, q;
	
	cin >> n >> q;
	for (int i = 0; i < q; i++) {
		int type;
		cin >> type;
		
		if (type == 0) {
			int s, t, x;
			cin >> s >> t >> x;
			seg.add(s, t + 1, x);
		}
		else {
			int s, t;
			cin >> s >> t;
			cout << seg.getSum(s, t + 1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 7228