akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int H, W; cin >> H >> W;
    vector<vector<int>> grids(H + 2, vector<int>(W + 2, 0));
    for (int r = 1; r <= H; ++r)
    {
        string row; cin >> row;
        for (int c = 1; c <= W; ++c)
        {
            grids[r][c] = row[c - 1] == '#' ? 1 : 0;
        }
    }
    bool isOK = true;
    for (int r = 1; r <= H; ++r)
    {
        for (int c = 1; c <= W; ++c)
        {
            if (grids[r][c] == 1)
            {
                if (grids[r - 1][c] == 0 && grids[r + 1][c] == 0
                    && grids[r][c - 1] == 0 && grids[r][c + 1] == 0)
                {
                    isOK = false;
                }
            }
        }
    }
    cout << (isOK ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int H, W;   cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++)
        cin >> s[i];

    vector<vector<int> > dist(H, vector<int>(W, -1));
    queue<pair<int, int> > que;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                que.push(pair<int, int>(i, j));
                dist[i][j] = 0;
            }
        }
    }

    int ans = 0;
    while (!que.empty()) {
        pair<int, int> v = que.front();
        for (int i = 0; i < 4; i++) {
            int nx = v.first + dx[i];
            int ny = v.second + dy[i];

            if (nx < 0 || H <= nx || ny < 0 || W <= ny || s[nx][ny] == '#' || dist[nx][ny] != -1)
                continue;
            
            ans = (dist[nx][ny] = dist[v.first][v.second] + 1);
            
            que.push(pair<int, int>(nx, ny));
        }
        que.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13568
local n = io.read("*n")
local v = {}
for i = 1, n do
  v[i] = io.read("*n")
end
table.sort(v, function(a, b) return a > b end)

local sum = 0
local mul = 2
for i = 1, n do
  sum = sum + v[i] / mul
  if i ~= n - 1 then mul = mul * 2 end
end
print(string.format("%.10f",sum))


Measured memory_bytes: 760
#include<stdio.h>
int main() {
	int A,B,C,D;
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&D);
if (A*B>=C*D){
	printf("%d",A*B);
}
 else {
 	printf("%d",C*D);
 }
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// 0 <= unsigned int <= 4.2e9


int main()
{
    ullong H, W;
    cin >> H >> W;
    if ((H == 1) || (W == 1)) {
        cout << 1 << endl;
        return 0;
    }
    if ((H % 2) == 0) {
        cout << (H / 2) * W << endl;
    }
    else if ((W % 2) == 0) {
        cout << H * (W / 2) << endl;
    }
    else {
        cout << H * W / 2  + 1 << endl;
    }
}


Measured memory_bytes: 256
#include<bitset>
#include<iostream>
using namespace std;
bitset<2000007>dp;
int main(){
	int n;
    cin>>n;
    int sum=0;
    dp[0]=1;
    for(int i=1;i<=n;i++){
    	int x;
        cin>>x;
        dp|=dp<<x;
        sum+=x;
    }
    for(int i=(sum+1)>>1;i<=sum;i++){
        if(dp[i]){
			cout<<i<<endl;
			break;
		}
    }
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
 
int main()
{
  int x, h=0;
  scanf("%d", &x);
  while(x>=5)
  {
      if(x>=500)
      {
      h=h+1000;
      x-=500;
      }
    else if(x>=5)
    {
      h=h+5;
      x-=5;  
    }
  }
  printf("%d", h);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}


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

  int n;
  cin>>n;
  vector<vector<PI>> es(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    es[a].PB(PI(P(b,0),i));
    es[b].PB(PI(P(a,0),i));
  }
  vi c(n-1,0);
  set<int> use[n];

  queue<int> q;
  q.push(0);
  while(q.size()){
    int x=q.front(); q.pop();
    int s=1;
    while(use[x].find(s)!=use[x].end()) s++;
    for(PI p:es[x]){
      if(c[p.S]) continue;
      c[p.S]=s;
      use[x].insert(s);
      use[p.F.F].insert(s);
      while(use[x].find(s)!=use[x].end()) s++;
      q.push(p.F.F);
    }
  }

  int maxc=0;
  rep(i,n-1) maxc=max(maxc,c[i]);

  cout<<maxc<<endl;
  rep(i,n-1){
    cout<<c[i]<<endl;
  }


}

Measured memory_bytes: 24192
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

std::string S;
ll cntB = 0, cntW = 0;
ll ans;

int main()
{
  std::cin >> S;

  if( S.back() == 'W' )
    S += "B";

  rep( i, S.size() )
  {
    if( S[i] == 'B' )
      ++cntB;
    if( S[i] == 'W' )
      ++cntW;

    if( S[i] != S[i+1] )
    {
      if( S[i+1] == 'B' )
      {
        ans += cntW*cntB;
        cntW = 0;
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
S = [list(input()[:-1]) for _ in range(H)]
L = [[0]*W for _ in range(H)]
R = [[0]*W for _ in range(H)]
U = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]

for i in range(H):
    if S[i][0]=='.':
        L[i][0] = 1

for i in range(H):
    for j in range(1, W):
        if S[i][j]=='.':
            L[i][j] = L[i][j-1]+1

for i in range(H):
    if S[i][W-1]=='.':
        R[i][W-1] = 1

for i in range(H):
    for j in range(W-2, -1, -1):
        if S[i][j]=='.':
            R[i][j] = R[i][j+1]+1

for i in range(W):
    if S[0][i]=='.':
        U[0][i] = 1

for i in range(1, H):
    for j in range(W):
        if S[i][j]=='.':
            U[i][j] = U[i-1][j]+1

for i in range(W):
    if S[H-1][i]=='.':
        D[H-1][i] = 1

for i in range(H-2, -1, -1):
    for j in range(W):
        if S[i][j]=='.':
            D[i][j] = D[i+1][j]+1

ans = 0

for i in range(H):
    for j in range(W):
        ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};

ll dp[1010][10010];

int main(){

  int h,n;
  cin >> h >> n;
  vector<int> a(n),b(n);
  REP(i,n)cin >> a[i] >> b[i];
  FILLl(dp,n+1,INF);
  REP(i,n+1)dp[i][h] = 0;
  for(int i = 0;i < n;i++){
    for(int j = h;j >= 0;j--){
      if(j >= a[i])dp[i+1][j-a[i]] = min({dp[i][j-a[i]],dp[i+1][j-a[i]],dp[i][j]+b[i],dp[i+1][j]+b[i]}),dp[i+1][j] = min(dp[i][j],dp[i+1][j]);
      else dp[i+1][0] = min({dp[i][0],dp[i+1][0],dp[i][j]+b[i],dp[i+1][j]+b[i]}),dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
    }
  }

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

  return 0;
}


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

int main(){
  int N, K, sum=0;
  cin >> N >> K;
  
  vector<int> price(N);
  for (int i=0; i<N; i++){
    cin >> price.at(i);
  }
  
  sort(price.begin(), price.end());
  
  for (int i=0; i<K; i++){
    sum += price.at(i);
  }
  cout << sum << endl;
} 

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
long long N, A[87], CM=1000;
int main() {
	cin>>N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N - 1; i++) {
		long long St = 0;
		if (A[i] < A[i + 1]) St = CM / A[i];
		CM += (A[i + 1] - A[i]) * St;
	}
	cout << CM << endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

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

		String word1 = sc.next();
		String word2 = sc.next();
		String result = "No";

		StringBuilder sb = new StringBuilder();
		sb.append(word1);


		int word1Size = word1.length();
		for (int i = word1Size-1; i >= 0; i--) {
			sb.insert(0, word1.charAt(i));
			sb.deleteCharAt(word1Size);
			if (sb.toString().equals(word2)) {
				result = "Yes";
				break;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define lg2 std::__lg

typedef long long ll;
const int N = 200054;
const ll INF = 0x3f3f3f3f3f3f3f3fll;

int n, q;
ll _[N * 2];

inline void down(ll &x, const ll y) {x > y ? x = y : 0;}
inline ll min(const ll x, const ll y) {return x < y ? x : y;}

struct ST {
	#define segc int M = (L + R - 1) >> 1, lc = id << 1, rc = lc | 1

	ll x[N * 4], GLOBAL;

	ST () : GLOBAL(0) {}

	inline void global_add(ll v) {GLOBAL += v;}

	void init(int id, int L, int R, ll v) {
		if (x[id] = v, L == R) return;
		segc; init(lc, L, M, v), init(rc, M + 1, R, v);
	}

	void adj(int id, int L, int R, int h, ll v) {
		if (L == R) return down(x[id], v - GLOBAL);
		segc; h <= M ? adj(lc, L, M, h, v) : adj(rc, M + 1, R, h, v);
		x[id] = min(x[lc], x[rc]);
	}

	ll range(int id, int L, int R, int ql, int qr) {
		if (ql <= L && R <= qr) return x[id] + GLOBAL;
		segc; ll s = LLONG_MAX;
		if (ql <= M) down(s, range(lc, L, M, ql, qr));
		if (qr > M) down(s, range(rc, M + 1, R, ql, qr));
		return s;
	}

	void traversal(int id, int L, int R, ll *ret) {
		if (L == R) {ret[L] = x[id] + GLOBAL; return;}
		segc; traversal(lc, L, M, ret), traversal(rc, M + 1, R, ret);
	}
} pos, neg;

int main() {
	int i, x, lx; ll v;
	scanf("%d%d%d%d", &n, &q, &i, &lx);
	pos.init(1, 1, n, INF), neg.init(1, 1, n, INF);
	pos.adj(1, 1, n, i, i), neg.adj(1, 1, n, i, -i);
	for (; q; --q, lx = x)
		scanf("%d", &x),
		v = min(pos.range(1, 1, n, x, n) - x, neg.range(1, 1, n, 1, x) + x),
		pos.global_add(abs(x - lx)), pos.adj(1, 1, n, lx, v + lx),
		neg.global_add(abs(x - lx)), neg.adj(1, 1, n, lx, v - lx);
	v = INF;
	pos.traversal(1, 1, n, _);
	for (i = 1; i <= n; ++i) down(v, _[i] - i);
	neg.traversal(1, 1, n, _);
	for (i = 1; i <= n; ++i) down(v, _[i] + i);
	printf("%lld\n", v);
	return 0;
}

Measured memory_bytes: 14592
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<stack>
#include<unordered_set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include <cstring>
#include <climits>
using namespace std;
int main() {
	int a[100000];
	int n,e=0,o=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2) {
			o++;
		}
		else {
			e++;
		}
	}
	if (o % 2 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;

class D
{
	static void Main()
	{
		Console.ReadLine();
		var d = Console.ReadLine().Select((c, i) => new { c, i }).GroupBy(_ => _.c).ToDictionary(g => g.Key, g => g.Select(_ => _.i).ToArray());

		var r = 0;
		foreach (var p1 in d)
		{
			var i1 = p1.Value[0];

			foreach (var p3 in d)
			{
				var i3 = p3.Value.Last();
				if (i3 - i1 < 2) continue;

				foreach (var p2 in d)
				{
					var j2 = Array.BinarySearch(p2.Value, i1 + 1);
					if (j2 < 0) j2 = ~j2;
					if (j2 >= p2.Value.Length || p2.Value[j2] >= i3) continue;
					r++;
				}
			}
		}
		Console.WriteLine(r);
	}
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;
int dy[]={1, 0, -1, 0, 0};
int dx[]={0, 1, 0, -1, 0};


int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> a(n+1, 0);
    rep(i, n) cin >> a[i];
    
    ll sum = 0;
    ll lsum = 0;
    ll rsum = 0;
    rep(i, k) sum += a[i];
    for(int i = k; i < n; i++) rsum += max(0ll, a[i]);
    ll maxx = sum;
    rep(i, n-k+1){
        maxx = max(maxx, max(0ll, sum)+lsum+rsum);
        sum -= a[i];
        sum += a[i+k];
        lsum += max(0ll, a[i]);
        rsum -= max(0ll, a[i+k]);
    }

    cout << maxx << endl;

    return 0;
}



Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split();
            var N = int.Parse(input[0]);
            var K = long.Parse(input[1]);
            var A = Console.ReadLine().Split().Select(int.Parse).Select(i => i - 1).ToArray();

            var path = Path(A);
            var loopFirst = Array.IndexOf(path, A[path.Last()]);
            var loopLength = path.Length - loopFirst;

            var ansIndex = K < path.Length ? K : loopFirst + (K - loopFirst) % loopLength;

            Console.WriteLine(path[ansIndex] + 1);
        }

        static int[] Path(int[] A)
        {
            var ret = new List<int>() { 0 };
            var set = new HashSet<int>() { 0 };

            var a = A[0];
            while (true)
            {
                if (set.Contains(a)) return ret.ToArray();
                ret.Add(a);
                set.Add(a);
                a = A[a];
            }
        }
    }
}


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

int main() {
	string s;
	cin >> s;
	string w[4] = {"Sunny", "Cloudy", "Rainy", "Sunny"};
	string ans;
	for (int i = 0; i < 3; i++) {
		if (s == w[i]) {
			ans = w[i+1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using ld = long double;                  //   | grep -v ' .* '  1300111 ~2^20.31
using vl = vector<ll>;                   //                    10300777 ~2^23.30
using vvl = vector<vl>;                  //                   100400999 ~2^26.58
using pll = pair<ll,ll>;                 //                  1300400999 ~2^30.28
using vpll = vector<pll>;                //                 10200500333 ~2^33.25
using vb = vector<bool>;                 //                100200400777 ~2^36.54
using vs = vector<string>;               //               1200300700111 ~2^40.13
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //              10200300500777 ~2^43.21
const ld eps = 1e-9;                     //             100200300400777 ~2^46.51
#define sz(c) ll((c).size())             //            1200300400600999 ~2^50.09
#define all(c) begin(c),end(c)           //           10200300400600111 ~2^53.18
#define mp make_pair                     //          100200300400600333 ~2^56.48
#define mt make_tuple                    //         1200300400500800999 ~2^60.06
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(0) cerr << "TR: " << (#X) << " = " << (X) << endl; })

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

	ll N, W; cin >> N >> W;
	vpll items(N+1);
	FOR(i,1,N+1) cin >> items[i].xx >> items[i].yy;

	map<ll, ll> best;
	best[0] = 0;

	FOR(i,1,N+1) {
		TR(i);
		ll w, v;
		tie(w, v) = items[i];
		TR(w);
		TR(v);

		map<ll, ll> old(best);

		for (auto c : old) {
			pll next = {c.xx + w, c.yy + v};

			if (old.count(next.xx)) {
				if (old[next.xx] < next.yy) {
					best[next.xx] = next.yy;
				}
			} else {
				best[next.xx] = next.yy;
			}
		}

		ll cur = -1;
		for (auto it = best.begin(); it != best.end(); ) {
			if (it->yy <= cur) {
				it = best.erase(it);
			} else {
				cur = it->yy;
				it++;
			}
		}

#if 0
		for (auto c : best) {
			cerr << c.xx << " " << c.yy << "\n";
		}
#endif
	}

	auto res = best.upper_bound(W);
	res--;
	cout << (*res).yy << "\n";

	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

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

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n,ans=0;
    cin >> n;
    vector<char> c(n);
    rep(i,n) cin >> c[i];
    
    ll now=n-1;
    ll i=0;
    
    while(1){
        while(c[i]=='R'){
            i++;
        }
        while(c[now]=='W'){
            now--;
        }
        if(i>=now) break;
        ans++;
        swap(c[i],c[now]);
    }
    
    cout << ans << endl;

    return 0;
}











Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std ;
class Cube {
  public:
  int f[6] ;
  Cube(){}
  void roll_z(){ roll(1,2,4,3); }
  void roll_y(){ roll(0,2,5,3); }
  void roll_x(){ roll(0,1,5,4); }
  void roll(int i , int j , int k , int l ){
    int t = f[i] ; f[i] = f[j] ;f[j] = f[k] ;f[k]= f[l];f[l]= t;
  }
} ;
int getRight(Cube c1 , int f1 ,int f2){
  for(int i = 0 ; i < 6 ; i++ ){
    for(int j = 0 ; j < 4 ; j++ ){
      if(c1.f[0] == f1 && c1.f[1]==f2) return c1.f[2] ;
      c1.roll_z() ;
    }
    if ( i % 2 == 0 )c1.roll_y();
    else c1.roll_x();
  }
  return -1 ;
}

int main () {
  Cube c ;
  int f1 , f2 ;
  
  for(int i = 0 ; i < 6 ; i++ ) cin >> c.f[i] ;
  int q ; cin >> q ;
  
  for(int i = 0 ; i < q ;i++){
    cin >> f1 >> f2 ;
    cout << getRight(c,f1,f2) << endl ;
  }
}


Measured memory_bytes: 3064
n = int(input())
mod = 10 ** 9 + 7

if n == 1:
  print(0)
elif n == 2:
  print(2)
else:
  a = 10 ** n % mod
  b = 9 ** n % mod
  c = 8 ** n % mod
  ans = a - 2 * b + c
  ans %= mod
  print(ans)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "yes" << endl;}
void no(){ cout << "no" << endl;}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n;
  cin >> n;
  vll a(n);
  REP(i,n) cin >> a[i];
  reverse(ALL(a));
  REP(i,n){
    if(i) cout << " ";
    cout << a[i];
  }
  cout <<endl;

  return 0;
}






Measured memory_bytes: 3232
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        const bool IsTest = false;

        const string t1 = "1 5 2";

        public static void Main(string[] args)
        {
            if (!IsTest) {
                new Program().Solve(new ConsoleInput(Console.In));
            } else {
                new Program().Solve(new ConsoleInput(new StringReader(t1)));
            }
        }

        public void Solve(ConsoleInput cin)
        {
            cin.ReadLine();
            var values = cin.ReadArray<int>(3);
            Array.Sort(values);
            Array.Reverse(values);
            var r = values[0] * 10 + values[1] + values[2];
            Console.WriteLine(r);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private readonly char _separator = ' ';
        private string _curLine;
        private string[] _curLineSplitted;
        private int _curItemIndex;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
        }
        public T Read<T>()
        {
            var converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(T));
            if (converter == null) {
                throw new Exception(string.Format("TypeDescriptor.GetConverter {0}", typeof(T).Name));
            }
            return (T)converter.ConvertFromString(ReadString());
        }
        public T[] ReadArray<T>(long N)
        {
            var ret = new T[N];
            for (long i = 0; i < N; i++) {
                ret[i] = Read<T>();
            }
            return ret;
        }
        public Tuple<T> ReadLineAs<T>()
        {
            ReadLine();
            return new Tuple<T>(Read<T>());
        }
        public Tuple<T, S> ReadLineAs<T, S>()
        {
            ReadLine();
            return new Tuple<T, S>(Read<T>(), Read<S>());
        }
        public Tuple<T, S, U> ReadLineAs<T, S, U>()
        {
            ReadLine();
            return new Tuple<T, S, U>(Read<T>(), Read<S>(), Read<U>());
        }
        public Tuple<T, S, U, V> ReadLineAs<T, S, U, V>()
        {
            ReadLine();
            return new Tuple<T, S, U, V>(Read<T>(), Read<S>(), Read<U>(), Read<V>());
        }
        public Tuple<T, S, U, V, R> ReadLineAs<T, S, U, V, R>()
        {
            ReadLine();
            return new Tuple<T, S, U, V, R>(Read<T>(), Read<S>(), Read<U>(), Read<V>(), Read<R>());
        }

        public string ReadString()
        {
            return _curLineSplitted[_curItemIndex++];
        }
        public void ReadLine()
        {
            _curLine = _stream.ReadLine();
            if (_curLine == null) {
                throw new System.Exception("No more lines");
            }
            _curLineSplitted = _curLine.Split(_separator);
            _curItemIndex = 0;
        }
    }
}



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

int main(){
    int q,c=0,a=0,n=0,t=0;
    
    cin >> q;
    
    for(int i=0; i<q;i++){
        cin >> c >> a >> n;
        t=0;
        for(;c>0&&a>0&&n>0;){
            c--; a--; n--;
            t++;
        }
        for(;c>1&&a>0;){
            c--; a--; c--;
            t++;
        }
        for(;c>2;){
            c--; c--; c--;
            t++;
        }
        cout << t << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 1160
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main implements Runnable {

    static Scanner sc = new Scanner(System.in);
    static final int N = 100005;
    static final int UNVISITED = -1;
    static int n, m, q;
    static ArrayList<ArrayList<Integer>> G;
    static int[] c = new int[N];

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    @Override
    public void run() {
        read();
        for (int i = 0; i < n; i++) {
            dfs(i, i);
        }
        out();

    }

    static void init(int n) {
        G = new ArrayList<ArrayList<Integer>>(n);
        for (int i = 0; i < n; i++) {
            G.add(new ArrayList<Integer>());
            c[i] = UNVISITED;
        }
    }

    static void read() {
        n = sc.nextInt();
        m = sc.nextInt();

        init(n);

        int u, v;
        for (int i = 0; i < m; i++) {
            u = sc.nextInt();
            v = sc.nextInt();

            G.get(u).add(v);
            G.get(v).add(u);
        }

        q = sc.nextInt();
    }

    static void dfs(int v, int cls) {
        if (c[v] != UNVISITED) {
            return;
        }

        c[v] = cls;
        for (int i = 0; i < G.get(v).size(); i++) {
            dfs(G.get(v).get(i), cls);
        }
    }

    static void out() {
        int u, v;
        for (int i = 0; i < q; i++) {
            u = sc.nextInt();
            v = sc.nextInt();

            if (c[u] == c[v]) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }
}

Measured memory_bytes: 128360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int x = s[s.size() - 1] - '0';
    if (x == 3) cout << "bon" << endl;
    else if (x == 0 || x == 1 || x == 6 || x == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long A, long long B, long long C, long long K){
	if (K%2 == 0) cout << A-B << endl; else cout << B-A << endl;
}

int main(){	
	long long K;
	long long A;
	long long B;
	long long C;
	scanf("%lld",&A);
	scanf("%lld",&B);
	scanf("%lld",&C);
	scanf("%lld",&K);
	solve(A, B, C, K);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll P[205000];
ll ans;
ll N;
ll mini = 1e9;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) cin >> P[i];
    for(int i = 0; i < N; i++) {
        if(P[i] <= mini) ans++;
        chmin(mini, P[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    string s;
    scan(s);
    int x, y;
    scan(x, y);

    auto xys = new int[][](2, 0);
    auto tk = 0;
    auto xb = 0;

    while (xb < s.length.to!int && s[xb] == 'F') xb++;

    s = s[xb .. $];

    debug {
        writeln(xb);
        writeln(s);
    }

    foreach (si ; s) {
        if (si == 'F') {
            xys[tk].back++;
        }
        else {
            tk ^= 1;
            xys[tk] ~= 0;
        }
    }

    xys[0] = xys[0].filter!"a > 0".array;
    xys[1] = xys[1].filter!"a > 0".array;

    debug {
        writeln(xys);
    }

    auto ans = knapsack(xys[0], x - xb) && knapsack(xys[1], y);

    writeln(ans ? "Yes" : "No");
}

bool knapsack(int[] x, int X) {
    int n = x.length.to!int;

    auto dp = new bool[][](n + 1, 40001);
    dp[0][20000] = 1;

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. 40001) {
            if (j-x[i]>=0) dp[i+1][j-x[i]] |= dp[i][j];
            if (j+x[i]<40001) dp[i+1][j+x[i]] |= dp[i][j];
        }

        debug {
            writefln("%(%b %)", dp[i+1][20000 - 10 .. 20000 + 10]);
        }
    }

    return dp[n][X + 20000];
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 162172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n';

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    ll arr[n+1];
    memset(arr, 0, sizeof(arr));
    for(int i = 0; i < n; ++i){
        cin>>arr[i+1];
        arr[i+1] += arr[i];
    }
    ll ans = 0, md = 1e9 + 7;
    for(int i = n; i>=1; --i){
        ans += (arr[i] - arr[i-1])*(arr[i-1]%md);
        ans %= md;
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 5228
#include <iostream>

using namespace std;

int main() {
		int N, X;
		cin >> N >> X;
		int L[N];
		int cnt = 0;
		int pos = 0;
		for (int i = 0; i < N; i++) {
				int t;
				cin >> t;
				pos += t;
				if (pos > X) {
						cout << cnt + 1 << endl;
						return 0;
				}
				cnt++;
				if (pos == X) {
						cout << cnt + 1 << endl;
						return 0;
				}
		}

		cout << cnt + 1 << endl;
		return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long cost[15], lev[15][15];
vector <long long> tmp, learn;
int main()
{

	long long k, j, i, n, m, x, books, algo, cnt=LLONG_MAX, val=0, fl=0;
	cin >> books >> algo >> x;
	for(i=0; i<books; i++){
		cin >> cost[i];
		for(j=0; j<algo; j++)
			cin >> lev[i][j];
	}

	for(i=0; i<algo; i++)
		learn.push_back(0);

    	for (i=0; i<(1<<books); ++i){
		
        	tmp.clear(); val=0; fl=0;

		for(k=0; k<algo; k++)
			learn[k] = 0;

        	for (j=0; j<books; ++j){
           	 //  1<<j shifts the 1 for j places and then we check j-th binary digit of i

			if (i&(1<<j))
                		tmp.push_back(j);
        	}

		for(j=0; j<tmp.size(); j++){
			val += cost[tmp[j]];
			for(k=0; k<algo; k++){
				learn[k] += lev[tmp[j]][k];
			}
		}
		
		for(k=0; k<algo; k++){
			
			if(learn[k] < x){
				fl = 1;  break; 
			}
		}

		if (fl == 0 && val < cnt)
			cnt = val;
    	}

	if (cnt == LLONG_MAX)
		cout << "-1" << endl;
	else
		cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 1e5 + 7;
bool vis[MAXN];
int dist[MAXN];
vector<pair<int, int> > G[MAXN];
queue<int> q;
int bfs(int st) {
	memset(vis, 0, sizeof(vis));
	memset(dist, 0, sizeof(dist));
	q.push(st);
	vis[st] = true;
	int ret = st, maxd = 0;
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		for (int i = 0; i < G[cur].size(); i++) {
			if (!vis[G[cur][i].first]) {
				vis[G[cur][i].first] = true;
				q.push(G[cur][i].first);
				dist[G[cur][i].first] = dist[cur] + G[cur][i].second;
				if (dist[G[cur][i].first] > maxd) {
					maxd = dist[G[cur][i].first];
					ret = G[cur][i].first;
				}
			}
		}
	}
	return ret;
}
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
    	int s, t, w;
    	scanf("%d%d%d", &s, &t, &w);
    	G[s].push_back(make_pair(t, w));
    	G[t].push_back(make_pair(s, w));
	}
	printf("%d\n", dist[bfs(bfs(0))]);
	return 0;
}


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

int main() {
	int n,x;
	cin>>n>>x;
	int ans = 0;
	for(int i = 0;i<n;i++){
		int t; cin>>t;
		ans = __gcd(ans, abs(t-x));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=2e3+20;

int n;
char str[maxn];
vector<int>ed[maxn];

inline void init()
{
	n=read();
	scanf("%s",str+1);
	REP(i,1,n-1)
	{
		int u=read(),v=read();
		ed[u].push_back(v);
		ed[v].push_back(u);
	}
}

int rt;

int Sum,mx,V;
int sz[maxn];
int f[maxn],g[maxn];

void dfs(int u,int fa)
{
	sz[u]=str[u]-'0'; f[u]=0;
	for(int v:ed[u])
	{
		if(v==fa)continue;
		dfs(v,u);
		f[u]+=f[v]+sz[v];
		sz[u]+=sz[v];
	}
}

void dfs1(int u,int fa)
{
	int sumg=0,sumf=0,mx=0;
	for(int v:ed[u])
	{
		if(v==fa)continue;
		dfs1(v,u);
		int val=g[v]+sz[v];
		sumg+=val;
		sumf+=f[v]+sz[v];
	}
	mx=0;
	for(int v:ed[u])
	{
		if(v==fa)continue;
		chkmax(mx,max(g[v]+sz[v]-(sumf-f[v]-sz[v]),0));
	}
	g[u]=mx;
}

inline void doing()
{
	int Ans=0x3f3f3f3f;
	for(rt=1;rt<=n;rt++)
	{
		dfs(rt,0);
		dfs1(rt,0);
		if((~f[rt]&1) && g[rt]==0)chkmin(Ans,f[rt]>>1);
	}
	if(Ans==0x3f3f3f3f)puts("-1");
	else printf("%d\n",Ans);
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(100000)

# m digits, k, less than flag
n = input()
K = int(input())


def func(i, k, free=False):
    # rest digits
    m = len(n) - i

    # cannot fill m digits with 0 * k
    if k > m:
        return 0

    if m == 0:
        return 1
    # fill all digits with 0
    if k == 0:
        return 1

    if free:
        a = 9 ** k
        # print(a)
        for j in range(k):
            a *= (m - j)
        for j in range(k):
            a = a // (j + 1)
        # print(a)
        return a

    else:
        if n[i] != '0':
            # fill with 0
            a = func(i + 1, k, free=True)

            # 1, 2, ..., n[i] - 1
            b = (int(n[i]) - 1) * func(i + 1, k - 1, free=True)

            # n[i]
            c = func(i + 1, k - 1, free=False) 
            # print(i, a, b, c, k, m)
            return a + b + c
        else:
            # fill with 0
            c = func(i + 1, k, free=False)
            return c


print(func(0, K, free=False))


Measured memory_bytes: 3064
#include <iostream>
#include <cstring>

using namespace std;

int dp[310];

int main(){
    memset(dp, 0, sizeof(dp));

    dp[0] = 1;

    for(int i=1; i < 17; i++){
        for(int j=1; j < 300; j++){
            if(j < i*i) continue;
            dp[j] += dp[j-i*i];
        }
    }

    int n;
    while(cin >> n, n){
        cout << dp[n] << endl;
    }
}

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

int main(){
	vector<char>v={'a','e','i','o','u'};
	char c;
	cin>>c;
	v.push_back(c);
	int i=0;
	while(v.at(i)!=c)++i;
	if(i!=v.size()-1)cout<<"vowel\n"s;
	else cout<<"consonant\n"s;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(){
	int i,j,n,sum,max;
	int *data;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		data=(int*)calloc(n,sizeof(int));
		for(i=0;i<n;i++){
			scanf("%d",&data[i]);
		}
		sum=max=-1000001;
		for(i=0;i<n;i++){
			sum=0;
			for(j=i;j<n;j++){
				sum+=data[j];
				if(max<sum) max=sum;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 628
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    int K = int.Parse(input[2]);
    
    if (K * 2 <= B - A) {
      for (int i = A; i < A + K; i++) {
        Console.WriteLine(i);
      }
      for (int i = B - (K - 1); i <= B; i++) {
        Console.WriteLine(i);
      }
    } else {
      for (int i = A; i <= B; i++) {
        Console.WriteLine(i);
      }
    }
  }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#ifndef U_L_LONG
typedef unsigned long long U_L_LONG;
#endif
#ifndef L_LONG
typedef long long L_LONG;
#endif

#ifndef LL_ABS
#define LL_ABS(x) (((((L_LONG)(x) < 0) ? ((L_LONG)(x) * (-1)) : ((L_LONG)(x)))))
#endif

//static void ABC120D_DecayedBridges();
//static void ABC119C_MonstersBattleRoyale();
//static void ABC117C_Streamline();
static void ABC119B_DigitalGifts();

#if 1
int main()
{
	//ABC120D_DecayedBridges();
	//ABC119C_MonstersBattleRoyale();
	//ABC117C_Streamline();
	ABC119B_DigitalGifts();

	fflush(stdout);
	return 0;
}
#endif



#define ABC119B_MAX (16)
#define ABC119B_BTC_RATE (380000.0)
static void ABC119B_DigitalGifts()
{
	int N = 0;
	const std::string JPY = "JPY";
	char szNum[ABC119B_MAX] = { 0 };
	char szKind[ABC119B_MAX] = { 0 };
	double moneySum = 0.0;

	scanf(" %d", &N);

	for (int i = 0; i < N; i++) {
		scanf(" %s %s", szNum, szKind);

		if (szKind == JPY) {
			moneySum += strtod(szNum, NULL);
		}
		else {
			moneySum += strtod(szNum, NULL) * ABC119B_BTC_RATE;
		}
	}

	printf("%f\n", moneySum);
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();

    //累積和の準備
    let mut whsum = vec![0; n + 1];
    let mut blsum = vec![0; n + 1];
    for i in 0..n {
        match s[i] {
            '.' => {
                whsum[i + 1] = whsum[i] + 1;
                blsum[i + 1] = blsum[i];
            }
            '#' => {
                whsum[i + 1] = whsum[i];
                blsum[i + 1] = blsum[i] + 1;
            }
            _ => {}
        }
    }

    let mut ret: u64 = std::u64::MAX;
    for left in 0..=n {
        let mut tmp: u64 = 0;
        // left の黒を白に変える
        tmp += blsum[left] - blsum[0];
        // right の白を黒に変える
        tmp += whsum[n] - whsum[left];

        ret = std::cmp::min(tmp, ret);
    }
    println!("{}", ret);
}


Measured memory_bytes: 6060
#include <stdio.h>

int main(){
  int n, a[101];
  scanf("%d", &n);
  for(int i=0;i<n;i++) scanf("%d", a+i);

  for(int i=0; i<n; i++){
    for(int j=n-1; j>i; j--){
      if(a[j] > a[j-1]){
	int t = a[j];
	a[j] = a[j-1];
	a[j-1] = t;
      }
    }
  }
  int t = 1;
  for(int i=1; i<n; i++){
    if(a[i] != a[i-1]){
      t++;
    }
  }
  printf("%d", t);

  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

public static class Program
{
    public static void Main(string[] args)
    {
        var s = Console.ReadLine().Select(x => x.ToString()).ToArray();
        var cnt1 = s.Count(x => x == "1");
        var cnt0 = s.Count(x => x == "0");
        if (cnt1 == cnt0)
            Console.WriteLine(cnt0 * 2);
        else if (cnt1 < cnt0)
            Console.WriteLine(cnt1 * 2);
        else
            Console.WriteLine(cnt0 * 2);
    }
}

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

int main(){
    double n;
    scanf("%lf",&n);
    double price=n/1.08;
    int ans;
    if(ceil(price)==floor(price)){
        ans=price;
        printf("%d\n",ans);
        return 0;
    }
    else{
        if(floor(ceil(price)*1.08)==n){
            ans=ceil(price);
            printf("%d\n",ans);
            return 0;
        }
        else if(floor(floor(price)*1.08)==n){
            ans=floor(price);
            printf("%d\n",ans);
            return 0;
        }
    }
    printf(":(\n");
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(){
  P x=Q[head];
  head=(head+1)%LEN;
  return x;
}

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


int main(){
  int e = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head=1;
  tail=n+1;

  while(head!=tail){
    u=dequeue();
    c=min(q,u.t);
    u.t-=c;
    e+=c;
    if(u.t>0)enqueue(u);
    else{
      printf("%s %d\n",u.name,e);
    }
  }
  
  return 0;
}



Measured memory_bytes: 11884
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <climits>
#include <list>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long int ll;
#define mod 1000000007

int main() {
    int x;
    cin >> x;
    if(x>=30) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int m,n;
string S,T;
int dp[2010][2010];

int solve(int s,int t){
  if(dp[s][t] != -1) return dp[s][t];
  int ret = 0;
  if(S[s] == 'O' && S[s+1] == 'I') ret = max(ret,solve(s+2,t)+2);
  if(T[t] == 'O' && T[t+1] == 'I') ret = max(ret,solve(s,t+2)+2);
  if(S[s] == 'O' && T[t] == 'I') ret = max(ret,solve(s+1,t+1)+2);
  if(T[t] == 'O' && S[s] == 'I') ret = max(ret,solve(s+1,t+1)+2);
  return dp[s][t] = ret;
}

int main(){
  cin >> m >> n;
  cin >> S;
  cin >> T;
  S += "HOGE";
  T += "HOGE";
  memset(dp,-1,sizeof(dp));
  int ans = 0;
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      if(S[i] == 'I'){
	ans = max(ans,solve(i+1,j)+1);
      }
      if(T[j] == 'I'){
	ans = max(ans,solve(i,j+1)+1);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 17128
#include <bits/stdc++.h>
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;

void solve(){
	int n ;
	cin >>n ;
	vector<int> f(n+1) ;
	for(int i = 1 ; i <= n ; i++){
		for(int j = i ; j <= n ; j+=i){
			f[j]++ ;
		}
	}
	int ans = 0LL ;
	for(int i = 1 ; i <= n ; i++){
		ans += i*f[i] ;
	}
	cout << ans << endl ;

}

int32_t main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	FAST_IO ;
	int tt = 1;
//	cin >> tt ;
	while(tt--){
		solve() ;
	}
	return 0 ;
}


Measured memory_bytes: 81320
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<double, int> P;
double dist(double x, double y){
  return sqrt(x*x + y*y);
}

int main(){
  int N, M;
  while(cin>>N>>M && N){
    int x[10000], y[10000];
    REP(i, N)cin>>x[i]>>y[i];
    vector<int> edges[10000];
    double ans = 0;
    REP(i, M){
      int u, v; cin>>u>>v; u--; v--;
      edges[u].push_back(v);
      edges[v].push_back(u);
      ans += dist(x[u]-x[v], y[u]-y[v]);
    }
    vector<bool> used(N);
    priority_queue<P> que;
    REP(i, N)if(!used[i]){
      que.push(P(0, i));
      while(!que.empty()){
        P p = que.top(); que.pop();
        if(used[p.second]) continue;
        used[p.second] = true;
        ans -= p.first;
        REP(j, edges[p.second].size()){
          int to = edges[p.second][j];
          double d = dist(x[p.second]-x[to], y[p.second]-y[to]);
          que.push(P(d, to));
        }
      }
    }
    printf("%.3lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1920
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
	if (a < b)swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

int main() {
	ll N, K, X, Y;
	cin >> N >> K >> X >> Y;
	if (N <= K)cout << N * X << endl;
	else cout << K * X + Y * (N - K) << endl;
}


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

using namespace std;

int a[16];
int x[16][16];
int y[16][16];

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        for (int j = 1; j <= a[i]; ++j) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for (int i = 1; i < (1 << n); ++i) {
        bool ok = true;
        for (int k = 1; k <= n; ++k) {
            if (i & (1 << (k-1))) {
                for (int j = 1; j <= a[k]; ++j) {
                    if (((i >> (x[k][j]-1)) & 1) ^ y[k][j]) ok = false;
                }
            }
        }
        if (ok) ans = max(ans, __builtin_popcount(i));
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256