akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>
#include <functional>

using namespace std;
using ll = long long;

#define all(x) (x).begin(),(x).end()
#define PRI(n) cout << n << " "<<endl;
#define PRI2(n, m) cout << n << " " << m << " "<<endl;

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

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

struct edge;
struct UnionFind;

bool isPrime(ll x);

ll GCD(ll a, ll b);

ll LCM(ll a, ll b);

ll nCr(int n, int r);


struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) {
        for (int i = 0; i < N; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

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

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

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

ll M, N;

int main() {
    ll N, M;
    string S;
    cin >> N >> S;
    ll w = 0;
    ll e = 0;
    REP(i, N) {
        if (S[i] == 'W')w++;
    }
    e = N - w;
    ll tmpw = 0;
    ll tmpe = 0;
    ll ans = N;
    REP(i, N) {
        ll cost = e - tmpe + tmpw;
        if (S[i] == 'E')cost--;
        ans = min(ans, cost);
        if (S[i] == 'W')tmpw++;
        else tmpe++;
    }
    PRI(ans)
    return 0;
}

struct edge {
    int to, cost;
    bool flag = false;
};

bool isPrime(ll x) {
    if (x == 0)return 0;
    if (x == 1)return 0;
    if (x == 2)return 1;
    if (x % 2 == 0)return 0;
    FOR(i, 3, x - 1) {
        if (x % i == 0)return 0;
    }
    return 1;
}

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}


Measured memory_bytes: 900
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int a,b,c;

  cin >> a >> b;

  if(a == 1){
    if(b == 2){
      c = 3;
    }
    if(b == 3){
      c = 2;
    }
  }

  if(a == 2){
    if(b == 1){
      c = 3;
    }
    if(b == 3){
      c = 1;
    }
  }

  if(a == 3){
    if(b == 1){
      c = 2;
    }
    if(b == 2){
      c = 1;
    }
  }

  cout << c << endl;
  


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(void)
{
    int n;
    double a[1000];
    while (cin >> n && n != 0) {
        for (int i = 0; i < n; ++i)
            cin >> a[i];
        double ave = std::accumulate(a, a + n, 0.0) / n;
        double dev = 0.0;
        for (int i = 0; i < n; ++i)
            dev += pow(a[i] - ave, 2.0);
        dev /= n;
        cout << fixed << setprecision(10) << sqrt(dev) << endl;
    }
    return 0;
}







Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)   for(signed i=0; i<n; i++)
#define yn(b)   cout << ((b)?"Yes":"No") << endl
#define YN(b)   cout << ((b)?"YES":"No") << endl
#define pr(r)   cout << r << endl
#define str string
int main(void){
    int N, i;
    double r=0;
    cin >> N;
    rep(i, N){
        double x;
        str u;
        cin >> x >> u;
        if(u == "JPY") r+=x;
        else r+=x*380000;
    }
    pr(r);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


template<class T>
class BIT {
    vector<T> bit;
public:
    BIT(int n): bit(vector<T>(n+1, 0)){}

    T sum(int k){
        T ret = 0;
        for (++k; k > 0; k -= (k & -k)) ret += bit[k];
        return ret;
    }

    void add(int k, T x){
        for (++k; k < bit.size(); k  += (k & -k)) bit[k] += x;
    }
};


int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%li", &i);
    int ok = 0, ng = INF<int>;
    ll s = (ll)n*(n+1)/2;
    while(ng-ok > 1){
        int mid = (ok+ng)/2;
        vector<int> u(n+1);
        int m = 0;
        for (int i = 0; i < n; ++i) {
            u[i+1] = u[i] + (v[i] >= mid ? 1 : -1);
            m = min(m, u[i+1]);
        }
        ll a = 0;
        BIT<int> b(n+1);
        for (auto &&i : u) {
            a += b.sum(i-m);
            b.add(i-m, 1);
        }
        if(2*a >= s) ok = mid;
        else ng = mid;
    }
    cout << ok << "\n";
    return 0;
}


Measured memory_bytes: 1860
s = list(input())
ss = ['k','e','y','e','n','c','e']
a = 0
b = 0
c = 0
for i in range(len(ss)):
    if s[i] == ss[i]:
        continue
    else:
        a = i
        break
else:
    print('YES')
    exit()


