akhauriyash/Code-Regression huggingface dataset:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
def main():
    N, K = MI()
    P = LI()
    a = sum(P[0:K])
    Sums = []
    Sum = 0
    for i in range(N):
        Sum += P[i]
        Sums.append(Sum)
    ans = [a, 0, K - 1]
    for i in range(K, N):
        X = Sums[i] - Sums[i - K]
        if X > ans[0]:
            ans[0] = X
            ans[1] = i - K + 1
            ans[2] = i
    cnt = 0
    for i in range(ans[1], ans[2] + 1):
        cnt += (P[i] + 1) / 2
    print(cnt)
if __name__ == "__main__":
    main()

Measured memory_bytes: 107556
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);


int a[20], c[20], s[20];
int get_rand(int min_rand, int max_rand){
  return rand()%(max_rand-min_rand)+min_rand;
}

signed main(){
  srand((unsigned int)time(NULL));
  int n = 10;
  rep(i,n)s[i] = i;
  rep(i,n)cin >> a[i];
  while(true){
    rep(i,n){
      int tmp = get_rand(i, n);
      swap(s[i], s[tmp]);
    }
    rep(i,n)c[i] = a[s[i]];
    int f = 1;
    rep(i, n-1)if(c[i] < c[i+1])f = 0;
    if(f){
      rep(i,3)cout << a[s[i]] << endl;
      break;
    }
  }
  return 0;
}







Measured memory_bytes: 3080
#include<algorithm>
#include<iostream>

using namespace std;
const int N = 3005;

int inverse[N], fac[N], a[N], b[N];
int temp[N];

int power(int p, int i, int mod){
  if (p == 0) return 1;
  int half = p / 2;
  int t = power(half, i, mod);
  if (p % 2 == 1){
      return (((t * t) % mod) * i) % mod;
  }
  return (t * t) % mod;
}

int inv_cal(int p, int i){
  return power(p - 2, i, p);
}

int evaluate(int v, int degree, int mod){
  int p = 1;
  int index = 0;
  int result = 0;
  while(index < degree){
    result = (result + b[index] * p) % mod;
    p = (p * v) % mod;
    index++;
  }
  return result;
}

