akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int MAXN = 3e5 + 100;

int R[MAXN];
int C[MAXN];

map<pair<int,int>, bool> mp;

int arr[MAXN];

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

    int N, M, Q;
    cin >> N >> M >> Q;

    for(int i = 0 ; i < Q ; i++)
    {
    	int x, y;
    	cin >> x >> y;
    	mp[{x,y}] = true;
    	R[x]++;
    	C[y]++;
    }

    vector<pair<int,int>> vect;

    for(int i = 1 ; i <= M ; i++)
    {
    	vect.push_back({C[i], i});
    }

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

    priority_queue<pair<int,int>> PQ;

    for(int i = 1 ; i <= N ; i++)
    {
    	int tp;

    	if(mp[{i, vect[arr[i]].second}])tp = 1;
    	else tp = 0;

    	PQ.push({R[i] + vect[arr[i]].first - tp, i});
    }

    int cont = Q + 100;

    int res = 0;

    while(PQ.size() && cont)
    {
    	cont--;

    	pair<int,int> pp = PQ.top();
    	PQ.pop();

    	res = max(res, pp.first);

    	arr[pp.second]++;

    	if(arr[pp.second] == M)continue;

    	int tp;

    	if(mp[{pp.second, vect[arr[pp.second]].second}])tp = 1;
    	else tp = 0;

    	PQ.push({R[pp.second] + vect[arr[pp.second]].first - tp, pp.second});
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 75900
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;


//ユークリッドの互除法　a,bは最大公約数を求めたい２つの数
long long int gcd(long long int a, long long int b) {
             long long int tmp;
             long long int r = 1;
             if (b > a) {
                           tmp = a;
                           a = b;
                           b = tmp;
             }
             r = a % b;
             while (r != 0) {
 
 
                           a = b;
                           b = r;
                           r = a % b;
 
             }
             return b;
}

const long long int mod=1000000007;
int main(){
	long long int n,m;
	string str;
	cin>>str;
	for(int i=0;i<4;i++){
		cout<<str[i];
	}
	cout<<" ";
	for(int i=4;i<12;i++){
		cout<<str[i];
	}
	cout<<endl;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char ch[100100][15];
unsigned long long hashh[100100];
const unsigned long long mod=212370440130137957ll;
unsigned long long a=233;
map<unsigned long long,int> mp;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",ch[i]+1); 
		int len=strlen(ch[i]+1); 
		sort(ch[i]+1,ch[i]+1+len);
	}
	long long anss=0;
	for(int i=1;i<=n;i++){
		int leni=strlen(ch[i]+1);
		for(int j=1;j<=leni;j++){
			hashh[i]=hashh[i]*a+(unsigned long long)ch[i][j];
		}
		mp[hashh[i]]++;
		anss=anss+mp[hashh[i]]-1;
	}
	
	printf("%lld",anss);
	return 0;
} 

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<string> s(n);
	vector<int> t(n);
	for(int i = 0; i < n; i++){
		cin >> s[i] >> t[i];
	}
	string x; cin >> x;
	long long ans = 0;
	bool ok = false;
	for(int i = 0; i < n; i++){
		if(ok) ans += t[i];
		if(s[i] == x) ok = true;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
 
int main() {
  int n, q, t;
  string name;
   
  queue<pair<string, int> > Q;
 
  cin >> n >> q;
 
  for ( int i = 0; i < n; i++ ) {
    cin >> name >> t;
    Q.push(make_pair(name, t));
  }
 
  pair<string, int> u;
  int elaps = 0, a;
 
  while ( !Q.empty() ) {
    u = Q.front(); Q.pop();
    a = min(u.second, q);
    u.second -= a;
    elaps += a;
    if ( u.second > 0) {
      Q.push(u);
    } else {
      cout << u.first << " " << elaps <<endl;
    }
  }
 
  return 0;
}


Measured memory_bytes: 6324
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	string s;cin>>s;
	ll k;cin>>k;
	int n=s.size();
	int j=-1;
	rep(i,n) if(s[i]!='1') {j=i;break;}
	int ans;
	if(j==-1) ans=1;
	else if(k<j+1) ans=1;
	else ans=s[j]-'0';
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int t;
    cin>>t;
    int i = t%10;
    if(i==2 || i==4 || i==5 || i==7 || i==9)cout<<"hon";
    else if(i==0 || i==1 || i==6 || i==8) cout<<"pon";
    else cout<<"bon";
    return 0;
    }

