akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }

int gcd(int a,int b){
    if(b==0) return a;
    else return gcd(b,a%b);
}
vector<int>v;
bool isPresent(int n){
    for(int i=0;i<v.size();i++){
        if(v[i]==n) return true;
    }
    return false;
}
int main(){
    int t=1 ;
    //cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        int x,y;
        cin>>x>>y;
        int a[n];
        int b[m];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<m;i++){
            cin>>b[i];
        }
        sort(a,a+n);
        sort(b,b+m);
        int m1x=a[n-1];
        int m2n=b[0];
        int flag=0;
        for(int i=x+1;i<=y;i++){
            if(m1x<i && m2n>=i) flag=1;
        }
        if(flag==0)cout<<"War";
        else cout<<"No War";
        return 0;
    }
}
    

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

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

    if((C >= A) && (C <= B)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
int main(){
    int n;
    cin>>n;
    string a;
    vector<string> v;
    for(int i=0; i<n; i++){
        cin >> a;
		v.push_back(a);
    }
    sort(v.begin(), v.end());
    int co[n];
    co[0]=0;
    int p=-1;
    rep11(i,n){
       if(v[i-1]==v[i]){
           co[i]=1+co[i-1];
       }
       else{
          co[i]=0;
       }
        p=max(co[i],p);

    }
    
    rep(i,n){
        if (co[i]==p){
            cout<<string(v[i])<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 15472
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
//#define x first
//#define y second
#define pb push_back
#define eb emplace_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
const int MAX_N = 1e5 + 5;
const LL mod = 1e9 + 7;

int n, a, b;

int main()
{
#ifdef ANONYM
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, w, h, x, y, ans = 0; cin >> w >> h >> n;
	int xx[1001] = { 0 }; int yy[1001] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		xx[i] = x; yy[i] = y;
		if (i >= 1) {
			if (xx[i] - xx[i - 1] > 0 && yy[i] - yy[i - 1] > 0) {
				ans += max(xx[i] - xx[i - 1], yy[i] - yy[i - 1]);
			}
			else if (xx[i] - xx[i - 1] < 0 && yy[i] - yy[i - 1] < 0) {
				ans += max(xx[i - 1] - xx[i], yy[i - 1] - yy[i]);
			}
			else {
				ans += abs(xx[i] - xx[i - 1]) + abs(yy[i] - yy[i - 1]);
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)

int main()
{
    int n,w;
    cin>>n>>w;
    int weight[n],value[n];
    REP(i,n)cin>>weight[i]>>value[i];
    vector<vector<ll>>dp(n+1,vector<ll>(w+1,0));
    REP(i,n)
        for(int j=0;j<=w;j++)
            dp[i+1][j]=j>=weight[i]?max(dp[i][j],dp[i][j-weight[i]]+value[i]):dp[i][j];
    cout<<dp[n][w]<<endl;
}


Measured memory_bytes: 80256
#include <iostream>
using namespace std;
int a[200005],n;
bool b[200005];
bool pd(int x){
	for(int i=1;i<=n*2-1;i++) b[i]=(a[i]>=x);
	b[0]=b[1];
	for(int i=n;i<=n+n-1;i++){
		if(b[i]==b[i+1]) return b[i];
		if(b[n+n-i]==b[n+n-i-1]) return b[n+n-i];
	}
	return b[1];
}
int main(){
	cin>>n;
	for(int i=1;i<=n*2-1;i++)cin>>a[i];
	int l=1,r=n*2,A=0,md;
	while(l<=r){
		md=(l+r)/2;
		if(pd(md)) l=md+1,A=max(A,md); 
		else r=md-1;
	}
	cout<<A;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>
#define INF 100000000
#define MOD 1000000007
using namespace std;



int main(){
    int A,B;
    cin >> A >> B;
    
    int ans=0;
    for(int i=A; i<=B; i++){
        int x=i;
        int j=0;
        while(x>0){
            j*=10;
            j+=x%10;
            x/=10;
        }
        if(i==j){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
A, B, C, X = (int(input()) for i in range(4))
res = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      total = 500*a + 100*b + 50*c
      if(total == X): res += 1
print(res)

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

#define ll long long
#define pb push_back
#define mp make_pair

int main() 
{
	 ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cin.tie(NULL);
     ll int n;
     cin>>n;
    int a[n],ans=0;
     for(int i=0;i<n;i++)cin>>a[i];
     for(int i=0;i<n;i++)
     {
		while(i+1<n && a[i]==a[i+1]){i++;}
		if(i+1<n && a[i+1]>a[i])
		{
			while(i<n-1 && a[i+1]>=a[i])
			i++;
		}
		else if(i+1<n && a[i+1]<a[i])
		{
			while(i<n-1 && a[i+1]<=a[i] )
			i++;
		}
		ans++;
	}
	cout<<ans<<endl;
			 
}
		 
    
            



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

struct state{
  int x,y,c;
  state(){}
  state(int x,int y,int c):x(x),y(y),c(c){}
  bool operator<( const state& st ) const {
    return c > st.c;
  }
};

int fie[1011][1011];
int cost[1011][1011];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int dc[256];

int W,H,N;

void posc(int &x,int &y){
  x = 2*x+1; y = 2*y+1;
}
bool check(int x,int y){
  return 0 <= x && x <= 2*W && 0 <= y && y <= 2 * H;
}

int main(){
  dc['R']=0;
  dc['D']=1;
  dc['L']=2;
  dc['U']=3;
  cin >> W >> H >> N;
  int sx,sy,ex,ey; cin >> sx >> sy >> ex >> ey;
  for(int i=0;i<N;i++){
    int x,y; cin >>x >> y;
    posc(x,y);
    int t; cin >> t;
    string s; cin >> s;
    for(int j=0;j<t;j++){
      for(int k=0;k<(int)s.size();k++){
        int nx = x + dx[dc[s[k]]]*2, ny = y + dy[dc[s[k]]]*2;
        if( check( nx, ny ) ){
          fie[(nx+x)/2][(ny+y)/2]++;
          x = nx; y = ny;
        }
      }
    }
  }


  fill(cost[0],cost[1000],(1<<29));
  sx*=2; sy*=2; ex*=2; ey*=2;
  priority_queue<state> q;
  q.push( state(sx,sy,0) );
  cost[sx][sy] = 0;
  while( !q.empty() ){
    state p = q.top(); q.pop();
    if( cost[p.x][p.y] < p.c ) continue;
    for(int i=0;i<4;i++){
      int nx = p.x + dx[i]*2, ny = p.y + dy[i]*2;
      if( check(nx,ny) ){        
        int nc = fie[(nx+p.x)/2][(ny+p.y)/2];
        if( cost[nx][ny] > p.c+nc ){
          q.push(state(nx,ny,p.c+nc ));
          cost[nx][ny] = p.c+nc;
        }
      }
    }
  }
  cout << cost[ex][ey] << endl;
}

Measured memory_bytes: 13104
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
def merge(target_list, left_index, mid_index,right_index):
    l = target_list[left_index:mid_index] + [pow(10,9) + 1]
    r = target_list[mid_index:right_index] + [pow(10,9) + 1]
    l_target = 0
    r_target = 0
    count = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1

    return count
    #print(target_list)
            
def merge_sort(target_list, left_index, right_index):
    count = 0
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        count += merge_sort(target_list, left_index, mid_index)
        count += merge_sort(target_list, mid_index, right_index)
        count += merge(target_list, left_index, mid_index,right_index)
    return count
if __name__ == "__main__":
    l = input()
    target_list = [int(a) for a in input().split()]
    count = 0
    count = merge_sort(target_list, 0, len(target_list))
    print(" ".join([str(n) for n in target_list]))
    print(count)

Measured memory_bytes: 69040
#include <bits/stdc++.h>
using namespace std;
#define sync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define repp(i,a,n) for(int i=a; i<int(n); ++i)
#define sz(x) int((x).size())
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define mp make_pair

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T> &input){for (auto const& i: input) {os << i << " ";}return os;}
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T> &input){for (auto const& i: input) {os << i << " ";}return os;}
template<class T, size_t n> std::ostream& operator<<(std::ostream& os, const std::array<T, n> &input){for (size_t i=0; i<n; ++i) {os << input[i] << " ";}return os;}
template<class T1, class T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1,T2> &input){os << "(" << input.first << ", " << input.second << ')';return os;}
template<class T1, class T2> std::ostream& operator<<(std::ostream& os, const std::unordered_map<T1,T2> &input){for (auto const& i: input) {os << i << " ";}return os;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << H;debug_out(T...);}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

double startTime;
double getCurrentTime(){return ((double)clock() - startTime) / CLOCKS_PER_SEC;}

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<pi> vp;
typedef vector<ll> vl;
typedef vector<vi> vvi;

// === temeplate ===

const int maxn = 50;

void solve(){
	int n; cin >> n;
	int last = 0;
	ll ans = 0;
	rep(i,n){
		int x; cin >> x;
		if(x < last) ans += last - x; else last = x;
	}
	cout << ans  << endl;
}

int main(){
    sync;
    int cas = 1;
    // cin >> cas;
    rep(ca, cas) solve();
    return 0;
}

Measured memory_bytes: 3668
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
#include<vector>
#include<cmath>

using namespace std;
int main()
{
    long long n, d;

    cin >> n >> d;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        long long x, y;
        cin >> x >> y;

        double a = sqrt(x * x + y * y);
        if (a <= d) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main()
{
  int a[3];

  cin>>a[0]>>a[1]>>a[2];

  sort(a,a+3);
  cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;

  return 0;
  
}



Measured memory_bytes: 3132
def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i = i + 1
            temp = A[i]
            A[i] = A[j]
            A[j] = temp
    temp = A[i+1]
    A[i+1] = A[r]
    A[r] = temp
    return i+1


if __name__ == "__main__":
    n = int(input())
    B = list(map(int, input().split()))
    p = partition(B, 0, n-1)
    print(" ".join(map(str, B[:p])) + " [" + str(B[p]) + "] " + " ".join(map(str, B[p+1:])))

Measured memory_bytes: 18412
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
#include <bitset>
#include <set>
using namespace std;

#define fi first
#define se second

typedef pair<int,int> pii;

const int dxy[] = {1, 0, -1, 0, 1};
char maze[15][15];
int ice[15][15];
vector<long long> icesq;

struct data {
	int x, y;
	int t;
	long long v;
	data(int x_, int y_, int t_, long long v_) {
		x = x_;
		y = y_;
		t = t_;
		v = v_;
	}
};

int maketag(int i, int j, int n) {
	if(maze[i][j] != 'X' || ice[i][j] != -1)
		return 0;
	ice[i][j] = n;
	int res = 1;
	for(int k = 0; k < 4; k++)
		res += maketag(i+dxy[k], j+dxy[k+1], n);
	return res;
}

int main() {
	int x, y;
	while(cin >> x >> y, x || y) {
		for(int i = 0; i < 15; i++) {
			for(int j = 0; j < 15; j++) {
				maze[i][j] = '#';
				ice[i][j] = -1;
			}
		}
		for(int i = 0; i < y; i++) {
			scanf("%s", maze[i+1]+1);
			maze[i+1][1+x] = '#';
		}
		icesq.clear();
		int tg = 0;
		pii S, G;
		for(int i = 0; i < y; i++) {
			for(int j = 0; j < x; j++) {
				int res;
				if(maze[i+1][j+1] == 'S') {
					maze[i+1][j+1] = '.';
					S.fi = i+1; S.se = j+1;
				}
				else if(maze[i+1][j+1] == 'G') {
					maze[i+1][j+1] = '.';
					G.fi = i+1; G.se = j+1;
				}

				res = maketag(i+1,j+1,tg);
				if(res != 0) {
					icesq.push_back(res / 2);
					tg++;
				}
			}
		}
/*
		for(int i = 0; i < 14; i++) {
			for(int j = 0; j < 14; j++) {
				cout << maze[i][j];
			} cout << endl;
		}
// */
/*
		for(int i = 0; i < icesq.size(); i++) {
			cout << icesq[i] << " ";
		} cout << endl;
// */
		queue<data> q;
		q.push(data(S.se, S.fi, 0, 0));
		vector<long long> radix;
		radix.resize(icesq.size() + 1);
		radix[0] = 1;
		for(int i = 1; i < radix.size(); i++) {
			radix[i] = radix[i-1] * (icesq[i-1] + 1);
		}
		set<long long> visited[12][12];
		for(int i = 0; i < 12; i++) {
			for(int j = 0; j < 12; j++) {
				visited[i][j].clear();
			}
		}
		visited[S.fi-1][S.se-1].insert(0LL);
		while(!q.empty()) {
			data cur = q.front();
			q.pop();
//			cout << cur.y << " " << cur.x << " " << cur.t << ":";
			if(cur.y == G.fi && cur.x == G.se) {
				cout << cur.t << endl;
				break;
			}
			for(int i = 0; i < 4; i++) {
				int nx, ny;
				ny = cur.y + dxy[i];
				nx = cur.x + dxy[i+1];

				if(!(0 < nx && nx <= x && 0 < ny && ny <= y)) {
					continue;
				}

				if(maze[ny][nx] == '.') {
					if(visited[ny-1][nx-1].find(cur.v) == visited[ny-1][nx-1].end()) {
						visited[ny-1][nx-1].insert(cur.v);
						q.push(data(nx, ny, cur.t + 1, cur.v));
					}
				}
				else if(maze[ny][nx] == 'X') {
					long long flgcnts;
					flgcnts = (cur.v % radix[ice[ny][nx]+1]) / radix[ice[ny][nx]];
					if(flgcnts < icesq[ice[ny][nx]]) {
						long long tmp = cur.v + radix[ice[ny][nx]];
						if(visited[ny-1][nx-1].find(tmp) == visited[ny-1][nx-1].end()) {
							visited[ny-1][nx-1].insert(tmp);
							q.push(data(nx, ny, cur.t + 1, tmp));
						}
					}
				}
			}
		}
//		cout << "----------" << endl;
	}
}

Measured memory_bytes: 40704
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){
string s;
cin>>s;
string t;
cin>>t;
int slen=s.size();
int tlen=t.size();
int  dp[slen+1][tlen+1]={};
//dp[i+1][j+1]:=
//Sのi文字めまでとTのj文字目まででのLCSの長さ
int size=0;
for (int i = 0; i < s.size(); ++i) {
    for (int j = 0; j < t.size(); ++j) {
      if (s[i] == t[j]) {
          if(dp[i+1][j+1]<dp[i][j]+1){
              dp[i+1][j+1]=dp[i][j] + 1;
          }
      }
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
    }
  }
//cout<<dp[s.size()][t.size()]<<endl;
string res="";
    int i=slen;
    int j=tlen;
    //dp[i][j]:=の値が変化した時のi,jについて
    //s[i]を先頭に挿入していく。
    //i,jがdp[][]テーブル外に出たら終了
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            res=s[i-1]+res;// add to the head
            //cout<<res<<endl;
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    cout<<res;  

 return 0;
}

Measured memory_bytes: 35456
/*
* @Author: kabbo
* @Date:   2020-06-24 08:40:07
* @Last Modified by:   kabbo
* @Last Modified time: 2020-06-24 08:49:58
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<long long,long long>
#define endl '\n'
#define ull unsigned long long
#define ll long long
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
#define sc1(x) scanf("%lld",&(x));
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int h, w;
char board[1005][1005];
bool legal(int x, int y) {
    if (x<0 or y<0 or y >= h or x >= w or board[x][y] == '#')return false;
    return true;
}
void solve() {

    cin >> w >> h;
    int sy, sx, ex, ey;
    cin >> sx >> sy;
    sx--, sy--;
    cin >> ex >> ey;
    ex--; ey--;

    for (int i(0); i < w; ++i) {
        for (int j(0); j < h; ++j) {
            cin >> board[i][j];
        }
    }
    deque<array<int, 2>>dq;
    dq.push_back({sx, sy});
    int dist[w][h];
    for (int i(0); i < w; ++i) {
        for (int j(0); j < h; ++j) {
            dist[i][j] = 1e7;
        }
    }
    /*for (auto& x : dist) {
        for (auto &c : x)
            cout << c << " ";
        cout << endl;
    }*/
    dist[sx][sy] = 0;
    int dx[4] = { -1, 1, 0, 0};
    int dy[4] = {0, 0, -1, 1};
    while (!dq.empty()) {
        auto k = dq.front(); dq.pop_front();
        int curx = k[0], cury = k[1];
        for (int d(0); d < 4; ++d) {
            int nx = curx + dx[d], ny = cury + dy[d];
            if (!legal(nx, ny))continue;
            if (dist[nx][ny] > dist[curx][cury]) {
                dist[nx][ny] = dist[curx][cury];
                dq.push_front({nx, ny});
            }
        }
        for (int x = curx - 2; x <= curx + 2; x++) {
            for (int y = cury - 2; y <= cury + 2; y++) {
                if (!legal(x, y))continue;

                if (dist[x][y] > dist[curx][cury] + 1) {
                    dist[x][y] = dist[curx][cury] + 1;
                    dq.push_back({x, y});
                }
            }
        }

    }
    if (dist[ex][ey] > 1e6) {
        cout << "-1" << endl;

    }
    else
        cout << dist[ex][ey] << endl;
}
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    /*int t;
    cin>>t;
    for (int i(1); i <= t; ++i) {
        printf("Case %d:\n", i);*/
    solve();
    //}
    return 0;
}

Measured memory_bytes: 8588
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main()
{
  string str;
  string pri;
  string rev;
  string p;
  string oreder;
  int q;
  int i;
  int a;
  int b;
  int j;
  int k;
  
  cin >> str >> q;
  
  for(k=0;k<q;k++)
  {
    cin >> oreder;
    if(oreder=="print")
    {
      cin >> a >> b;
      
      pri=str.substr(a,(b-a+1));
      
      cout << pri <<"\n";
      continue;
    }
    
    if(oreder=="reverse")
    {
      cin >> a >> b;
      rev=str.substr(a,(b-a+1));
      for(i=a,j=(b-a);i<=b;i++,j--)
      {
        str[i]=rev[j];
      }
      continue;
    }
    
    if(oreder=="replace")
    {
      cin >> a >> b >> p;
      
      for(i=a,j=0;i<=b;i++,j++)
      {
        str[i]=p[j];
      }
      continue;
    }
    
  }
}

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

using namespace std;

void solve()
{
    int n;
    string s;
    cin >> n >> s;
    vector<int> ws(n + 1), bs(n + 1);
    for (int i = 0; i < n; i++)
    {
        bs[i + 1] = bs[i] + (s[i] == '#');
    }
    for (int i = n; i > 0; i--)
    {
        ws[i - 1] = ws[i] + (s[i - 1] == '.');
    }
    int ans = n;
    for (int i = 0; i <= n; i++)
    {
        ans = min(ans, ws[i] + bs[i]);
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 2180
a, b, k = (int(i) for i in input().split())
l = [i for i in range(a,b+1)] if b - a < 110 else [i for i in range(a,a+110)] + [i for i in range(b-110,b+1)]
for i in sorted(set(l[:k]) | set(l[-k:])):
    print(i)

Measured memory_bytes: 38324
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include <limits>
#include <iomanip>

using namespace std;

int main(){
	long long int a,b,k;
	
	cin >> a >> b >> k;
	
	if(k > a+b){
		cout << 0 << ' ' << 0 << endl;
	}else if(k > a){
		cout << 0 << ' ' << b+a-k << endl;
	}else cout << a-k << ' ' << b << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
   
   int N;
   scanf("%d",&N);
   
   int i;
   double A[N];
   
   for (i = 0;i < N;i++) {
      scanf("%lf",&A[i]);
   }
   
   double ans = 0;
   double min1,min2;
   int ind1,ind2;
   int check;
   
   while (1) {
      min1 = 2000;
      for (i = 0;i < N;i++) {
         if (min1 > A[i] && A[i] > 0) {
            min1 = A[i];
            ind1 = i;
         }
      }
      min2 = 2000;
      for (i = 0;i < N;i++) {
         if (min2 > A[i] && A[i] > 0 && i != ind1) {
            min2 = A[i];
            ind2 = i;
         }
      }
      check = 0;
      for (i = 0;i < N;i++) {
         if (A[i] > 0) {
            check++;
         }
      }

      if (check == 1) {
         ans = min1;
         break;
      }
   
      A[ind2] = (min1 + min2)*0.5;
      A[ind1] = -1;
      
   }
 
   printf("%lf\n",ans);
   
   return 0;
}



Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void){
	char sstr[4];
	cin >> sstr;
	
	char tstr[4];
	cin >> tstr;
	
	int res = 0;
	if(sstr[0] == tstr[0]) ++res;
	if(sstr[1] == tstr[1]) ++res;
	if(sstr[2] == tstr[2]) ++res;
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
main(){char* l="RYBMGC";int i,j,n,a,c[6],f,s,t[4],r[][4]={{1,2,4,3},{5,2,0,3},{0,1,5,4},{0,4,5,1},{0,2,5,3},{2,1,3,4}};while(scanf("%d",&n),n){a=0;int u[9999]={0};while(n--){char b[16];for(i=0;i<6;++i){scanf("%s",b);for(j=0;l[j]!=*b;++j);c[i]=j;if(j==0)f=i;}for(i=0;i<4;++i)t[i]=c[r[f][i]];for(i=0;i<3;++i){s=0;for(j=0;j<4;++j)s=s*10+t[(i+j)%4];if(u[s]){++a;break;}else u[s]=1;}}printf("%d\n",a);}exit(0);}

Measured memory_bytes: 0
#include<iostream>
#include<string>
using namespace std;
struct man{int x,y,d;};
int main(){
  string st[9];
  int i,j,k;
  for(i=0;i<9;i++) cin >> st[i];
  bool f=false,mo=false;
  man m;
  m.x=1;m.y=0;m.d=0;
  int c=0;
  cout << "R";
  while(1){
    c++;
    mo=false;
     
    if(m.x==1&&m.y==1&&m.d==2) {
      //cout << "L";
      break;
    }
    if(m.x==0&&m.y==1&&f) {
      //cout << "U";
      break;
    }
    f=true;
     
    //cout << m.x<<":"<<m.y<<":"<<m.d << endl;
    if(m.d==0){
      if(m.y>0){
    if(st[m.y*2-1][m.x]=='1') {
      cout << "U";
      m.d=3;
      continue;
    }
      }
      if(m.y<5){
    if(st[m.y*2][m.x]=='1') {
      m.x++;
      cout << "R";
      continue;
    }
      }
      if(m.y<4){
    if(st[m.y*2+1][m.x]=='1') {
      m.x++;
      m.y++;
      cout << "D";
      m.d=1;
      continue;
    }
      }
      m.y++;
      cout << "L";
      m.d=2;
      continue;
    }
     
    if(m.d==1){
      if(m.y<5){
    if(st[m.y*2][m.x-1]=='1') {
      cout <<"R";
      m.d=0;
      continue;
    }
      }
      if(m.x>0&&m.y<4){
    if(st[m.y*2+1][m.x-1]=='1') {
      m.y++;
      cout << "D" ;
      mo=true;
      continue;
    }
      }
      if(m.x>1&&m.y<5){
    if(st[m.y*2][m.x-2]=='1') {
      m.x--;
      m.y++;
      cout << "L";
      m.d=2;
      continue;
    }
      }
      m.x--;
      cout << "U";
      m.d=3;
      continue;
    }
    if(m.d==2){
      if(m.x>0){
    if(st[m.y*2-1][m.x-1]=='1') {
      cout << "D";
      m.d=1;
      continue;
    }
      }
      if(m.x>1&&m.y>0){
    if(st[(m.y-1)*2][m.x-2]=='1') {
      m.x--;
      cout << "L" ;
      mo=true;
      continue;
    }
      }
      if(m.x>0&&m.y>1){
    if(st[(m.y-1)*2-1][m.x-1]=='1') {
      m.x--;
      m.y--;
      cout << "U";
      m.d=3;
      continue;
    }
      }
      m.y--;
      cout << "R";
      m.d=0;
      continue;
    }
    if(m.d==3){
 
      if(m.y>0){
    if(st[(m.y-1)*2][m.x-1]=='1') {
      cout << "L";
      m.d=2;
      continue;
    }
      }
      if(m.y>1){
    if(st[(m.y-1)*2-1][m.x]=='1') {
      m.y--;
      cout << "U" ;
      mo=true;
      continue;
    }
      }
      if(m.y>0){
    if(st[(m.y-1)*2][m.x]=='1') {
      m.x++;
      m.y--;
      cout << "R";
      m.d=0;
      continue;
    }
      }
      m.x++;
      cout << "D";
      m.d=1;
      continue;
    }
    //if(!mo)m.d=(m.d+2)%4;
  }
   
  cout  << endl;
  return 0;
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char S[6];
int main(){
  rd(S);
  if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3]){
    wt_L("Bad");
    wt_L('\n');
  }
  else{
    wt_L("Good");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190706-1

// --- original code ---
// char S[6];
// {
//   rd(S);
//   wt( if[S[0]==S[1]||S[1]==S[2]||S[2]==S[3], "Bad", "Good"] );
// }


Measured memory_bytes: 256
#include <iostream>
#include "string.h"
using namespace std;
int main(){
char a,b;
cin>>a>>b;
if(a =='H'){
    if(b=='H')
        cout<<"H \n";
    else{
        cout<<"D \n";
    }
}
else if(a=='D'){
        if(b=='D')
        cout<<"H \n";
    else{
        cout<<"D \n";
    }
}
}


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

int main()
{
    string S; cin >> S;
    int count = 0;
    char tmp;
    for (int i=0; i<S.size(); i++) {
        if (tmp != S.at(i)) {
            tmp = S.at(i);
            count++;
            continue;
        }
        if (i+1<S.size()) {
            tmp = S.at(i) + S.at(i+1);
            count++;
            i++;
            continue;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 640
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M = read_ints()
    odds = set()
    for _ in range(M):
        for c in read_ints():
            if c in odds:
                odds.discard(c)
            else:
                odds.add(c)
    if odds:
        return 'NO'
    return 'YES'


if __name__ == '__main__':
    print(solve())


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

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a - c) <= d){
        cout << "Yes" << endl;
        return 0;
    }
    if(abs(a - b) <= d and abs(b - c) <= d){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

abc_input = list(map(int, input().split()))
a = abc_input[0]
b = abc_input[1]
c = abc_input[2]

factor = gcd(a, b)

for i in range(1,b+1):
    if i*factor == c:
        print('YES')
        exit()
print('NO')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

//UnionFind
//How to use
//unite(x,y) : 集合 x と y を併合する. 併合済のとき false, 未併合のとき true が返される
//find(k) : 要素 k が属する集合を求める
//size(k) : 要素 k が属する集合の要素の数を求める
struct UnionFind {
    vector<int> data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    UnionFind uf(202020);
    int ans = 0;
    int N, M;
    cin >> N >> M;
    while (M--) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }
    for (int i = 0; i < N; i++) {
        chmax(ans, uf.size(i));
    }
    cout << ans << endl;

    solve();
    return 0;
}


Measured memory_bytes: 4720
/*
	* ernestvw
	* C++
	* April 2020
	* ABC164/D
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define veci vector<int>
#define vecs vector<string>
#define amax(x, v) x = max(x, (v))
#define amin(x, v) x = min(x, (v))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define nl '\n'

using ll = long long;
using ld = long double;
template <class T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

const int oo = 1e9; // INT_MAX
const int OO = 1e18; // LLONG_MAX
const double eps = 1e-9;

#define TEST_CASES 0

void solve(int test_case);

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

	int T = 1;
	if(TEST_CASES) cin >> T;
	for(int t = 1; t <= T; t++)
		solve(t);

	return 0;
}

// ---------------------------------------------------

map<int, int> occ;

void solve(int test_case) {
	string s;
	cin >> s;
	int cur = 0;
	int power = 1;
	reverse(all(s));
	occ[0]++;
	FOR(i, sz(s)) {
		cur += power * ((int)(s[i] - '0'));
		power *= 10;
		power %= 2019;
		cur %= 2019;
		occ[cur]++;
	}
	int rep = 0;
	for(auto p : occ) {
		rep += (p.second *(p.second - 1LL))/2LL;
	}
	cout<<rep<<endl;
}



















































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

int main(){
    std::string S;
    std::cin >> S;
    for(int i = 1; i < 3; i++){
        if(S[0] != S[i]){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10]={0};
int main()
{
	int n,m;
	int flag=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int s,c;
		scanf("%d%d",&s,&c);
		if(s==1&&c==0&&n!=1)
		{
			flag=1;
		}
		if(a[s-1]==c)
		{
			a[s-1]=c;
		}
		else if(a[s-1]!=0)
		{
			flag=1;
		}
		else
		{
			a[s-1]=c;
		}
	}
	if(flag)
	{
		printf("-1");
	}
	else if(n==1&&a[0]==0)
	{
		printf("0");
	}
	else
	{
		if(a[0]!=0)
		{
			printf("%d",a[0]);
		}
		else
		{
			printf("1");
		}
		for(int i=1;i<n;i++)
		{
			printf("%d",a[i]);
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a, b, c, d, e, f;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    e = a*b;
    f = c*d;
    if(e>f)
    {
        printf("%d", e);
    }
    else
    {
        printf("%d", f);
    }
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int w,h;
int x[555],y[555];
int s,t;

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n;
		if(n==0)break;
		cin>>w>>h;
		rep(i,n){
			cin>>x[i]>>y[i];
			x[i]--; y[i]--;
		}
		cin>>s>>t;
		int res=0;
		rep(i,h-t+1)rep(j,w-s+1){
			int cnt=0;
			rep(k,n){
				if(y[k]>=i&&y[k]<i+t&&x[k]>=j&&x[k]<j+s)cnt++;
			}
			maxch(res,cnt);
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<vector <int>> G(n);
    vector<int> nums(n, 0);
    for(int i=0; i<n-1; i++){
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[x].push_back(y);
    G[y].push_back(x);
    for(int i=0; i<n; i++){
        vector<int> nums_tmp(n, -1);
        queue<int> que;
        nums_tmp[i] = 0;
        que.push(i);
        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(auto nv : G[v]){
                if(nums_tmp[nv] != -1) continue;
                nums_tmp[nv] = nums_tmp[v] + 1;
                que.push(nv);
            }
        }
        for(int j=0; j<n; j++){
            nums[nums_tmp[j]]++;
        }
    }
    for(int i=1; i<n; i++){
        cout << nums[i] / 2 << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);


int main() {
    int k, s;
    cin >> k >> s;
    int ans = 0;
    rep(i, k + 1) {
        rep(j, k + 1) {
            if (s - i - j >= 0 && s - i - j <= k)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}	

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

int main(){
  int A,B,C,D,E,F,W,S;
  cin >> A >> B >> C >> D >> E >> F;
  double temp,max;
  max = 0.0;
  W = 0;
  S = 0;
  for(int a=0;100*A*a<=F;a++){
    for(int b=0;100*B*b<=F-100*A*a;b++){
      for(int c=0;c*C<=F-100*A*a-100*B*b;c++){
        for(int d=0;d*D<=F-100*A*a-100*B*b-c*C;d++){
          temp = 100.0*(double)(C*c+D*d)/(double)(100*A*a+100*B*b+c*C+d*D);
          if(C*c+D*d<=(A*a+B*b)*E){
          if(temp >= max){
            max = temp;
            W = 100*(A*a+B*b)+c*C+d*D;
            S = C*c + D*d;
          }
          }   
        }
      }
    }
  }
  cout << W << " " <<S << endl;
}

Measured memory_bytes: 3620
<?php
$n=intval(trim(fgets(STDIN)));

$Ln = [];

$input=explode(' ',trim(fgets(STDIN)));
for($i = 0; $i < $n; $i++){
    $Ln[] = intval($input[$i]);
}

//echo var_export($Ln, true) . PHP_EOL;

$maxLength = max($Ln);
$sum = 0;
$isLookMaxData = false;
foreach ($Ln as $data) {
    if (!$isLookMaxData && $data == $maxLength) {
        $isLookMaxData = true;
        continue;
    }

    $sum += $data;
}
//echo "max: " . $maxLength . PHP_EOL;
//echo "sum:" . $sum . PHP_EOL;

$result = ($maxLength < $sum) ? 'Yes' : 'No';


echo $result . PHP_EOL;



Measured memory_bytes: 3956
def main():
    n = int(input())
    s = input()
    q = int(input())
    k = list(map(int, input().split()))
    for ki in k:
        D=M=DM=C=0
        for i in range(n):
            if s[i] == "D":
                D += 1
            elif s[i] == "M":
                M += 1
                DM += D
            elif s[i] == "C":
                C += DM
            if i >= ki-1:
                j = i-ki+1
                if s[j] == "D":
                    D -= 1
                    DM -= M
                elif s[j] == "M":
                    M -= 1
        print(C)

if __name__ == "__main__":
    main()

Measured memory_bytes: 55916
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define rsi resize
 
#define er(x) cerr<<#x<<": "<<x<<" "<<endl
#define er2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define er3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define er4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define erar(a) {cerr<<#a<<" "; for(auto x : a) cerr<<x<<" "; cerr<<endl;}
 
#define int long long
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define mii map< int,int >
 
#define rep(i,a,b) for(i=a; i<b; i++)
#define repr(i,a,b) for(i=a; i>b; i--)
#define put(a,b) cout<<a<<b
#define sz(a) (int)a.size()
#define all(v) v.begin(),v.end()

 
struct node { double x,y; };
 
#define inf 100000000000000
#define M 1000000007
 
int n,m,k;


void solve()
{
    int i,j,x,y,z;
    string s;
    cin>>s;
    
    vi a;
    
    n = sz(s);
    int ct = 0;
    int ans = 0;
    
    rep(i,0,n-1)
    {
        if ( s[i] == 'B' && s[i+1] == 'C' )
        {
            a.pb(ct);
            i++;
            ct = 0;
            continue;
        }
        
        if ( s[i] == 'A' ) ct++;
        else
        {
            ct = 0;
            rep(j,0, sz(a) )
                ans += (sz(a)-j)*a[j];
            a.clear();
        }
    }
    
    rep(j,0, sz(a) )
                ans += (sz(a)-j)*a[j];
    
    put(ans,'\n');

}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    
    // cin>>t; 
    
    while(t--) solve();
}

Measured memory_bytes: 1680
n, a, b = map(int,input().split())
x = list(map(int,input().split()))
dp = [10**9]*(n+1)
dp[0] = 0
for i in range(n - 1):
    dp[i + 1] = min(dp[i] + a*(x[i + 1]-x[i]), dp[i] + b)
print(dp[n-1])

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

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

  int n, x;
  cin >> n >> x;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a,a+n);
  int ans = 0;
  for (int i = 0; i < n-1; i++) {
    if (x-a[i] >= 0) {
      x -= a[i];
      ans++;
    }
    else {
      cout << ans << '\n';
      return 0;
    }
  }
  if (x - a[n-1] == 0) cout << ans +1 << '\n';
  else cout << ans << '\n';
}

Measured memory_bytes: 256
fun main(s: Array<String>) {
    val (_d,cc) = readLine()!!.split(' ').map { it.toLong() }
    val hpList = readLine()!!.split(' ').map { it.toLong() }
    when {
        // すべての敵に必殺技を使える場合
        hpList.size <= cc -> {
            println(0)
        }
        // 1回も使えない場合、地道に攻撃するしか無い
        cc == 0L -> {
            println(hpList.sum())
        }
        else -> {
            // n log nだが間に合うだろう
            val strongSorted = hpList.sortedDescending()
            val sz = strongSorted.size
            // sz>cc
            println(strongSorted.takeLast(sz-cc.toInt()).sum())
        }
    }
}

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

using namespace std;

struct DATA{
  int id;
  int x;
  int y;
  int z;
};

int main(){
  int i, n, a, b, c, d;
  vector<int> ans;
  DATA _data;
  vector<DATA> data;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; ++i){
      cin >> a >> b >> c >> d;
      _data.id = a;
      _data.x = b;
      _data.y = c;
      _data.z = d;
      data.push_back(_data);
    }

    cin >> a >> b >> c >> d;

    for(i=0; i<data.size(); ++i){
      if(a >= data[i].x && b >= data[i].y && c >= data[i].z &&
	 d >= (4*data[i].x + 9*data[i].y + 4*data[i].z))
	ans.push_back(data[i].id);
    }

    if(ans.size() == 0){
      cout << "NA" << endl;
    }else{
      for(i=0; i<ans.size(); ++i)
	cout << ans[i] << endl;
    }

    ans.clear();
    data.clear();
  }
  return 0;
}

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

typedef long long ll;
const int maxn = 2e5 + 10;
int n, a[maxn], h[maxn]; ll c[maxn], f[maxn];

void upd(int pos, ll x) {
	for (; pos <= n; pos += pos & -pos) {
		c[pos] = max(c[pos], x);
	}
}

ll query(int pos) {
	ll res = 0;
	for (; pos; pos &= pos - 1) {
		res = max(res, c[pos]);
	}
	return res;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", h + i);
	}
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, (f[i] = query(h[i]) + a[i])), upd(h[i], f[i]);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 4992
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
ll n,k; 
int main(){
    read(n),read(k);
    n%=k;
    cout<<min(n,k-n);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int N;
ll D[100010];
vector<pair<int,int>> ans;
vector<vector<int>> v(100010);
ll dist[100010] = {0},inf = 1e18;

void dfs(int n){
	for(int i=0;i<v[n].size();i++){
		int s = v[n][i];
		if(dist[s]==inf){
			dist[s] = dist[n]+1;
			dfs(s);
		}
	}
}

int main(){
	cin >> N;
	map<ll,int> m,num;
	priority_queue<ll> Q;
	for(int i=1;i<=N;i++){
		cin >> D[i];
		m[D[i]] = i;
		num[D[i]] = 1;
		Q.push(D[i]);
		dist[i] = inf;
	}
	int count = 0;
	while(count<N-1 && !Q.empty()){
		ll s = Q.top();
		Q.pop();
		ll t = s-(N-2*num[s]);
		if(t<=0) continue;
		if(m.count(t)){
			ans.push_back({m[s],m[t]});
			v[m[s]].push_back(m[t]);
			v[m[t]].push_back(m[s]);
			count++;
			num[t] += num[s];
		}
	}
	dist[1] = 0;
	dfs(1);
	ll sum = 0;
	for(int i=2;i<=N;i++) sum += dist[i];
	if(count!=N-1 || sum!=D[1]) cout << -1 << endl;
	else{
		for(int i=0;i<N-1;i++){
			cout << ans[i].first << " " << ans[i].second << endl;
		}
	}
}

Measured memory_bytes: 25588
#include <iostream>

using namespace std;

int main(){
	int N, T, c[120], t[105];
	cin >> N >> T;
	
	for(int i=0; i<N; i++){
		cin >> c[i] >> t[i];
	}
	int ans = 99999;
	
	for(int i=0;i<N;i++){
		if(t[i] <= T){
			if(c[i] < ans){
				ans = c[i];
			}
		}
	}
	if(ans < 99999){
		cout << ans << endl;
	}
	else{
		cout << "TLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    s = S()
    n = len(s)+1
    a = [0]*n
    for i in range(n-1):
        if s[i] == "<":
            a[i+1] = max(a[i+1],a[i]+1)
    for i in range(n-2,-1,-1):
        if s[i] == ">":
            a[i] = max(a[i],a[i+1]+1)
    print(sum(a))

Measured memory_bytes: 29172
#include <string>
#include <stack>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <utility>
using namespace std;


#if 0
queue<pair<string, int>>はダメです。queue<pair<string, int> >の中の’’は必要です。
#endif
#define MAX_SIZE 100000
pair<string, int> process1, process2;
queue<pair<string, int> > Q;
int main()
{
	int j = 0, sum = 0;
	int n, t, flag = 0;
	cin >> n >> t;
	for (int i = 0; i<n; i++)
	{
		cin >> process1.first >> process1.second;
		Q.push(process1);
	}
	while (!Q.empty()) {
		process2 = Q.front(); Q.pop();
		if (process2.second > t) {
			process2.second -= t;
			sum += t;
			Q.push(process2);
		}
		else {
			sum += process2.second;
			cout << process2.first << " " << sum << endl;
		}
	}
	return 0;
}




Measured memory_bytes: 6212
a,b,c,d,e,f=map(int,input().split())
checklist=[]
for num1 in range(f//(100*a)+1):
    for num2 in range((f//100*b)+1):
        #(0からfまでの値を num1とnum2に代入して調べる)
        if (100*a)*(num1)+(100*b)*(num2)<=f and [num1,num2]!=[0,0] and (100*num1)*a+(100*num2)*b not in checklist:
            checklist.append((100*num1)*a+(100*num2)*b)
sugarlist=[]
for i in range(f//c+1):
    for j in range(f//d+1):
        ch=c*(i)+d*(j)
        if ch<f and ch not in sugarlist and [i,j]!=[0,0]:
            sugarlist.append(ch)           
sugarlist .append(0)
maxsugar=0
ratio=-1
good=0           
for x in sugarlist:
    for y in checklist:
        allsum=x+y
        if allsum<=f and 100*x<=e*y:
            if x/y>=ratio:
                ratio=x/y
                maxsugar=x
                good=x+y      
            else:
            	continue       
        else:
            continue  
print(good,maxsugar)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

	string ans = "";
	while (N != 0)
	{
		if (N % 2 != 0)
		{
			ans.insert(0, "1");
			N--;
		}
		else
		{
			ans.insert(0, "0");
		}

		N /= -2;
	}

	if (ans == "")
	{
		ans = "0";
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 768
/*
Problem : https://atcoder.jp/contests/abc126/tasks/abc126_e
Algorithm : 并查集 
Status : AC
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

int n,m,cnt;
int f[MAXN];

int find(int x){
	if(x == f[x])
	    return x;
	else
	    return f[x] = find(f[x]);
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;i++)
	    f[i] = i;
	
	while(m--){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		int fx = find(x);
		int fy = find(y);
		if(fx != fy){
			f[fx] = fy;
			cnt++;
		}
	}
	printf("%d\n",n - cnt);
	return 0;
}


Measured memory_bytes: 640