akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bits/allocator.h>
#include<bits/basic_ios.h>
#include<bits/basic_string.h>
#include<bits/basic_string.tcc>
#include<bits/c++config.h>
#include<bits/char_traits.h>
#include<bits/cpp_type_traits.h>
#include<bits/cxxabi_forced.h>
#include<bits/ios_base.h>
#include<bits/locale_classes.h>
#include<bits/localefwd.h>
#include<bits/ostream_insert.h>
#include<bits/postypes.h>
#include<bits/range_access.h>
#include<bits/stl_algobase.h>
#include<bits/stl_function.h>
#include<bits/stl_iterator.h>
#include<bits/stl_iterator_base_funcs.h>
#include<bits/stl_iterator_base_types.h>
#include<bits/stringfwd.h>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwchar>
#include<cwctype>
#include<debug/debug.h>
#include<deque>
#include<exception>
#include<ext/atomicity.h>
#include<ext/numeric_traits.h>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
long long n,m,a,way[100][100];
char c[100][100];
queue<pair<int,int> > q;
bool used[100][100];
int main()
{
	cin>>n>>m;
	for (int i=0;i<n;i++) cin>>c[i];
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
			if (c[i][j]=='#') a++;
	way[0][0]=1;
	memset(way,-1,sizeof(way));
	q.push(pair<int,int>(0,0));
	while (!q.empty()){
		int x=q.front().first,y=q.front().second;q.pop();
		if (x+1<n&&c[x+1][y]!='#'&&used[x+1][y]==0){
			used[x+1][y]=1;way[x+1][y]=way[x][y]+1;
			q.push(pair<int,int>(x+1,y));
		}
		if (x-1>=0&&c[x-1][y]!='#'&&used[x-1][y]==0){
			used[x-1][y]=1;way[x-1][y]=way[x][y]+1;
			q.push(pair<int,int>(x-1,y));
		}
		if (y+1<m&&c[x][y+1]!='#'&&used[x][y+1]==0){
			used[x][y+1]=1;way[x][y+1]=way[x][y]+1;
			q.push(pair<int,int>(x,y+1));
		}
		if (y-1>=0&&c[x][y-1]!='#'&&used[x][y-1]==0){
			used[x][y-1]=1;way[x][y-1]=way[x][y]+1;
			q.push(pair<int,int>(x,y-1));
		}
	}
	if (way[n-1][m-1]!=-1)
		cout<<n*m-a-way[n-1][m-1]-2;
	else
		cout<<-1;
	return 0;
}

Measured memory_bytes: 384
S = ''.join(list(reversed(input())))
N = len(S)
p = 13
mod = 10**9 + 7

dp = [[0]*p for _ in range(N)]

if S[0] == '?':
    for j in range(10):
        dp[0][j] = 1
else:
    dp[0][int(S[0])] = 1

b = 10
for i in range(N - 1):
    r = []
    if S[i + 1] == '?':
        for j in range(10):
            r.append(b * j % p)
    else:
        r.append(b * int(S[i + 1]) % p)

    for j in range(len(r)):
        for k in range(p):
            if dp[i][k] > 0:
                dp[i + 1][(k + r[j]) % p] += dp[i][k]
                dp[i + 1][(k + r[j]) % p] %= mod

    b *= 10
    b %= p

print(dp[N - 1][5] % mod)

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

using namespace std;

#define ll long long
#define pi pair<ll,ll>
 
vector<ll>v[200005];
ll arr[500005];
ll brr[500005];
 
map<char,ll>mp;
map<char,ll>cnt;
ll digits[13];
vector<string>names;
int main()
{
   ll i,j,k,l,p,q,r,s=1,t,n=3,money,sum=0;
   cin>>p>>q;
   for(i=1;i<=3;i++)
   {
     if(i!=p&&i!=q)
     {
       cout<<i;
       return 0;	
     }	
   }
   	
}

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


Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	string s;
	cin >> s;
	cout << (s[0] == s[1] && s[1] == s[2] ? "No" : "Yes") << endl;
}


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

namespace Miscelleneous {
   class Program {
      public static string[] Poker = { "null","one pair","two pair",
         "three card","straight","full house","four card" };
      public static int cin() { return int.Parse(Console.ReadLine()); }
      public static int[] cins() {
         string s = Console.ReadLine();
         if (string.IsNullOrEmpty(s)) return new int[]{ };
         string[] ss = s.Split(',');
         int[] Res = new int[ss.Length];
         for (int i = 0; i<ss.Length; i++) Res[i]=int.Parse(ss[i]);
         return Res;
      }
      public static void print(object s) { Console.WriteLine(s.ToString()); }
      static void Main(string[] args) {
         int[] ss;
         int[] card = new int[13];
         while (true) {
            ss=cins();
            if (ss.Count()==0) break;
            for (int i = 0; i<13; i++)
               card[i]=ss.Where(j => j-1==i).Count();
            print(Poker[Explore(card)]);
         }
      }

