akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {


  while(1) {
    int a[5];
    int tu[3]={};
    for(int i=0;i<5;i++) {
      cin >> a[i];
      if(a[0] == 0) break;
      tu[a[i]-1]++;
    }

    if(a[0] == 0) break;

    int count = 0;
    int win = a[0];
    for(int i=1;i<5;i++) {
      if(a[0] == 1 && a[i] == 3) win = 3;
      else if(a[0] == 2 && a[i] ==1) win =1;
      else if(a[0] == 3 && a[i] == 2)win = 2;
    }
    for(int i=0;i<3;i++)
      if(tu[i] > 0) count++;
    
    if(count == 3 || count == 1){
      for(int i=0;i<5;i++) cout << 3 << endl;
      continue;
    }

    for(int i=0;i<5;i++) {
      if(a[i] == win) cout << 1 << endl;
      else cout << 2 << endl;
    }

    
  
  }
  
  return 0;
  
}
  

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

const int MAXN = 3002;

double dp[MAXN][MAXN],P[MAXN];
int vis[MAXN][MAXN],N;

double solve(int pos,int heads){
	
	if(heads < 0) return 0.0;

	if(pos == 0){
		return (heads == 0);
	}

	if(vis[pos][heads]) return dp[pos][heads];
	vis[pos][heads] = 1;

	return dp[pos][heads] =  (P[pos])*solve(pos-1,heads-1) + (1.0 - P[pos])*solve(pos-1,heads);

}

int main(){

	cin >> N;
	for(int i = 1;i<=N;i++){
		cin >> P[i];
	}

	double tot = 0;
	for(int heads = 0;heads<=N;heads++){
		int tails = N - heads;
		if(heads > tails) tot += solve(N,heads);
	}

	printf("%.9lf\n",tot);

	return 0;

}

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

constexpr int64_t MOD = 1e9 + 7;

