akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ac = 0
wa = defaultdict(lambda: 0) # wa = {} だと 存在しないkeyにおいて wa[key] = ○ で代入できない
already = set()
sum_wa = 0
for line in range(m):
    p, s = input().split() # forでその都度入力を受け取る
    p = int(p)
    if p in already: # acを見つけたときのみalreadyにpをいれるので、ac後のwaのカウントを避けている。
        continue
    if s == 'AC':
        ac += 1
        already.add(p) # acするとalreadyにpを追加 集合への値追加はaddを用いる。
        # sum_wa += wa[p]
    else:
        wa[p] += 1 #{1: 3, 2: 2, 3: 0, 4: 5 ...}のように辞書が作られていく。

# print(ac, sum(wa[i] for i in wa.keys())) のようにするとac出来ていないwaについても数えてしまうので×
# print(ac, sum_wa)
print(ac, sum(wa[i] for i in already))


Measured memory_bytes: 22888
def dfs(i, a, b, c):
    if i == n:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return f_inf

    ret0 = dfs(i + 1, a, b, c)
    ret1 = dfs(i + 1, a + l[i], b, c) + 10
    ret2 = dfs(i + 1, a, b + l[i], c) + 10
    ret3 = dfs(i + 1, a, b, c + l[i]) + 10

    return min(ret0, ret1, ret2, ret3)


n, A, B, C = map(int, input().split())
l = list(int(input()) for _ in range(n))
f_inf = float("inf")
print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define REPR(i, n) for(ll i = n; i >= 1; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define INF 1e9+123
#define VEC(type,A,N) vector<type> A(N+10)
#define VEC2(type,A,N,M) vector<vector<type>> A(N+10,vector<type>(M+10))
#define ALL(v) v.begin()+1, v.end()-9

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> a(N+10,0);
    vector<ll> w(N+10,-1);
    
    w[1]=1;w[2]=2;
    REP(i,M){
        cin>>a[i];
        w[a[i]]=0;
    }
    if(w[1]==0)w[2]=w[2]==0?0:1;
    
    
    FOR(i,3,N){
        if(w[i]==-1){
            w[i]=(w[i-1]+w[i-2])%1000000007;
        };
    }
    cout<<w[N];
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    random_device seed_gen;
    mt19937_64 rnd(seed_gen());
    uniform_int_distribution<int> dist_d(0, 364), dist_q(0, 25);

    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26)cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d)rep(j, 26)cin >> s[i][j];

    vector<int> t(d);
    rep(i, d){
        t[i] = dist_q(rnd);
    }

    int m = 1;

    vector<set<int>> last(26);
    rep(i, 26){
        last[i].insert(-1);
        last[i].insert(d);
    }
    rep(i, d)last[t[i]].insert(i);
    int sum = 0;
    rep(i, d){
        sum += s[i][t[i]];
        rep(j, 26){
            if(last[j].find(i) == last[j].end()){
                auto itr = lower_bound(last[j].begin(), last[j].end(), i);
                itr--;
                int day = i - *itr;
                sum -= c[j] * day;
            }
        }
    }
    
    rep(i, m){
        int day = dist_d(rnd);
        int que = dist_q(rnd);
        int diff = 0;
        
        int cont;
        rep(j, 26){
            if(last[j].find(day) != last[j].end()){
                cont = j;
                break;
            }
        }
        diff += s[day][que] - s[day][cont];
        auto itr1 = last[cont].find(day);
        auto itr2 = lower_bound(last[que].begin(), last[que].end(), day);
        int x = *itr1;
        int y = *itr2;
        int dx = day - *(--itr1);
        int dy = day - *(--itr2);
        itr1++; itr1++;
        itr2++;
        diff -= c[cont] * dx * (*itr1 - day);
        diff += c[que] * dy * (*itr2 - day);
        if(diff > 0){
            last[cont].erase(day);
            last[que].insert(day);
            t[day] = que;
            sum += diff;
        }
    }
    
    rep(i, d){
        cout << t[i] + 1 << endl;
    }
    
    
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
typedef vector<ll> vecll;
const ll inf =1000000007;

ll n,k;
const ll max_N=60;
ll v[max_N];

//l,r value pre compute

ll rval[max_N];
ll lval[max_N];

vecll lminus[max_N];
vecll rminus[max_N];

void prekeisan(){
    lval[0]=v[0];
    rval[n-1]=v[n-1];
    lminus[0]={};rminus[n-1]={};
    if(v[0]<0) lminus[0].pb(v[0]);
    if(v[n-1]<0) rminus[n-1].pb(v[n-1]);
    for(ll i=1;i<n;i++){
        lval[i]=lval[i-1]+v[i];
        rval[n-1-i]=rval[n-i]+v[n-1-i];
        lminus[i]=lminus[i-1];
        if(v[i]<0) lminus[i].pb(v[i]);
        rminus[n-1-i]=rminus[n-i];
        if(v[n-1-i]<0) rminus[n-1-i].pb(v[n-1-i]);
    }
}
ll ans;

void keisan(){
    ans=0;
    for(ll i=0;i<=k;i++){//左からi個
        for(ll j=0;i+j<=k && i+j<=n;j++){//右からj個
            ll score=0;
            ll yobun=k-i-j;
            if(i>0){
                score+=lval[i-1];
            }
            if(j>0){
                score+=rval[n-1-j+1];
            }
            vecll vec;
            if(i>0) vec=lminus[i-1];
            else vec={};
            if(j>0) vec.insert(vec.end(),rminus[n-1-j+1].begin(),rminus[n-1-j+1].end());

            isort(vec);
            for(ll i=0;i<yobun && i<vec.size();i++){
                score-=vec[i];
            }
            ans=max(ans,score);
        }
    }
}