Measured memory_bytes: 3004
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str[15];

int main(int argc, char* argv[])
{
    scanf("%s", str);
    if(str[0]=='S') {
        printf("Cloudy\n");
    }
    else if(str[0]=='C') {
        printf("Rainy\n");
    }
    else {
        printf("Sunny\n");
    }


    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef long double ld;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
map<ll,ll> ma;
void solve(ll n){
  for(ll i=2 ; i*i<=n ; i++){
    while(n%i==0){
      ma[i]++;
      n /= i;
    }
  }
  if(n) ma[n]++;
}
int main(){
  ll N,P; cin>>N>>P;
  solve(P);

  ll value=1;
  for(auto j : ma){
    if(j.se >= N){
      value *= pow(j.fi , j.se/N);
    }
  }

  cout << value << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
#define rep0(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define rep1(kk, l1, l2)for(ll kk = l1; kk <= l2; kk++)
#define foritr(itr, A) for(set<ll>::iterator itr = A.begin(); itr != A.end(); itr++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define cr(x) cerr << #x << " = " << x << "\n";
#define crA(x, A) cerr << #x << " = " << A[x] << "\n";
#define spacing cout << " ";
#define mmst(x, v) memset((x), v, sizeof ((x)));
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll nb, nw;
string s;
int main()
{
	cin >> s;
	for(auto i : s) if(i=='W') nw ++;
	for(auto i : s)
	{
		if(i=='W') {nw --; continue; }
		nb += nw;
	}
	cout << nb << "\n";
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(){
	int N;
	int min_num = 1000001;
	int max_num = -1000001;
	long long int sum=0;  // 一定要初始化赋值为0不然会出错 
	int k;
	scanf("%d", &N);
	
	bool flag = 1;
	for(int i =0;i<N;i++){
		scanf("%d", &k);
		sum+=k;
		min_num = min(k, min_num);
		max_num = max(k, max_num);
	}
	cout<<min_num<<" "<<max_num<<" "<<sum<<endl;
	
	return 0;
}


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

typedef long long ll;
const ll INF = 1001001001001001001;
int n, m;
struct edge{
    int from, to;
    ll cost;
};
vector<edge> es;
ll dist[1005];
bool negative[1005];

void shortest_path(int s){
    fill(dist, dist + n, INF);
    dist[s] = 0;
    
    for(int i = 0; i < n - 1; ++i){
        bool update = false;
        
        for(int j = 0; j < m; ++j){
            edge& e = es[j];
            
            if(dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                update = true;
            }
        }
        
        if(!update)     break;
    }
}

bool link_negative_loop(){
    fill(negative, negative + n, false);
    
    for(int i = 0; i < n; ++i){
        for(int i = 0; i < m; ++i){
            edge& e = es[i];
        
            if(negative[e.from])    negative[e.to] = true;
        
            if(dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
            
                negative[e.to] = true;
            }
        }
    }
    
    return negative[n - 1];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        --a;
        --b;
        es.push_back((edge){a, b, -c});
    }
    
    shortest_path(0);
    if(link_negative_loop()){
        cout << "inf\n";
    }
    else{
        cout << -dist[n - 1] << "\n";
    }
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
using ll = long long;
int main() {
  int n; cin >> n;
  ll h[n]; int suffix[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  suffix[n-1] = 0; int answer = 0;
  for (int i = n - 2; i >= 0; i--) {
    if (h[i] >= h[i+1]) {
      suffix[i] = 1 + suffix[i+1];
    }
    else {
      suffix[i] = 0;
    }
    //cout << suffix[i] << "\n";
    answer = max(answer, suffix[i]);
  }
  cout << answer;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cmath>

using namespace std;
int main(int argc, const char * argv[]) {
    int N, A, B;
    cin >> N >> A >> B;
    int sum2 = 0;
    for(int n = 0; n <= N; ++n){
        int nn = n;
        int sum = 0;
        while(nn){
            sum += nn % 10;
            nn = nn / 10;
        }
        if(sum >= A && sum <= B){
            sum2 += n;
        }
    }
    cout << sum2;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

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

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); };

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 7;

struct edge {
	int to, cost;
	edge(int to, int cost) : to(to), cost(cost) {}
};

int N, M;
vector<edge> G[100010];
bool vis[100010];
int d[100010];

signed main()
{
	cin >> N >> M;

	rep(i, M) {
		int l, r, d; scanf("%lld%lld%lld", &l, &r, &d);
		--r, --l;
		G[l].PB(r, d);
		G[r].PB(l, -d);
	}

	memset(d, -1, sizeof d);

	rep(i, N) {
		if (vis[i]) continue;

		d[i] = 0;
		queue<int> q;
		q.push(i);

		while (q.size()) {
			int cur = q.front(); q.pop();

			if (vis[cur]) continue;
			vis[cur] = true;

			for (edge &e : G[cur]) {
				if (vis[e.to]) {
					if (d[e.to] != d[cur] + e.cost) {
						cout << "No" << endl;
						return 0;
					}

					continue;
				}

				d[e.to] = d[cur] + e.cost;
				q.push(e.to);
			}
		}
	}

	cout << "Yes" << endl;
}


Measured memory_bytes: 14464
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var tx = Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
            Console.WriteLine(tx[0] / tx[1]);
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,P> PP;
typedef pair<ll,PP> PPP;
int h,w,k,sx,sy,gx,gy;
vector<vector<char>> C;
ll INF=1e18;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w>>k>>sx>>sy>>gx>>gy;
    sx--,sy--,gx--,gy--;
    vec B(w,INF);
    ll d[4][h][w];
    rep(i,h){
        vector<char> A;
        rep(j,w){
            char a;
            cin>>a;
            A.push_back(a);
            rep(k,4) d[k][i][j]=INF;
        }
        C.push_back(A);
    }
    priority_queue<PPP,vector<PPP>,greater<PPP>> que;
    d[0][sx][sy]=0;
    que.push(PPP(0,PP(0,P(sx,sy))));
    while(!que.empty()){
        PPP p=que.top();que.pop();
        ll dir=p.second.first,vx=p.second.second.first,vy=p.second.second.second;
        if(d[dir][vx][vy]<p.first) continue;
        ll nx=vx+dx[dir],ny=vy+dy[dir];
        if(!(nx<0||nx>=h||ny<0||ny>=w||C[nx][ny]=='@'))
        if(d[dir][nx][ny]>d[dir][vx][vy]+1){
            d[dir][nx][ny]=d[dir][vx][vy]+1;
            ll x=d[dir][nx][ny];
            que.push(PPP(x,PP(dir,P(nx,ny))));
        }
        if(d[(dir+1)%4][vx][vy]>(d[dir][vx][vy]+k-1)/k*k){
            d[(dir+1)%4][vx][vy]=(d[dir][vx][vy]+k-1)/k*k;
            ll x=d[(dir+1)%4][vx][vy];
            que.push(PPP(x,PP((dir+1)%4,P(vx,vy))));
        }
    }
    if(d[0][gx][gy]==INF) cout<<-1;
    else cout<<(d[0][gx][gy]+k-1)/k;
}

Measured memory_bytes: 44292
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s;
	int B = 0;
	long long ans = 0;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i] == 'B'){
            B++;
        }else{
            ans += B;
        } 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
# from math import ceil,sqrt,log,gcd
# def ii():return int(input())
# def si():return input()
# def mi():return map(int,input().split())
# def li():return list(mi())



n,m=map(int,input().split())

if(n<m):
    c=chr(48+n)
    print(c*m)
else:
    c=chr(48+m)
    print(c*n)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n,k; cin >>n >>k;
  int a[n],ans,l=1,r=1;
  for(auto &i:a){
    cin >>i;
    r=max(r,i);
  }
  while(l<=r){
    int m=(l+r)/2,cnt=0;
    for(auto i:a) cnt+=(i-1)/m;
    if(cnt>k) l=m+1;
    else{ans=m; r=m-1;}
  }
  cout <<ans;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 4388
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

int change_color(vector<vector<int>>&fi, const int to_co) {
	queue<pair<int, int>>que;
	const int from_co = fi[1][1];
	que.push(make_pair(1, 1));
	fi[1][1] = -1;
	while (!que.empty()) {
		const auto p(que.front());
		que.pop();
		for (int way = 0; way < 4; ++way) {
			const int nextx = p.first + dx[way];
			const int nexty = p.second + dy[way];
			if (fi[nexty][nextx] == from_co) {
				fi[nexty][nextx] = -1;
				que.push(make_pair(nextx, nexty));
			}
		}
	}
	int num = 0;
	for (auto& l : fi) {
		for (auto& e : l) {
			if (e == -1) {
				num++;
				e = to_co;
			}
		}
	}
	return num;
}

int solve(const vector<vector<int>>&ori_fi, const int rest,const int fin) {
	if (!rest) {
		vector<vector<int>>n_fi(ori_fi);
		return change_color(n_fi, -1);
	}
	int amax = 0;
	for (int nc = 1; nc <= 6; ++nc) {
		if (rest == 1 && nc != fin)continue;
		vector<vector<int>>n_fi(ori_fi);
		change_color(n_fi, nc);
		amax = max(amax, solve(n_fi, rest - 1,fin));
	}
	return amax;
}
int main() {
	while (1) {
		int H, W, C; cin >> H >> W >> C;
		if (!H)break;
		vector<vector<int>>field(H + 2, vector<int>(W + 2));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cin >> field[i + 1][j + 1];
			}
		}
		int ans = solve(field, 5,C);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int n;
	string s;
	cin >> s;
	n = (int)s.size();
	vector<int> pd;
	for (int i = 0; i + 1 < n; i++) {
		if (s[i] != s[i + 1]) {
			pd.push_back(i);
		}
	}	
	vector<int> ans(n);
	for (int i = 0; i < n; i++){
		if (s[i] == 'L') {
			int v = *prev(lower_bound(pd.begin(), pd.end(), i));
			int dl = i - v;
			dl %= 2;
			if (dl % 2 == 0) ans[v]++;
			else ans[v + 1]++; 
		} else {
			int v = *lower_bound(pd.begin(), pd.end(), i);
			int dl = i - v;
			dl %= 2;
			if (dl % 2 == 0) ans[v]++;
			else ans[v + 1]++; 
		}
	}
	for (auto t : ans) {
		cout << t << ' ';
	}
	cout << '\n';
}