      static int Explore(int[] card) {
         Func<int,bool> co = i => card.Contains(i);
         Func<int,bool> Av = i => i!=-1;
         if (co(4)) return 6;
         if (co(3)&&co(2)) return 5;
         //straight
         var G = card.Select((i,j)=>i==1? j :-1);
         if (G.Where(Av).Count()==5) {
            if (G.Last(Av)-G.First(Av)==4) return 4;
            if (G.Skip(1).First(Av)==9) return 4;
         }
         if(co(3))return 3;
         if (card.Where(i => i>=2).Count()==2) return 2;
         if (co(2)) return 1;
         return 0;
      }
   }
}

Measured memory_bytes: 9372
import sys

input = sys.stdin.readline

n, m = map(int, input().split())

l_list = []
r_list = []

for _ in range(m):
    l, r = map(int, input().split())
    l_list.append(l)
    r_list.append(r)

l_maybe_answer = max(l_list)
r_maybe_answer = min(r_list)

if l_maybe_answer <= r_maybe_answer:
    print(min(r_list) - max(l_list) + 1)
else:
    print(0)


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

int main() {
  int N, M, i;
  int sum = 0;
  vector<int> A(N);
  cin >> N >> M;
  
  for (i = 0; i < N; i++){
    cin >> A.at(i);
    sum += A.at(i);
  }
  
  double Si = (double) sum / (4 * M);
  int count = 0;
  
  for (i : A){
    if (i >= Si){
      count++;
    }
  }
  if (count >= M){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 16640
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    rep(i,0,n) cin>>s[i];
    rep(i,0,n){
        int cnt=0;
        rep(j,0,n){
            if(s[i]==s[j]) cnt++;
        }
        if (cnt>1) {
            cout<<"No";
            return 0;
        }
    }
    rep(i,0,n-1){
        if(s[i][s[i].size()-1] != s[i+1][0]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int edges = sc.nextInt(), nodes = sc.nextInt();
			
			if(edges == 0 && nodes == 0){
				break;
			}
			
			int[][] cost_adj = new int[nodes][nodes];
			int[][] time_adj = new int[nodes][nodes];
			
			for(int i = 0; i < nodes; i++){
				for(int j = 0; j < nodes; j++){
					cost_adj[i][j] = time_adj[i][j] = Integer.MAX_VALUE / 4;
				}
			}
			
			for(int i = 0; i < edges; i++){
				int start = sc.nextInt() - 1, end = sc.nextInt() - 1;
				
				cost_adj[start][end] = cost_adj[end][start] = sc.nextInt();
				time_adj[start][end] = time_adj[end][start] = sc.nextInt();
			}
			
			for(int k = 0; k < nodes; k++){
				for(int i = 0; i < nodes; i++){
					for(int j = 0; j < nodes; j++){
						cost_adj[i][j] = Math.min(cost_adj[i][j], cost_adj[i][k] + cost_adj[k][j]);
						time_adj[i][j] = Math.min(time_adj[i][j], time_adj[i][k] + time_adj[k][j]);
					}
				}
			}
			/*
			for(int i = 0; i < nodes; i++){
				for(int j = 0; j < nodes; j++){
					System.out.print(time_adj[i][j] + " ");
				}
				System.out.println();
			}
			*/
			
			final int nums = sc.nextInt();
			for(int i = 0; i < nums; i++){
				int start = sc.nextInt() - 1, end = sc.nextInt() - 1, r = sc.nextInt();
				
				System.out.println(r == 1 ? time_adj[start][end] : cost_adj[start][end]);
			}
			
		}

	}

}

Measured memory_bytes: 14000
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=2005;
ll a[N],b[N],n,x;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>x;
    for(ll i=0;i<n;i++)cin>>a[i],b[i]=a[i];
    ll ans = LLONG_MAX;
    for(ll i=0;i<n;i++){
        ll cur = i*x;
        for(ll j=0;j<n;j++){
            b[j] = min(b[j] , a[(j-i+n)%n]);
            cur+=b[j];
        }
        ans=min(ans , cur);
    }
    cout<<ans;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    int n, k;
    cin >> n >> k;
    int h[100100];
    rep(i,n) {
        cin >> h[i];
    }
    int res = 0;
    rep(i,n) {
        if (h[i] >= k ) res++;
    }
    cout << res << "\n";
}

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

int a[4];
int sum = 0;
int x, y;