void solve(){
    cin >> n >>k;
    rep(i,n) cin >> v[i];
    prekeisan();
    keisan();
    kaku(ans);
}

 int main(){
     solve();
 }


Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            int N = int.Parse(NK[0]);int K = int.Parse(NK[1]);
            string[] hi = Console.ReadLine().Split(' ');

            int cnt = 0;
            for(int i=0;i<N;i++)
            {
                if(int.Parse(hi[i]) >= K)
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 15584
#include <stdio.h>

int main(void) {
	int H,W,i,t;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0){
			break;
		}
		for(i=1;i<=W;i++){
			printf("#");
		}
		printf("\n");
		for(i=2;i<=H-1;i++){
			printf("#");
			for(t=2;t<=W-1;t++){
				printf(".");
			}
			printf("#\n");
		}
		for(i=1;i<=W;i++){
			printf("#");
		}
		printf("\n\n");
	}
	return 0;
}

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

int main() {
	int A, B, N; string S; cin >> A >> B >> S;
	N = A + B + 1;
	if( N != S.size() ){
		cout << "No" << endl;
		return 0;
	}
	
	for( int i = 0; i < N; i++ ){
		if( i != A && 48 <= S[i] && S[i] <= 57 )
		continue;
		else if( i == A && S[i] == '-' )
		continue;
		
		cout << "No" << endl;
		return 0;
	}
	
	cout << "Yes" << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> T ceil(T a, T b) { return a / b + !!(a%b); }
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
	out << '(' << a.first << ',' << a.second << ')';
	return out;
}
template<class T>
ostream &operator <<(ostream& out, const vector<T>& a) {
	out << '[';
	REP(i, a.size()) { out << a[i]; if (i != a.size() - 1)out << ','; }
	out << ']';
	return out;
}

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

signed main(void) {
	int n;
	cin >> n;
	VI a(n), b(n);
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];
	
	VI v1, v2;
	REP(i, n) {
		if (a[i] > b[i]) {
			v2.push_back(a[i] - b[i]);
		}
		else if (a[i] < b[i]) {
			v1.push_back(b[i] - a[i]);
		}
	}

	int idx = 0;
	for (int &i : v2) {
		// 2*i点分
		while (idx < v1.size() && i > 0) {
			if (v1[idx] >= i*2) {
				v1[idx] -= i*2;
				i = 0;
			}
			else {
				i -= v1[idx]/2;
				v1[idx++] %= 2;
			}
		}
	}

	for (int i : v2) {
		if (i != 0) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int A[100];
void dump(char *s, int len)
{   
    int i;
    for(i=0;i<len-1;i++)
    {
        printf("%d ",A[i]);
    }
    printf("%d\n",A[len-1]);
}

int main()
{
    int num,i,j;
    int key;

    scanf("%d",&num);
    for(i=0;i<num;i++)
    {
        scanf("%d",&A[i]);
    }
    dump(A,num);
    
    for(i=1;i<num;i++)
    {
        key = A[i];
        j=i-1;
        while(j>=0 && A[j] > key)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = key;
        dump(A,num);
    }
}


Measured memory_bytes: 2108
/*input
5
1 3 4 5 7
*/

// #include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <cstdint>
#endif
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 1e5+100;
typedef long long int lld;
typedef long long ll;


ll A[lim];

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    lld T,i,p,j,l,n,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum,ans,val,countA,indicator=0,pos,h,minA,maxA,type;
    ans=0;
    cin>>n;
    for (int i=1;i<=n;i++) {
        cin>>A[i];
        if(i%2==1 and A[i]%2==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

struct range_t {
  int l, r;
};

lint solve(const vector<range_t> &ranges, int dir) {
  auto l_cmp = [&](int a, int b) {
    if (ranges[a].l != ranges[b].l)
      return ranges[a].l < ranges[b].l;
    return a < b;
  };
  auto r_cmp = [&](int a, int b) {
        if (ranges[a].r != ranges[b].r)
      return ranges[a].r < ranges[b].r;
    return a < b;
  };
  set<int, decltype(l_cmp)> active_l(l_cmp);
  set<int, decltype(r_cmp)> active_r(r_cmp);
  int n = ranges.size();
  for (int i = 0; i < n; ++i) {
    active_l.insert(i);
    active_r.insert(i);
  }

  lint result = 0LL;
  int pos = 0;

  while (true) {
    if (dir == +1) {
      if (active_l.empty() || ranges[*active_l.rbegin()].l <= pos)
        break;
      int id = *active_l.rbegin();
      result += ranges[id].l - pos;
      pos = ranges[id].l;
      active_l.erase(id);
      active_r.erase(id);
    } else {
      if (active_r.empty() || ranges[*active_r.begin()].r >= pos)
        break;
      int id =  *active_r.begin();
      result += pos - ranges[id].r;
      pos = ranges[id].r;
      active_l.erase(id);
      active_r.erase(id);
    }
    dir *= -1;
  }
  result += abs(pos);
  pos = 0;

  return result;
}

int main() {
  int n;
  scanf("%d", &n);
  vector<range_t> ranges(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &ranges[i].l, &ranges[i].r);
  }
  lint result = max(solve(ranges, -1), solve(ranges, +1));
  printf("%lld\n", result);
  return 0;
}


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

#define int long long

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

    map <int, int> F;
    int n;
    cin >> n;
    vector <int> arr(n);
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        F[arr[i]]++;
    }
    int sum = 0;
    for(auto it = F.begin(); it != F.end(); it++){
        sum += ((it->second)*(it->second-1))/2;
    }
    for(int i = 0; i < n; i++){
        int x = F[arr[i]];
        cout << sum-(x*(x-1))/2 + ((x-1)*(x-2))/2 << endl;
    }
}