int main(){
  int p;
  cin >> p;
  for(int i = 0; i < p; ++i){
    cin >> a[i];
  }

  fac[0] = 1;
  for(int i = 1; i < p; ++ i){
    inverse[i] = inv_cal(p, i);
    fac[i] = (fac[i-1] * inverse[i]) % p;
  }


  for(int i = 0; i < p; ++i){
    int acc = evaluate(i, i, p);
    int t = (((a[i] - acc + p) % p) * fac[i]) % p;
    temp[i] = 1;
    for (int j = i-1; j > 0; -- j){
      temp[j] = ((p - i + 1) * temp[j] + temp[j - 1]) % p;
    }


    if (i > 0){
        temp[0] = ((p - i + 1) * temp[0]) % p;
    }

    for (int j = 0; j <= i; ++ j){
      b[j] = (b[j] + t * temp[j]) % p;
    }
  }

  for (int i = 0; i < p ; ++ i){
    cout << b[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple


signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	sort(all(s));
	if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,t,x,y;
int main()
{
  int n,x,y,z,i;	
  cin>>n;
  for(i=1;i<=n;i++)
  {
    cin>>x>>y>>z;
    if(!(y+z<=x&&(x-y-z)%2==0))
	{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

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

int main()
{
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(auto& ai:a) cin >> ai;

    vector<ll> b(n+1, 0);
    ll sum = 0;
    rep(i,n) {
        sum += a[i];
        b[i+1] = (sum-(i+1)) % k; 
    }

    unordered_map<ll, int> mp;
    ll ans = 0;
    rep(i,n+1) {
        if(i-k>=0) mp[b[i-k]]--;

        if(mp.count(b[i])) {
            ans += mp[b[i]];
            mp[b[i]]++;
        }
        else {
            mp[b[i]] = 1;
        }
    }

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

Measured memory_bytes: 11592
#include<bits/stdc++.h>
using namespace std;
int main(){

       long long int a,b,c,k;
        cin>>a>>b>>c>>k;

          if(a >= k)
           cout<<k;

          else{

              long long int total = a;
               k=k-a;


                   if(k > b)
                   k=k-b;

                   else
                   k=0;

                   total-=k;
              cout<<total;
          }
}


Measured memory_bytes: 3628
N = int(input())
a = []
a = input().split()
S = a[0]
T = a[1]

SLIST = list(S)
TLIST = list(T)

STLIST = []

for i in range(2 * N):
  if i % 2 == 0:
    STLIST.append(SLIST[int(i / 2)])
  if i % 2 == 1:
    STLIST.append(TLIST[int(i // 2)])

ans = ''
for i in STLIST:
  ans += i

#print('N = ', N)
#print('S = ', S, ' T = ', T)
#print('SLIST = ', SLIST, ' TLIST = ', TLIST)

print(ans)

Measured memory_bytes: 3064
n,m=map(int,input().split())
h=list(map(int,input().split()))
g=[1 for i in range(n)]
for i in range(m):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  if h[a]<=h[b]:
      g[a]=0
  if h[b]<=h[a]:
      g[b]=0
ans=g.count(1)
print(ans)

Measured memory_bytes: 20116
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 100005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e8;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}
vvl adj(MAXN);
vl vis(MAXN), par(MAXN, -1);
void addedge()
{
	ll a, b;
	cin >> a >> b;
	adj[a].pb(b);
	adj[b].pb(a);
}
void bfs(ll x)
{
	queue<ll> q;
	q.push(x);
	while (!q.empty())
	{
		ll node = q.front();
		q.pop();
		vis[node] = 1;
		for (auto child : adj[node])
		{
			if (vis[child] == 0)
			{
				par[child] = node;
				vis[child] = 1;
				q.push(child);
			}
		}
	}
}
signed main() {

	fast
	ll n, m;
	cin >> n >> m;
	loop(i, m)	addedge();
	bfs(1);
	bool ok = 1;
	FOR(i, 1, n)
	{
		if (vis[i] == 0)
		{
			ok = 0;
			break;
		}
	}
	if (ok)
	{
		cout << "Yes\n";
		FOR(i, 2, n)	cout << par[i] << END;
	}
	else
	{
		cout << "No\n";
	}




	return 0;
}

Measured memory_bytes: 13772
#define _crt_secure_no_warnings

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif


#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>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#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 <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

vector<vector<int>>data;

int x[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int y[] = { 1, 1, 0, -1, -1, -1, 0, 1 };

void serch(int i, int j)
{
	data[i][j] = 0;
	for (size_t k = 0; k < 8; k++)
	{
		if (data[i + x[k]][j + y[k]])
		{
			serch(i + x[k], j + y[k]);
		}
	}
}

int main()
{
	int N, M;
	int ans = 0;
	while (1)
	{
		data.clear();
		ans = 0;
		cin >> N >> M;
		if (N == 0 && M == 0)break;
		swap(M, N);
		data.resize(N + 2);
		for (size_t i = 0; i < N + 2; i++)
		{
			data[i].resize(M + 2);
			for (size_t j = 0; j < M+2; j++)
			{
				data[i][j] = 0;
			}
		}
		for (size_t i = 1; i <= N; i++)
		{
			for (size_t j = 1; j <= M; j++)
			{
				cin >> data[i][j];
			}
		}
		for (size_t i = 1; i <= N; i++)
		{
			for (size_t j = 1; j <= M; j++)
			{
				if (data[i][j])
				{
					ans++;
					serch(i, j);
				}
			}
		}
		cout << ans<<endl;
	}
}

Measured memory_bytes: 1280
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>
#pragma comment(linker, "/STACK:836777216")

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define N 3005

int a[N];

ll sum[N];

int main(void) {
	int n, s;
	scanf("%d%d", &n, &s);
	REP(i, n) {
		scanf("%d", &a[i]);
	}

	CL(sum, 0);
	sum[0] = 1;

	ll mod = 998244353;
	ll total = 0;

	REP(i, n) {
		REPD(j, s) {
			if (sum[j]) {
				if (j + a[i] < s) {
					if (!j) {
						sum[j + a[i]] = (sum[j + a[i]] + (i + 1)) % mod;
					}
					else {
						sum[j + a[i]] = (sum[j + a[i]] + sum[j]) % mod;
					}
				}
				else
					if (j + a[i] == s) {
						if (!j) {
							total = (total + (i + 1) * (n - i)) % mod;
						}
						else {
							total = (total + sum[j] * (n - i)) % mod;
						}
					}
			}
		}
	}

	printf("%lld\n", total);
	//scanf("%d\n", &n);

	return 0;
}

Measured memory_bytes: 256
import queue
h, w, k = map(int, input().split())
s=[input() for i in range(h)]
ans = [[0]*w for i in range(h)]

def BFS(i, j, count):
  ans[i][j]=str(count)
  movex = [0, 0]
  movey = [1, -1]
  q = queue.Queue()
  q.put([i, j])
  while not q.empty():
    y, x = q.get()
    for i in range(2):
      nx = x+movex[i]
      ny = y+movey[i]
      if 0<=ny<=h-1 and ans[ny][nx]==0 and s[ny][nx]==".":
        ans[ny][nx]=str(count)
        q.put([ny, nx])

def DFS(i, j): 
  movex = [1, -1]
  movey = [0, 0]
  x = j
  y = i
  #右を見る
  while x<=w-1:
    if ans[y][x]==0:
       x+=1
    else:
       return ans[y][x]
  x=j
  while x>=0:
    if ans[y][x]==0:
      x-=1
    else:
      return ans[y][x]

count = 1
for i in range(h):
  for j in range(w):
    if s[i][j]== "#":
      BFS(i, j, count)
      count+=1
  
for i in range(h):
  for j in range(w):
    if ans[i][j]==0:
      ans[i][j]=DFS(i, j)
      
for i in range(h):
  print(" ".join(ans[i]))


Measured memory_bytes: 87748
#include <iostream>
#include <deque>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
using namespace std;

int main() {
  string str;
  int Q;
  cin >> str >> Q;
  deque<char> deq;
  for (auto c : str) deq.push_back(c);
  bool rev = false;

  for (int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) rev ^= 1;

    if (t == 2) {
      int f;
      char c;
      cin >> f >> c;

      if ((f - 1) ^ rev) {
        deq.push_back(c);
      } else {
        deq.push_front(c);
      }
    }
  }

  if (!rev) {
    for (auto it = deq.begin(); it != deq.end(); ++it) cout << *it;
  } else if (rev == 1) {
    for (auto it = deq.rbegin(); it != deq.rend(); ++it) cout << *it;
  }
  cout << '\n';

  return 0;
}


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

#define pb push_back

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;	

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

	int N, M, Ai;
	vi vet;
	int cont = 0;
	int polls = 0;

	cin >> N >> M;
	for(int i = 0; i < N; i++){
		cin >> Ai;
		vet.pb(Ai);
		polls += Ai;
	}

	double tmp1 = (double)polls/(4*M);

	sort(vet.begin(), vet.end());
	reverse(vet.begin(), vet.end());

	cout << (vet[M-1] >= tmp1 ? "Yes\n" : "No\n");

	return 0;	
}



Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=200005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n,a[max_n];
ll cnt[max_n];
ll cur;
void add(int x){
    cur-=cnt[x]*(cnt[x]-1)/2;
    cnt[x]++;
    cur+=cnt[x]*(cnt[x]-1)/2;
}
void del(int x){
    cur-=cnt[x]*(cnt[x]-1)/2;
    cnt[x]--;
    cur+=cnt[x]*(cnt[x]-1)/2;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=1;i<=n;i++)add(a[i]);
    for(int i=1;i<=n;i++){
        del(a[i]);
        printf("%lld\n",cur);
        add(a[i]);
    }
    return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int x1,yy1,x2,yy2;
int n;
struct node
{
    int x,y;
    friend bool operator < (const node &aa,const node &bb)
    {
        return aa.y<bb.y;
    }
}a[N];
int f[N];
const double pi = acos(-1);
int main()
{
    cin>>x1>>yy1>>x2>>yy2;
    if(yy1>yy2)swap(yy1,yy2),swap(x1,x2);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1,a+n+1);
    double ans=abs(yy2-yy1)+abs(x2-x1);ans*=100;
    int len;
    if(x1<=x2)
    {

        len=0;f[0]=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i].y>=yy1&&a[i].y<=yy2&&a[i].x>=x1&&a[i].x<=x2)
            {
                if(a[i].x>=f[len])f[++len]=a[i].x;
                else
                {
                    int l=1,r=len;
                    while(l<r)
                    {
                        int mid=(l+r)>>1;
                        if(a[i].x<f[mid])r=mid;
                        else l=mid+1;
                    }
                    f[l]=a[i].x;
                }
            }
        }
    }
    else
    {
        len=0;f[0]=0x3f3f3f3f;
        for(int i=1;i<=n;i++)
        {
            if(a[i].y>=yy1&&a[i].y<=yy2&&a[i].x>=x2&&a[i].x<=x1)
            {
                if(a[i].x<=f[len])f[++len]=a[i].x;
                else
                {
                    int l=1,r=len;
                    while(l<r)
                    {
                        int mid=(l+r)>>1;
                        if(a[i].x>f[mid])r=mid;
                        else l=mid+1;
                    }
                    f[l]=a[i].x;
                }
            }
        }
    }
    ans-=len*20;ans+=len*5*pi;
    if(len==min(abs(yy2-yy1),abs(x2-x1))+1)ans+=5*pi;
    printf("%.14lf\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in(),ans=0;
    for(ll i=0;i<n;++i)if(ll foo=in();i%2==0&&foo%2==1)++ans;
    cout<<ans<<endl;
}


Measured memory_bytes: 3592
m = input()
n = input()
in_edges = [[] for _ in xrange(m+1)]
in_edges[2] = [i for i in xrange(1,m+1) if not i == 2]
for _ in xrange(n):
    x,y = map(int,raw_input().split())
    if not x in in_edges[y]:
        in_edges[y].append(x) 
row = []
while not len(row) == m:
    for i in xrange(1,m+1):
        if in_edges[i] == [] and not i in row:
            row.append(i)
            for ii in xrange(1,m+1):
                if i in in_edges[ii]:
                    in_edges[ii].remove(i)
print "\n".join(map(str,row))

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

using namespace std;
using ll = long long;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(m, vector<int>());
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < a; j++) {
      int b;
      cin >> b;
      v[i].push_back(b - 1);
    }
  }
  vector<int> v2(n);
  for (int i = 0; i < m; i++) {
    cin >> v2[i];
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    bitset<10> b(i);
    bool f = true;
    for (int j = 0; j < m; j++) {
      int tmp = 0;
      for (int k = 0; k < v[j].size(); k++) {
        if (b[v[j][k]] == 1) {
          tmp++; 
        } 
      }
      if (tmp % 2 != v2[j]) {
        f = false; 
      }
    }
    if (f) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5+5;
int n, m;
struct Tree {
    int ls, rs; ll val; // 左右儿子的编号, 和维护的一个值.
}tre[maxn*100];
int idx = 0, root[maxn];
int build(int l, int r) {
    int nod = ++idx;
    tre[nod].val = 0;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    tre[nod].ls = build(l, mid);
    tre[nod].rs = build(mid+1, r);
    return nod;
}
int update(int pre, int l, int r, int pos, ll v) {
    int nod = ++idx;
    tre[nod] = tre[pre]; tre[nod].val += v;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    if (pos <= mid) tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
    else tre[nod].rs = update(tre[pre].rs, mid+1, r, pos, v);
    return nod;
}
ll query(int id, int l, int r, int pos) {
    if (l == r) return tre[id].val;
    int mid = (l + r) >> 1;
    if (pos <= mid) {
        return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
    }
    else return query(tre[id].rs, mid+1, r, pos);
}
int a[maxn], vis[maxn];
void solve() {
    scanf("%d%d", &n,&m);
    for (int i = 1 ; i <= n ; i ++) {
        scanf("%d", &a[i]);
    }
    root[0] = build(1, n);    //根节点
    for (int i = 1 ; i <= n ; i ++) {
        if (!vis[a[i]])
            root[i] = update(root[i-1], 1, n, i, 1);
        else {
            int t = update(root[i-1], 1, n, vis[a[i]], -1);
            root[i] = update(t, 1, n, i, 1);
        }
        vis[a[i]] = i;
    }
    while (m--) {
        int l, r; scanf("%d%d", &l, &r);
        ll tmp = query(root[r], 1, n, l);
        printf("%lld\n", tmp);
    }
}
int main(){
    solve();
    return 0;
}


Measured memory_bytes: 334628
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

void solve(){
  int n, x;
  cin >> n >> x;
  int m[n], res = n;
  rep(i, n) cin >> m[i], x -= m[i];

  sort(m, m+n);
  res += x/m[0];
  cout << res << endl;
}

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


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

int main() {
	// your code goes here
	long long n,k,sum = 0;
	cin >> n;
	k = n;
	while(n > 0)
	{
	    sum += n % 10;
	    n /= 10;
	}
	if(k % sum == 0)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll MAX = 10000000;
ll fac[MAX], finv[MAX], inv[MAX];
 
//テーブルを作る前処理
 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i%MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
 
//二項計数計算
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}	
int main(){
	COMinit();
	int n,m;
	cin>>n>>m;
	map<int,int>res;
	for(int i=2; i*i<=m; i++){
		while(m%i==0){
			res[i]++;
			m/=i;
		}
	}	
	if(m!=1)res[m]++;
	ll ans=1;
	for(auto p:res){
		ans *=COM(n+p.second-1,p.second);
		ans%=MOD;
	}
	cout<<ans<<endl;
}

		

Measured memory_bytes: 234624
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2000 + 5, mod = 1e9 + 7;

int fact[N], inv[N];

int add(int a, int b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (a + b) % mod;
}

ll mul(ll a, ll b){
    return a * b % mod;
}

int fp(int b, int p){
    if(!p) return 1;
    ll ret = fp(b, p >> 1);
    ret = ret * ret % mod;
    if(p&1) ret = ret * b % mod;
    return ret;
}

void pre(){
    fact[0] = inv[0] = 1;
    for(int i = 1; i < N; i++){
        fact[i] = mul(fact[i - 1], i);
        inv[i] = fp(fact[i], mod - 2);
    }
}

int ncr(int n, int r){
    int ret = mul(fact[n], inv[n - r]);
    return mul(ret, inv[r]);
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    pre();
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i; i++){
        int tmp = n - i * 3;
        if(tmp < 0) break;
        ans = add(ans, ncr(tmp + i - 1, i - 1));
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <cstdio>
#include <cstring>

#define int long long
#define Accepted 0; 

const int Maxv = 100010; 
int d[Maxv], d1[Maxv], u[Maxv], ghostfly233[Maxv], siz[Maxv], cnt, n;  

inline int GldHkkowoSearch(int x) {
    int tmp = std::lower_bound(d + 1, d + n + 1, x) - d;

    if (d[tmp] != x) {
        puts("-1"); 
        exit(0); 
    }

    return tmp; 
}

signed main() {
    scanf("%lld", &n); 
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &d[i]); 
        d1[i] = d[i]; 
    }

    std::sort(d + 1, d + n + 1); 
    for (int i = 1; i <= n; i++) 
        ghostfly233[GldHkkowoSearch(d1[i])] = i;       

    for (int i = 1; i <= n; i++)
        siz[i] = 1; 

    for (int i = n; i > 1; i--) {
        u[i] = GldHkkowoSearch(d[i] - n + (siz[i] << 1)); 
        siz[ u[i] ] += siz[i]; 
        cnt += siz[i]; 
    }

    if (cnt != d[1]) {
        puts("-1"); 
        return 0; 
    }

    for (int i = 2; i <= n; i++)
        printf("%lld %lld\n", ghostfly233[i], ghostfly233[ u[i] ]); 

    return Accepted;  
}

Measured memory_bytes: 5248
import Data.Vector.Unboxed as V(fromList,(!),Vector)
import Control.Monad

inf :: Int
inf = 200000000

main :: IO ()
main = do
  [n,k] <- map read.words <$> getLine
  as <- V.fromList . map read.words <$> getLine :: IO (Vector Int)
  ls <- forM [0..n-k] $ \i -> return $ (min (abs $ as!i) $ (abs $ as!(i+k-1))) + (as!(i+k-1) - as!i)
  print $ minimum ls


Measured memory_bytes: 57852
# # n = int(input())
# s = input()

# # a = [int(i) for i in input().split()]

# if s.isupper():
#     print('A')
# else:
#     # print('a')

n, k = map(int, input().split())
# print(n, k)

p = [int(i) for i in input().split()]

# print(p)

p.sort()

sum = 0
for i in range(0, k):
    sum += p[i]

print(sum)

Measured memory_bytes: 9240
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
#from fractions import gcd
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

S = input()

res = 10000
for i in range(len(S)-2):
    num = int(S[i:i+3])
    val = abs(753 - num)
    if val < res:
        res = val
print(res)





Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin>>N;
    vector<int>A(N),A_copy(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
        A_copy.at(i)=A.at(i);
    }

    sort(A_copy.begin(),A_copy.end());
    int max_number=A_copy.at(N-1);
    int secondmax_number=A_copy.at(N-2);

    for(int i=0;i<N;i++){
        if(A.at(i)!=max_number) cout<<max_number<<endl;
        else cout<<secondmax_number<<endl;
    }
}

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

int main() {
    const int max = 600;
    int d;
    while(cin >> d)
    {
        int s = 0;
        int times = max / d;
        for(int i = 1; i < times; i++)
        {
            s += i*i;
        }
        s *= d*d*d;
        cout << s << endl;
    }
    
    return 0;
}

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

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

using namespace std;

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

  ll DIV = 1000000007;
  ll a[100001];

  REP(i, m)
  {
    cin >> a[i];
  }
  sort(a, a + m);

  ll dp[100001] = {};

  dp[0] = 1;
  int index = 0;
  FOR(i, 1, n + 1)
  {
    while (i > a[index] && index < m - 1)
    {
      index++;
    }
    if (i != a[index])
    {
      if (i >= 2)
      {
        dp[i] = (dp[i - 1] + dp[i - 2]) % DIV;
      }
      else
      {
        dp[i] = dp[i - 1];
      }
    }
    else
    {
      dp[i] = 0LL;
    }
  }

  cout << dp[n] << endl;
}


Measured memory_bytes: 1792
n = gets.to_i
songs = []
times = []
n.times do
  tmp1, tmp2 = gets.split
  songs << tmp1
  times << tmp2.to_i
end
name = gets.chomp
index = songs.find_index(name)
time = times[index + 1..-1].inject(:+)
if time
  puts time
else
  puts 0
end


Measured memory_bytes: 1788
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>

#define fo(i,j,l) for(i=j;i<=l;i++)
#define fd(i,j,l) for(i=j;i>=l;i--)

using namespace std;
typedef long long ll;
const ll N=2e3+100,mo=1e9+7,NN=1e4+50;
ll f[2*N][2*N],a[NN*100],b[100*NN];
ll jc[NN+10],ny[NN+10],ans;
int i,j,k,l,o,p,n,m;

ll ksm(ll o,ll t)
{
	ll yy=1;
	for(;t;t/=2,o=(o*o)%mo)
	if(t%2)yy=(yy*o)%mo;
	return yy;
}

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

ll C(ll a,ll b)
{
	return (jc[a]*ny[b]%mo)*ny[a-b]%mo;
}

int main()
{
	cin>>n;
	fo(i,1,n)
	scanf("%lld%lld",&a[i],&b[i]);
	ny[1]=jc[1]=ny[0]=jc[0]=1;
	fo(i,2,NN)jc[i]=jc[i-1]*i%mo,ny[i]=ksm(jc[i],mo-2);
	ans=0;
	fo(i,1,n)
	ans=(ans+C(2*(a[i]+b[i]),a[i]+a[i]))%mo;
	ans=mo-ans;
	int k1=0,k2=0;
	fo(i,1,n)k1=max(k1,a[i]),k2=max(k2,b[i]);
	fo(i,1,n)f[-a[i]+k1][-b[i]+k2]++;
	fo(i,1,2*k2)f[0][i]=(f[0][i]+f[0][i-1])%mo;
	fo(i,1,2*k1)
	fo(l,0,2*k2)
	f[i][l]=(f[i][l]+f[i-1][l]+f[i][l-1])%mo;
	ll ddd=0;
	fo(i,1,n)
	ddd=(ddd+f[a[i]+k1][b[i]+k2])%mo;
	ans=(ans+ddd)*ny[2]%mo;
	printf("%lld",ans);
}

Measured memory_bytes: 139136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s1[100];
    char s2[100],s3[100];
    cin>>s2>>s1>>s3;
    if(s2[0]>='a' && s2[0]<='z')
    s2[0]-=32;
    if(s1[0]>='a' && s1[0]<='z')
    s1[0]-=32;
    if(s3[0]>='a' && s3[0]<='z')
    s3[0]-=32;
    cout<<s2[0]<<s1[0]<<s3[0];
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100
static const int INFINITY = 1 << 21;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;

static int n;
static int M[MAX][MAX];

static void dijkstra()
{
    int d[MAX];
    int color[MAX];

    for (int i = 0; i < n; i++) {
        d[i] = INFINITY;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;

    while (1) {
        int minv = INFINITY;
        int u = -1;
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }

        if (u == -1)
            break;

        color[u] = BLACK;

        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFINITY) {
                if (d[v] > d[u] + M[u][v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

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

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = INFINITY;
        }
    }

    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            M[u][v] = c;
        }
    }

    dijkstra();
    return 0;
}


