akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ITP1_10_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int member = int.Parse(Console.ReadLine());

            double[] x = Console.ReadLine().Split(' ').Select(a => Convert.ToDouble(a)).ToArray();
            double[] y = Console.ReadLine().Split(' ').Select(a => Convert.ToDouble(a)).ToArray();
            double[] p = { 0.0, 0.0, 0.0, double.MinValue };

            for (int i = 0; i < member; i++)
            {
                double abs = Math.Abs(x[i] - y[i]);
                p[0] += abs;
                p[1] += Math.Pow(abs, 2);
                p[2] += Math.Pow(abs, 3);
                if (p[3] < abs) p[3] = abs;
            }
            p[1] = Math.Sqrt(p[1]);
            p[2] = Math.Pow(p[2], 1.0 / 3.0);

            foreach (var i in p)
                Console.WriteLine(i.ToString("f6"));    
        }
    }
}

Measured memory_bytes: 10020
#include<bits/stdc++.h>
#define int long long
using namespace std;
int N,M,R;
int p[300][300],q[300][300];
signed main(){
	int i,j,k;
	cin>>N;
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			cin>>p[i][j];
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			for(k=0;k<N;k++)
				if(p[j][k]>p[j][i]+p[i][k]){
					cout<<"-1"<<endl;
					return 0;
				}
	vector<pair<int,int> > ve;
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			ve.push_back({i,j});
	sort(begin(ve),end(ve),[](pair<int,int> x,pair<int,int> y){return p[x.first][x.second]<p[y.first][y.second];});
	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
			q[i][j]=1145141919810893;
	int ans=0;
	for(auto x:ve){
		if(p[x.first][x.second]>=q[x.first][x.second])
			continue;
		q[x.first][x.second]=p[x.first][x.second];
		for(j=0;j<N;j++)
			for(k=0;k<N;k++)
				if(q[j][k]>q[j][x.first]+q[x.first][x.second]+q[x.second][k])
					q[j][k]=q[j][x.first]+q[x.first][x.second]+q[x.second][k];
		ans+=q[x.first][x.second];
	}
	cout<<((ans==-1)?-1ll:ans/2)<<endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int b[n - 1];
    rep(i, n - 1) cin >> b[i];
    ll ans = 0;
    int a[n];
    memset(a, 0, sizeof(a));
    a[0] = b[0];
    rep(i, n - 1)a[i + 1] = b[i];
    rep(i, n - 1){
        a[i] = min(a[i],b[i]);
        //if(b[i + 1] < b[i]) a[i + 1] = b[i + 1];
        //if(i == n - 2)a[i + 1] = min(b[n - 1], b[n - 2]);
    }
    rep(i, n){
        ans += (ll)a[i];
        //cout << a[i] << endl;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N), height(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    long long sum = 0;
    int max_height = 0;
    for (int i = 0; i < N; i++) {
        max_height = max(max_height, A[i]);
        sum += max_height - A[i];
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 4792
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie();cout.tie();
	ll k,a,b;
	cin>>k>>a>>b;
	if(a>=k)
		puts("1");
	else if(a-b<=0)
		puts("-1");
	else {
		ll ans=(k-a)/(a-b);
		if((k-a)%(a-b)!=0)
			ans++;
		cout<<(ans*2+1)<<endl;
	}
		
	return 0;
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if (A >= K) {
    cout << 1 * K << endl;
  }
  
  else if (A < K && K <= (A + B)) {
    cout << A << endl;
  }
  else {
    cout << A + -1*(K-A-B) << endl;
  }
  
  
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int q = 0;
    for (int i = 0; i < n; i++){
        if (a[i] < 0) q += 1;
        else break;
    }
    if (q == 0) q = 1;
    else if (q == n) q = n - 1;

    vector<vector<int>> v;
    int x = a[0];
    for (int i = q; i < n - 1; i++){
        v.push_back(vector<int> {x, a[i]});
        x -= a[i];
    }
    v.push_back(vector<int> {a[n - 1], x});
    x = a[n - 1] - x;
    for (int i = 1; i < q; i++){
        v.push_back(vector<int> {x, a[i]});
        x -= a[i];
    }
    cout << x << endl;
    for (int i = 0; i < n - 1; i++){
        cout << v[i][0] << ' ' << v[i][1] << endl;
    }
}


Measured memory_bytes: 8112
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */
ll gcd (ll a, ll b){
  if(b == 0) return a;
  return gcd(b, a%b);
}

ll func(ll C, ll D, ll A){
  return A - (A/C + A/D - A/(C*D/gcd(C,D)));
} 

int main() {
  ll A, B, C, D; cin >> A >> B >> C >> D;
  cout << func(C, D, B) - func(C, D, A-1) << endl;
}


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

int main()
{
	string s;
	cin>>s;
	
	string t=s;
	do{
		t.pop_back();
		t.pop_back();
		if(t.substr(0,t.length()/2)==t.substr(t.length()/2,t.length()/2)) break;
	}while(t.length()>0);
	
	cout<<t.length()<<endl;
	
	return 0;
}


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

int main()
{
    int n,m,a[10005],sum=0,i;
    scanf("%d%d",&n,&m);

    for(i=0; i<m; i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    if(sum>n)
        printf("-1\n");
    else
        printf("%d\n",n-sum);

    return 0;
}


Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define repd(i,j,k) for(int i=j;i>=k;--i)
#define pb push_back
#define db double
#define mp make_pair
#define mp3(a,b,c) mp(mp(a,b),c)
#define pii pair<int,int>
#define piii pair<pii,int>
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pbc(x) __builtin_popcount(x)
#define clr(x) memset(x,0,sizeof x)
#define SIZE(x) (int)(x.size())
const int mod=1e9+7;
IL int pls(int x,int y){x+=y;return x>=mod?x-mod:x;}
IL int dec(int x,int y){x-=y;return x<0?x+mod:x;}
IL int mul(int x,int y){return 1ll*x*y%mod;}
IL int mul(int x,int y,int z){return mul(mul(x,y),z);}
IL int mul(int x,int y,int z,int p){return mul(mul(x,y),mul(z,p));}
IL void add(int &x,int y){x+=y;x=(x>=mod)?x-mod:x;}
IL int fpw(int x,int y,int r=1){for(;y;y>>=1,x=mul(x,x))if(y&1)r=mul(r,x);return r;}
IL int inv(int x){return fpw(x,mod-2);}
IL int gi(){int x;int _w=scanf("%d",&x);return x;}
IL void gi(int &x){int _w=scanf("%d",&x);}
IL void write(int x){printf("%d\n",x);}
void chkmax(int &x,int y){x=(x>y)?x:y;}
void chkmin(int &x,int y){x=(x<y)?x:y;}
const int INF=0x3f3f3f3f;
template<typename T>IL void debug(T x){cerr<<x;return;}
/* --------------------------------------------------------------------------------------------------------- */
const int maxn=1e5+10;
int n;
int a[maxn];
namespace sub1{
	const int sub1_maxn=3005;
	int SG[sub1_maxn][sub1_maxn];
	IL bool check(){
		return 0;
		int mx=0;
		rep(i,1,n)chkmax(mx,a[i]);
		return n<=3000&&mx<=3000;
	}
	int workSG(int x,int y){
		if(SG[x][y]!=-1)return SG[x][y];
		SG[x][y]=0;
		int &ans=SG[x][y];
		set<int>q;
		if(y+1<=a[x])q.insert(workSG(x,y+1));
		if(x+1<=n&&y<=a[x+1])q.insert(workSG(x+1,y));
		while(q.count(ans))ans++;
		return ans;
	}
	IL void work(){
		memset(SG,-1,sizeof SG);
		workSG(1,1);
		rep(i,1,n){rep(j,1,a[i])cerr<<SG[i][j]<<' ';cerr<<endl;}
		puts(SG[1][1]?"First":"Second");
	}
}
namespace sub2{
	int last[maxn];
	IL bool check(int cor){
		if(cor==n)return false;
		int cur=last[cor]?((a[cor]-a[cor+1])&1):((a[cor]-a[cor+1])%2);
		return cur==last[cor+1];
	}
	IL void work(){
		int p;
		rep(i,1,n)if(i<=a[i])p=i;
		last[n]=0;
		repd(i,n-1,1)last[i]=(a[i]==a[i+1])?(!last[i+1]):0;
		if(check(p)){
			if(p>a[p+1]){
				int cur=last[p]?((a[p]-p)&1):((a[p]-p)%2);
				puts(cur?"First":"Second");
			}else{
				int cur=1;
				puts(cur?"First":"Second");
			}
		}else{
			int cur=(a[p]-p)%2;
			cur=last[p]?(!cur):cur;
			puts(cur?"First":"Second");
		}
	}
}
int main(){
	#ifdef LOCAL
		freopen("/home/noilinux/Desktop/input.txt","r",stdin);
	#endif
	n=gi();
	rep(i,1,n)a[i]=gi();
	sort(a+1,a+1+n,greater<int>());
	if(sub1::check())sub1::work();
	else sub2::work();
	return 0;
}
/*
2 0 1 0 1 0 1 0 2 1 0 1 0 1 0 1 0 
1 2 0 1 0 1 0 1 0 2 1 0 
0 1 2 0 1 0 1 0 1 0 
1 0 1 2 0 1 0 1 
0 1 0 1 2 0 1 0 
1 0 1 0 1 2 0 1 
0 1 0 1 0 1 2 0 
1 0 1 0 1 0 1 
2 1 0 1 0 1 0 
0 2 1 0 1 0 
1 0 2 1 0 
0 1 0 
First 
*/

Measured memory_bytes: 1024
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    // read input
    int N, M;
    cin >> N >> M;

    vector<bool> ac(N, false);
    vector<int> cnts(N, 0);
    rep(i, 0, M)
    {
        int p;
        string S;
        cin >> p >> S;
        --p;

        if (ac[p]) continue;
        
        if (S == "AC")
            ac[p] = true;
        else
            ++cnts[p];
    }

    int num_ac, num_wa;
    num_ac = num_wa = 0;
    rep(i, 0, N)
    if (ac[i])
    {
        ++num_ac;
        num_wa += cnts[i];
    }
    cout << num_ac << ' ' << num_wa << endl;
    return 0;
}


Measured memory_bytes: 640
N, K = map(int, input().split())
H = list(map(int, input().split()))
C = [10**13 for i in range(N)]
C[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            C[i+j] = min(C[i] + abs(H[i+j]-H[i]), C[i+j])
print(C[-1])


Measured memory_bytes: 56544
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
using namespace std;
int n;
double a[100005];
double dp[3000][3000];
double sol(int i,int h)
{
    double res=1;
    //cout<<i<<" "<<h<<endl;
   // cout<<i<<" "<<h<<" "<<dp[i][h]<<endl;
    if(dp[i][h]!=(double)-1)return dp[i][h];
    if(i>=n)
    {
        if(h>(n-h))return 1;
        else return 0;
    }
    res+=sol(i+1,h+1)*a[i];
    res+=sol(i+1,h)*(1-a[i]);
    return dp[i][h]=res;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<3000;i++)
        for(int j=0;j<3000;j++)dp[i][j]=-1;
    cout<<fixed<<setprecision(10)<<sol(0,0)-n;
}


Measured memory_bytes: 70784
def divisors(N):
    res = []
    i = 1
    while i * i <= N:
        q, r = N // i, N % i
        if r == 0:
            res.append(i)
            if i != q:
                res.append(q)
        i += 1
    res.sort()
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int n,y;cin>>n>>y;
	for(int i=0;i<=n;i++)for(int j=i;j<=n;j++)
	{
		if(10000*i+5000*(j-i)+1000*(n-j)==y)
		{
			cout<<i<<" "<<j-i<<" "<<n-j<<endl;
			return 0;
		}
	}
	cout<<"-1 -1 -1"<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
const int mod =1000000007;
int main(){
	//freopen("input.txt","r",stdin);// <--Remove Before Submit
	char s1[53],s2[53];
	int i,n,p,flage;
	ll sum;
	cin >> n;
	cin >> s1 >> s2;
	if(s1[0]==s1[1])	{
		p=2;
		sum=6;
		flage=2;
	}
	else {
		p=1;
		sum=3;
		flage=1;
	}
	while(p<n)	{
		if(s1[p]!=s1[p+1])	{
			if(flage==1)	{
				sum=(sum*2)%mod;
				p++;
			}
			else {
				flage=1;
				p++;
			}
		}
		else {
			if(flage==1)	{
				flage=2;
				p+=2;
				sum=(sum*2)%mod;
			}
			else {
				sum=(sum*3)%mod;
				p+=2;
			}
		}
	}
	cout << sum << endl;
	return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> P(N); cin >> P;
        int ans = 0;
        int cnt = 0;
        rep(i, N) {
            if(P[i] == i + 1) {
                cnt++;
            } else {
                if(cnt > 0) {
                    ans += (cnt + 1) / 2;
                }
                cnt = 0;
            }
        }
        if(cnt > 0) {
            ans += (cnt + 1) / 2;
        }
        cout << ans << endl;
        
        return 0;
    }
};

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


Measured memory_bytes: 640
#include <stdio.h>
#include <vector>
using namespace std;
const int N=2e5+10;
#define PB push_back
vector<int> graph[N];
int dep[N];
void dfs(int now){
  for(int i:graph[now])if(dep[i]==-1){
    dep[i]=dep[now]+1;
    dfs(i);
  }
  return ;
}
int max(int a,int b){return a>b?a:b;}
int main(){
  int n,l,r,root=1,ans=0;
  scanf("%d",&n);
  for(int i=1;i<n;i++){
	scanf("%d%d",&l,&r);
    graph[l].PB(r);
    graph[r].PB(l);
  }
  dep[1]=1;
  for(int i=2;i<=n;i++)dep[i]=-1;
  dfs(1);
  for(int i=1;i<=n;i++)if(dep[i]>dep[root])root=i;
  for(int i=1;i<=n;i++)dep[i]=-1;
  dep[root]=1;
  dfs(root);
  for(int i=1;i<=n;i++)ans=max(ans,dep[i]);
  if(ans%3==2)printf("Second\n");
  else printf("First\n");
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }

  for (int i = 0; i < N; i++){
    cout << A.at(i);
    if (i < N-1){
      cout << " ";
    }
    else{
      cout << endl;
    }
  }

  for (int i = 1; i < N; i++){
    int v = A.at(i);
    int j = i - 1;
    while (j >= 0 && A.at(j) > v){
      A.at(j+1) = A.at(j);
      j--;
    }
    A.at(j+1) = v;

    for (int i = 0; i < N; i++){
      cout << A.at(i);
      if (i < N-1){
        cout << " ";
      }
      else{
      cout << endl;
      }
    }
  }
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)