Measured memory_bytes: 11136
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
    X = int(input())

    ans = 0 
    ans += (X // 500) * 1000

    X = X - (X // 500) * 500 

    ans += (X // 5) * 5

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

int partition(int ,int);

int A[MAX],n;

int main(){
  int i,q;

	scanf("%d", &n);
	for(i=0;i < n;i++){
		scanf("%d",&A[i]);
	}
	q =  partition(0,n -1);

	for( i=0;i < n;i++){
		if(i) printf(" ");
		if(i == q)printf("[");
		printf("%d",A[i]);
		if(i == q)printf("]");	
	}
	printf("\n");
	
	return 0;
}

int partition(int p,int r) {
	int x,i,j,tmp;
	 x = A[r];
	 i = p-1;
	for (j = p;j<r;j++){
	     if (A[j] <= x){
	     	i++;
	     	tmp = A[i];
	     	A[i] = A[j];
	     	A[j] = tmp;
	     }
	    }
	    tmp = A[i+1];
	    A[i+1] = A[r];
		A[r] = tmp;
		return i + 1;
}


Measured memory_bytes: 2116
/*0429??????????????§??£?§£????????????boolean??§???byte??§?????§???????????? : Accepted        01.11 sec        116760 KB
 * 12??????????????????????¢???? ????????°???????????????????????????????????????????????????????´???°??§???????¢???????
 * ?????????????´???°????????????int ????????§????????????.?????????maxvalue???memory limit ?¶??????????????????????
 * 
 * Created by SharpDevelop.
 * User: yog-sothoth
 * Date: 2017/04/23
 * Time: 17:25
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */


using System;
using System.IO;

namespace Dictionary
{
	
	public class DictionaryList
	{
		
		
		public static void Main(string[] args)
		{		
			int num = int.Parse(Console.ReadLine());// the number of instructions
			
			
			byte[] table = new byte[33555000];
			string iands;
			string[] instAndStr;
			int index=0;
			var sw = new StreamWriter(Console.OpenStandardOutput())
	    	{ AutoFlush = false };
			
			Console.SetOut(sw);
			
			for (int i = 0; i < num; i++) {
				iands = Console.ReadLine();//instruction and s tring
				 instAndStr = iands.Split();
			
				
				//Add list instAndStr[1]		
				if (instAndStr[0] == "insert") {//??????????????\???
					//??????????????°????????????????????????table[index]???????????°??????????????????????????¨????????????????????§????????????
					//????????°???????????????
					 index = 0;
					for (int j = 0; j < instAndStr[1].Length; j++) {
			
						index *= 4;
				
						switch (instAndStr[1][j]) {
							case 'A':
								index += 1;
								break;
							case 'C':
						
								index += 2;
						
								break;
							case 'G':
						
								index += 3;
								break;
							case 'T':
						
								index += 4;
								break;			
						}
						
		
					}
					table[index]=1;
		
					
				} else { //?????????find
					
					
					 index = 0;
					for (int k = 0; k < instAndStr[1].Length; k++) {
			
						index *= 4;
				
						switch (instAndStr[1][k]) {
							case 'A':
								index += 1;
								break;
							case 'C':
						
								index += 2;
						
								break;
							case 'G':
						
								index += 3;
								break;
							case 'T':
						
								index += 4;
								break;			
						}
						
		
					}
					if(table[index]!=1)
					{
						Console.WriteLine("no");
					}else
						Console.WriteLine("yes");
				}
				
			}
			Console.Out.Flush();
		}
		
	}
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,d,a;
    cin>>n>>d>>a;
    Vi x(n),h(n),newx(n),newh(n);
    VPii xh(n);
    REP(i,0,n){
        cin>>x[i]>>h[i];
        xh[i]=mp(x[i],h[i]);
    }


    sort(ALL(xh));
    REP(i,0,n){
        newx[i]=xh[i].first;
        newh[i]=xh[i].second;
    }

    Vi imos(n+1,0);
    int now=0,ans=0;
    REP(i,0,n){
        now += imos[i];
        if(newh[i]-now<=0) continue;
        int bomb=RUP(newh[i]-now,a);
        now += bomb*a;
        int bombd=(lower_bound(ALL(newx),newx[i]+2*d+1)-newx.begin());
        imos[bombd] -= bomb*a;
        ans += bomb;

        // cout<<now<<" "<<ans<<endl;
        // vout(imos);
        // cout<<endl;
    }
    cout<<ans<<endl;

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int tmp = 0, ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
      tmp++;
    }
    else {
      ans = max(ans, tmp);
      tmp = 0;
    }
  }

  ans = max(ans, tmp);
  cout << ans << endl;
}


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

using namespace std;

int main()
{
    int arr[21],n,c=0;


    cin>>n;

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

    for(int i=1;i<n-1;i++){
        if((arr[i]>arr[i-1] && arr[i]<arr[i+1])|| (arr[i]<arr[i-1] && arr[i]>arr[i+1])){
            c++;
        }
    }

    cout<<c<<endl;
}


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

int main() {
    string s;
    cin >> s;
    int counter[26] = {0};
    for (char &c : s)
        counter[c - 'A']++;
    bool isYes = true;
    int lettercounter = 0;
    for (int &c : counter) {
        if (c > 0) {
            lettercounter++;
            if (c != 2)
                isYes = false;
        }
    }
    cout << (isYes && lettercounter == 2?"Yes":"No") << endl;
}


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

constexpr int nax = 1e5;

vector< int > gr[nax + 1];
int n, val[nax + 1];

int dfs(int v, int oj)
{
    if (gr[v].size() == 1)
        return val[v];

    vector< int > ilo;

    for (int s : gr[v])
        if (s != oj)
            ilo.push_back(dfs(s, v));

    ll sum = 0;

    for (int q : ilo)
        sum += q;

    //cerr << v << ' ' << sum << '\n';

    ll r = 2 * val[v] - sum;

    if (r < 0) 
    {
        //cerr << r << ' ' << v << endl;
        cout << "NO" << '\n';
        exit(0);
    }

    for (int q : ilo)
        if (q > val[v]) 
        {
            //cerr << q << ' ' << v << endl;
            exit((cout << "NO" << '\n', 0));
        }

    if (r > val[v]) 
    {
        //cerr << v << ' ' << r << endl;
        exit((cout << "NO" << '\n', 0));
    }

    return r;
}

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

    cin >> n;

    for (int i = 1; i <= n; ++i)
        cin >> val[i];

    for (int i = 0; i < n - 1; ++i)
    {
        int p, q; cin >> p >> q;
        gr[p].push_back(q);
        gr[q].push_back(p);
    }

    if (n == 2)
        return cout << (val[1] == val[2]? "YES" : "NO") << '\n', 0;

    for (int i = 1; i <= n; ++i)
        if (gr[i].size() > 1)
        {
            if (not dfs(i, i))
                cout << "YES" << '\n';
            else
                cout << "NO" << '\n'; //cerr << dfs(i, i) << endl;
            return 0;
        }
}

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