Measured memory_bytes: 2040
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let N = read::<i32>();
    let K = read::<i32>();
    let mut mlp = 1;
    for n in 0..N {
        if mlp < K {
            mlp *= 2;
        } else {
            mlp += K;
        }
    }
    println!("{}", mlp);

}


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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s; cin >> s;
    reverse(all(s));
    int pnt=0;
    while(s.size()-pnt != 0) {
        if(s.size()-pnt < 5) {
            cout << s.size()-pnt << endl;
            cout << "NO" << endl;
            return 0;
        }
        if(s.substr(pnt,5) == "maerd") { pnt+=5;continue; }
        if(s.substr(pnt,5) == "esare") { pnt+=5;continue; }
        if(s.size()-pnt < 6) {
            cout << "NO" << endl;
            return 0;
        }
        if(s.substr(pnt,6) == "resare") { pnt+=6;continue; }
        if(s.size()-pnt < 7) {
            cout << "NO" << endl;
            return 0;
        }
        if(s.substr(pnt,7) == "remaerd") { pnt+=7;continue; }
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 3776
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    vl k(q);
    for (int i = 0; i < q; ++i) {
        cin >> k[i];
        k[i]--;
    }
    for (int i = 0; i < q; ++i) {
        vl dp(3, 0);
        vl cnt(3, 0);
        for (int j = 0; j < n; ++j) {
            if (s[j] == 'D') {
                dp[0]++;
                cnt[0]++;
            } else if (s[j] == 'M') {
                dp[1] += dp[0];
                cnt[1]++;
            } else if (s[j] == 'C') {
                dp[2] += dp[1];
            }

            if (j >= k[i]) {
                if (s[j - k[i]] == 'D') {
                    dp[0]--;
                    dp[1] -= cnt[1];
                    cnt[0]--;
                } else if (s[j - k[i]] == 'M') {
                    cnt[1]--;
                }
            }
        }
        cout << dp[2] << "\n";
    }
    return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[200005];
 main()
{
    int n,x,y;
    cin>>n>>x>>y;
    for(int i =1; i<=n; i++){
        for(int j =i+1; j<=n; j++){
            int cur = min(abs(i-j),min(abs(i-x)+1 +abs(j-y),abs(i-y)+1+abs(j-x)));
            dp[cur]++;
        }
    }
    for(int i =1; i<=n-1; i++)
        cout<<dp[i]<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    string s;
    cin >> s;
    map<char, int> m;
    for (auto x: s) {
        m[x]++;
    }
    for (auto x: m) {
        if (x.second % 2 == 1) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}

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

using namespace std;

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

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1412
#include<bits/stdc++.h>
#define MAXN 2005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int N,K,ans;
vector<int> G[MAXN];
int f[2][MAXN];
int dfs(int id,int v,int p,int k)
{
    f[id][v]=1;
    if(k==0) return f[id][v];
    for(auto to:G[v]) if(to!=p) f[id][v]+=dfs(id,to,v,k-1);
    return f[id][v];
}
int main()
{
    int ans=0;
    scanf("%d%d",&N,&K);
    for(int i=0;i<N-1;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v); G[v].push_back(u);
    }
    for(int root=1;root<=N;root++)
    {
        dfs(0,root,0,K/2);
        dfs(1,root,0,(K+1)/2);
        int res=f[0][root],maxi=0;
        for(auto v:G[root]) maxi=max(maxi,f[1][v]-f[0][v]);
        if(K&1) ans=max(ans,res+maxi); else ans=max(ans,res);
    }
    printf("%d\n",N-ans);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
void fast(){
cin.tie(0);
cin.sync_with_stdio(0);
}

int main()
{
	fast();
   int n;cin>>n;int a[n];bool ch=1;cin>>a[0];
   for(int i=1;i<n;i++){cin>>a[i];
   	if(a[i]!=a[i-1]){ch=0;}
   }
   if(ch){cout<<0;}
   else{ sort(a,a+n);long long mn=LONG_LONG_MAX;
   for(int i=a[0];i<=a[n-1];i++){
   		long long cost=0;
   		for(int j=0;j<n;j++){
   			cost+=(a[j]-i)*(a[j]-i);
   		}
   	mn=min(mn,cost);
   }
   cout<<mn;
   }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        char[] ch = sc.next().toCharArray();
        final int N = ch.length;
        int min = 1000;
        
        for (int i = 0; i < N - 2; i++) {
            String s = "";
            s += ch[i];
            s += ch[i + 1];
            s += ch[i + 2];
            int x = Integer.parseInt(s);
            min = Math.min(Math.abs(753 - x), min);
        }
        
        out.println(min);
        
        out.flush();
    }
}

Measured memory_bytes: 23764
h,w,n = map(int, input().split())
l=[list(map(int,input().split())) for i in range(n)]

from collections import defaultdict
d = defaultdict(int)
for tmp in l:
    y=tmp[0]-1
    x=tmp[1]-1
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 1<=x+i<w-1 and 1<=y+j <h-1:
                s = str(x+i) + "_" + str(y+j)
                d[s]+=1

import collections
lis = list(d.values())
c = collections.Counter(lis)

ans=[0]*10
for itm in c.items():
    ans[itm[0]]=itm[1]

ans[0]=(h-2)*(w-2)-sum(ans)

for a in ans:
    print(a)

Measured memory_bytes: 230392
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int64_t s[100'002];
int64_t t[100'002];

const int64_t XMAX = 10'000'000'001LL;

int main()
{
    int a, b, q;

    cin >> a >> b >> q;
    s[0] = 0;
    s[a + 1] = XMAX;
    for (int i = 1; i <= a; i++)
    {
        cin >> s[i];
    }
    t[0] = 0;
    t[b + 1] = XMAX;
    for (int i = 1; i <= b; i++)
    {
        cin >> t[i];
    }

    for (int i = 0; i < q; i++)
    {
        int64_t x;
        cin >> x;

        int sUb = a + 1;
        int sLb = 0;
        while (sLb + 1 < sUb)
        {
            int mid = (sLb + sUb) / 2;
            if (s[mid] < x)
            {
                sLb = mid;
            }
            else
            {
                sUb = mid;
            }
        }

        int tUb = b + 1;
        int tLb = 0;
        while (tLb + 1 < tUb)
        {
            int mid = (tLb + tUb) / 2;
            if (t[mid] < x)
            {
                tLb = mid;
            }
            else
            {
                tUb = mid;
            }
        }

        int shrines[] = {sLb, sUb};
        int temples[] = {tLb, tUb};
        int64_t result = 2 * XMAX;
        for (int sidx : shrines)
        {
            for (int tidx : temples)
            {
                if (sidx == 0 || sidx == a + 1 || tidx == 0 || tidx == b + 1)
                {
                    continue;
                }
                int64_t cand = min(abs(s[sidx] - x) + abs(t[tidx] - s[sidx]), abs(t[tidx] - x) + abs(s[sidx] - t[tidx]));
                result = min(result, cand);
            }
        }

        cout << result << endl;
    }
    return 0;
}

Measured memory_bytes: 2816
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;
int n,x,a[2005], ans = 1e18, premin[2005];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> n >> x;
for(int i =0;i<n;i++){
	cin >> a[i];
	premin[i]=a[i];
}
for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
		premin[j] = min(premin[j], a[(j-i+n)%(n)] );
		//cout << a[(j-i+n+1)%(n+1)];
	}
	int cur = i*x;
	for(int j=0;j<n;j++){
		cur+= premin[j];
		//cout << premin[j] << endl;
	}
	ans = min(ans, cur);
}
cout << ans << endl;
return 0;}
///....


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
#include<math.h>