using ll = long long;
using namespace std;

const ll INF = 5000000000000000;
ll n, m, a = 0, A[10101];
string s;
int main() {
	cin >> s >> n;
	rep(i, s.size()) {
		if (s[i] != '1') {
			m = s[i] - '0';
			break;
		}
		else {
			n--;
			if (n == 0) {
				m = 1;
				break;
			}
		}
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i,y,n,inc)	for(int i=y;i<n+y;i+=inc)
#define cin(t) int t;cin>>t
#define w(t) while(t--)
#define nl cout<<endl;
#define pb push_back
#define ft(i) (i&(-1*i))
#define arrIn(arr,size)		for(int i=0;i<size;i++){cin>>arr[i];}
#define arrOut(arr,size,seperater)	for(int i=0;i<size;i++){cout<<arr[i]<<seperater;}
using namespace std;

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

int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

void fastIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}

struct item
{
	int value;
	int weight;
};

int n, w;

void solve(item arr[]) {

	int maxValue = (n * 1000) + 1;
	int dp[n + 5][maxValue + 5];

	fo(i, 0, n + 1, 1)	dp[i][0] = 0;
	fo(i, 1, maxValue - 1, 1)	dp[0][i] = inf;

	fo(i, 1, n, 1) {
		fo(j, 1, maxValue - 1, 1) {
			dp[i][j] = dp[i - 1][j];
			if (j >= arr[i - 1].value) {
				int temp = (dp[i - 1][j - arr[i - 1].value] + arr[i - 1].weight);
				dp[i][j] = min(dp[i][j], temp);
			}
		}
	}

	int ans = 0;
	fo(i, 1, maxValue - 1, 1) {
		if (dp[n][i] <= w) {
			ans = i;
		}
	}

	cout << ans << endl;
	return;
}