bool is_digit(const char value) { return std::isdigit(value); }
bool is_numeric(const std::string& value) { return std::all_of(value.begin(), value.end(), is_digit); }



int main (){
	
	int x,y,z;
	
	cin>>x>>y>>z;	
	
	

	
	cout<<z<<" "<<x<<" "<<y<<endl;
	
	return 0;
 
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main(void){
    string S;
    cin>>S;
    int A,B,n,T;
    A=0;
    B=0;
    
    n=S.size();
    for(int i=0;i<n;i++){
        if(i%2==0){
            if(S[i]=='0'){
                A=A+1;
            }
        }
        if(i%2==1){
            if(S[i]=='1'){
                A=A+1;
            }
        }
        
    }
    for(int i=0;i<n;i++){
        if(i%2==1){
            if(S[i]=='0'){
                B=B+1;
            }
        }
        if(i%2==0){
            if(S[i]=='1'){
                B=B+1;
            }
        }
        
    }
    
    T=min(A,B);

    cout<<T<<endl;
    return 0;
}

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

#include<unordered_map>


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

	int k=0;
	while (T--) {
		k++;
		int dx[] = { -1,0,1,0 };
		int dy[] = { 0,1,0,-1 };
		vector<pair<int, int>>que;
		vector<vector<int>>field(8, vector<int>(8));
		for (int y = 0; y < 8; ++y) {
			string st; cin >> st;
			for (int x = 0; x < 8; ++x) {
				field[y][x] = st[x] - '0';

			}
		}

		int sx, sy; cin >> sx >> sy;
		sx--; sy--;
		{
			field[sy][sx]=0;
			que.push_back(make_pair(sx,sy));
		}
		while (!que.empty()) {
			auto q(que.back());
			que.pop_back();

			int ax=q.first;
			int ay=q.second;
			for (int way = 0; way < 4; ++way) {
				for (int num = 0; num <= 3; ++num) {
					int nx=ax+dx[way]*num;
					int ny=ay+dy[way]*num;

					if (nx >= 0 && nx <= 7 && ny >= 0 && ny <= 7) {
						if (field[ny][nx]) {
							field[ny][nx]=0;
							que.push_back(make_pair(nx,ny));
						}
					}
				}
			}
		}

		cout<<"Data "<<k<<":"<<endl;
		for (int y = 0; y < 8; ++y) {
			for (int x = 0; x < 8; ++x) {
				cout<<field[y][x];
			}
			cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
const int mod = 1e9+7;

vector<double> p;
double dp[3000][3000];

int main(){
    int N;
    cin >> N;
    double ans = 0.0;
    p.resize(N);
    rep(i,N) cin >> p[i];

    //初期値
    dp[1][1] = p[0];
    dp[1][0] = 1-p[0];

    reps(i,2,N+1){
        rep(j,i+1){
            if(j == 0)
                dp[i][j] = dp[i-1][j] * (1-p[i-1]); 
            else if(j == i)
                dp[i][j] = dp[i-1][j-1] * p[i-1];
            else 
                dp[i][j] = dp[i-1][j] * (1-p[i-1]) + dp[i-1][j-1] * p[i-1];
        }
    }

    reps(i,N/2+1,N+1){
        ans += dp[N][i];
    }
    printf("%.10f\n",ans);
    return 0;
}


Measured memory_bytes: 68864
#include <iostream>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <cstring>
#include <climits>
#include <iomanip>

#define EPS 1e-7
#define LLMAX 9223372036854775807
#define INTMAX 2147483647
#define ULLMAX 18446744073709551615
#define precision(n) cout << setprecision(n) << fixed
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rforr(i, t, n) (int i = n-1; i>=t; --i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MAXN = 1e6;

//STRUCTS


//OPERATORS


//GLOBALS
/*
bool primes[MAXN+1];
vector<ll> p;


//FUNCTIONS
void criba()
{
	primes[0] = true;
	primes[1] = true;
	for (ll i = 2; i*i<= 1e6; i++)
	{
		if (not primes[i])
		{
			p.pb(i);
			for (ll j = i*i; j<=1e6; j+=i) primes[j] = true;
		}
	}
}
*/
//PROBLEM: 
//LINK: 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
		ll a, b;
		cin >> a >> b;
		ll aux = __gcd(a, b);
		ll ans = 1;
		//criba();
		if (aux%2 == 0)
		{
			ans++;
			while (aux%2==0) aux/=2;
		}
		for(ll i = 3; i*i<=aux; i+=2)
		{
			if (aux%i == 0) 
			{
				ans++;
				while (aux%i == 0) aux/=i;
			}
		}
		if (aux>2) ans++;
		cout << ans;



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

int main() {
    LL n, a, b, c, k;
    vector<LL> v;
    string s;
    cin >> n >> k;

    if (n%k == 0) {
        cout << 0 << endl;
    }
    else {
        cout << 1 << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int A[200000];
int Mo[200001];
void Calc(){
	int N = rei();
	int P = rei();
	string S = res();
	for(int i=0;i<N;i++){
		A[i] = S[i]-'0';
	}
	if(P == 2 || P == 5){
		long ans = 0;
		for(int i=0;i<N;i++){
			if(A[i] % P == 0){
				ans += i+1;
			}
		}
		cout << ans << endl;
	}
	else{
		int T = 1;
		Mo[N] = 0;
		for(int i=N-1;i>=0;i--){
			Mo[i] = (Mo[i+1] + T*A[i]) % P;
			T *= 10;
			T %= P;
		}
		sort(Mo,Mo+N+1);
		long ans = 0;
		int c = 1;
		for(int i=1;i<=N;i++){
			if(Mo[i] == Mo[i-1]){
				c++;
			}
			else{
				ans += 1LL*c*(c-1)/2;
				c = 1;
			}
		}
		ans += 1LL*c*(c-1)/2;
		cout << ans << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 2196
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

int main()
{
    std::string str;
    std::size_t q;
    std::cin >> str >> q;

    for (std::size_t i = 0; i < q; ++i) {
        std::string command;
        std::size_t a, b;
        std::cin >> command;
        if (command == "replace") {
            std::string p;
            std::cin >> a >> b >> p;

            for (std::size_t j = a; j <= b; ++j) {
                str[j] = p[j-a];
            }

        } else if (command == "reverse") {
            std::cin >> a >> b;

            for (std::size_t j = 0; j <= (b -a)/2; ++j) {
                std::swap(str[a + j], str[b - j]);
            }

        } else if (command == "print") {
            std::cin >> a >> b;
            std::cout << str.substr(a, b-a+1) << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3208
#include <iostream>
using namespace std;
const int num = 200002, INF = 2000000000;
int a[num], n;
inline long long me(int left, int mid, int right) {
	int long long cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	int l[num / 2], r[num/2];
	l[n1] = r[n2] = INF;
	for (int i = 0; i < n1; i++) 
		l[i] = a[left + i];
	for (int i = 0; i < n2; i++)
		r[i] = a[mid + i];
	int s = 0, t = 0;
	for (int i = left; i < right; i++) {
		if (l[s] > r[t]) {
			a[i] = r[t];
			t++;
			cnt += n1 - s;
		}
		else {
			a[i] = l[s];
			s++;
		}
	}
	return cnt;
}
inline long long ms(int l, int r) {
	long long s1 = 0, s2 = 0, v = 0;
	if (l != r - 1) {
		int m = (l + r) / 2;
		 s1 = ms(l, m);
		 s2 = ms(m, r);
		 v = me(l, m, r);
	}
	return s1 + s2 + v;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {

		cin >> a[i];
	}
	long long ans = ms(0, n);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4652
#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

}
double dp[3005][3005];
double arr[3005];
int n;

double solve(int i, int x) {
	if (x == 0)		return 1;
	if (i < 0)		return 0;

	if (dp[i][x] != -1)		return dp[i][x];

	double ans = (solve(i - 1, x) * (double)(1 - arr[i]) + solve(i - 1, x - 1) * arr[i]);

	return dp[i][x] = ans;
}

int32_t main() {

	fo(i, 0, 3005, 1) {
		fo(j, 0, 3005, 1) {
			dp[i][j] = -1;
		}
	}

	cin >> n;

	arrIn(arr, n);

	cout << fixed << setprecision(9) << solve(n - 1, (n + 1) / 2); nl;

	return 0;
}

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

Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,t; cin>>n>>t;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  long long s=t;
  for(int i=0;i<n-1;i++) s+=min(t,a[i+1]-a[i]);
  cout<<s<<endl;
}

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

void AT1995(int a,int b)
{
  if(a>0)
  {
    cout<<"Positive\n";
    return ;
  }
  else if(a==0||(a<0&&b>0))
  {
    cout<<"Zero\n";
    return ;
  }
  else if((abs(b)-abs(a))%2!=0)
  {
    cout<<"Positive\n";
    return ;
  }
  else
  {
    cout<<"Negative";
    return ;
  }
}

int main()
{
  int a,b;
  cin>>a>>b;
  AT1995(a,b);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  string a,b;
  cin>>a>>b;
  int n=a.size();
  int m=b.size();
  if(n>m){
    cout<<"GREATER"<<endl;
  }
  else if(n<m){
    cout<<"LESS"<<endl;
  }
  else{
    if(a>b){
      cout<<"GREATER"<<endl;
    }
    else if(a<b){
      cout<<"LESS"<<endl;
    }
    else{
      cout<<"EQUAL"<<endl;
    }
  }
  return(0);
}


Measured memory_bytes: 256
H,W = map(int, input().split())
Ch,Cw = map(int, input().split())
Dh,Dw = map(int, input().split())

Ch += 1
Cw += 1
Dh += 1
Dw += 1

S = [["#" for _ in range(W + 4)] for _ in range(2)]
for _ in range(H):
    S.append(["#"] * 2 + list(input()) + ["#"] * 2)
S.append(["#" for _ in range(W + 4)])
S.append(["#" for _ in range(W + 4)])

cnt = [[float("inf")] * (W + 4) for _ in range(H + 4)]
cnt[Ch][Cw] = 0

DX = [0, 0, -1, 1]
DY = [-1, 1, 0, 0]

from collections import deque

def serch(Sh, Sw, count):
    q = [(Sh, Sw)]
    done = [(Sh, Sw)]
    while q:
        qq = []
        for h, w in q:
            for dy, dx in zip(DY, DX):
                nh = h + dy
                nw = w + dx

                if S[nh][nw] == "." and cnt[nh][nw] > count:
                    qq.append((nh, nw))
                    done.append((nh, nw))
                    cnt[nh][nw] = count
        q = qq
    
    return done

DONE = serch(Ch, Cw, 0)
ans = 1
while DONE:
    DDONE = []
    for h, w in DONE:
        for dy in range(-2, 3):
            for dx in range(-2, 3):
                nh = h + dy
                nw = w + dx

                if S[nh][nw] == "." and cnt[nh][nw] > ans:
                    cnt[nh][nw] = ans
                    DDONE += serch(nh, nw, ans)
    
    ans += 1
    DONE = DDONE

if cnt[Dh][Dw] == float("inf"):
    print(-1)
else:
    print(cnt[Dh][Dw])

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

int main(void){
  const int inf = 1 << 30;
  typedef tuple<int, int, int> t3;
  int n, Q;
  priority_queue<t3, vector<t3>, greater<t3>> q;
  cin >> n >> Q;
  vector<int> ans(Q, -1), ds(Q);
  // multiset<int> ms; ms.insert(inf);
  set<int> ms; ms.insert(inf);
  for (int i = 0; i < n; i++){
    int s, t, x;
    scanf("%d %d %d", &s, &t, &x);
    q.push(make_tuple(s - x, x, 1));
    q.push(make_tuple(t - x, x, 0));
  }

  for (int i = 0; i < Q; i++) scanf("%d", &ds[i]);

  int cur = 0;
  while (!q.empty()){
    t3 e = q.top(); q.pop();
    int t, x, act, v;
    tie(t, x, act) = e; v = *ms.begin();
    while (cur < Q && ds[cur] < t)
      ans[cur++] = v;
    
    if (act) ms.insert(x);
    else ms.erase(x);
    // else ms.erase(ms.find(x));
  }

  for (int i = 0; i < Q; i++) printf("%d\n", ans[i] == inf ? -1 : ans[i]);
  return 0;
}


Measured memory_bytes: 18920
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop pop_back()
#define sz size()
using namespace std;
typedef long long ll;
bool isPrime(ll n)
{
    if(n==1)
        return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
        return false;
    return true;
}
int lcm(ll a, ll b)
{
    ll temp = __gcd(a, b);

    return temp ? (a / temp * b) : 0;
}
unordered_map<ll,ll>mapp;
ll ma=-999;
///////////////////////////////////////////
ll n,m,i,j,in=-1,cnt,sum;
vector<ll>vi;
string s;
long double r;
long double mi=100000000;
ll a[200000],c,x,y;
int main(){
    cin>>n;
    cout<<n*(n+1)/2;
}


Measured memory_bytes: 764
import numpy as np
n = int(input())
x = []
y = []
for i in range(n):
  xy = input().split(" ")
  x.append(int(xy[0]))
  y.append(int(xy[1]))
sum_length = 0
for i in range(n-1):
  for j in range(i+1,n):
    sum_length += np.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
print(sum_length*2/n)



Measured memory_bytes: 12424
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;

// Morris-Pratt
// https://youtu.be/9MphwmIsO7Q?t=7283
template<typename T>
struct MP {
  int n;
  T t;
  vector<int> a;
  MP() {}
  MP(const T& t): t(t) {
    n = t.size();
    a = vector<int>(n+1);
    a[0] = -1;
    int j = -1;
    for (int i = 0; i < n; ++i) {
      while (j != -1 && t[j] != t[i]) j = a[j];
      j++;
      a[i+1] = j;
    }
  }
  int operator[](int i) { return a[i];}
  vector<int> findAll(const T& s) {
    vector<int> res;
    int j = 0;
    for (int i = 0; i < s.size(); ++i) {
      while (j != -1 && t[j] != s[i]) j = a[j];
      j++;
      if (j == n) {
        res.push_back(i-j+1);
        j = a[j];
      }
    }
    return res;
  }
};
vector<int>f(vector<int>& a){
    int n = a.size();
    vector<int> res(n);
    rep(i,n) res[i] = a[i]^a[(i+1)%n];
    return res;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    vector<int> xa = f(a);
    vector<int> xb = f(b);
    MP<vector<int>> mp(xa);
    xb.insert(xb.end(), xb.begin(), xb.end());
    vector<int> res = mp.findAll(xb);
    vector<int> ks;
    for(int p: res) ks.push_back(n-p);
    sort(ks.begin(), ks.end());
    for(int k: ks) {
        if (k >= n) continue;
        int x = a[k]^b[0];
        printf("%d %d\n", k, x);
    }

    return 0;
}



Measured memory_bytes: 11504
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

struct edge{
	int v; LL w;
};

vector<vector<edge>> adj;
vector<LL> dist;

void bfs(int root){
	queue<int> frontier;
	dist[root] = 0;
	frontier.push(root);
	while(not frontier.empty()){
		int here = frontier.front(); frontier.pop();
		for (edge& e : adj[here]){
			if (dist[e.v] == -1){
				dist[e.v] = dist[here] + e.w;
				frontier.push(e.v);
			}
		}
	}
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int N; cin >> N;
	adj.resize(N+1);
	dist.assign(N+1, -1);
	int a, b, c;
	for (int i = 0; i < N-1; ++i){
		cin >> a >> b >> c;
		adj[a].push_back({b, (LL)c});
		adj[b].push_back({a, (LL)c});
	}
	int T, K; cin >> T >> K;
	bfs(K);
	int x, y;
	while(T-->0){
		cin >> x >> y;
		cout << dist[x] + dist[y] << '\n';
	}

    return 0;
}

Measured memory_bytes: 9984
N,K=list(map(int,input().split()))
arr=list(map(int,input().split()))

B=[0]
for a in arr:
    B.append(B[-1]+a)

C=[]
for i in range(N+1):
    for j in range(i+1,N+1):
        C.append(B[j]-B[i])

ans=0
for i in range(40,-1,-1):
    log=2**i
    tmp=[x for x in C if x&log==log]
    if len(tmp)>=K:
        ans+=log
        C=tmp
print(ans)

Measured memory_bytes: 23856
#include<stdio.h>
#include<stdlib.h>
int main(){
    int n;
    char *s;
    int i;
    int tmp=0,min;
    scanf("%d",&n);
    s=(char*)malloc(sizeof(char)*n);
    scanf("%s",s);
    for(i=0;i<n;i++){
        if(s[i]=='.')tmp++;
    }
    if(s[0]=='.')tmp--;
    min=tmp;
    for(i=1;i<n;i++){
        if(s[i]=='.')tmp--;
        if(s[i-1]=='#')tmp++;
        if(min>tmp)min=tmp;
    }
    printf("%d\n",min);
    free(s);
    return 0;
}

Measured memory_bytes: 384
"use strict";

var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );

readable.on( 'data', function( chunk ) {
		var data = chunk.split( '\n' );
		var time = parseInt( data[0] );
		var h = Math.floor(time/3600);
		var t = time%3600;
		var m =  Math.floor(t/60);
		var s =  t%60;

		var output = [];
		output.push( h );
		output.push( m );
		output.push( s );
		console.log( output.join( ":" ) );
});


Measured memory_bytes: 15244
#include <stdio.h>

int main(){
    int h,w,n;
    scanf("%d", &h);
	scanf("%d", &w);
	scanf("%d", &n);
  
    int ans = 0, count = 0;
   
    while (n > ans){
        if(w >= h){
            ans += w;
            count++;
        }else if(h>w){
            ans += h;
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


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

using namespace std;
using ll = long long;
 
#define rep(i, n)      for (int i = 0; i < (n); i++)
#define repr(i, n)     for (int i = (n) - 1; i >= 0; i--)
#define repe(i, l, r)  for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define repi(i, l, r)  for (int i = (l); i <= (r); i++)
#define repir(i, l, r) for (int i = (r); i >= (l); i--)
#define range(a) a.begin(), a.end()
void initio() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() { initio();
  // sum (A[i] - 1) = 0 (mod K)
  int N; ll K; cin >> N >> K;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  ll ans = 0;
  map<ll, ll> mp;
  mp[0] = 1;
  vector<ll> sum(N + 1); rep(i, N) sum[i + 1] = (sum[i] + A[i] - 1) % K;
  rep(i, N) {
    if (i+1-K>=0) {
      mp[sum[i+1-K]]--;
    }
    ans += mp[sum[i+1]];
    mp[sum[i+1]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 15872
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

int main(void){
    char S[6];
    cin >> S;
    
    int len = 0;
    while(S[len])
        len++;
    
    int k = 0;
    
    for(int i = 0; i < (len - 1); i++){
        if(S[i] == 'A' && S[i + 1] == 'C'){
            k = 1;
            break;
        }
    }
    
    if(k == 1){
        cout << "Yes" << endl;
    }
    
    else{
        cout << "No" << endl;
    }
    
    return 0;
        }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  while(1){
    scanf("%d %d",&h,&w);
    if(h==0 && w==0) break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 3116
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <iostream>
 
void swap(int * a, int * b)
{
    int t = *a;
    *a = *b;
    *b = t;
}
 
void print_int(int n)
{
    printf("%d\n",n);
    
}
 
void sort(int a[], int n)
{
    int h, i, j;
 
    for(h = 1; h < n / 9; h = h * 3 + 1)
        continue;
 
    for(; h > 0; h /= 3)
    {
        for(i = h; i < n; i++)
        {
            j = i;
            while(j >= h && a[j] < a[j-h])
            {
                swap(&a[j], &a[j-h]);
                j -= h;
            }
        }
    }
}
 
void print_list(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        printf("%d ", a[i]);
    }
}
 
void intcpy(int a[], const int b[], int count)
{
    for(int i = 0; i < count; i++)
    {
        a[i] = b[i];
    }
}
 
int list_sum(int a[], int n)
{
    int sum = 0;
 
    for(int i = 0; i < n; i++)
    {
        sum += a[i];
    }
 
    return sum;
}
 
 
void permutate(int s[], int count, int n)
{
    if(n == count)
        return;
 
    for(int i = n; i < count; i++)
    {
        swap(&s[i], &s[n]);
 
        if(i != n)
        {
            //intcpy(result[j++], s, count);
        }
        
        permutate(s, count, n+1);
        swap(&s[i], &s[n]);
    }
}
 
 
 
using namespace std;
int main(void)
{
    cout.precision(15);
    int n, k;
    cin >> n >> k;
    long double pos = 0;
    for (int i = 1; i <= n; i++)
    {
        long double x = ceill(logl((long double)k/(long double)i)/logl(2));
        x = x < 0 ? 0 : x;
        //cout << x << endl;
        pos += (1/(long double)n)*powl(0.5,x);
    }
    cout << pos << endl;
   
 
    return 0;
}
    



Measured memory_bytes: 256
s = list(input())
s.reverse()
s_r = ""
for i in s:
    s_r+=i
s_r = s_r.replace("resare","")
s_r = s_r.replace("esare","")
s_r = s_r.replace("remaerd","")
s_r = s_r.replace("maerd","")
if len(s_r)==0:
    print("YES")
else:
    print("NO")


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int N;
int A[222222];
int X[222222];
int dp[222222];
int ans[1000001];
signed main(){
    cin>>N;
    rep(i,N-1)cin>>A[i];

    int M;cin>>M;
    rep(i,M)cin>>X[i];

    UnionFindTree uf(1000001);
    deque<int>dp(1000001);
    rep(i,1000001)dp[i]=i;
    for(int i=N-2;i>=2;i--){
        vint v;
        rep(j,A[i]){
            v.pb(dp.front());
            dp.pop_front();
            dp.push_back(-1);
        }
        rep(j,A[i]){
            if(v[j]!=-1&&dp[A[i]-j]!=-1)uf.unite(v[j],dp[A[i]-j]);
            if(v[j]!=-1)dp[A[i]-j]=v[j];
        }
    }
    rep(i,1000001)if(dp[i]!=-1)ans[uf.find(dp[i])]=i;
    rep(i,1000001)ans[i]=ans[uf.find(i)];

    int sum=0;
    for(int i=2;i<N-1;i++)sum+=A[i];

    rep(i,M){
        int tmp;
        if(X[i]>1000000)tmp=X[i]-sum;
        else tmp=ans[X[i]];
        cout<<tmp+A[0]-A[1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 41856
#include<bits/stdc++.h>
using namespace std;
int a[20001],n,ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n-2;i++)
        for(int j=i+1;j<=n-1;j++)
        {
            int k=j+1;
            while(a[k]<a[i]+a[j]&&k<=n)
            {
                k++;
                ans++;
            }
        }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int b[105];
int ans=0;

int main()

{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<n;i++)
		cin>>b[i];

	ans+=b[1];
	for (int i=1;i<n-1;i++){
		ans+=min(b[i],b[i+1]);
	}
	ans+=b[n-1];

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

Measured memory_bytes: 256
#include<stdio.h>
int main(void){

  int k,n=0;
  char a[1200];
  for(k=1;k<=1200;k++){
    scanf("%c",&a[k-1]);
    n++;
    if(a[k-1]=='\n') break;
    if(0x41<=a[k-1]&&a[k-1]<=0x5a){ //???????????????????¶?????????????????????§??????????????¬
      a[k-1] += 0x20;
    }
    else if(0x61<=a[k-1]&&a[k-1]<=0x7a){
      a[k-1] -= 0x20;
    }
  }
  for(k=1;k<=n;k++){
   printf("%c",a[k-1]);
  }
  return 0;
}

Measured memory_bytes: 524
def KP(Val,Wei,N,W):
    v_sum = sum(Val)
    #dp[i][j]:i番目までの品,価値の合計がjでの最小の重さ
    INF = 10**9+1
    dp = [[INF for _ in range(v_sum+1)] for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(N):
        for j in range(v_sum+1):
            if j - Val[i] >= 0:
                dp[i+1][j] = min(dp[i][j-Val[i]]+Wei[i],dp[i][j])
            else:
                dp[i+1][j] = dp[i][j]

    output = 0
    for j in range(v_sum+1):
        if dp[N][j] <= W:
            output = j

    return output

def main():
    N,W = map(int,input().split())
    VW = [list(map(int,input().split())) for _ in range(N)]
    Val = [VW[i][0] for i in range(N)]
    Wei = [VW[i][1] for i in range(N)]
    ans = KP(Val,Wei,N,W)
    print(ans)

if __name__ == "__main__":
    main()



Measured memory_bytes: 14348