sss = ss[a:]
for i in range(len(sss)):
    if sss[len(sss)-i-1] == s[len(s)-i-1]:
        continue
    else:
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ifor(i,n) for(i=0;i<n;i++)
#define ll long long
///vector<int>vec;
///sort(s.begin(),s.endl());
///sort(ara,ara+n);
bool sortby(const pair<int,string> &i,const pair<int,string> &j)
{
    if(i.first==j.first) return i.second<j.second; return i.first>j.first;
}
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int i,n,t,p,j=0;
     cin>>n;
     unordered_map<string,int> print;
     vector<pair<int,string>> arr;
     string s,m;
     while(n--)
     {
         cin>>s;
         print[s]+=1;
     }

     for(auto i:print)
     {
         arr.push_back(make_pair(i.second,i.first));
     }

     sort(arr.begin(),arr.end(),sortby);


  int x=arr[0].first;
    for (auto i:arr)
    {
        if(i.first<x)break;
        cout<<i.second<<endl;

    }




     return EXIT_SUCCESS;
}


Measured memory_bytes: 28100
import java.util.Scanner;

class Main {
    private static void solve() {
        Scanner scanner = new Scanner(System.in).useDelimiter("[,\\s]+");

        int w = scanner.nextInt();
        int n = scanner.nextInt();
        int[] number = new int[w + 1];
        for (int i = 1; i <= w; i++) {
            number[i] = i;
        }
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int temp = number[a];
            number[a] = number[b];
            number[b] = temp;
        }
        for (int i = 1; i <= w; i++) {
            System.out.println(number[i]);
        }
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 11000
#include <stdio.h>
#include <stdlib.h>
int main(void) {
  void* m=malloc( 2*sizeof(int) );
  scanf("%d%d", (int*)m, (int*)m+1);
  *(double*)m= (double) *(int*)m / *((int*)m+1);
  printf("%f\n", *(double*)m);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;


int main(void) {

    int a, b; cin >> a >> b;
    if(a >= 13) cout << b << endl;
    else if(a >= 6) cout << b/2 << endl;
    else cout << 0 << endl;

  return 0;
}



// EOF


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 ALL(n) begin(n), end(n)

int k, n, maxgap = 0;

int main()
{
  cin >> k >> n;
  vector<int> a(n);

  REP(i, n){
    cin >> a.at(i);
    if(i != 0){
      maxgap = max(a.at(i) - a.at(i - 1), maxgap);
    }
    if(i == n - 1){
      maxgap = max(a.at(i) - a.at(i - 1), maxgap);
      maxgap = max(a.at(0) + k - a.at(i), maxgap);
    }
  }
  int ans = k - maxgap;

  cout << ans << endl;
}

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

int main() {
  int N;
  cin>>N;
  int K;
  cin>>K;
  int a=0;
  
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    if(x<K-x)
    a+=x;
    else
    a+=K-x;}
  cout<<a*2<<endl;
  
    
}

Measured memory_bytes: 256
//2020-04-12 17:29:15
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll n;cin>>n;
    ll sum=0;
    rep(i,1,n+1)
    if(i%3==0)continue;
    else if(i%5==0)continue;
    else sum+=i;
    cout<<sum;
}