bool is_agc(string str) {
    vector<string> tests = { str };
    for(int i=0; i<str.size()-1; i++) {
        string tmp = str;
        swap(tmp[i], tmp[i+1]);
        tests.push_back(tmp);
    }
    return any_of(tests.begin(), tests.end(), [&](auto test) {
        return (test.find("AGC") != string::npos);
    });
}

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

    vector<map<string, int>> dp(n+1, map<string, int>());
    dp[0]["TTT"] = 1;

    for (int i=0; i<n; i++) {
        for (auto last : dp[i]) {
            for (auto e : { 'A', 'C', 'G', 'T' }) {
                string next = last.first + e;
                if (!is_agc(next)) (dp[i+1][next.substr(1, 3)] += last.second) %= MOD;
            }
        }
    }
    
    int64_t ans = 0;
    for (auto e : dp[n]) {
        (ans += e.second) %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

struct edge{
  ll to,cost;
  edge(ll x,ll y){
    to = x;
    cost = y;
  }
};
int main(){
  ll N; cin >> N;
  vector<edge> list[N+1];
  ll dist[N+1];
  memset(dist,-1,sizeof(dist));
  for(ll i=0;i<N;i++){
    ll v,u,w; cin >> v >> u >> w;
    list[v].push_back({u,w});
    list[u].push_back({v,w});
  }
  dist[1] = 0;
  queue<ll> que; 
  que.push(1);
  while(!que.empty()){
    ll v = que.front(); que.pop();
    for(ll i=0;i<list[v].size();i++){
      edge e = list[v][i];
      if(dist[e.to]==-1||dist[e.to]>dist[v]+e.cost){
        dist[e.to] = dist[v]+e.cost;
        que.push(e.to);
      }
    }   
  }
  for(int i=1;i<=N;i++){
    if(dist[i]%2==0) cout << 0 << endl;
    else cout << 1 << endl;
  }
}


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

int main()
{
    string s;
    cin>>s;
    int res,counter=0;
    
    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
      res=3; 
    else if(s[0] == 'S' && s[1] == 'S' && s[2] == 'S')
      res=0;
    else if(s[0] == 'R' && s[1]=='R' && s[2]=='S')
      res=2;
    else if(s[0]=='S' && s[1]=='R' && s[2] == 'R')
      res=2;
    else
      res=1;
    
    cout<<res<<endl;
    return 0;
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)


inline bool check() {
	li n;
	cin >> n;
	rep(i, n) {
		li x;
		cin >> x;
		if (x % 2 > 0) {
			continue;
		}
		if (x % 3 != 0 && x % 5 != 0) {
			return false;
		}
	}
	return true;
}

int main() {
	cout << (check() ? "APPROVED" : "DENIED") << endl;

	return 0;
}


Measured memory_bytes: 256
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int N=200005;
///Code begin..................................................................
inline LL Scan() {
    LL x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int a[55];

int main ()
{
    int n;
    scanf("%d",&n);
    int ma=0, p=1;
    FOR(i,1,n) {
        scanf("%d",a+i);
        if (abs(a[i])>ma) ma=abs(a[i]), p=i;
    }
    printf("%d\n",2*n-1);
    FOR(i,1,n) printf("%d %d\n",p,i);
    if (a[p]<0) FDR(i,n,2) printf("%d %d\n",i,i-1);
    else FOR(i,1,n-1) printf("%d %d\n",i,i+1);
    return 0;
}


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

int main () {
  map<int, int> m;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    int x;
    cin >> x;
    if (!(m.count(x))) {
      m[x] = 1;
      count++;
    }
  }
  
  cout << count << endl;
}

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

vector<string> tile;

void solve(string s) {
    vector<string> _tile(3);
    _tile[0] = s.substr(0, 3);
    _tile[1] = s.substr(3, 3);
    _tile[2] = s.substr(6, 3);
//    cout << _tile[0] << endl << _tile[1] << endl << _tile[2] << endl;
    // check horizontal
    for (int i = 0; i < 3; i++) {
        if (_tile[i][0] == _tile[i][1] && _tile[i][1] == _tile[i][2]) {
//            cout << i << endl;
            if (_tile[i][0] == 's') {
                continue;
            }
            cout << _tile[i][0] << endl;
            return;
        }
    }
    // check vertical
    for (int i = 0; i < 3; i++) {
        if (_tile[0][i] == _tile[1][i] && _tile[1][i] == _tile[2][i]) {
            if (_tile[0][i] == 's') {
                continue;
            }
            cout << _tile[0][i] << endl;
            return;
        }
    }
    // check diag
    if (_tile[0][0] == _tile[1][1] && _tile[1][1] == _tile[2][2]) {
        if (_tile[0][0] == 's') {
            cout << 'd' <<endl;
            return;
        }
        cout << _tile[0][0] << endl;
        return;
    }
    if (_tile[0][2] == _tile[1][1] && _tile[1][1] == _tile[2][0]) {
        if (_tile[0][2] == 's') {
            cout << 'd' << endl;
            return;
        }
        cout << _tile[0][2] << endl;
        return;
    }
    cout << 'd' << endl;
}



//void solve(int n) {
//    vector<string> _tile(3);
//    for (int i = 0; i < 3; i++) {
//        _tile[i] = tile[i].substr(n, 3);
//    }
//
////    for (int i = 0; i < 3; i++) {
////        cout << _tile[i] << endl;
////    }
//
//    // check horizontal
//    for (int i = 0; i < 3; i++) {
//        if (_tile[i][0] == _tile[i][1] && _tile[i][1] == _tile[i][2]) {
//            if (_tile[i][0] == 's') {
//                cout << 'd' << endl;
//                return;
//            }
//            cout << _tile[i][0] << endl;
//            return;
//        }
//    }
//    // check vertical
//    for (int i = 0; i < 3; i++) {
//        if (_tile[0][i] == _tile[1][i] && _tile[1][i] == _tile[2][i]) {
//            if (_tile[0][i] == 's') {
//                cout << 'd' << endl;
//                return;
//            }
//            cout << _tile[0][i] << endl;
//            return;
//        }
//    }
//    // check diag
//    if (_tile[0][0] == _tile[1][1] && _tile[1][1] == _tile[2][2]) {
//        if (_tile[0][0] == 's') {
//            cout << 'd' <<endl;
//            return;
//        }
//        cout << _tile[0][0] << endl;
//        return;
//    }
//    if (_tile[0][2] == _tile[1][1] && _tile[1][1] == _tile[2][0]) {
//        if (_tile[0][2] == 's') {
//            cout << 'd' << endl;
//            return;
//        }
//        cout << _tile[0][2] << endl;
//        return;
//    }
//    cout << 'd' << endl;
//}

int main() {
//    tile.resize(3);
//    for (int i = 0; i < 3; i++) {
//        cin >> tile[i];
//    }
//    int lim = tile[0].size();
//    for (int i = 0; i < lim; i+=3) {
//        solve(i);
//    }
//    return 0;
    string s;
    while (cin >> s) {
        solve(s);
    }
    return 0;
}

Measured memory_bytes: 0
H,W = map(int, input().split())
Ss = [[j for j in input()] for i in range(H)]

ans = [[0 for j in range(W)] for i in range(H)]

mapping = {'.':0, '#':1}

for i in range(H):
    for j in range(W):
        if Ss[i][j] == '#':
            ans[i][j] = '#'
            continue
            
        if i>0 and j>0:
            ans[i][j] += mapping[Ss[i-1][j-1]]
        if j>0:
            ans[i][j] += mapping[Ss[i+0][j-1]]
        if i<H-1 and j>0:
            ans[i][j] += mapping[Ss[i+1][j-1]]
            
        if i>0:
            ans[i][j] += mapping[Ss[i-1][j+0]]
        if i<H-1:
            ans[i][j] += mapping[Ss[i+1][j+0]]
            
        if i>0 and j<W-1:
            ans[i][j] += mapping[Ss[i-1][j+1]]
        if j<W-1:
            ans[i][j] += mapping[Ss[i+0][j+1]]
        if i<H-1 and j<W-1:
            ans[i][j] += mapping[Ss[i+1][j+1]]
        
for i in range(H):
  ans_=''
  for j in range(W):
    ans_ += str(ans[i][j])
  print(ans_)

Measured memory_bytes: 41324
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)