Measured memory_bytes: 1480
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let mut S = rl().chars().collect::<Vec<_>>();
    S.sort();
    let ok = S[0] == S[1] && S[1] != S[2] && S[2] == S[3];
    println!("{}", if ok { "Yes" } else { "No" })
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#define inf 1000000007
#define ll long long int
using namespace std;
int main()
{
    ll n;
    cin>>n;
    vector<ll> h(n+2);
    vector<ll> cost(n+2,inf);
    cost[0]=0;
    cost[1]=0;
    
    for(ll i=1;i<=n;i++)
         cin>>h[i];
         
    for(ll i=1;i<=n;i++)
    {
        if(i+1<=n)
        {
            cost[i+1]=min(cost[i+1],abs(h[i+1]-h[i])+cost[i]);
        }
          if(i+2<=n)
        {
            cost[i+2]=min(cost[i+2],abs(h[i+2]-h[i])+cost[i]);
        }
        
    }
         
    cout<<cost[n]<<"\n";
    return 0;
}

Measured memory_bytes: 1792
/**
 *    author:  erekle
 *    created: 19.09.2020 12:43:13
**/
#include <bits/stdc++.h>

using namespace std;

#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define swap2(x,y) x=x^y; y=x^y; x=x^y;




int main() {
	fastIO
	
	int n; cin >> n;
	long long ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; i*j < n; ++j) ++ans;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n; cin >> n;
  vector<ll> a(n), b(n), c(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  sort(a); sort(b); sort(c);

  ll ans = 0;
  rep(i, n) {
    ll ai = distance(a.begin(), lower_bound(all(a), b[i]));
    ll ci = distance(c.begin(), upper_bound(all(c), b[i]));
    // debug3(i, ai, ci);
    ans += ai * (n-ci);
  }
  outl(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll cyc = n / (a + b);
  ll rem = n % (a + b);
  ll tot = cyc * a;
  tot += min(rem, a);
  cout << tot << endl;
  return 0;
}

Measured memory_bytes: 256
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1):
        if i + j > n or i * 10000 + j * 5000 > y:
            break
        elif y - i * 10000 - j * 5000 == (n - i - j) * 1000:
            print(i, j, (n - i - j))
            exit()