Measured memory_bytes: 3636
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	int n, ans = 0;
	cin >> n;
	vector<int> cnt(n + 1);
	for (int a = 1; a <= 100; ++a) {
		for (int b = 1; b <= 100; ++b) {
			for (int c = 1; c <= 100; ++c) {
				int d = a * a + b * b + c * c + a * b + b * c + c * a;
				if (d <= n) {
					cnt[d] += 1;
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		cout << cnt[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int x, y;
    cin >> x >> y;
    if((4*x-y)%2!=0||(y-2*x)%2!=0){
        cout << "No" << endl;
        return;
    }
    int a = (4 * x - y) / 2;
    int b = (y - 2 * x) / 2;
    if (a >= 0 && b >= 0) cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

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

int main(){
    string s;
    cin>>s;
    int l=s.size()-2;int n=0;
    while(l>0){
      n=0;  
      for(int k=0;k<l/2;k++){
            if(s.at(k)==s.at((l/2)+k)) n++;
      }
      if(n==l/2) break;
      l-=2;
    }
    cout<<l<<endl;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate

def main():
    input = sys.stdin.readline
    N = int(input())
    S = [0 if c == '.' else 1 for c in input().strip()]
    T = [0] + list(accumulate(S))

    B = T[N]
    ans = 10**5
    for i in range(N+1):
        convert_w = T[i]
        convert_b = (N - i) - (B - T[i])
        ans = min(ans, convert_w + convert_b)

    return ans


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


Measured memory_bytes: 14372
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void output(int a, int b){
  for(int i=0; i<b; i++)
    printf("%d", a);
  printf("\n");
}   

int main(void){
  int a, b, i;
  scanf("%d %d", &a, &b);

  if(a<b)
    output(a, b);
  else
    output(b, a);
  
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();

        ArrayList<Integer> positiveList = new ArrayList<>();
        ArrayList<Integer> negativeList = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            int ret = sc.nextInt();
            if (ret >= 0) {
                positiveList.add(ret);
            } else {
                negativeList.add(Math.abs(ret));
            }
        }

        Collections.sort(positiveList);
        Collections.sort(negativeList);

        long minDistance = Long.MAX_VALUE;
        for (int positiveNum = Math.max(0, K - negativeList.size()); positiveNum <= positiveList.size(); positiveNum++) {
            long positiveRoute = 0;
            if (K - positiveNum - 1 >= 0) positiveRoute += negativeList.get(K - positiveNum - 1);
            if (positiveNum - 1 >= 0) positiveRoute += 2 * positiveList.get(positiveNum - 1);

            long negativeRoute = 0;
            if (K - positiveNum - 1 >= 0) negativeRoute += 2 * negativeList.get(K - positiveNum - 1);
            if (positiveNum - 1 >= 0) negativeRoute += positiveList.get(positiveNum - 1);


            long route = Math.min(positiveRoute, negativeRoute);

            minDistance = Math.min(minDistance, route);
        }

        System.out.println(minDistance);

    }
}

Measured memory_bytes: 60420
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = next()
    println("${s.first()}${s.length-2}${s.last()}")
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35844
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

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

	X -= A;
	int n = X / B;
	X -= n * B;

	cout << X << endl;

	return 0;
}

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

int main(){
string s,t;cin>>s>>t;
sort(s.begin(),s.end());
sort(t.begin(),t.end());
string a=string(t.rbegin(),t.rend());
if(a>s)cout<<"Yes";
else cout<<"No";
    
}

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

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

    long long int x;

    if (a>b){
        int tmp = a;
        a = b;
        b = tmp;
    }

    x = a * b;

    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    cout << x / b << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vi x;
vi to[MX];
vi t;

P dfs(int v, int p=-1) {
  int mx = 0, res = 0;
  vp rs;
  for (int u : to[v]) {
    if (u == p) continue;
    P r = dfs(u,v);
    t[v] += t[u];
    r.fi += t[u];
    r.se += t[u];
    mx += r.fi;
    rs.pb(r);
  }
  if (sz(rs)) {
    sort(rng(rs));
    P r = rs.back();
    rs.pop_back();
    int o = 0;
    rep(i,sz(rs)) o += rs[i].fi;
    res = r.se-o;
    if (res < 0) res = abs(res)%2;
  }
  // cerr<<mx<<" "<<res<<endl;
  return P(mx,res);
}

int main() {
  int n;
  scanf("%d",&n);
  string s;
  cin>>s;
  x = vi(n);
  rep(i,n) x[i] = s[i]-'0';
  rep(i,n-1) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  int ans = INF;
  rep(i,n) {
    // cerr<<i<<endl;
    t = x;
    P p = dfs(i);
    if (p.se) continue;
    mins(ans,p.fi/2);
  }
  if (ans == INF) dame;
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 5248
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define rep_itr(it, M) for (auto it = M.begin(); it != M.end(); ++it)
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, X[101];

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

  cin >> N;
  rep(i, N) cin >> X[i];

  // 0-index
  int minx = INF;
  rep(i, 100) {
    int ans = 0;
    rep(j, N) {
      ans += pow(X[j]-i-1, 2);
    }
    minx =min(minx, ans);
  }
  cout << minx << "\n";
  return 0;
}

Measured memory_bytes: 256
N,Q=map(int,input().split())
S=input()
count=[0]*N
for i in range(1,N):
    count[i]+=count[i-1]
    if S[i-1:i+1]=="AC":count[i]+=1
for i in range(Q):
    l,r=map(int,input().split())
    print(count[r-1]-count[l-1])



Measured memory_bytes: 9364
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

long int modpow(long int a, long int n, long int mod) {
    long int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

long int modcomb(long int a, long int b, long int mod){
    long int res = 1;
    for(long int i = a; i > a - b; i--){
        res *= i % mod;
        res %= mod;
    }
    res %= mod;
    for(long int i = 1; i <= b; i++){
        long int i_inv = modpow(i, mod - 2, mod);
        res *= i_inv % mod;
        res %= mod;
    }
    res %= mod;
    // cout << res << endl;
    return res;
}


int main(){
    int x, y;
    cin >> x >> y;
    int a = 2 * x - y, b = 2 * y - x;
    if(a < 0 || b < 0 || a % 3 != 0 || b % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    int h = a / 3, w = b / 3;
    ll ans = modcomb((ll)(h+w), (ll)w, mod);
    cout << ans << endl;
}

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

using namespace std;

#define pb push_back
#define all(v) (v).begin(),v.end()
typedef long long ll;

int count_one(int x) {
    int cnt = 0;
    while (x) {
        x &= (x - 1);
        cnt++;
    }
    return cnt;
}

/*signed main() {
    int t;
    cin >> t;
    while (t--) {
        int a, b, n;
        cin >> n >> a >> b;
        int cnt = 0;
        set<int> s;
        for (int i = 0; i < (1 << n); ++i) {
            for (int j = 0; j < (1 << n); ++j) {
                if (count_one(i) == a && count_one(j) == b)s.insert(i ^ j);
            }
        }
        cout << s.size() << endl;
    }
    return 0;
}*/
int one(string s) {
    int cnt = 0;
    for (auto i:s) {
        if (s[i] == 1)cnt++;
    }
    return cnt;
};

signed main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split("").map(&:to_i)
end

nlist = gets_i_list
c = nlist.first
k = nlist.size

dpp nlist

if nlist.sum == c + 9 * (k -1)
  puts c + 9 * (k -1)
elsif k == 1
  puts c
else
  puts c + 9 * (k - 1) - 1
end

Measured memory_bytes: 14524
#include<stdio.h>
int main(){
  int y,m,d,s;
  while(scanf("%d %d %d",&y,&m,&d)!=EOF){
    s=y*10000;
    s+=m*100;
    s+=d;
    if     (s<18680908)printf("pre-meiji\n");
    else if(s<19120730)printf("meiji %d %d %d\n",y-1867,m,d);
    else if(s<19261225)printf("taisho %d %d %d\n",y-1911,m,d);
    else if(s<19890108)printf("showa %d %d %d\n",y-1925,m,d);
    else               printf("heisei %d %d %d\n",y-1988,m,d);
  }
  return 0;
}

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

/*================================================
	Factorial and Combination
================================================*/
int factorial[200001];

void set_factorial(int n)
{
	ll f = 1;

	factorial[0] = 1;
	repc(i, 1, n) {
		f = (ll)i * (ll)factorial[i - 1];
		factorial[i] = (int)(f % MOD);
	}
}

int powbin(int base, int p)
{
	ll mul;

	if (p == 1) mul = base;
	else {
		mul = (ll)powbin(base, p / 2);
		mul = (mul * mul) % MOD;
		if (p % 2) mul *= base;
	}

	return (int)(mul % MOD);
}

int combination(int n, int r)
{
	ll mul;

	mul = factorial[n];
	mul = (mul * powbin(factorial[r], MOD - 2)) % MOD;
	mul = (mul * powbin(factorial[n - r], MOD - 2)) % MOD;

	return (int)mul;
}

ll A[100000];
ll Cmax[100000];
ll Cmin[100000];

int main()
{
	int N, K, index;
	ll ans = 0;

	cin >> N >> K;
	rep(i, N) cin >> A[i];

	set_factorial(N);
	sort(A, A + N);

	index = 1;
	rrep(i, N) {
		if (N - index >= K - 1) Cmax[i] = (ll)combination(N - index, K - 1);
		else Cmax[i] = 0;
		index++;
	}

	index = 1;
	rep(i, N) {
		if (N - index >= K - 1) Cmin[i] = (ll)combination(N - index, K - 1);
		else Cmin[i] = 0;
		index++;
	}

	rep(i, N) {
		ll add, sub;
		add = (Cmax[i] * A[i]) % MOD;
		sub = (Cmin[i] * A[i]) % MOD;

		ans = (ans + add) % MOD;
		ans = ((ans - sub) + MOD) % MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2944
A,B,Q=map(int,input().split())
s=[]
for _ in range(A):
    s.append(int(input()))
t=[]
for _ in range(B):
    t.append(int(input()))
from bisect import bisect
infty=1e50
for _ in range(Q):
    x=int(input())
    i=bisect(s,x)
    j=bisect(t,x)
    if 0<i<A:
        sL=x-s[i-1]
        sR=s[i]-x
    elif i==0:
        sL=infty
        sR=s[i]-x
    else:
        sL=x-s[-1]
        sR=infty
    
    if 0<j<B:
        tL=x-t[j-1]
        tR=t[j]-x
    elif j==0:
        tL=infty
        tR=t[j]-x
    else:
        tL=x-t[-1]
        tR=infty
    print(min(max(sR,tR),max(sL,tL),sR+tL+min(sR,tL),sL+tR+min(sL,tR)))




Measured memory_bytes: 12128
#include<stdio.h>

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

int search(int S[], int n, int key){
  int left = 0;
  int right = n;
  int mid = (right + left) / 2;

  while (left < right){
    // if find a key value in array S
    if (S[mid] == key) return 1;
    
    // もしS[mid]がkeyより小さければ, 左側(小さい方)の範囲を狭める
    if (S[mid] < key)
      left = mid+1;
    // もしS[mid]がkeyより大きければ, 右側(大きい方)の範囲を狭める
    if (S[mid] > key)
      right = mid;

    mid = (right + left) / 2;
  }
  return 0;

}

int main(int argc, char const *argv[])
{
  int n, q, key, ans;
  int S[100100];
  
  scanf("%d", &n);
  // input S is already sorted
  rep(i, n) scanf("%d", &S[i]);

  scanf("%d", &q);
  rep(i, q){
    scanf("%d", &key);
    ans += search(S, n, key);
  }

  printf("%d\n", ans);

  return 0;
}



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

int main(){
  double a,b,h,m;
  cin >>a >>b >>h >>m;
  h = h*30+m*0.5, m*=6;
  double theta = abs(h-m)*3.14159265358979323846264338327950/180;
  double ans = sqrt(a*a+b*b-2*a*b*cos(theta));
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}


Measured memory_bytes: 4096
#include<stdio.h>
int main(){
  int min = 1000000, max = -min,
    scan = 0,i = 0,count = 0;
  unsigned long sum = 0;
  scanf("%d",&count);

  for(i = 1;i<= count;i++){
    scanf("%d",&scan);

    if(scan < min){
      min = scan;
    }

    if(max < scan){
      max = scan;
    }

    sum += scan;
  }

  printf("%d %d %ld\n",min,max,sum);
  return 0;
}

Measured memory_bytes: 600
// author <Maksud alam Rony>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define it iterator
#define pb push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define fill(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
#define pi acos(-1)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) (v).erase(unique(all(v)),(v).end())
#define endl "\n"
string digit="0123456789";
string small="abcdefghijklmnopqrstuvwxyz";
string capital="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};

int main(){
   ll n;
   cin>>n;
   ll arr[n];
   ll k=0;
   For(i,0,n){
       cin>>arr[i];
       k = k^arr[i];
   }
   For(i,0,n){
       cout<<(k^arr[i])<<" ";
   }

}



Measured memory_bytes: 5148
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<list>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {1, 1, 0, -1, -1, 0};
int dx[] = {1, 0, -1, -1, 0, 1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int n;
    while (cin >> n && n) {
        int m[n];
        vector<int> v[n];
        rep(i, n) {
            cin >> m[i];
            rep(j, m[i]) {
                int tmp;
                cin >> tmp;
                v[i].push_back(tmp);
            }
            sort(v[i].begin(), v[i].end());
        }
        int k;
        cin >> k;
        int l[k];
        rep(i, k) cin >> l[i];
        sort(l, l + k);
        vector<int> ans;
        /*
        rep(i, n) {
            rep(j, v[i].size()) cout << v[i][j] << " ";
            cout << endl;
        }
         */
        rep(i, n) {
            /*
            int table[k];
            rep(i, k) table[k] = 0;
             */
            int key = 0;
            rep(j, v[i].size()) {
                if (v[i][j] == l[key]) {
                    key++;
                   // cout << key << endl;
                }
            }
            if (key == k) ans.push_back(i);
        }
        //rep(i, ans.size()) cout << ans[i] << " "; cout << endl;
        if (ans.size() == 1) cout << ans[0] + 1 << endl;
        else cout << -1 << endl;
    }
}



Measured memory_bytes: 3180
while true
  line = gets
  break if line == nil
  n = line.to_i
  ans = 0
  10.times{|a|
    10.times{|b|
      10.times{|c|
        10.times{|d|
          ans += 1 if a+b+c+d == n
        }
      }
    }
  }
  p ans
end

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

vector<int> par;
vector<int> RA;
vector<int64_t> cou;
int root(int a){
  if(a==par[a]){
    return a;
  }
  else{
    return par[a]=root(par[a]);
  }
}
void UN(int a,int b){
  a=root(a);
  b=root(b);
  if(a==b){
    return;
  }
  int A=cou[a];
  int B=cou[b];
  cou[a]=A+B;
  cou[b]=A+B;
  if(RA[a]<RA[b]){
    par[a]=b;
  }
  else{
    par[b]=a;
  }
  if(RA[a]==RA[b]){
    RA[a]++;
  }
}
bool same(int a,int b){
  if(root(a)==root(b)){
    return true;
  }
  else{
    return false;
  }
}


int main(){
  int64_t N,M;
  cin>>N>>M;
  vector<pair<int,int>> p(M);
  for(int i=M-1;i>=0;i--){
    int a,b;
    cin>>a>>b;
    a--,b--;
    p[i]=make_pair(a,b);
  }
  int64_t Z=N*(N-1)/2;
  par.resize(N);
  RA.resize(N);
  cou.resize(N);
  for(int i=0;i<N;i++){
    par[i]=i;
    RA[i]=1;
    cou[i]=1;
  }
  vector<int64_t> ans(M);
  ans[0]=Z;
  for(int i=0;i<M-1;i++){
    int a,b;
    tie(a,b)=p[i];
    if(!same(a,b)){
      Z-=cou[root(a)]*cou[root(b)];
      UN(a,b);
    }
    ans[i+1]=Z;
  }
  for(int i=M-1;i>=0;i--){
    cout<<ans[i]<<endl;
  }
}
  

Measured memory_bytes: 6308
#include <cstdint>
#include <iostream>
#include <map>

using namespace std;

int main() {
  int n;
  cin >> n;
  int64_t s = 0;
  map<int64_t, int> m;
  m[0] = 1;
  int64_t a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    s += a;
    m[s]++;
  }
  int64_t ans = 0;
  for (auto p : m) {
    int64_t v = p.second;
    if (v > 1) {
      ans += (v * (v - 1) / 2);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12800
function main(input){
    let numarray=input.split("\n").map(Number);
	let i=0;
	while (numarray[i]!=0) {
        console.log('Case ' + (i+1) + ': ' + numarray[i]);
        i += 1;
	}
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  int s;
  cin >> s;
  int m, n;
  m = s / 100;
  n = s - 100 * m;
  if (m > 0 && m < 13) {
    if (n > 0 && n < 13) {
      cout << "AMBIGUOUS" <<endl;
    }
    else {
      cout << "MMYY" <<endl;
    }
  }
  else {
    if (n > 0 && n < 13) {
      cout << "YYMM" <<endl;
    }
    else {
      cout << "NA" <<endl;
    }
  }
}

Measured memory_bytes: 256
from collections import defaultdict
N, X, Y = map(int, input().split())
d = [[0 for _ in range(N)] for _ in range(N)]
for i in range(N-1):
    for j in range(i+1, N):
        d[i][j] = d[i][j-1] + 1
X -= 1
Y -= 1
for i in range(N-1):
    for j in range(i + 1, N):
        diff = abs(X - i) + abs(Y - j) + 1
        if diff < d[i][j]:
            d[i][j] = diff
#print(d)
ans = defaultdict(int)
for i in range(N-1):
    for j in range(i + 1, N):
        ans[d[i][j]] += 1
for k in range(1, N):
    print(ans[k])

Measured memory_bytes: 82396
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, C, K = MAP()
T = [INT() for _ in range(N)]

T.sort()
idx = 0
ans = 0

while idx < N :
	tmp = T[idx]
	if idx+C <= bisect(T, tmp+K):
		idx += C
	else:
		idx = bisect(T, tmp+K)
	ans += 1

print(ans)

Measured memory_bytes: 9564
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  V<> a(5); for (int i = 0; i < 5; ++i) cin >> a[i];
  sort(rbegin(a), rend(a));
  for (int i = 0; i < 5; ++i) {
    cout << a[i] << (i != 4 ? ' ' : '\n');
  }
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
double a[10010];
using namespace std;
int main(){
    int n;
    cin >> n;

    REP(i, 0, n){
        cin >> a[i];
    }
    sort(a, a+n);
    double sum = 0;
    REP(i, 1, n){
        a[i] = (double)(a[i-1] + a[i])/2;
    }
    //cout << a[n - 1] << '\n';
    printf("%.5f\n", a[n - 1]);
}


Measured memory_bytes: 256
# 24
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, k = LI()
d = set(LI())
# 最小金額から条件を満たすまで増やしていく
while True:
    if all([int(j) not in d for j in str(n)]):  # 全ての桁の数字が d に属さない
        print(n)
        exit()
    n += 1


Measured memory_bytes: 9144
var lines = [];
var result = [];
var readline = require("readline");

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0].split(" ")[0]);
    var M = Number(lines[0].split(" ")[1]);

    lines.shift();

    var array = lines.map(value => value.split(" ").map(value => Number(value)));

    for (var i = 0; i < M; i++) {
        array[i].push(i);
    }

    var city = array.concat().sort((a, b) => a[1] - b[1]);
    ite = Array(N + 1).fill(0);
    for (var i = 0; i < M; i++) {
        var ken = city[i][0].toString(); var shi = (ite[city[i][0]] + 1).toString();

        len = ken.length
        for (var x = 0; x < 6 - len; x++) { ken = "0" + ken; }

        len = shi.length
        for (var x = 0; x < 6 - len; x++) { shi = "0" + shi; }

        city[i].push(ken + shi);
        ite[city[i][0]]++;
    }

    city.sort((a, b) => a[2] - b[2]);
    for (var i = 0; i < M; i++) {
        console.log(city[i][3]);
    }
});

Measured memory_bytes: 84148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

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

  vector<int> divisor(N+1, 0);
  for(int i=2;i<=N;i++){
	if(divisor[i] == 0){
	  // is prime
	  for(int j=i;j<=N;j+=i){
		divisor[j] = i;
	  }
	}
  }

  vector<int> count(N+1, 0);
  for(int i=2;i<=N;i++){
	int j = i;
	while(j > 1){
	  count[divisor[j]]++;
	  j /= divisor[j];
	}
  }

  ll ans = 1;
  for(int i=2;i<=N;i++){
	ans = (ans * (count[i] + 1)) % MOD;
  }
  cout << ans << endl;

  return 0;
}

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

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

    int n;
    string s;
    cin >> n >> s;

    int cntW = 0;
    rep(i,n) {
        if(s[i] == '.') cntW++;
    }
    int ans = cntW;
    int b = 0, w = 0;
    rep(i,n){
        if(s[i] == '.') w++;
        else b++;

        ans = min(ans,cntW - w + b);
    }
    cout << ans << endl;
}



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

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

    ll g = __gcd(a, b);
    ll ans = 1;

    for (ll i = 2; i * i <= g; i++) {
        if (g % i == 0) ans++;
        while (g % i == 0) g /= i;
    }

    if (g == 1)
        cout << ans << endl;
    else
        cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,a,b;
  char str[21];
  scanf("%s",str);
  a=strlen(str);
  for(i=a-1;i>=0;i--){
    printf("%c",str[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 0
// 2014/11/05 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int sum = 0;

	for(int i=0; i<5; i++){
		int s;
		cin >> s;

		if(s>=40){
			sum += s;
		}
		else{
			sum += 40;
		}
	}

	cout << sum/5 << endl;

	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        do{
        	int n = sc.nextInt();
        	int sum = 0;
        	for(int i = 0;i < n;i++){
        		sum += Math.abs(sc.nextInt() - sc.nextInt());
        	}
        	if(sum >= t){
        		System.out.println("OK");
        	}else{
        		System.out.println(t - sum);
        	}
        } while((t = sc.nextInt()) != 0);
    }
}


Measured memory_bytes: 31428
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String[] s = bf.readLine().split(" ");
		int H = Integer.parseInt(s[0]);int W = Integer.parseInt(s[1]);
		int A = Integer.parseInt(s[2]);int B = Integer.parseInt(s[3]);
		bf.close();
		for(int i = 0;i < H;i++) {
			for(int j = 0;j < W;j++) {
				if((i<B)^(j<A)) {
					System.out.print(1);
				}else {
					System.out.print(0);
				}
			}
			System.out.print("\n");
		}
	}
}

Measured memory_bytes: 45004
from copy import deepcopy
N=int(input())
A=list(map(int,input().split()))
if N==2:
    print(max(A[0]-A[1],A[1],A[0]))
    print(max(A[0],A[1]),min(A[0],A[1]))
    quit()
A.sort()
ans=10**(-50)
S=sum(A)
for i in range(N-1):
    S=S-A[i]+(-A[i])
    if ans<S:
        ans=S
        j=i
print(ans)
for i in range(j+1,N-1):
    print(A[0],A[i])
    A[0]-=A[i]
for i in range(j+1):
    print(A[N-1],A[i])
    A[N-1]-=A[i]


Measured memory_bytes: 61776
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    int n, m; cin >> n >> m;
    string res;
    if(n == 3) {
        res = "aaa";
        rep(i, m) {
            int s; char c; cin >> s >> c;
            if(res[s-1] != c && res[s-1] != 'a') {
                cout << -1 << endl;
                return 0;
            }
            res[s-1] = c;
        }
        if(res[0] == '0') {
            cout << -1 << endl;
            return 0;
        }
        if(res[0] == 'a') res[0] = '1';
        if(res[1] == 'a') res[1] = '0';
        if(res[2] == 'a') res[2] = '0';
        cout << res << endl;
    }
    else if(n == 2) {
        res = "aa";
        rep(i, m) {
            int s; char c; cin >> s >> c;
            if(res[s-1] != c && res[s-1] != 'a') {
                cout << -1 << endl;
                return 0;
            }
            res[s-1] = c;
        }
        if(res[0] == '0') {
            cout << -1 << endl;
            return 0;
        }
        if(res[0] == 'a') res[0] = '1';
        if(res[1] == 'a') res[1] = '0';
        cout << res << endl;
    }
    else if(n == 1) {
        res = "a";
        rep(i, m) {
            int s; char c; cin >> s >> c;
            if(res[s-1] != c && res[s-1] != 'a') {
                cout << -1 << endl;
                return 0;
            }
            res[s-1] = c;
        }
        if(res[0] == 0) cout << -1 << endl;
        if(res[0] == 'a') res[0] = '0';
        cout << res << endl;
    }
}

Measured memory_bytes: 256
import java.math.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 1; i < N; i++) A[i] = sc.nextInt();
    sc.close();

    int[] ans = new int[N];
    for (int i = 1; i < N; i++) ans[A[i] - 1]++;

    for (int i = 0; i < N; i++)
      System.out.println(ans[i]);
  }
}