int main(){
	for(int i = 0; i < 4; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < 4; i++){
		sum += a[i];
	}
	
	x = sum / 60;
	y = sum % 60;
	
	cout << x << endl;
	cout << y << endl;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int q1,badget,c1,c2,lower,upper,mid,lim;

bool s(int arg){
  int qn = (badget - arg * c1) / c2;
  if(qn < 0) return false;
  if(qn+arg < q1) return false;
  if(arg > lim) return false;
  if(badget - arg * c1 < 0) return false;
  return true;
}

int main(){

  while(cin >> q1 && q1){
    cin >> badget >> c1 >> c2 >> lim;
    lower = 0;
    upper = 1000000;

    //binary search
    while(upper - lower > 1){
      mid = (upper + lower) / 2;
      if(s(mid)){
	lower = mid;
      }else{
	upper = mid;
      }
    }
    if(lower == 0){
      cout << "NA" << endl;
    }else{
      cout << lower << " " << (badget - lower*c1)/c2 << endl;
    }
  }
}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory>
#include<cmath>
#include<algorithm>
#include<vector>
double min_double(double a,double  b){
    if(a<b) return a;
    else return b;
}
void swap(int *x,int *y){
    int tmp;
    tmp=*x;
    *x=*y;  
    *y=tmp;
}
int gcd(int a,int b){
    if(a<b) swap(&a,&b);
    if(b<1) return -1;

    if(a%b==0) return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a * b / gcd(a,b);
}

int main(){
    int N;
    std::cin>>N;
    std::vector<int> A(N+1);
    long long sum=0;
    for(int i=0;i<N+1;i++) {
        std::cin>>A[i];
        sum+=A[i];
    }
    std::vector<int> B(N);
    for(int i=0;i<N;i++) {
        std::cin>>B[i];
        if(B[i]>=A[i]){
            B[i]-=A[i];
            A[i]=0;
            if(B[i]>=A[i+1]) A[i+1]=0;
            else             A[i+1]-=B[i];
        }
        else A[i]-=B[i];
    }
    long long rest=0;
    for(int i=0;i<N+1;i++) rest+=A[i];

    long long ans=sum-rest;
    std::cout<<ans<<std::endl;

    

    return 0;
}



Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
int main(){
int R, C; 
cin >> R >> C; 
int A[110][110] = {0}; 
for (int i = 0; i < R; ++i) {
  for (int j = 0; j < C; ++j){
   cin >> A[i][j]; 
  }
 }
for (int i = 0; i < R; ++i) {
  for (int j = 0; j < C; ++j){
   A[i][C] += A[i][j]; 
   A[R][j] += A[i][j]; 
   A[R][C] += A[i][j]; 
  }
 }
for (int i = 0; i <= R; ++i) {
  for (int j = 0; j <= C; ++j){
   if(j != C) cout << A[i][j] << " ";
   if(j == C) cout << A[i][j];  
  }
  cout << endl; 
 }
}


Measured memory_bytes: 3140
import copy

def main():
    temp=input()

    a,b,c=list(temp.split(" "))
    a=int(a)
    b=int(b)
    c=int(c)
    l1=[]
    l2=[]
    for i in range(c):
        l1.append(i+a)
    for i in range(c):
        l1.append(b-i)
    l1=list(set(l1))
    l1.sort()
    
    # print(l1)
    l2=copy.deepcopy(l1)
    for l in l2:
        if l<a or l>b:
            # print(l)
            l1.remove(l)
    for l in l1:
       print(l)




if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
 
#define             ll  long long
#define            ull  unsigned long long
#define            P_B  push_back
#define            M_P  make_pair
#define         DBG(x)  printf("%s %d\n", #x, x)
#define       DBGLL(x)  printf("%s %lld\n", #x, x)
#define         SCI(x)  scanf("%d",&x)
#define         SCD(x)  scanf("%lf",&x)
#define         SCS(x)  scanf("%s",x)
#define         CLR(x)  memset(x, 0, sizeof(x))
#define        CLRN(x)  memset(x, -1, sizeof(x))
#define        SCLL(x)  scanf("%lld", &x)
#define      FOR(i, n)  for(int i = 0; i < n; i++)
#define  FORR(i, m, n)  for(int i = m; i < n; i++)
#define     SCI2(m, n)  scanf("%d%d", &m, &n)
#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)
#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)
#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)
#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)
#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)
#define             vi  vector<int>
#define            vii  vector<pair<int, int> >
#define            vll  vector<pair<ll, ll> >
#define            Mod  998244353
#define            INF  1000000000
 
int n;
int w[105][2];
int m;
int dp[105];
int fl[105];
int x[10000005];

int main()
{
	CLR(fl);	
	int hudai = SCI2(n, m);
	FOR(i, n)hudai = SCI2(w[i][0], w[i][1]);
	CLRN(x);
	FOR(i, n){
		for(int j = 10000000; j > 0; j--){
			if(x[j] != -1){
				if(x[j] + w[i][0] <= m){
					if(x[j + w[i][1]] != -1)
						x[j + w[i][1]] = min(x[j] + w[i][0], x[j+w[i][1]]);
					else
						x[j + w[i][1]] = x[j] + w[i][0];
				}
			}
		}
		if(w[i][0] <= m){
			if(x[w[i][1]] != -1)x[w[i][1]] = min(x[w[i][1]], w[i][0]);
			else x[w[i][1]] = w[i][0];
		}
	}
	int y = 0;
	for(int i = 1000000; i >= 0; i--) 
		if(x[i] > 0){
			y = i;
			break;	
		}
	printf("%d\n", y);
}

Measured memory_bytes: 39296
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,i,t,h,l,j;
    cin >> n;
    t=0;h=0;
    string a,b;
    for(i=0;i<n;i++){
        cin >> a >> b;
        l=min(a.length(),b.length());
        for(j=0;j<l;j++){
            if(a.at(j)>b.at(j)){
                t += 3;
                break;
            }
            else if(a.at(j)<b.at(j)){
                h += 3;
                break;
            }
        }
        if(j==l){
            if(a.length()>b.length()) t+=3;
            else if(a.length()<b.length()) h+=3;
            else{
                t++;h++;
            }
        }
    }
    cout << t << " " <<h << endl;
    return 0;
}


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