print(-1, -1, -1)


Measured memory_bytes: 40812
use std::cmp::min;

fn main() {
    let (n, k) = read_tuple::<i64>();

    println!("{}", min(n % k, (n % k - k).abs()));
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}
const int N = 1005;
int cnt[N + 5];
vector<int>ar;
int main(){
  FASTER;
  int n, m;
  cin >> n >> m;
  cout << ((n * 3) + m) / 2 << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstring>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
ll a,b,c,k;
int main(void){
    cin>>a>>b>>c>>k;
    if(k%2==0)cout<<a-b<<endl;
    else cout<<b-a<<endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;
    Vs w(n);
    rep(i,n)cin>>w[i];

    rep(i,n){
        if(i==0)continue;
        if(w[i-1][w[i-1].length()-1] != w[i][0]){
            Yes(false);
            return 0;
        }
    }

    map<string,int> mp;
    rep(i,n){
        mp[w[i]]++;
    }
    Each(elm,mp){
        if(elm.se>1){
            Yes(false);
            return 0;
        }
    }
    Yes(true);
    return  0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100000 + 233];
int main(){
	scanf("%s",s+1);
	int n = strlen(s+1);
	bool bad = s[n]-'0';
	for(int i=1;i<n;i++){
		if(s[i]!=s[n-i])bad = 1;
	}
	if(s[1]=='0')bad = 1;
	s[1] = '0';
	if(bad){
		puts("-1");
		return 0;
	}
	int last = 1;
	for(int i=2;i<=n;i++){
		if(s[i-1]=='1'){
			printf("%d %d\n",last,i);
			last = i;
		}
		else{
			printf("%d %d\n",last,i);
		}
	}
}

Measured memory_bytes: 1536
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <assert.h>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n = in();
    VI a(n);
    REP(i,n) a[i] = in();

    int m2 = 0, m1 = 0;
    REP(i,n){
        if (a[i] == -2) m2++;
        if (a[i] == -1) m1++;
    }

    VI ans;
    if (m2 % 2 == 0){
        REP(i,n){
            if (abs(a[i]) == 2) ans.push_back(i);
        }
    }else{
        if (m1){
            int c = 1;
            REP(i,n){
                if (abs(a[i]) == 2 || (a[i] == -1 && c == 1)){
                    ans.push_back(i);
                    if (a[i] == -1) c = 0;
                }
            }
        }else{
            int c = m2 - 1;
            REP(i,n){
                if (a[i] == 2 || (a[i] == -2 && c > 0)){
                    ans.push_back(i);
                    if (a[i] == -2) c--;
                }
            }
        }
    }

    cout << ans.size() << endl;
    for (int x : ans) cout << x + 1 << endl;

    return 0;
}