Measured memory_bytes: 61700
x,y,z,k = $stdin.gets.split.map(&:to_i)
a_ary = $stdin.gets.split.map(&:to_i)
b_ary = $stdin.gets.split.map(&:to_i)
c_ary = $stdin.gets.split.map(&:to_i)
ab = []
x.times do |a|
  y.times do |b|
    ab.push(a_ary[a]+b_ary[b])
  end
end
ab.sort!.reverse!
result = []
[ab.size,k].min.times do |i|
  z.times do |j|
    result.push(ab[i]+c_ary[j])
  end
end
result.sort!.reverse!
k.times do |i|
  puts result[i]
end


Measured memory_bytes: 70152
package main
 
import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}
 
func scanString() string {
	sc.Scan()
	return sc.Text()
}
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

var N, COUNT int
var S string
var DICT map[string]int

func main() {
  N = scanInt()
  DICT = make(map[string]int, N)
  l := []int {}
  makeDict(l, 0)
  keyA := ""
  for i := 0; i < N; i++ {
	S = scanString()
	keyA = keyA + S
  }

  keyB := ""
  for i := 0; i < N; i++ {
	S = scanString()
	keyB = keyB + S
  }
  fmt.Println(abs(DICT[keyA], DICT[keyB]))
}

func makeDict(l []int, depth int) {
	if len(l) == N {
		addDict(l)
		return
	}
	for i := 1; i <= N; i++ {
		if notExist(l, i) {
	      makeDict(append(l, i), depth + 1)
		}
	}
}

func notExist(l []int, i int) bool {
	for _, v := range l {
		if v == i {
			return false
		}
	}
	return true
}

func  addDict(l []int) {
	key := ""
	COUNT++
	for _, v := range l {
		key = key + strconv.Itoa(v)
	}
	DICT[key] = COUNT
}

func abs(a, b int) int {
	ans := a - b
	if ans < 0 {
		ans = ans * -1
	}
	return ans
}

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

using namespace std;

int main() {
	int n; cin >> n;
	int p[n];
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int count = 0;
	for (int i = 1; i < n - 1; i++) {
		if ((p[i - 1] < p[i] && p[i + 1] > p[i]) || (p[i - 1] > p[i] && p[i + 1] < p[i])) { count++; }
	}
	cout << count;
	return 0;
}


Measured memory_bytes: 3476
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from fractions import gcd

N = int(input())
A = list(map(int, input().split()))

tmp1 = A[0]
for a in A:
    tmp2 = gcd(tmp1, a)
    tmp1 = a * tmp1 // tmp2

ans = 0
for a in A:
    ans += (tmp1 - 1) % a

print (ans)

Measured memory_bytes: 5344
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    int k, x;
    cin >> k >> x;
    if(500*k>=x){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256