const int NMAX=1e6;
int BIT[NMAX+1],NN;

int SUM(int i){
  int s=0;
  while(i>0){
    s+=BIT[i];
    i-=i&-i;
  }
  return s;
}

void ADD(int i,int x){
  while(i<=NN){
    BIT[i]+=x;
    i+=i&-i;
  }
}

int M[202020];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  string S; cin>>S;
  int N=S.length();
  NN=N+1;
  vector<vector<int>> V(26);
  rep(i,N) V[S[i]-'a'].push_back(i);
  int cnt=0, od=-1;
  rep(i,26){
    cnt+=V[i].size()%2;
    if(V[i].size()%2) od=V[i][0];
  }
  if(cnt>1){
    cout<<-1<<endl;
    return 0;
  }
  string T="";
  int pos[26]={};
  rep(i,N){
    int c=S[i]-'a';
    if(pos[c]>=V[c].size()/2) continue;
    T+=S[i];
    pos[c]++;
  }
  string U=T;
  if(N%2) U+=S[od];
  reverse(T.begin(),T.end());
  U+=T;
  rep(i,26) pos[i]=max(0,(int)V[i].size()-1);
  for(int i=N-1;i>=0;i--){
    int c=U[i]-'a';
    M[V[c][pos[c]]]=N-i;
    pos[c]--;
  }
  ll ans=0;
  rep(i,N){
    ans+=1LL*SUM(M[i]);
    ADD(M[i],1);
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main(void){
  string arg;

  while(cin >> arg){
	int n=arg.size();
	int tmpi;
	char tmpc;
	string str = "";
	bool ok = true;
	if(n%2==1){
	  cout << "NA" << endl;
	  continue;
	}
	for(int i=0;i<n/2;i++){
	  tmpi = 0;
	  tmpc = arg[i*2];
	  tmpi += (tmpc - '0') * 10;
	  tmpc = arg[i*2+1];
	  tmpi += tmpc - '0';
	  switch(tmpi){
	  case 11:
		str +="a";
		break;
	  case 12:
		str +="b";
		break;
	  case 13:
		str +="c";
		break;
	  case 14:
		str +="d";
		break;
	  case 15:
		str +="e";
		break;
	  case 21:
		str +="f";
		break;
	  case 22:
		str +="g";
		break;
	  case 23:
		str +="h";
		break;
	  case 24:
		str +="i";
		break;
	  case 25:
		str +="j";
		break;
	  case 31:
		str +="k";
		break;
	  case 32:
		str +="l";
		break;
	  case 33:
		str +="m";
		break;
	  case 34:
		str +="n";
		break;
	  case 35:
		str +="o";
		break;
	  case 41:
		str +="p";
		break;
	  case 42:
		str +="q";
		break;
	  case 43:
		str +="r";
		break;
	  case 44:
		str +="s";
		break;
	  case 45:
		str +="t";
		break;
	  case 51:
		str +="u";
		break;
	  case 52:
		str +="v";
		break;
	  case 53:
		str +="w";
		break;
	  case 54:
		str +="x";
		break;
	  case 55:
		str +="y";
		break;
	  case 61:
		str +="z";
		break;
	  case 62:
		str +=".";
		break;
	  case 63:
		str +="?";
		break;
	  case 64:
		str +="!";
		break;
	  case 65:
		str +=" ";
		break;
	  default:
		ok = false;
	  }
	  if(!ok) break;
	}
	if(ok){
	  cout << str << endl;
	}else{
	  cout << "NA" << endl;
	}
  }
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

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

    if (max(x, a) - min(x, a) < max(x, b) - min(x, b)) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }
}

Measured memory_bytes: 3040
import math

N, D = map(int, input().split())
X = list()
cnt = 0
for _ in range(N):
	X.append(list(map(int, input().split())))

for i in range(N):
	for j in range(i+1, N):
		_sum = 0
		for k in range(D):
			_sum += (X[i][k] - X[j][k])**2

		if math.sqrt(_sum).is_integer():
			cnt += 1

print(cnt)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String[] str = s.split("");

        int rightWhite = 0;
        int leftBlack = 0;
        for (int i = 0; i < str.length; i++) {
            if (".".equals(str[i])) {
                rightWhite++;
            }
        }
        int min = leftBlack + rightWhite;
        for (int i = 0; i < str.length; i++) {
            if ("#".equals(str[i])) {
                leftBlack++;
            } else {
                rightWhite--;
            }
            if ((leftBlack + rightWhite) < min) {
                min = leftBlack + rightWhite;
            }
        }
        System.out.println(min);
    }

}


Measured memory_bytes: 53280
from collections import Counter

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

if N == 1:
    print(1)
    exit()

xy.sort(key=lambda x: x[1])
xy.sort(key=lambda x: x[0])

ans = N
diff = []

for i in range(N-1):
    for j in range(i+1, N):
        diff.append((xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]))

c = Counter(diff)
print(N - c.most_common()[0][1])

Measured memory_bytes: 3564
#include <stdio.h>