Measured memory_bytes: 3232
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }


    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);


        var input = Reads();
        var n = input[0];
        var input0 = Reads();
        var h = new long[n];
        for (long i = 0; i < n; i++)
            h[i] = input0[i];
        long count = 1;
       
        for(int i = 1; i < n; i++)
        {
            bool b = false;
            for (int j = 0; j < i; j++)
            {
                if (h[i] < h[j])
                    b = true;
            }
            if (!b)
                count++;
        }
        Console.WriteLine(count);


        Console.Out.Flush();
    }
}

Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
	char[][] map;
	int h, w;
	char c;
	
	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			h = scan.nextInt();
			w = scan.nextInt();
			if (w == 0 && h == 0) break;
			map = new char[h][];
			int section = 0;
			for (int i = 0; i < h; i++)
				map[i] = new char[w];
			for (int y = 0; y < h; y++) {
				char[] str = scan.next().toCharArray();
				for (int x = 0; x < w; x++) {
					map[y][x] = str[x];
				}
			}
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					if (map[y][x] != 'x') {
						c = map[y][x];
						solve(y, x);
						section++;
					}
				}
			}
			System.out.println(section);
		}
	}
	
	void solve(int y, int x) {
		if (y < 0 || x < 0 || y >= h || x >= w || map[y][x] != c) return;
		map[y][x] = 'x';
		solve(y + 1, x);
		solve(y - 1, x);
		solve(y, x + 1);
		solve(y, x - 1);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 29836
n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
B = [[1] * n for _ in range(n)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            if k != i and k != j:
                if A[i][j] > A[i][k] + A[k][j]:
                    print(-1)
                    exit()
                elif A[i][j] == A[i][k] + A[k][j]:
                    B[i][j] = 0

ans = 0
for i in range(n):
    for j in range(i):
        if B[i][j]:
            ans += A[i][j]

print(ans)


Measured memory_bytes: 46172
import java.util.Scanner;

public class Main {

	static boolean[] primes;

	static void primeSet(final int MAX){
		primes = new boolean[MAX+1];

		primes[2] = true;
		for(int i=3;i<=MAX;i+=2){
			primes[i] = true;
		}
		int rt = (int) Math.sqrt(MAX);
		for(int i=3;i<=rt;i+=2){
			if(primes[i]){
				for(int j=i*2;j<=MAX;j+=i){
					primes[j] = false;
				}
			}
		}
	}

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

		primeSet(110000);

		while(true){
			int n = stdIn.nextInt();
			int sum = 0;
			int cnt = 0;
			
			if(n==0){
				return;
			}
			
			for(int i=2;;i++){
				if(primes[i]){
					cnt++;
					sum+=i;
				}
				if(cnt==n){
					break;
				}
			}
			System.out.println(sum);
		}	
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N=1e5+10;
typedef long long ll;
typedef pair<int,ll> pil;
ll gi() {
    ll x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,m,top=0;
ll a[N],st[N],cnt[N],ans[N];
int rt[N],tr[N*50],ls[N*50],rs[N*50],tot=0;
void update(int &o,int l,int r,int x,int p,int v) {
    o=++tot;ls[o]=ls[x];rs[o]=rs[x];tr[o]=v;
    if(l==r) return; int mid=(l+r)>>1;
    p<=mid?update(ls[o],l,mid,ls[x],p,v):update(rs[o],mid+1,r,rs[x],p,v);
}
int query(int o,int l,int r,int L,int R) {
    if(!o||L>R) return 0;
    if(L<=l&&r<=R) return tr[o];
    int mid=(l+r)>>1,ret=0;
    if(L<=mid) ret=max(ret,query(ls[o],l,mid,L,R));
    if(R>mid) ret=max(ret,query(rs[o],mid+1,r,L,R));
    return ret;
}
vector<pil> op[N];
void solve(int now,int x,ll l) {
    int p=upper_bound(st+1,st+top+1,l)-st-1;
    int y=query(rt[x-1],1,top,1,p);
    if(!y) {
        if(l>=n) op[now].pb(mp(0,l/n)),l%=n;
        op[now].pb(mp(l,0));return;
    }
    op[now].pb(mp(y,l/a[y]));
    solve(now,y,l%a[y]);
}
int main() {
    cin>>n>>m;
    for(int i=1;i<=m;i++) a[i]=gi(),st[++top]=a[i];
    sort(st+1,st+top+1);top=unique(st+1,st+top+1)-st-1;
    for(int i=1;i<=m;i++) {
        int p=lower_bound(st+1,st+top+1,a[i])-st;
        update(rt[i],1,top,rt[i-1],p,i);
    }
    for(int i=1;i<=m;i++) solve(i,i,a[i]);
    cnt[m]=1;
    for(int i=m;i;i--) {
        for(int j=0;j<int(op[i].size())-1;j++) cnt[op[i][j].fi]+=cnt[i]*op[i][j].se;
        ans[op[i].back().fi]+=cnt[i];
    }
    ans[n]+=cnt[0];
    for(int i=n-1;i;i--) ans[i]+=ans[i+1];
    for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 55936
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

bool used1[4], used2[4];

int main()
{
//	cut here before submit 
//	freopen ("testcase.HB", "r", stdin );
	while (1 ){
		memset (used1, false, sizeof (used1 ) );
		memset (used2, false, sizeof (used2 ) );

		string s1 = "", s2 = "";
		getline (cin, s1 );
		getline (cin, s2 );
		if (s1.empty() || s2.empty() ) break;
		int hit = 0, blow = 0;
		vector<int> a (4, 0 ), b (4, 0 );
		stringstream ssa (s1 ), ssb (s2 );
		rep (i, 4 ) ssa >> a[i];
		rep (j, 4 ) ssb >> b[j];

		rep (i, 4 ){
			if (a[i] == b[i] ){
				hit++;
				used1[i] = true; used2[i] = true;
			} // end if
		} // end rep
		rep (i, 4 ){
			rep (j, 4 ){
				if (!used1[i] && !used2[j] && a[i] == b[j] ){
					blow++;
					used1[i] = true;
					used2[j] = true;
				} // end if
			} // end rep
		} // end rep
		cout << hit << ' ' << blow << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, m, n) for (int i = m; i < n; i++)
using T = tuple<int, int, int>;

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  vector<string> s(h);
  for (string &i : s) cin >> i;
  vector<vector<int>> l(h, vector<int>(w, -1));
  deque<tuple<int,int,int>> q;
  q.push_back(T(ch, cw, 0));
  while (!q.empty()) {
    auto [gh, gw, gl] = q.front();
    q.pop_front();
    if (l[gh][gw] != -1) continue;
    l[gh][gw] = gl;
    if (gh + 1 < h and s[gh + 1][gw] == '.') q.push_front(T(gh + 1, gw, gl));
    if (gh - 1 >= 0 and s[gh - 1][gw] == '.') q.push_front(T(gh - 1, gw, gl));
    if (gw + 1 < w and s[gh][gw + 1] == '.') q.push_front(T(gh, gw + 1, gl));
    if (gw - 1 >= 0 and s[gh][gw - 1] == '.') q.push_front(T(gh, gw - 1, gl));
    FOR(i, -2, 3) FOR(j, -2, 3) {
      int nh = gh + i, nw = gw + j;
      if (0 <= nh and nh < h and 0 <= nw and nw < w and s[nh][nw] == '.') q.push_back(T(nh, nw, gl + 1));
    }
  }
  cout << l[dh][dw] << endl;
  return 0;
}

Measured memory_bytes: 10832
x, k, d = map(int, input().split())
x = abs(x)

if x - k*d > 0:
    print(x-k*d)
else:
    v = x // d
    k -= v
    x = x - d*v
    if k % 2 == 0:
        print(x)
    else:
        print(min(abs(x-d), abs(x+d)))

Measured memory_bytes: 9148
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */
ll n,k;

/* add your algorithm here */

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


Measured memory_bytes: 256
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		int a=gInt(),b=gInt();
		String x="",y="";

		for(int i:rep(a))
			x+=b;
		for(int i:rep(b))
			y+=a;

		System.out.println(a<b?y:x);
	}

	public static void main(String[] args){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}

Measured memory_bytes: 29140
int N, i;
int n, sum, max;
char* s[] = {"No", "Yes"};
int main(){
  scanf("%d", &N);
  for(i=0; i<N; i++){
    scanf("%d", &n);
    if(n>max){max=n;}
    sum += n;
  }
  puts(s[max<<1<sum]);
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    string s; cin >> s;
    string y = s.substr(0, 4);
    string m = s.substr(5, 2);
    string d = s.substr(8, 2);

    if(y > "2019" || y == "2019" && m > "04") {
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def main():
    input = sys.stdin.readline
    h, w, k = map(int, input().split())
    C = []
    for _ in range(h):
        C.append(input())
    ans = 0

    for hbit in range(1<<h): # red row bit h = 2なら 00 ~ 11 100(=2^2)　左ビットシフト 1 -> 100
        for wbit in range(1<<w): # red col bit
            c = 0
            for i in range(h):
                for j in range(w):
                    #9 = 0b1001　を 右ビットシフト　9 >> 1 にすると 100
                    #i, jだけそれぞれ右ビットシフトした時に1になっていたらフラグが立っている.
                    #この実装だと 1だと上書きしないパターン
                    if hbit>>i & 1 and wbit>>j & 1:
                        if C[i][j] =='#': c += 1
            if c == k: ans += 1
    print(ans)

    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
signed main(){
 	int n; cin>>n;
  	if(n%2)
      cout<<0;
  	else{
      n /= 2;
    	if(n==0)
          cout<<0;
      	else{
        	int k = 5;
          int ans =0;
          while(n/k > 0){
          	ans += n/k;
            k *= 5ll;
          }
          cout<<ans;
        }
    }
  	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	const int m = 1000;
	int n, t, a, i, j = 1;
	float h[m], min;
	cin >> n>>t>>a;
	for (i = 1; i <= n; i++)
	{
		cin >> h[i];
		h[i] = t - 0.006*h[i];
	}
	for (i = 1; i <= n; i++)
	{
		h[i] = abs(h[i] - a);
	}
	min = h[1];
	for (i = 1; i < n; i++)
	{
		if (min > h[i + 1]) { min = h[i + 1]; j=i+1; }
	}

	cout << j;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


const ll MAX = 202020;
const ll MOD = 1e9+7;
ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll p[202020], q[202020];
ll modpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % MOD;
		a = a * a % MOD;
		n >>= 1;
	}
	return res;
}


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

	int B, W;
	cin >> B >> W;
	combinit();
	
	ll mul = 1;
	for (int i = 1; i <= B + W; i++) {
		mul *= inv[2];
		mul %= MOD;
		p[i] = p[i - 1] + mul*comb(i-1,B-1);
		q[i] = q[i - 1] + mul*comb(i-1,W-1);
		p[i] %= MOD;
		q[i] %= MOD;
		ll ans = inv[2] * (1LL + q[i-1] - p[i-1] +8LL * MOD);
		puts(ans % MOD);
	}
	
	return 0;
}


Measured memory_bytes: 10112