n=int(input())
table=[(x-y,x+y)for x,y in [map(int,input().split()) for i in range(n)]]
a,b=[table[0][0]]*2,[table[0][1]]*2
ans=0
for x,y in table:
    ans=max(ans,abs(x-a[0]),abs(x-a[1]),abs(y-b[0]),abs(y-b[1]))
    a[0]=min(x,a[0])
    a[1]=max(a[1],x)
    b[0]=min(b[0],y)
    b[1]=max(b[1],y)
print(ans)

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

using namespace std;

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

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

char s[N];

bool isPal(string a) {
	int i = 0;
	int j = sz(a) - 1;
	while (i < j) {
		if (a[i] != a[j]) {
			return false;
		}
		i++;
		j--;
	}

	return true;
}

int main(void) {
	scanf("%s", &s);
	string a = (string)s;
	bool p = isPal(a);
	bool lp = isPal(a.substr(0, sz(a) / 2));
	bool rp = isPal(a.substr(sz(a) / 2 + 1));

	if (p && lp && rp) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	//scanf("%s", &s);
	return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, h, w = nin(3)

print((n - h + 1) * (n - w + 1))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
		int N;
		cin >> N;
		int a;
		int ans = 0;
		for (int i = 0; i < N; i++) {
				cin >> a;
				while(a > 0) {
						if (a % 2 == 0) {
								a /= 2;
								ans++;
						} else break;
				}
		}

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


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,a,b = map(int,input().split()) 
s = list(input())

count = 0
tmp = 0
for i in range(n):
    if s[i] == 'a' and count < a + b:
        count += 1
        print("Yes")
    elif s[i] == 'b' and count < a + b and tmp < b:
        count += 1
        tmp += 1
        print("Yes")
    else:
        print("No")


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

int c_neighbor[31];             // c???closed neighbor
int union_neighbor[31];         // {c,..,n-1}??§????????§?????????????????????
int n;

/* ???????????????
   c:    ?????¨?????????
   cost: ?????¨???????????????????????????
   mask: ?????§???????????????????????????????????????
   ans:  ???????????????????????????????????????

   0??????c-1?????§??????????????????cost??????????????§??§????????¨?????????????????????
   dominated???????????????????????¨?????????

   ????????¨???{c,...,n-1}?????????????????£?????§??????????????????????????§???????°????????´???°
   ???ans?????\?????????????????????ans??????????°??????????????????????????????´?????????????????????
   ????????¨???????????´?????????ans????????????????????????
*/
void dfs(int c, int cost, int dominated, int &ans)
{
  // ????????????
  if (cost >= ans) return;
  if ((dominated|union_neighbor[c]) != (1<<n)-1) return;

  // ??¨???????????§??????
  if (dominated == (1<<n)-1)
  {
    ans = min(ans, cost);
    return;
  }
  if (c >= n) return;

  dfs(c+1, cost, dominated, ans);                 // c????????????????????\?????????
  dfs(c+1, cost+1, dominated|c_neighbor[c], ans); // c????????????????????\??????
}

int main()
{
  int m;
  int u, v;
  while (cin >> n >> m)
  {
    bool found = false;

    if (n == 0) return 0;
    for (int i=0;i<n;i++) c_neighbor[i]=1<<i;
    for (int i=0;i<m;i++)
    {
      cin >> u >> v;
      c_neighbor[u] |= (1<<v);
      c_neighbor[v] |= (1<<u);
    }
    union_neighbor[n]=0;
    for (int i=n-1;i>=0;i--)
    {
      union_neighbor[i] = union_neighbor[i+1] | c_neighbor[i];
    }

    int ans = n;
    dfs(0, 0, 0, ans);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N=int(input())
A=list(map(int,input().split()))
dp=[0 for i in range(110000)]

for i in A:
    dp[i]+=1

S=sum(A)

Q=int(input())
for i in range(Q):
    b,c=map(int,input().split())
    bb,cc=dp[b],dp[c]
    S-=bb*b
    S+=bb*c
    dp[b]=0
    dp[c]+=bb
    print(S)

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

N = INT()
F = [LIST() for _ in range(N)]
P = [LIST() for _ in range(N)]

ans = -INF
for i in range(1, 1<<10):
	i = list("{:b}".format(i).zfill(10))
	profit = 0
	for j in range(N):
		cnt = sum([int(i[k])*F[j][k] for k in range(10)])
		profit += P[j][cnt]
	ans = max(ans, profit)

print(ans)

Measured memory_bytes: 5200
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,count;
	string s,a,b,temp;
	cin>>n;
	map<string,int> mp;
	while(n--){
		cin>>s;
		count=0;
		for(int i=1;i<(int)s.size();i++){
			a=s.substr(0,i);
			b=s.substr(i,s.size()-i);
			
			temp=a+b;
			if(!mp[temp]){
				count++;
				mp[temp]++;
			}
			temp=b+a;
			if(!mp[temp]){
				count++;
				mp[temp]++;
			}
			reverse(a.begin(),a.end());
			temp=a+b;
			if(!mp[temp]){
				count++;
				mp[temp]++;
			}
			temp=b+a;
			if(!mp[temp]){
				count++;
				mp[temp]++;
			}
			reverse(a.begin(),a.end());
			reverse(b.begin(),b.end());
			temp=a+b;
			if(!mp[temp]){
				count++;
				mp[temp]++;
			}
			temp=b+a;
			if(!mp[temp]){
				count++;
				mp[temp]++;
			}
			reverse(a.begin(),a.end());
			temp=a+b;
			if(!mp[temp]){
				count++;
				mp[temp]++;
			}
			temp=b+a;
			if(!mp[temp]){
				count++;
				mp[temp]++;
			}
		}
		mp.clear();
		cout<<count<<endl;
	}
	return 0;
}

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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

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

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    const ll maxN = 100;
    ll X, N;
    cin >> X >> N;
    vector<ll> p(N);
    vector<bool> inP(maxN + 1, false);
    REP(i, N)
    {
        cin >> p[i];
        inP[p[i]] = true;
    }

    vector<ll> a;
    REP(i, maxN + 1)
    {
        if (!inP[i])
        {
            a.push_back(i);
        }
    }
    a.push_back(maxN + 1);
    ll minV = LONG_MAX;
    ll ans;
    REPV(it, a)
    {
        if (minV > abs(X - *it))
        {
            minV = abs(X - *it);
            ans = *it;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int n; ll a, b;
VL h;
bool check(ll t) {
    ll dam = b * t, count = t;
    VL hp = h;
    for (ll &i : hp) {
        i -= dam;
        if (i > 0) {
            count -= i / a + (bool)(i % a);
        }
    }
    if (count >= 0)return true;
    return false;
}

int main() {
    init();
    cin >> n >> a >> b;
    a -= b;
    h.resize(n);
    cin >> h;

    ll ng = 0, ok = INF;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (check(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << "\n";
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
const MAX = 2000000000

var sc = bufio.NewScanner(os.Stdin)
var N int

type Arm struct {
	l, r int
}

var arms []Arm

type Arms []Arm

func (a Arms) Len() int           { return len(a) }
func (a Arms) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Arms) Less(i, j int) bool { return a[i].r < a[j].r }

func main() {
	sc.Split(bufio.ScanWords)
	N = nextInt()
	arms := make([]Arm, N)
	for i := 0; i < N; i++ {
		tmpX := nextInt()
		tmpL := nextInt()
		arms[i].l = tmpX - tmpL
		arms[i].r = tmpX + tmpL
	}

	sort.Sort(Arms(arms))
	//fmt.Println(arms[:N])

	prevR := arms[0].r
	ans := 1
	for i := 1; i < N; i++ {
		if arms[i].l >= prevR {
			ans++
			prevR = arms[i].r
		}
	}

	fmt.Println(ans)

}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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 int INF = 1e9;
const long long INFL = 1LL<<60;

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

  int n, m;
  cin >> n >> m;
  vector<pair<ll, int>> ab;
  rep(i, n) {
    int a, b; cin >> a >> b;
    ab.emplace_back(a, b);
  }

  sort(ALL(ab));

  ll ans = 0;
  ll rem = m;
  for (auto& p : ab) {
    if (p.second <= m) {
      ans += p.first * p.second;
      m -= p.second;
    } else {
      ans += p.first * m;
      m = 0;
    }
    if (m <= 0) break;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
  long long A;
  cin >> A;
  int ans = 9999;
  while(A>99){
    int d = A%1000 - 753;
    //cout << A << " " << d << endl;
    ans = min(ans,max(d,-d));
    A /= 10;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections
from heapq import *

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**8
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,M,R = LI()
    r = _LI()
    root = [[] for _ in range(N)]
    for _ in range(M):
        a,b,c = LI()
        root[a-1].append((b-1,c))
        root[b-1].append((a-1,c))

    memo = [[0] * N for _ in range(N)]

    min_r = INF
    for x in itertools.permutations(r):
        it = 0
        s = x[0]
        for t in x[1:]:
            if memo[s][t]:
                it += memo[s][t]
            else:
                node = [INF] * N
                q = []
                heapify(q)
                heappush(q,(0,s))
                node[s] = 0
                while q:
                    l,u = heappop(q)
                    if l > node[u]: continue
                    for v,m in root[u]:
                        if node[v] > l + m:
                            node[v] = l + m
                            heappush(q,(l+m,v))
                memo[s][t] = node[t]
                memo[t][s] = node[t]
                it += node[t]
            s = t
        min_r = min(min_r,it)
    print(min_r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 55384
from itertools import combinations
import numpy as np
import sys
input   = sys.stdin.readline
        #買う本
N, M, X = map(int, input().split())
C_np    = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)
all_book= [i for i in range(N)]  
flag    =False
price_list  =[]
#C_np        =np.array(C,dtype=int)
price       =C_np[:,0]
understand  =np.delete(C_np,0,1)
#for c in itertools.product([False, True], repeat=N):
for num in range(1,N+1): #1冊からN冊まで
    for t in combinations(all_book,num): #参考書を買う組合せ、全列挙
        book_buy        =np.array(t,dtype=int) 
        understand_now  = understand[book_buy] 
        understand_sum  = np.sum(understand_now, axis=0)
        if np.all(understand_sum >= X):
            price_now =price[book_buy]
            price_list.append(np.sum(price_now))
            flag =True
if flag ==True:
    print(min(price_list))
else:
    print(-1)

Measured memory_bytes: 27448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int N,M;cin >> N >> M;
  vector<ll> A(M,0);
  for(int i=0;i<M;i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  if(M==1){
    cout << 0 << endl;
    return 0;
  }
  vector<ll> B(M-1,0);
  for(int i=0;i<M-1;i++){
    B[i] = A[i+1] - A[i];
  }
  sort(B.begin(),B.end());
  ll ans = 0;
  for(int i=0;i<M-N;i++){
    ans += B[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
[N,Z,W]=map(int,raw_input().split())
A=map(int,raw_input().split())

if len(A)==1:
    print abs(A[-1]-W)
else:
    if abs(A[-1]-W)>abs(A[-1]-A[-2]):
        print abs(A[-1]-W)
    else:
        print abs(A[-1]-A[-2])


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    string s;
    cin >> s;
    int ans=0,x=0,y=0;
    for(char c:s){
        if(x<y){
            if(c=='g') ++ans;
            ++x;
        }else{
            if(c=='p') --ans;
            ++y;
        }
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

int main(){
  int N, L, R, sum;
  cin >> N;
  sum = 0;
   for (int i = 0; i < N; i++){
        cin >> L >> R;
        sum += R - L + 1;
   }
  cout << sum << endl;
}
      	    

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

int main() {
  ll h;
  cin >> h;
  int j;
  for(int i=0;i<1000;i++){
    if(h<pow(2,i)){
      j=i;
      break;
    }
  }
  ll ans=pow(2,j)-1;
  cout << ans << endl;
}




Measured memory_bytes: 256
#include <stdio.h>

#define DOUBLE(numb) (numb*2)
#define SUM(x ,y) (x + y)

int main() {
    int n, k, numb = 1;
    scanf("%d%d", &n, &k);

    for (int i = 0; i < n; ++i) {
        if((DOUBLE(numb)) > SUM(numb, k)){
            numb += k;
        }else{
            numb *= 2;
        }
    }

    printf("%d\n", numb);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll a, b, c;
    cin>>a>>b>>c;
    ll x = max(a, max(b, c));
    ll y = (x - a) + (x - b) + (x - c);
    ll ans;
    if(y % 2 == 0){
        ans = y / 2;
    }else{
        ans = y / 2 + 2;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

int n, m; set<int> S;

bool Check() {
	int nn = n;
	while (nn) {
		int digit = nn % 10;
		if (S.find(digit) != S.end()) {
			return false;
		}
		nn /= 10;
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i ++) {
		int x;
		scanf("%d", &x);
		S.insert(x);
	}
	while (!Check()) n ++;
	printf("%d\n", n);
}

Measured memory_bytes: 760
s = input()+'R'
dp = [0] * (len(s))
rr = 0
ll = 0
for i in range(len(s) - 1):
    if (s[i] == 'R'): rr += 1
    else: ll += 1
    if (s[i] == 'R' and s[i + 1] == 'L'):
        l = i
        r = i+1
    if (s[i] == 'L' and s[i + 1] == 'R'):
        dp[l] = (ll+rr) // 2
        dp[r] = (ll + rr) // 2
        if (rr - ll) % 2 == 1 and rr > ll and rr % 2 == 0: dp[r] += 1
        if (rr - ll) % 2 == 1 and rr > ll and rr % 2 == 1: dp[l] += 1
        if (rr - ll) % 2 == 1 and rr < ll and ll % 2 == 1: dp[r] += 1
        if (rr - ll) % 2 == 1 and rr < ll and ll % 2 == 0: dp[l] += 1
        ll = 0
        rr = 0
print(*dp[:-1]) 

Measured memory_bytes: 6376
#include <iostream>
//#include <map>
//#include <iterator>
//#include <fstream>
//#include <iomanip>
//#include <omp.h>
//#include <vector>
#include <string>
//#include <algorithm>
//#include <stdlib.h>
//#include <thread>
//#include <chrono>
//#include <cmath>
using namespace std;

int main()
{
	string A, B, C;
	cin >> A >> B >> C;
	cout << A.at(0) << B.at(0) << C.at(0);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

using P = pair<int, int>;
vector<int> s;
vector<vector<P>> g;
vector<int> es;
vector<bool> vis;
bool dfs(int u, int p) {
    if (vis[u]) return true;
    vis[u] = true;
    for (auto vi : g[u]) {
        int v, i;
        tie(v, i) = vi;
        if (v == p) continue;
        if (!vis[v]) {
            dfs(v, u);
            s[u] ^= s[v];
            es[i] = s[v];
        }
    }
    return s[u] == 0;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<P> ab(n);
    for (int i = 0; i < n; ++i) {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(begin(ab), end(ab));
    s.resize(n + 1);
    for (int i = 0; i < n; ++i) s[i] = ab[i].second;
    for (int i = 0; i <= n; ++i) cerr << s[i]; cerr << endl;
    for (int i = n; i >= 0; --i) s[i] ^= s[i - 1];
    for (int i = 0; i <= n; ++i) cerr << s[i]; cerr << endl;
    g.resize(n + 1);
    for (int i = 1; i <= m; ++i) {
        int l, r;
        cin >> l >> r;
        ++r;
        int li = lower_bound(begin(ab), end(ab), make_pair(l, 0)) - begin(ab);
        int ri = lower_bound(begin(ab), end(ab), make_pair(r, 0)) - begin(ab);
        g[li].emplace_back(ri, i);
        g[ri].emplace_back(li, i);
    }
    es.resize(m + 1);
    vis.resize(n + 1);
    for (int u = 0; u <= n; ++u) {
        if (!dfs(u, -1)) {
            cerr << u << endl;
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> res;
    for (int i = 1; i <= m; ++i) {
        if (es[i]) res.push_back(i);
    }
    cout << res.size() << '\n';
    for (int i : res) cout << i << ' ';
    cout << '\n';
    return 0;
}

Measured memory_bytes: 17020
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    long int x,a,b;
    cin >> x >> a >> b;
    if(a-b>=0){
        cout << "delicious";
    }else if(b-a<=x){
        cout << "safe";
    }else{
        cout << "dangerous";
    }
    
    return 0;
}

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

int main() {
    int N, T; cin >> N >> T;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }

    int cnt = 0;
    int maxsa = 0;
    int mi = A[0];
    for (int i = 1; i < N; i++){
        int sanow = A[i] - mi;
        if(sanow > maxsa){
            maxsa = sanow;
            cnt = 1;
        } else if(sanow == maxsa){
            cnt++;
        }
        mi = min(mi, A[i]);
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3772
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T& a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U>& p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector< T > &v) { rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "b.cpp"

int main() {
  ll x;
  cin >> x;
  ll cnt = 0;
  ll m = 100;

  while (x > m) {
    m += m / 100;
    cnt++;
  }
  cout << cnt << el;
}


Measured memory_bytes: 3652
st = input().split("T")
x, y = map(int, input().split())
XL = []; YL = []; t = 0
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))
    t += len(st[i])
if abs(x) + abs(y) > t:
    print("No")
else:
    T = max([abs(x), abs(y), t])
    xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
    yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
    xx[0][T]=True
    yy[0][T]=True
    xx[1][T+XL[0]]=True
    for i in range(2, len(XL)+1):
        for j in range(2*T+1):
            if j-XL[i-1] < 0:
                xx[i][j]=xx[i-1][j+XL[i-1]]
            elif j+XL[i-1] > 2*T:
                xx[i][j]=xx[i-1][j-XL[i-1]]
            else:
                xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]
    
    for i in range(1,len(YL)+1):
        for j in range(2*T+1):
            if j-YL[i-1] < 0:
                yy[i][j]=yy[i-1][j+YL[i-1]]
            elif j+YL[i-1] > 2*T:
                yy[i][j]=yy[i-1][j-YL[i-1]]
            else:
                yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

    if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
        print("Yes")
    else:
        print("No")


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

int main(){
	// sengen
	string s;

	// nyuryoku
	cin >> s;
	// keisan
	if(s[2] == s[3] && s[4] == s[5]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

string str;
void so(int& i,string& r,int k,char c){
    while(str[i]!=c&&i!=str.length()){
        if(str[i]=='X')
            r+=char(k+'0');
        else
            r+=str[i];
        i++;
    }
}
string add(string a,string b){
    string r;
    int p=0;
    if(a.length()>b.length())swap(a, b);
    for(int i=0;i<b.length();i++){
        if(i>=a.length()){
            r=char(b[b.length()-1-i]+p)+r;
            p=0;
        }
        else{
            int g=b[b.length()-1-i]+a[a.length()-1-i]-2*'0'+p;
            r=char('0'+g%10)+r;
            p=g/10;
        }
    }
    if(p)r=char('0'+p)+r;
    return r;
}
int main(){
    while(cin>>str){
        int s=0,k=0;
        for(;k<10;k++){
            string a,b,c;
            int i=0;
            so(  i,a,k,'+');
            so(++i,b,k,'=');
            so(++i,c,k,'.');
            if(add(a,b)==c){cout<<k<<endl;s=1;break;}
        }
        if(!s)cout<<"NA"<<endl;
    }
}

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

int		main()
{
	int N; cin >> N;
	vector<int> V(N);
	for (int i = 0; i < N; i++) cin >> V[i];
	
	bool f = true;
	int ans = 0;
	while (f)
	{
		for (int i = 0; i < N; i++)
		{
			if (V[i] % 2 != 0)
			{
				f = false;
				break;
			}
			V[i] /= 2;
		}
		if (f) ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

frame_in :: Int -> Int -> Char -> Char -> String
frame_in 0 _ _ _ = []
frame_in h w b i = [b] ++ inner ++ [b] ++ ['\n'] ++ frame_in (h - 1) w b i
  where inner = replicate (w - 2) i

frame :: Int -> Int -> Char -> Char -> String
frame 0 _ _ _ = []
frame h w b i = edge ++ ['\n'] ++ frame_in (h - 2) w b i ++ edge ++ ['\n']
  where edge = replicate w b

main = do
  [h, w] <- map (\x -> read x :: Int) . words <$> getLine
  when (h /= 0 || w /= 0) $ putStr (frame h w '#' '.') >> putChar '\n' >> main

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

int main(void) {
	i64 k, a, b;
	cin >> k >> a >> b;
	if (b - a <= 2) cout << 1 + k << endl;
	else {
		i64 kane = 0, hosi = 1, c = 1;
		while (c <= k) {
			if (kane == 1) {
				kane = 0;
				hosi += b;
			}
			else if (hosi >= a && c + 1 <= k) {
				kane = 1;
				hosi -= a;
			}
			else hosi++;
			
			//cout << hosi << ' ' << kane <<' '<< c << endl;
			
			c++;
		}
		cout << hosi << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
string x;
int main(){
	cin>>x;
	x[3]='8';
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 764
from operator import mul
from functools import reduce

n, m = map(int, input().split())
mod = 10 ** 9 + 7


def factorization(n):  # => {p:count,...}
    fac = {}
    for i in range(2, int(n ** .5) + 1):
        count = 0
        while n % i == 0:
            n //= i
            count += 1
        if count > 0:
            fac[i] = count
    if n > 1:
        fac[n] = 1
    return fac


def C(n, r , mod):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under % mod


ans = 1
for c in factorization(m).values():
    ans *= C(c + n - 1, c, mod)
    ans %= mod
print(ans)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n;
    string s;
    cin >> s;
    n = s.size();
    vector<int> ans(n, 0);
    int ev = 1, od = 0;
    for(int i=0;i<n-1;i++){
        if(s[i+1] == 'R'){
            if((i+1)%2) od++;
            else ev++;
        }
        else{
            if(i%2){
                ans[i] += od;
                ans[i+1] += ev;
            }
            else{
                ans[i] += ev;
                ans[i+1] += od;
            }
            od = 0;
            ev = 0;
        }
    }
    if(n%2){
        ev = 1;
        od = 0;
    }
    else{
        ev = 0;
        od = 1;
    }
    for(int i=n-1;i>0;i--){
        if(s[i-1] == 'L'){
            if((i-1)%2) od++;
            else ev++;
        }
        else{
            if(i%2){
                ans[i] += od;
                ans[i-1] += ev;
            }
            else{
                ans[i] += ev;
                ans[i-1] += od;
            }
            od = 0;
            ev = 0;
        }
    }
    REP(i,n){
        cout << ans[i] << " \n"[i==n-1];
    }
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+7;
int n;
ll A[N],F[N];
ll k;
bool cmp(ll a,ll b){
    return a>b;
}
bool check(ll ans){
    ll cnt=0;
    for(int i=0;i<n;i++){
        cnt+=max(0ll,A[i]-ans/F[i]);
    }
    if(cnt>k)return 0;
    return 1;
}
int main(){
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",&A[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%lld",&F[i]);
    }
    sort(A,A+n,cmp);
    sort(F,F+n);
    ll l=0,r=1e12,mid;
    while(l<r){
        mid=(l+r)/2;
        if(check(mid)){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    printf("%lld\n",l);
    return 0;
}


Measured memory_bytes: 3328
def resolve():
	n=int(input())
	w=[]
	sm=[]
	s=0
	w=list(map(int,input().split()))
	for i in w:
		s+=i
		sm.append(s)
	i=0
	while sm[i]*2<sm[-1]:
		i+=1
	print(min(abs(sm[i]*2-sm[-1]),abs(sm[i-1]*2-sm[-1])))
resolve()

Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int count = 0;
  int l = max({a,c});
  int r = min({b,d});
  //cout << l << "," << r << endl;
  int dis = max(r - l, 0);
  cout << dis << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <random>
#include <map>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)

int n;
int b[120];
int ans[120];

signed main(){
	cin>>n;
	rep(i,n)cin>>b[i];
	for(int i=0;i<n;i++){
		int val=0;
		for(int j=0;j<n-i;j++){
			if(b[j]==j+1)val=j+1;
		}
		if(val==0){
			cout<<-1<<endl;
			return 0;
		}
		else{
			ans[i]=val;
			for(int j=val;j<n-i;j++)b[j-1]=b[j];
		}
	}
	reverse(ans,ans+n);
	rep(i,n)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;
string s;
int main(){
    cin>>s;
    ll ans=0;
    for(ll i=0;i<s.length()/2;i++){
      if(s[i]!=s[s.length()-1-i]){
        ans++;
      }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    int n,k;
    string s;
    cin>>n>>k>>s;
    int i;
    vector<int> num(s.length(),0);
    int now=0;
    int ans=0;
    num.at(0)++;
    for(i=1;i<s.length();i++)
    {
        if(s.at(i)==s.at(i-1))num.at(now)++;
        else
        {
            now++;
            num.at(now)++;
        }
    }
    int len = now+1;
    for(i=0;i<len;i++)
    {
        num.at(i)--;
        ans+=num.at(i);
    }
    if(len%2==0)
    {
        ans += 2*min(len/2-1,k);
        k -= min(len/2-1,k);
        if(k>0)ans++;
    }
    else
    {
        ans += 2*min(len/2,k);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        long m = 0;
        long a = 0;
        long r = 0;
        long c = 0;
        long h = 0;
        for (int i = 0 ; i < N ; i++) {
            String s = sc.next();
            char ch = s.charAt(0);
            switch (ch) {
            case 'M':
                m++;
                break;
            case 'A' :
                a++;
                break;
            case 'R' :
                r++;
                break;
            case 'C' :
                c++;
                break;
            case 'H' :
                h++;
                break;
             default:
            }
        }
        long ans = m * a * r + m * a * c + m * a * h + m * r * c +
                m * r * h + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h;
        System.out.println(ans);
    }

}

Measured memory_bytes: 48404
# Author: cr4zjh0bp
# Created: Sat Mar 28 11:53:27 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict
from heapq import *

n, x, y = na()
x -= 1
y -= 1

g = [[] for _ in range(n)]
for i in range(n - 1):
    g[i].append(i + 1)
    g[i + 1].append(i)
g[x].append(y)
g[y].append(x)

def dijkstra(g, x):
    dist = [inf] * len(g)
    dist[x] = 0
    q = []
    proc = [False for _ in range(len(g))]
    heappush(q, (0, x))
    while len(q):
        p = heappop(q)
        a = p[1]
        if proc[a]:
            continue
        for b in g[a]:
            if dist[a] + 1 < dist[b]:
                dist[b] = dist[a] + 1
                heappush(q, (-dist[b], b))
    
    return dist

dic = defaultdict(int)
for i in range(n):
    dist = dijkstra(g, i)
    for i in range(n):
        dic[dist[i]] += 1

for i in range(1, n):
    print(dic[i] // 2)

Measured memory_bytes: 92892