int max(int a, int b){
	if(a>b){
		return a;
	}
	return b;
}

int main(){
	int N;
	scanf("%d",&N);
	int a[100001];
	int b[100001];
	int c[100001];
	int i;
	for(i=1;i<=N;i++){
		scanf("%d",&a[i]);
		scanf("%d",&b[i]);
		scanf("%d",&c[i]);
	}
	int dp[100001][3];
	dp[1][0]=a[1];
	dp[1][1]=b[1];
	dp[1][2]=c[1];
	for(i=2;i<=N;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
	}
	printf("%d",max(dp[N][0],max(dp[N][1],dp[N][2])));
}

Measured memory_bytes: 2560
N, K = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)

dp = [10 ** 9] * N

dp[0] = 0

1.upto(N - 1).each do |n|
  K.times do |k|
    if n - (k + 1) < 0
      break
    end

    s = dp[n - (k + 1)] + (h[n] - h[n - (k + 1)]).abs

    dp[n] = s if s < dp[n]
  end
end

puts dp[N - 1]


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

int main(){
    int s;
    cin >> s;
    int h, m;
    h = s / 3600;
    s %= 3600;
    m = s / 60;
    s %= 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>

int main(void){
  int i,j;
  int n,a,b,c,x;
  int res;
  int y[102];

  while(scanf("%d%d%d%d%d",&n,&a,&b,&c,&x),n){
    for(i=0;i<n;i++){
      scanf("%d",&y[i]);
    }

    res = 0;
    for(i=0;i<n;i++,x=(a * x + b)%c,res++){
      while(y[i] != x){
        x = (a * x + b) % c;
        res++;
        if(res > 10000){
          res = -1;
          break;
        }
      }
      if(res == -1) break;
    }
    if(res != -1) res--;
    printf("%d\n",res);
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


ll mod=1000000007;
ll vis[212345]={0};
vvi v(212345);
ll d[212345]={0};


ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}


//extended euclidean algorithm( x is inverse of a wrt b onlt if gcd!=1)
ll gcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1,y1;
	ll d=gcd(b,a%b,x1,y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;

}


int main()
{
speed


string s,t;
cin>>s>>t;
ll n1=s.size();
ll n2=t.size();
ll mx=n2;

rep(i,0,n1-n2+1)
{
	ll z=0;
	rep(j,i,i+n2)
	{
		if(s[j]==t[j-i]) z++;
	}
	mx=min(mx,n2-z);
}
cout<<mx;
}



Measured memory_bytes: 8044
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int overlap[15][15];
int dp[1<<15][15][15];

// s ++ t
int calc1(const string &s,const string &t) {
    int ret = 0;
    for(int k=1; k<=min(s.length(),t.length()); ++k) {
        for(int i=0; i<k; ++i) {
            if(s[s.length()-k+i] != t[i]) break;
            if(i == k-1) ret = k;
        }
    }
    return ret;
}

// app j in i ??
bool include(const string &s,const string &t) {
    if(t.length() > s.length()) return false;
    for(int i=0; i<=s.length()-t.length(); i++) {
        if(s.substr(i,t.length()) == t) return true;
    }
    return false;
}

int main() {
    int n,cnt;

    while(cin>>n, n) {
        vector<string> in(n);
        vector<bool> use(n,true);
        for(int i=0; i<n; ++i) cin>>in[i];
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                if(i == j) continue;
                if(include(in[i],in[j]))
                    use[j] = false;
            }
        }

        cnt = 0;
        for(int i=0; i<n; ++i)
            if(use[i]) in[cnt++] = in[i];
        n = cnt;

        for(int i=0; i<n; ++i)
            for(int j=0; j<n; ++j)
                if(i != j) overlap[i][j] = calc1(in[i],in[j]);

        for(int i=0; i<(1<<n); ++i)
            for(int j=0; j<n; ++j)
                for(int k=0; k<n; ++k)
                    dp[i][j][k] = 1<<29;

        for(int i=0; i<n; ++i) dp[1<<i][i][i] = in[i].length();

        for(int i=1; i<(1<<n); ++i) {
            for(int j=0; j<n; ++j) {
                if((1<<j)&i) continue;
                int len = in[j].length();
                for(int k=0; k<n; ++k) {
                    for(int l=0; l<n; ++l) {
                        dp[i|(1<<j)][j][l] = min(dp[i|(1<<j)][j][l],dp[i][k][l] + len - overlap[j][k]);
                        dp[i|(1<<j)][k][j] = min(dp[i|(1<<j)][k][j],dp[i][k][l] + len - overlap[l][j]);
                    }
                }
            }
        }

        int ans = 1<<29;
        for(int i=0; i<n; ++i)
            for(int j=0; j<n; ++j)
                ans = min(ans, dp[(1<<n)-1][i][j]);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 14000
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char a[N];

int main()
{
    cin>>a;
    int flag=0;
    for(int i=1;i<=3;i++)
    {
        if(a[i]==a[i-1])
            flag=1;
    }
    if(flag)
        cout<<"Bad"<<endl;

    else
        cout<<"Good"<<endl;



    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MAXN
#define rep(i,j,k) for(i = j; i <= k; i++)
#define per(i,j,k) for(i = k; i >= j; i--)
using namespace std;

long long sum, ans;
int num, n, i ,j;
map <long long, long long> s;

int main(void) {
    cin >> n;
    scanf("%d", &sum);

    s[sum]++;
    ans = !sum;

    rep(i,2,n) {
        scanf("%d", &num);
        sum += num;

        s[sum]++;
        ans += !sum;
    }

    map<long long, long long> ::iterator it;
    for (it = s.begin(); it != s.end(); it++) {
        ans += it->second * (it->second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 100100;

void solve() {
	ll n,ans=0,prev=-1;
	string s;
	cin>>s;
	n=s.length();
	for(int i=0;i<n;i++)
		if(s[i]=='B' && prev==-1)
			prev=i;
		else if(s[i]=='W') {
			if(prev==-1)
				continue;
			else ans+=i-prev,prev++;
		}
	cout<<ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
//	pre();
//	ll t;cin>>t;while (t--)
	solve();

}


Measured memory_bytes: 720
from queue import Queue

N = int(input())
d = {}
for i in range(N-1):
    u, v, w = map(int, input().split())
    if u in d:
        d[u].append([v, w])
    else:
        d[u] = [[v, w]]
    if v in d:
        d[v].append([u, w])
    else:
        d[v] = [[u, w]]

isChecked = [False for i in range(N)]
ans = [0 for i in range(N)]
q = Queue()
# [current v, sum length]
q.put([1, 0])
while not q.empty():
    v, l = q.get()
    if isChecked[v-1]:
        continue
    ans[v-1] = 0 if l%2 == 0 else 1
    isChecked[v-1] = True
    for u, w in d[v]:
        q.put([u, l+w])

for i in range(N):
    print(ans[i])


Measured memory_bytes: 110932
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 
		 String str = scan.nextLine();
		 
		 int  flag = 0;
		 
		 for (int i = 1; i < 4; i++ ) {
			if (str.charAt(i) == str.charAt(i-1)) {
				flag = 1;
			}
		 }
		 
		 if (flag == 1) {
			 System.out.println("Bad");
		 } else {
			 System.out.println("Good");
		 }
		 
		 scan.close();
		 

	}

}


Measured memory_bytes: 21460
def main():
    n = int(input())
    values = list(map(int, input().split()))
    count = 0
    while canBeDevide(values, 2):
        count += 1
        values = list(map(lambda x: x / 2, values))

    print(count)

def canBeDevide(values, num):
    return all(x % 2 == 0 for x in values)








main()


Measured memory_bytes: 2940
//Gvs Akhil (Vicennial)
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ld(a) while(a--)
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define tcf(v,i) for(auto i : v)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator
#define INF 		0x3f3f3f3f
#define LLINF       1000111000111000111LL
#define PI 			3.14159265358979323
#define endl '\n'
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N=1000006;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<ii,vii,greater<ii> > spq;
const ll MOD=1000000007LL;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T> T power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
int32_t main(){
	int n,x; cin>>n>>x;
	vi v(n);
	rep(i,0,n) cin>>v[i];
	sort(all(v));
	int ans=0;
	rep(i,0,n){
		if(x>=v[i]) ++ans,x-=v[i];
		else{
			x=0; break;
		}
	}
	if(x) --ans;
	cout<<ans;
}

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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define v(d_type) vector<d_type>
#define p(d_type1, d_type2) pair<d_type1, d_type2>
#define F first
#define S second
#define loop(i, s, n) for(int i = s; i < n; i++)
#define nl "\n"
#define fat 1000000007

int main()
{
    boost;
    
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    string s1(w, '0'), s2(w, '1');

    loop(i, a, w) s1[i] = '1', s2[i] = '0';

    loop(i, 0, h - b) cout << s1 << nl;
    loop(i, h - b, h) cout << s2 << nl;  

    return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> data(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
  vector<bool> h(H, false);
  vector<bool> w(W, false);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if(data.at(i).at(j) == '#') {
        h.at(i) = true;
        w.at(j) = true;
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    if (!h.at(i)) {
      continue;
    }
    
    for (int j = 0; j < W; j++) {
      if (!w.at(j)) {
        continue;
      }
      
      cout << data.at(i).at(j);
    }
    
    cout << endl;
  }
  
}

Measured memory_bytes: 256
use std::collections::{HashMap, HashSet, VecDeque};
use std::io::{self, BufRead};
fn main() {
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    let mut buf = String::new();
    handle.read_line(&mut buf).unwrap();
    let tmp = buf
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .collect::<Vec<_>>();
    let N = tmp[0];
    let M = tmp[1];
    buf.clear();

    let LRD = {
        let mut ret = Vec::with_capacity(M);
        for i in 0..M {
            handle.read_line(&mut buf).unwrap();
            let tmp = buf
                .trim()
                .split_whitespace()
                .map(|x| x.parse::<usize>().unwrap())
                .collect::<Vec<_>>();
            ret.push((tmp[0] - 1, tmp[1] - 1, tmp[2] as i64));
            buf.clear();
        }
        ret
    };

    let mut edges = Vec::new();
    for _ in 0..N {
        edges.push(vec![]);
    }
    for &(l, r, d) in &LRD {
        edges[l].push((r, d));
        edges[r].push((l, -d));
    }

    println!("{}", if solve2(N, &edges) { "Yes" } else { "No" });
}

fn solve(N: usize, edges: &Vec<Vec<(usize, i64)>>) -> bool {
    let mut visited = HashSet::new();
    for i in 0..N {
        if visited.contains(&i) {
            continue;
        }
        let mut rel_pos = HashMap::new();
        let mut queue = VecDeque::new();
        queue.push_back((i, 0));
        while let Some((n, pos)) = queue.pop_front() {
            if visited.contains(&n) {
                continue;
            }
            rel_pos.insert(n, pos);
            visited.insert(n);
            for &(to, d) in &edges[n] {
                if let Some(&r) = rel_pos.get(&to) {
                    if pos + d != r {
                        return false;
                    }
                }
                queue.push_back((to, pos + d));
            }
        }
    }
    true
}

fn solve2(N: usize, edges: &Vec<Vec<(usize, i64)>>) -> bool {
    let mut visited = HashSet::new();
    let mut rel_pos = vec![None; N];
    for i in 0..N {
        if visited.contains(&i) {
            continue;
        }
        let mut queue = VecDeque::new();
        queue.push_back((i, 0));
        while let Some((n, pos)) = queue.pop_front() {
            if visited.contains(&n) {
                continue;
            }
            rel_pos[n] = Some(pos);
            visited.insert(n);
            for &(to, d) in &edges[n] {
                if let Some(r) = rel_pos[to] {
                    if pos + d != r {
                        return false;
                    }
                }
                queue.push_back((to, pos + d));
            }
        }
    }
    true
}


Measured memory_bytes: 38136
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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;
}

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//素因数分解
vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int N; cin >> N;
    FOR(i,1,11){
        if(i*1000>=N){
            cout << i*1000 - N << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3624
n = int(input())
s = input()

r_num, g_num, b_num = 0, 0, 0
for i in s :
    if i == "R":
        r_num+=1
    elif i== "G":
        g_num +=1
    else:
        b_num+=1

ans = r_num * g_num *b_num

for i in range(len(s)):
    for j in range(i,len(s)):
        k = 2*j -i 
        if k <= j :
            continue
        else:
            if len(s) > k and k > 0  and s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                ans  -=1

print(ans)



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

int count(int x){
  if(x%2 != 0){
    return 0;
  }else{
    return 1+count(x/2);
  }
}
  
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int ans=0;
  REP(i,n){
    cin>>a[i];
    ans += count(a[i]);
  }
  
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

int main()
{
  int R, G, B;
  cin >> R >> G >> B;
  if((R * 100 + G * 10 + B) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

for i in range(n+1)[1:]:
  if i % 3 == 0:
    print(" {}".format(i),end="")
    continue

  if i % 10 == 3:
    print(" {}".format(i),end="")
    continue

  x = i
  while x > 1:
    x = int(x / 10)
    if x % 10 == 3:
      print(" {}".format(i),end="")
      break


print()


Measured memory_bytes: 5876
#include <iostream>

int main()
{
    int hp1 = 0;
    std::cin >> hp1;
    int atk1 = 0;
    std::cin >> atk1;

    int hp2 = 0;
    std::cin >> hp2;
    int atk2 = 0;
    std::cin >> atk2;

    auto calcTurn = [](int hp, int atk)
    {
        auto mod = hp % atk;
        auto turn = hp / atk + (mod > 0 ? 1 : 0);
        return turn;
    };
    auto turn2 = calcTurn(hp2, atk1);
    auto turn1 = calcTurn(hp1, atk2);
    if (turn2 > turn1)
    {
        std::cout << "No";
    }
    else
    {
        std::cout << "Yes";
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,h;
    cin>>n>>h;
    int a;
    vi b(n);
    int maa=0;
    REP(i,n){
        cin>>a>>b[i];
        chmax(maa,a);
    }
    sort(all(b),greater<int>());
    int cnt=0;
    REP(i,n){
        if(maa>b[i])break;
        h-=b[i];
        cnt++;
        if(h<=0)break;
    }
    if(h>0){
        cnt+=(h+maa-1)/maa;
    }
    cout<<cnt<<endl;

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++){
    cin >> B[i];
  }
  A[N-1] = B[N-2];
  A[0] = B[0];
  for(int j=N-2;j>0;j--){
    if(B[j]>=B[j-1]){
      A[j] = B[j-1];
    }
    else if(B[j]<B[j-1]){
      A[j] = B[j];
    }
  }
  cout << accumulate(A.begin(),A.end(),0) << endl;
  return 0;
}

Measured memory_bytes: 256
//18-1 鉛筆
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
    double N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    cout << min(ceil(N/A)*B,ceil(N/C)*D) << endl;
    return 0;
}


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

int main()
{
	ll a,b,k;
	scanf("%lld%lld%lld",&a,&b,&k);
	if(k <= a) printf("%lld %lld\n",a-k,b);
	else printf("0 %lld\n",max(0ll,b-(k-a)));
	return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
           int[] X = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            for(int i = 0; i < X.Length; i++)
            {
                if(X[i] == 0)
                {
                    Console.WriteLine(i + 1);
                }
            }
        }
    }
}

Measured memory_bytes: 27968
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n, d;
    cin >> n >> d;
    cout << (int)ceil((float)n / (float)(d * 2 + 1)) << endl;

    return 0;
}


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

int N, M;
vector<vector<int>> E;

bool try_path(vector<int> A) {
    bool can_go = true;
    for (int i = 0; i < A.size() - 1; i++) {
        int p_node = A.at(i);
        int n_node = A.at(i + 1);
        vector<int> adj = E.at(p_node);
        if (adj.end() == find(adj.begin(), adj.end(), n_node)) {
            can_go = false;
            break;
        }
    }
    return can_go;
}

int main() {
    cin >> N >> M;
    E.resize(N, vector<int>());
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        E.at(a).push_back(b);
        E.at(b).push_back(a);
    }
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        A.at(i) = i;
    }

    int num_path = 0;
    do {
        if (try_path(A)) {
            num_path++;
        }
    } while(next_permutation(A.begin() + 1, A.end()));

    cout << num_path << endl;
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)
#define IINF 2e9
#define MOD 1e9+7

int main(void){

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int t1 = h1*60 + m1;
    int t2 = h2*60 + m2;

    if(t2 - t1 < k) cout << 0 << endl;
    else cout << t2 - t1 - k << endl;


    return 0;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
N,A,B=map(int, raw_input().split())
if N==1:    #整数が1個のとき
    if A!=B:    #minとmaxが異なる場合はない
        print 0
    else:
        print 1
else:   #整数が2個以上のとき
    if B<A:
        print 0
    elif B==A:
        print 1  
    elif A<B:
        print A+B+B*(N-2)-(A+B+A*(N-2))+1

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

using namespace std;

int main(){
	int h, n;
	scanf("%d %d", &h, &n);
	for (int i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		h -= x;
	}
	if (h <= 0)
		puts("Yes");
	else 
		puts("No");
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	S, T := ReadString(), ReadString()
	s := make([]int, len(S)+1)
	for i := 0; i < len(S); i++ {
		v := 1
		if S[i] == 'B' {
			v = 2
		}
		s[i+1] = s[i] + v
		s[i+1] %= 3
	}
	t := make([]int, len(T)+1)
	for i := 0; i < len(T); i++ {
		v := 1
		if T[i] == 'B' {
			v = 2
		}
		t[i+1] = t[i] + v
		t[i+1] %= 3
	}

	q := ReadInt()
	for i := 0; i < q; i++ {
		a, b, c, d := ReadInt(), ReadInt(), ReadInt(), ReadInt()
		if (s[b]+3-s[a-1])%3 == (t[d]+3-t[c-1])%3 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

using namespace std;

int solve(){
    int x,n;
    cin>>x>>n;
    vector<int> v(n);
    int exists=0;
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
        if(x==v[i]) exists=1;
    }

    if(exists==0){
        cout<<x;
        return 0;
    }

    sort(v.begin(),v.end());

    int indexl=lower_bound(v.begin(), v.end(), x) - v.begin();
    int indexu=indexl;

    int res=0,lower=x,upper=x;
    while(1){
        indexl--;
        lower--;
        upper++;
        indexu++;
        if(indexl>=0 && lower!=v[indexl]){
            res=lower;
            break;
        }
        if(indexl<0){
            res=lower;
            break;
        }

        if(indexu<n && upper!=v[indexu]){
            res=upper;
            break;
        }
        if(indexu>=n){
            res=upper;
            break;
        }

    }

    cout<<res;
    

    return 0;
}

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


Measured memory_bytes: 3664
#include <iostream>
#include <cmath>
#include <vector>
#include <cctype>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;

#define MAXVALUE 1 << 21

vector<int> dp(5001, MAXVALUE);

int init(){
    int item[6] = {200, 300, 500, 1000, 1200, 1500};
    int price[6] = {380, 550, 850, 1520, 1870, 2244};
    dp[0] = 0;
    for (int k = 0; k < 6; k++){
	for (int i = 0; i + item[k] <= 5000; i++){
	    dp[i+item[k]] = min(dp[i+item[k]], dp[i] + price[k]);
	}
    }
}

int main(){
    init();
    int n, mi;
    while (cin >> n && n){
	mi = dp[n];
	cout << mi << endl;
    }
}

Measured memory_bytes: 0
from collections import deque

areas = input()
S1 = deque([])
S2 = deque([])

sum_ = 0

for i,ch in enumerate(areas):
    if ch == "\\":
        S1.append(i)
    elif ch == "/" and len(S1) > 0:
        j = S1.pop()
        sum_ += i-j
        a = i-j
        while len(S2) > 0 and S2[-1][0] > j:
            a += S2.pop()[1]
        S2.append([j,a])

ans = []
while len(S2) > 0:
    ans.append(S2.pop()[1])

ans.reverse()

A = sum(ans)
print(A)

ans.insert(0,len(ans))
L = map(str,ans)
print(" ".join(L))


Measured memory_bytes: 6564