int main(){
    int N,M;
    cin >> N >> M;
    long long int A[N],B[N];
    for(int i=0;i<N;++i){
        cin >> A[i] >> B[i];
    } 
    pair<long long int,long long int> p[N];
    for(int i=0;i<N;++i){
        p[i]=make_pair(A[i],B[i]);
    }
    sort(p,p+N);
    int res=0;
    long long int money=0;
    int num_dri=0;
    int num_dri_pas=0;
    int num_dri_dif=0;
    for(int i=0;i<N;++i){
        num_dri+=p[i].second;
        if(num_dri<=M){
            money+=p[i].first*p[i].second;
            num_dri_pas=num_dri;
        }
        else{
            res=i;
            num_dri_dif=M-num_dri_pas;
            money+=p[res].first*num_dri_dif;
            break;
                }
            }
    cout << money;
}

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

int main(){
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int ans = 0;
  
  for(int i = 0; i < n; i++){
    if(s.at(i) != t.at(i)){
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 16050, M = 8010;

int n, x, y;
char s[M];
set<int> fx[2], fy[2];
vector<int> X, Y;

int main()
{
	scanf("%s%d%d", s, &x, &y);
	n = strlen(s);
	
	for (int i = 0, t = 0; i < n; i ++ , t ^= 1)
	{
		int j = i;
		while (j < n && s[j] != 'T') j ++ ;
		
		if (!t) X.push_back(j - i);
		else Y.push_back(j - i);
		i = j;
	}
	
	int tx = 0;
	fx[tx].insert(X[0] + M);
	for (int i = 1; i < X.size(); i ++ )
	{
		tx ^= 1, fx[tx].clear();
		for (auto u : fx[tx ^ 1])
		{
			fx[tx].insert(u + X[i]);
			fx[tx].insert(u - X[i]);
		}
	}
	
	int ty = 0;
	fy[ty].insert(M);
	for (int i = 0; i < Y.size(); i ++ )
	{
		ty ^= 1, fy[ty].clear();
		for (auto u : fy[ty ^ 1])
		{
			fy[ty].insert(u + Y[i]);
			fy[ty].insert(u - Y[i]);
		}
	}
	
	if (fx[tx].count(x + M) && fy[ty].count(y + M)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;


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

	string s;
	cin >> s;

	int n = s.size();

	string ans;
	rep(i, n){
		char c = s[i];
		if(c == 'B'){
			if(ans.size() > 0){
				ans.pop_back();
			}
		}else{
			ans.push_back(c);
		}
	}

	cout << ans << endl;
}


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

ll N,P,Q;
ll C[500005];
ll D[500005];
ll ans,sum,x;

int main(){
  cin>>N>>P>>Q;
  for(int i=0;i<N;i++){
    cin>>C[i];
    D[i]=(Q-i)*P-C[i];
    sum+=C[i];
  }
  sort(D,D+N);
  reverse(D,D+N);
  ans=sum;
  
  for(int i=0;i<N;i++){
    sum+=D[i];
    x+=2*i*P;
    ans=max(ans,sum+x);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 8984