int32_t main() {

	// fastIO();

	cin >> n >> w;
	item arr[n];

	fo(i, 0, n, 1) {
		cin >> arr[i].weight;
		cin >> arr[i].value;
	}

	solve(arr);

	return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

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

using namespace std;

const int N = 2e5 + 5;

int lef[N], rig[N];

int p[N];
bool incr[N];

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i)
    scanf("%d", p+i);
  stack<int> st;
  for (int i = 0; i < n; ++i) {
    while (!st.empty() && p[st.top()] <= p[i]) st.pop();
    lef[i] = st.empty() ? -1 : st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (int i = n-1; i >= 0; --i) {
    while (!st.empty() && p[st.top()] >= p[i]) st.pop();
    rig[i] = st.empty() ? n : st.top();
    st.push(i);
  }
  int cnt = 1, ada = 0;
  for (int i = 1; i < n; ++i) {
    if (p[i-1] < p[i])
      ++cnt;
    else
      cnt = 1;
    if (incr[i] = (cnt >= k))
      ++ada;
  }
  int ans = !incr[k-1];
  ans += (ada > 0);
  for (int i = 0; i + k < n; ++i) {
    if ((rig[i] > i+k && lef[i+k] < i) || incr[i+k])
      continue;
    ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

int main(void) {
    string s; cin >> s;
    if (s == "SUN") cout << 7 << endl;
    else if (s == "MON") cout << 6 << endl;
    else if (s == "TUE") cout << 5 << endl;
    else if (s == "WED") cout << 4 << endl;
    else if (s == "THU") cout << 3 << endl;
    else if (s == "FRI") cout << 2 << endl;
    else cout << 1 << endl;
}

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

int main() {
  long long int n;
  cin>>n;
  vector<long long int> vec(100001);
  long long int a=0,b;
  for(long long int i=0;i<n;i++){
    cin>>b;
    if(b<=100000){
      vec.at(b)++;
      if(vec.at(b)==b){
        a+=b;
      } 
    }
  }
  cout<<n-a<<endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int N,a[100000 + 500];
ll res = 0;

int main()
{
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
    {
        scanf("%d",&a[i]);
    }

    for(int i=1;i<=N;i++)
    {
        if(a[i]==i)
        {
            if(i+1<=N&&a[i+1]==i+1)swap(a[i],a[i+1]);
            else if(i-1>=1&&a[i-1]==i-1)swap(a[i-1],a[i]);
            else if(i+1<=N)swap(a[i],a[i+1]);
            else if(i-1>=1)swap(a[i],a[i-1]);
            res++;
        }
    }
    printf("%I64d\n",res);
    return 0;
}


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

using namespace std;

int main()
{
    int x, n;
    int p = 0;
    int chk = 1000;
    bool flag = false;
    vector<int> vec(200);
    cin >> x >> n;
    vector<int> vec2;

    for (int i = -200; i < 200; i++) {
        vec2.push_back(i);
    }

    for (int i = 0; i < n; i++) {
        cin >> p;
        vec2[p + 200] = -9999;
        if (p == x) {
            flag = true;
        }
    }
    if (flag == false) {
        cout << x << endl;
    } else {
        for (int i = 0; i < vec2.size(); i++) {
            if (chk > abs((vec2.at(i) - x))) {
                chk = abs((vec2.at(i) - x));
                p = vec2.at(i);
            }
        }
        cout << p << endl;
    }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    string s;cin>>s;
    int x =s.length();
    if(s[x-1]=='s')s+="es";
    else s+='s';
    cout<<s<<endl;

}

Measured memory_bytes: 3592
//AtCoder ABC055 B - Training Camp
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
constexpr ll MOD=1e9+7;

int main() {
    int N;
    cin>>N;
    ll ans=1;
    for(int i=1;i<=N;++i){
        ans *= i;
        ans %= MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
using namespace std;

int main(){
  int n, x;
  while(1){
    cin >> n >> x;
    if (n == 0 && x == 0) break;
    int ans = 0;
    rep2(i, 1, n+1){
      int num = x - i;
      if (num <= 0) break;
      rep2(j, i+1, n+1){
        int num2 = num - j;
        if (num2 <= 0) break;
        if (num2 != i && num2 != j && num2 <= n && num2 > j)
          ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3088
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  bool graph[n][n] ;

  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) graph[i][j] = false;

  int v,k,v1;
  for(int i = 0; i < n; i++){
    cin >> v >> k;
    v--; //0index
    for(int j = 0; j < k; j++){
      cin >> v1;
      v1 --; //0index
      graph[v][v1] = true;
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(graph[i][j]) cout << 1;
      else cout << 0 ;

      if(j == n-1) cout << endl;
      else cout << ' ';
    }
  }
  return 0;
}



Measured memory_bytes: 3136
import fractions

A, B, C, D = map(int, input().split())

lower_C = -(-A//C)
upper_C = B//C
num_C = upper_C - lower_C + 1
lower_D = -(-A//D)
upper_D = B//D
num_D = upper_D - lower_D + 1
lcm = C*D//fractions.gcd(C, D)
lower_lcm = -(-A//lcm)
upper_lcm = B//lcm
num_lcm = upper_lcm - lower_lcm + 1

print(B - A + 1 - num_C - num_D + num_lcm)

Measured memory_bytes: 5076
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> input(N,0);
  for(int i=0;i<N;i++){
    cin>>input[i];
  }
  vector<int> color(9,0);
  for(int i=0;i<N;i++){
    if(input[i]<400)  color[0]++;
    else if(input[i]<800)  color[1]++; 
    else if(input[i]<1200) color[2]++;
    else if(input[i]<1600) color[3]++;
    else if(input[i]<2000) color[4]++;
    else if(input[i]<2400) color[5]++;
    else if(input[i]<2800) color[6]++;
    else if(input[i]<3200) color[7]++;
    else                   color[8]++;
  }
  int ans=0;
  for(int i=0;i<8;i++){
    if(color[i]!=0)   ans++;
  }
  if(ans!=0){
    cout<<ans<<" "<<ans+color[8]<<endl;
    }
  else cout<<1<<" "<<ans+color[8]<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int len = s.length();
        int[] mod2019count = new int[2019];
        long count = 0;
        for(int i=0; i<len; i++) {
            int[] newModCount = new int[2019];
            int theDigit = Integer.parseInt(s.substring(i, i+1));
            for(int j=0; j<2019; j++) {
                int mod = (j*10 + theDigit) % 2019;
                newModCount[mod] = mod2019count[j];
            }
            int mod = theDigit % 2019;
            newModCount[mod]++;
            
            count += newModCount[0];
            mod2019count = newModCount;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 57084
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            diff = sum([(s-t)**2 for s,t in zip(X[i],X[j])])
        if (diff**.5).is_integer():c += 1
print(c)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,m;
	cin>>n>>m;
	vector<int> s(n+1),t(m+1);
	s[0] = -1;t[0]=-1;
	for (int i = 1; i <= n; i++){
		cin>>s[i];
	}
	for (int i = 1; i <= m; i++){
		cin>>t[i];
	}
	
	vector<vector<ll> > dp(max(n,m)+2,vector<ll>(max(n,m)+2,0));
	for (int i = 0;i <= n; i++){
		dp[i][0] = 1;
	}
	for (int i = 0; i <= m; i++){
		dp[0][i] = 1;
	}

	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			dp[i][j] = (s[i]==t[j]?dp[i][j-1]+dp[i-1][j]:(dp[i][j-1]+dp[i-1][j])%mod-dp[i-1][j-1]+mod);
			dp[i][j] %= mod;
		}
		
	}
	cout<<dp[n][m]<<endl;
	
	return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/22  Problem: 073_arc_a / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	LL T; cin >> N >> T;
	VL t(N + 1, 0);
	t[N] = LINF;
	FOR(i, 0, N)cin >> t[i];
	FOR(i, 0, N) {
		ans += min(t[i + 1] - t[i], T);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	xs := make([]int, n)
	ys := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i], &ys[i])
	}

	var sum float64
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			xd := xs[i] - xs[j]
			yd := ys[i] - ys[j]
			d := math.Sqrt(float64(xd*xd + yd*yd))
			sum += d
		}
	}

	fmt.Println(sum * 2 / float64(n))
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1848
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue

using namespace std;

bool comp(pair<int, string> a, pair<int, string> b) {
    if (a.first < b.first) {
        return false;
    } else if (b.first < a.first) {
        return true;
    } else {
        return a.second < b.second;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    map<string, int> appear_map;
    vector<pair<int, string>> appear;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (appear_map.find(s) != appear_map.end()) {
            appear_map[s]++;
        } else {
            appear_map[s] = 1;
        }
    }
    for (map<string, int>::iterator it = appear_map.begin(); it != appear_map.end(); it++) {
        appear.push_back( make_pair(it->second, it->first) );
    }
    sort(appear.begin(), appear.end(), comp);
    int biggest_no = appear[0].first;
    for (int i = 0; i < n; i++) {
        if (appear[i].first == biggest_no) {
            cout << appear[i].second << '\n';
        } else {
            break;
        }
    }
}

Measured memory_bytes: 29328
#include <iostream>
#include <cmath>
#include <numeric>

using namespace std;

long long gcd(long long x, long long y) { return (x % y)? gcd(y, x % y): y; }

int main(int argc, char* argv[]) {
  long long N, X;
  cin >> N >> X;

  long long x[N];
  long long diff[N];
  for (int i = 0; i < N; ++i) {
    cin >> x[i];
    diff[i] = abs(X - x[i]);
  }

  long long ret = diff[0];
  for (int i = 1; i < N; ++i) {
    ret = gcd(ret, diff[i]);
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	string s, t;
	


	ll x[10004] = {};
	cin >> a;
	b = 0;

	for (int i = 0; i < a; i++)
	{
		cin >> x[i];
		if (b<x[i])
		{
			b = x[i];
			c = i;
		}
	}
	x[c] /= 2;
	for (int i = 0; i < a; i++)
	{
		d += x[i];
	}
	cout << d << endl;

	//cout << ans << endl;
	//cout <<  << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 384
from collections import defaultdict
def solve():
    N = int(input())
    progression = list(map(int, input().split()))
    cuml = [0]*(N+1)
    for i in range(len(progression)):
        cuml[i+1] = cuml[i] + progression[i]
    cuml_dic = defaultdict(list)
    for i, num in enumerate(cuml):
        cuml_dic[num].append(i)
    ans = 0
    for key, value in cuml_dic.items():
        n = len(value)-1
        ans += int((n+1)*n/2)

    print(ans)

solve()

Measured memory_bytes: 63304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M =1000000007;
//MOD??
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}
ll mpow(ll x, ll n){ //x^n(mod M) ????pow(x,n)?????????????mod??
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
int main (){
  int i;
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(1){
    c-=b;
    if(c<=0){
      cout<<"Yes"<<endl;
      break;
    }
    a-=d;
    if(a<=0){
      cout<<"No"<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

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

	int n, k;
	string s;
	cin >> n >> s >> k;
	char c = s[k - 1];
	string ans = s;
	rep(i, n) {
		if (ans[i] != c) {
			ans[i] = '*';
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  string S;
  cin >> S;
  deque<char> q;
  for (char c : S) {
    q.push_back(c);
  }
  int Q;
  cin >> Q;
  bool reversed = false;
  for (int i = 0; i < Q; ++i) {
    int cmd;
    cin >> cmd;
    if (cmd == 1) {
      reversed = (not reversed);
    } else {
      int F;
      char C;
      cin >> F >> C;
      if ((F == 1 and (not reversed)) or (F == 2 and reversed)) {
  	q.push_front(C);
      } else {
  	q.push_back(C);
      }
    }
  }
  if (reversed) {
    reverse(q.begin(), q.end());
  }
  for (char c : q) {
    cout << c;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
ll modPow(ll a, ll n, ll p){
  if(!n) return 1;
  if(a == 1) return a % p;
  if(n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}
ll choose(ll n, ll k){
  ll x = 1, y = 1;
  rep(i, k){
    x *= n - i;
    y *= i + 1;
    x %= mod;
    y %= mod;
  }
  y = modPow(y, mod - 2, mod);
  return x * y % mod;
}
int main(){
  int x,y;
  cin >> x >> y;
  int m = (2 * x - y) / 3;
  int n = (2 * y - x) / 3;
  if((x + y) % 3 != 0 || m < 0 || n < 0) cout << 0 << endl;
  else{
    cout << choose(m + n, n) << endl;
  }
}

Measured memory_bytes: 256
A,B=map(int,input().split())
a=[1]
con=True
while con:
    con=False
    for i in range(2,int(A**0.5)+1):
        if A%i==0:
            con=True
            a.append(i)
            A=A//i
            break
a.append(A)
b=[1]
con=True
while con:
    con=False
    for i in range(2,int(B**0.5)+1):
        if B%i==0:
            con=True
            b.append(i)
            B=B//i
            break
b.append(B)
a=set(a)
b=set(b)
c=list(a&b)
from copy import copy
d=copy(c)
for i in range(len(d)):
    for j in range(len(c)):
        if i!=j:
            for k in range(2 ,min(d[i],c[j])):
                if d[i]%k==0 and c[j]%k==0:
                    c[j]=0
ans=0
for i in range(len(c)):
    if c[i]!=0:
        ans+=1
print(ans)

Measured memory_bytes: 40044
#include <iostream>

using namespace std;

int br[2], n, sad;
string s;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
cin >> s;
for(int i = 0 ; i < n ; ++i){
	br[(s[i] == '#')]++;
}
int sol = br[0];
for(int i = 0 ; i < n ; ++i){
	sad += (s[i] == '#');
	int cur = sad + br[0] - (i + 1 - sad);
	sol = min(sol, cur);
}
cout << sol << endl;

return 0;
}



Measured memory_bytes: 720
#include<stdio.h>

long long int FiveFactorical(long long int r){
    return r * r * r * r * r;
}

int main(void){
    
    long long int X,i,j,ans;
    
    scanf("%lld",&X);

    for(i = -200;i <= 200;i++){
        for(j = -200;j <= 200;j++){
            if(FiveFactorical(i) - FiveFactorical(j) == X){
                printf("%lld %lld\n",i,j);
                return 0;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9 + 7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

struct edge{
    int to, cap, rev, id;
    bool isrev, ininv;
};

vector<vector<edge> > G;
vector<bool> used;

void add_edge(int from, int to, int cap, int id, bool inv){
    G[from].emplace_back((edge){to, cap, int(G[to].size()), id, false, inv});
    G[to].emplace_back((edge){from, 0, int(G[from].size())-1, id, true, inv});
}

// 増加路の探索
int dfs(int v, int t, int f){
    if(v == t) return f;
    used[v] = true;
    for(auto &e : G[v]){
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    used.resize(G.size());
    int flow = 0;
    while(1){
        fill(used.begin(), used.end(), false);
        int f = dfs(s, t, IINF);
        if(f==0) break;
        flow += f;
    }
    return flow;
}

int main() {
    int n, m, s, t;
    cin >> n >> m;
    G.resize(n);
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        add_edge(u, v, 1, i, false);
        add_edge(v, u, 1, i, true);
    }
    cin >> s >> t;
    s--; t--;
    cout << max_flow(s, t) << endl;
    vector<int> r;
    for(int i=0;i<n;i++){
        for(auto &e : G[i]){
            if(e.isrev && e.ininv && e.cap > 0){
                r.push_back(e.id);
            }
        }
    }
    cout << r.size() << endl;
    for(auto id : r){
        cout << id+1 << endl;
    }
    return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    if (N % 1000 == 0){
        cout << 0 << endl;
    } else {
        cout << 1000 - N % 1000 << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, D);
	if (D == 25) {
		OUT("Christmas")BR;
	} else if (D == 24) {
		OUT("Christmas Eve")BR;
	} else if (D == 23) {
		OUT("Christmas Eve Eve")BR;
	} else  {
		OUT("Christmas Eve Eve Eve")BR;
	}
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main(){
   int a,b,c;
   cin >> a >> b >> c;
   int d = a-b;
   cout << max(0,c-d)<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <map>
typedef long long int ll;
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	string st;
	map<string, ll> mp;
	for(ll i=0; i<n; i++){
		cin >> st;
		mp[st]+=1;
	}
	cout << "AC x " << mp["AC"] << "\n";
	cout << "WA x " << mp["WA"] << "\n";
	cout << "TLE x " << mp["TLE"] << "\n";
	cout << "RE x " << mp["RE"] << "\n";
	return 0;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; ++i) {
    string s, t;
    cin >> s >> t;
    if (s == "insert") {
      mp[t]++;
    } else {
      if (mp[t] == 0) {
        cout << "no" << endl;
      } else {
        cout << "yes" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 52464
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (h, w, k) = InputLine.to_ia
  c = [''] * h
  h.times{|y| c[y] = InputLine.to_s}
  
  t = 0
  h.times do |y|
    w.times do |x|
      t += 1 if c[y][x] == '#'
    end
  end

  cols = [0] * h
  rows = [0] * w
  h.times do |y|
    w.times do |x|
      cols[y] += 1 if c[y][x] == '#'
    end
  end
  w.times do |x|
    h.times do |y|
      rows[x] += 1 if c[y][x] == '#'
    end
  end

  m = [h, w].max
  bs = [nil] * (2 ** m)
  bs.size.times do |bits|
    bs[bits] = []
    m.times do |i|
      if bits & (1 << i) != 0 then
        #p [bits, i]
        bs[bits].push(i)
      end
    end
  end

  a = 2 ** h
  b = 2 ** w
  sy = [0] * a
  sx = [0] * b
  a.times do |i|
    bs[i].each{|p| sy[i] += cols[p]}
  end
  b.times do |j|
    bs[j].each{|q| sx[j] += rows[q]}
  end

  count = 0
  a.times do |i|
    b.times do |j|
      s = sy[i] + sx[j]
      bs[i].each do |y|
        bs[j].each do |x|
          s -= 1 if c[y][x] == '#'
        end
      end
      count += 1 if (t - s) == k
    end
  end
  puts count.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 14396
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include<vector>

using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i =0;i<n;++i)
//#define mod (ll)(1e9+7)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;

    return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b;
  c = 0;

  for(int i=0; i<2; i++) {
    if(a>b) {
      c += a;
      a--;
    }
    else {
      c += b;
      b--;
    }
  }

  cout << c << endl;
  
  return 0;
}


Measured memory_bytes: 256