akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
char a[50][50];
int main()
{

    int h, w;
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    cin >> h >> w;
    char c;
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (a[i][j] == '#')
            {
                int count = 0;
                for (int k = 0; k < 4; ++k)
                {
                    if (i + dy[k] >= 0 && i + dy[k] < 50 && j + dx[k] >= 0 && j + dx[k] < 50 && a[i + dy[k]][j + dx[k]] == '.')
                    {
                        ++count;
                    }
                }
                if (count == 4)
                {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int N,M;
int students[50][2];
int checkpoints[50][2];
int abs(int i){
  if(i<0) return -i;
  else return i;
}
int sum(int i,int j){
  return abs(students[i][0]-checkpoints[j][0])+abs(students[i][1]-checkpoints[j][1]);
}
int main(){
  scanf("%d %d",&N,&M);
  for(int i=0;i<N;i++){
    scanf("%d %d",&students[i][0],&students[i][1]);
  }
  for(int i=0;i<M;i++){
    scanf("%d %d",&checkpoints[i][0],&checkpoints[i][1]);
  }
  for(int i=0;i<N;i++){
    int min=987654321;
    int cnt=-1;
    for(int j=0;j<M;j++){
      if(min>sum(i,j)){
        min=sum(i,j);
        cnt=j;
      }
    }
    printf("%d\n",cnt+1);
  }
}


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

typedef long long ll;

int n;
ll dp[1 << 17];
ll t[102];
ll bit[102];

void solve(){
  ll ans = 0;

  memset(dp, -1, sizeof(dp));
  dp[0] = 0;

  for(int i = 0; i < (1 << 16); i++){
    if(dp[i] == -1) continue;
    ans = max(ans, dp[i]);

    for(int j = 0; j < n; j++){
      if((i & bit[j]) != 0) continue;

      int idx = (i | bit[j]);
      dp[idx] = max(dp[idx], dp[i] + t[j]);
    }
  }

  cout << ans << endl;
}

int main(){
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      int m;
      cin >> m >> t[i];
      bit[i] = 0;

      for(int j = 0; j < m; j++){
        int from, to;
        cin >> from >> to;

        from -= 6;
        to -= 6;

        for(int k = from; k < to; k++){
          bit[i] |= (1 << k);
        }
      }
    }
    solve();
  }
}

Measured memory_bytes: 2196
from collections import Counter
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
while True:
    W, D = map(int, input().split())
    if not (W | D):
        break
    hw = [int(x) for x in input().split()]
    hd = [int(x) for x in input().split()]
    print(sum(hw) + sum(hd) - sum(k * v for k, v in (Counter(hw) & Counter(hd)).items()))

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

int main()
{
	int a, b;
	cin >> a >> b;
	if (a == 1)
	{
		switch (b)
		{
		case 1:cout << "Draw";
			break;
		default:cout << "Alice";
			break;
		}
	}
	else if (b == 1)
	{
		switch (a)
		{
		case 1:cout << "Draw";
			break;
		default:cout << "Bob";
			break;
		}
	}
	else
	{
		if (a == b)
		{
			cout << "Draw";
		}
		else if (a > b)
		{
			cout << "Alice";
		}
		else
		{
			cout << "Bob";
		}
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
alst = list(map(int, input().split()))
for i in range(n):
  alst[i] -= (i + 1)
alst.sort()
c1 = alst[n // 2]
c2 = alst[n // 2 - 1]

ans = min(sum([abs(a - c1) for a in alst]), sum([abs(a - c2) for a in alst]))
print(ans)


Measured memory_bytes: 26180
#editorial参照
#ga = 0,,,aのxor
#fab = gb-ga
a,b = map(int, input().split( ))

def g(x):
    x1 = (x&1) ^ (x>>1&1)
    x2 = 0
    if not x%2:
        x2 = (x>>1)<<1
    return x1^x2

ans = g(b)^g(a-1)

print(ans)

        

Measured memory_bytes: 39856
N, *X = map(int, open(0).read().split())
sorted_X = sorted(X)
median_l = sorted_X[N // 2 - 1]
median_r = sorted_X[N // 2]

for x in X:
    if x < median_l:
        print(median_r)
    elif x == median_l:
        print(median_r)
    elif x == median_r:
        print(median_l)
    else:
        print(median_l)


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

using namespace std;

int main(){
	int N, X, Y;
	cin >> N >> X >> Y;
	X--; Y--;
	vector<vector<int>> G(N);
	rep(i,N-1){
		G[i].emplace_back(i+1);
		G[i+1].emplace_back(i);
	}
	G[X].emplace_back(Y);
	G[Y].emplace_back(X);
	vector<int> ans(N);
	rep(i,N){
		vector<int> dist(N,-1);
		dist[i]=0;
		queue<int> q;
		q.push(i);
		while(!q.empty()){
			int n=q.front(); q.pop();
			int d=dist[n];
			ans[d]++;
			rep(j,G[n].size()){
				int next=G[n][j];
				if(dist[next]!=-1) continue;
				dist[next]=d+1;
				q.push(next);
			}
		}
	}
	for(int i=1; i<N; i++) cout << ans[i]/2 << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ls (rt << 1)
#define rs (rt << 1 | 1)
const int maxn = 4e5 + 10;
int n, m, tot, ans;
int Max[maxn << 2], Add[maxn << 2], C[maxn];
struct seg
{
	int l, r;
}a[maxn];
bool cmp(const seg & i, const seg & j)
{
	return i.r < j.r;
}
inline int lowbit(const int & x) { return x & (-x);}
void add(int x, int val)
{
	for(int i = x; i < maxn; i += lowbit(i)) C[i] += val;
}
int sum(int x) 
{
	int ret = 0;
	for(int i = x; i; i -= lowbit(i)) ret += C[i];
	return ret;
}
void pushup(int rt)
{
	Max[rt] = max(Max[ls], Max[rs]);
}
void build(int rt, int l, int r)
{
	if(l == r) 
	{
		Max[rt] = l - 1;
		return;
	}
	int mid = l + r >> 1;
	build(ls, l, mid); build(rs, mid + 1, r);
	pushup(rt);
}
void lazy(int rt, int val)
{
	Max[rt] += val;
	Add[rt] += val;
}
void pushdown(int rt)
{
	if(Add[rt])
	{
		lazy(ls, Add[rt]);
		lazy(rs, Add[rt]);
		Add[rt] = 0;
	}
}
void update(int rt, int l, int r, int a, int b, int val)
{
	if(a <= l && r <= b)
	{
		lazy(rt, val);
		return;
	}
	pushdown(rt);
	int mid = l + r >> 1;
	if(a <= mid) update(ls, l, mid, a, b, val);
	if(b > mid) update(rs, mid + 1, r, a, b, val);
	pushup(rt);
}
int query(int rt, int l, int r, int a, int b)
{
	if(a <= l && r <= b)
		return Max[rt];
	pushdown(rt);
	int mid = l + r >> 1;
	int lMax = 0, rMax = 0;
	if(a <= mid) lMax = query(ls, l, mid, a, b);
	if(b > mid) rMax = query(rs, mid + 1, r, a, b);
	return max(lMax, rMax);
}
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		if(l == 0 && r == m + 1) ++ans;
		else
		{
			++tot;
			a[tot].l = r;
			a[tot].r = l + m;
			if(a[tot].r <= m)
			{
				++tot; a[tot] = a[tot - 1];
				a[tot].l += m;
				a[tot].r += m;
			}
		}
	}
	sort(a + 1, a + tot + 1, cmp);
	build(1, 1, 2 * m);
	for(int i = 1; i <= 2 * m; ++i) add(i, 1);
	for(int i = 1; i <= tot; ++i)
	{
		//cout << ' ' << a[i].l << ' ' << a[i].r << endl;
		update(1, 1, 2 * m, 1, a[i].l, 1);
		int ret = query(1, 1, 2 * m, max(1, a[i].r - m + 1), a[i].r);
		if(ret > sum(a[i].r))
		{
			++ans;
			add(a[i].r, 1);
			if(a[i].r + 1 <= 2 * m)
				update(1, 1, 2 * m, a[i].r + 1, 2 * m, 1);
			if(a[i].r <= m)
			{
				add(a[i].r + m, 1);
				if(a[i].r + m + 1 <= 2 * m)
					update(1, 1, 2 * m, a[i].r + m + 1, 2 * m, 1);
			}
		}
	}
	ans = max(ans, n - m);
	cout << ans << endl;
	return 0;
}
/*
3 2
0 1
1 2
2 3
*/

Measured memory_bytes: 13640
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define ld long double
#define pii pair <int,int>
#define pll pair <ll,ll>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define ull unsigned long long
#define pdd pair <double,double>
#define pb push_back
#define mp make_pair
#define puu pair<ull,ull>
#define pvv pair<vector<int>, vector<int> >
#define _bp __builtin_popcount
#define ptt pair <Tree*,Tree*>
#define all(v) v.begin(),v.end();
const long double pi = acos(-1);
void boos()
{
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file()
{
   freopen(".in","r",stdin);
   freopen(".out","w",stdout);
}
const ll INF = 1e9 + 7;
const ll INF1 = 998244353;
const ll LLINF = (ll)1e18;
const int  INTmx = (int)1e9;
const int N = 2e5 + 100;
ll dp[N];
ll a[N];
int main()
{
    //file();
    boos();
    int n,k;
    cin >> n >> k;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        dp[i] = LLINF;
    }
    dp[1] = 0;
    for(int i = 1;i < n;i++)
    {
        for(int j = i + 1;j <= min(i + k,n);j++)
        {
            dp[j] = min(dp[j],dp[i] + abs(a[j] - a[i]));
        }
    }
    cout << dp[n];
}

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

#define int             long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

int gcd(int a, int b)
{
	return !b ? a : gcd(b, a % b);
}

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

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}



void solve()
{
	int n,k,count=0;
	cin>>n>>k;
	vector<int>v(n);
	for(int i =0;i<n;i++)
	cin>>v[i];
	sort(v.begin(),v.end());
	for(int i =0;i<k;i++)
	count+=v[i];
	cout<<count<<endl;
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;

signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n;
	string s,t;
	cin>>n>>s>>t;
	for(int i=0;i<n;i++)
	{
		cout<<s[i]<<t[i];
	}
	cout<<"\n";
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	var S string
	var zero, one float64
	var r float64
	s := bufio.NewScanner(os.Stdin)
	b := make([]byte, 1000000)
	s.Buffer(b, 1000000)
	s.Scan()
	S = s.Text()
	for i := 0; i < len(S); i++ {
		if S[i:i+1] == "0" {
			zero++
		} else {
			one++
		}
	}
	r = math.Min(zero, one) * 2
	fmt.Println(r)
}

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int gSum;

struct Input {
    int a;
    int b;
    int c;
    int d;
};

void combination(vector<int> &A, uint i, int M, vector<Input> &data) {
    //cout << i << endl;
    if (i == A.size()) {
        int sum = 0;
        for (auto &dt: data) {
            if ((A[dt.b] - A[dt.a]) == dt.c) {
                sum += dt.d;
            }
        }
        gSum = max(sum, gSum);
        return;
    }

    for (int v=A[i-1]; v <= M; v++) {
        A[i] = v;
        combination(A, i+1, M, data);
    }
}

int main() {

    int N, M, Q;
    cin >> N >> M >> Q;
    vector<Input> data(Q);
    vector<int> A(N+1, 0);
    for (size_t i=0; i<data.size(); i++) {
        cin >> data[i].a >> data[i].b >> data[i].c >> data[i].d;
    }
    gSum = 0;
    for (int v = 1; v <= M; v++) {
        A[1] = v;
        combination(A, 2, M, data);
    }
    cout << gSum << endl;
}



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

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

int main()
{
	int N;
	set<string> st;

	cin >> N;
	rep(i, N) {
		string S;
		cin >> S;
		st.insert(S);
	}

	cout << st.size() << endl;

	return 0;
}


Measured memory_bytes: 19216
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

vector<int> children[100010];
priority_queue<int> query[100010];
int markedAt[100010];
using ll = long long;

ll pull(int v) {
    ll res = 0;
    for (int c : children[v]) {
        res += pull(c);
        if (query[v].size() < query[c].size()) {
            swap(query[v], query[c]);
        }
        while (query[c].size()) {
            query[v].push(query[c].top());
            query[c].pop();
        }
    }
    while (query[v].size() && query[v].top() > markedAt[v]) {
        res += v + 1;
        query[v].pop();
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    while (cin >> n >> q && n) {
        fill(children, children + n, vector<int>());
        fill(query, query + n, priority_queue<int>());
        fill(markedAt, markedAt+n, 1e9);
        for (int i = 1; i < n; ++i) {
            int p;
            cin >> p;
            --p;
            children[p].push_back(i);
        }
        markedAt[0] = -1;
        for (int i = 0; i < q; i++) {
            char c;
            int v;
            cin >> c >> v;
            --v;
            if (c == 'Q') {
                query[v].push(i);
            } else {
                if (markedAt[v] == 1e9) {
                    markedAt[v] = i;
                }
            }
        }
        cout << pull(0) << endl;
    }
}

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

int main() {
  string S;
  cin >> S;

  int ans = 0;
  int l = S.length() - 1;
  for (int i = 0; i < S.length() / 2; ++i) {
    if (S[i] != S[l - i]) ans++;
  }
  cout << ans << endl;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007

// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <ll>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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



void solve() {
    int A,B;
    cin >> A >> B;
    int N8[10001];
    int N10[10001];
    FOR(i,1,10001){
        N8[i] = floor((double)i*0.08);
        N10[i] = floor((double)i*0.1);
    }    
    int min8=100000,min10=100000,max8=-1,max10=-1;
    FOR(i,1,10001){
        if(N8[i]==A){
            if(min8 == 100000){
                min8 = i;
            }
            max8 = i;
        }

        if(N10[i]==B){
            if(min10 == 100000){
                min10 = i;
            }
            max10 = i;
        }
    }
    if(min8 > max10 || min10 > max8){
        cout << -1;
        return;
    }

    cout << max(min8,min10);
    }

signed main() {

    solve();

    return 0;
}

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

#define AAA 10

void solve(long long A, long long B, long long K)
{
    long long ans_a, ans_b;
    if (K < A)
    {
        ans_a = A - K;
        ans_b = B;
    }
    else
    {
        ans_a = 0;
        ans_b = A + B - K;
    }

    if (ans_b < 0)
        ans_b = 0;

    cout << ans_a << " " << ans_b << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;--i)
#define ll long long
#define add(x,y)(x=((ll)y+x)%mo)
using namespace std;
const int N=55,mo=1e9+7;
int n,jc[N],ny[N],iv[N][N],f[N][N],v,ans,o;
int ksm(int x,int y){
	int t=1;
	for(;y;y>>=1,x=(ll)x*x%mo)if(y&1)t=(ll)t*x%mo;
	return t;
}
int main(){
	cin>>n;
	jc[0]=1;
	fo(i,1,n)jc[i]=(ll)jc[i-1]*i%mo;
	ny[n]=ksm(jc[n],mo-2);
	fd(i,0,n-1)ny[i]=(ll)ny[i+1]*(i+1)%mo;
	fo(i,0,n)fo(j,0,n-i)iv[i][j]=(ll)ny[i]*ny[j]%mo;
	f[1][0]=1;
	f[1][1]=1;
	fo(i,1,n)fo(j,0,n)if(v=f[i][j])
		fo(p,max(j,1),n-i)if(!(j+p&1))
			fo(l,0,p)
				add(f[i+p][abs(j+p-l*2>>1)],v*iv[p-l][l]);
	cout<<(ll)f[n][0]*jc[n]%mo;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 25

struct Node{
  int p,l,r;
};

struct Node t[N];
int n;
void preorder(int u){
  if(u==-1) return;
  printf(" %d",u);
  preorder(t[u].l);
  preorder(t[u].r);
}
void inorder(int u){
  if(u==-1) return;
  inorder(t[u].l);
  printf(" %d",u);
  inorder(t[u].r);
}
void postorder(int u){
  if(u==-1) return;
  postorder(t[u].l);
  postorder(t[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;
  scanf("%d",&n);
  for(i=0;i<n;i++){
        t[i].p=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    t[v].l=l;
    t[v].r=r;
    if(l!=-1){
      t[l].p=v;
    }
    if(r!=-1){
      t[r].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(t[i].p==-1) root=i;
  }
  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
    inorder(root);
  printf("\n");
  printf("Postorder\n");
  postorder(root);
  printf("\n");
  return 0;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    bool flag = true;
    for(int i=0;i<n;++i)
        cin >> a[i];
    for(int i=0;i<n;++i){
        if(!(a[i] & 1)){
            if(!(a[i]%3) || !(a[i]%5))
                flag = true;
            else { 
                flag = false;
                break;
            }
        }
    }
    if(flag)
        cout << "APPROVED\n";
    else 
        cout << "DENIED\n";
    return 0;
}

Measured memory_bytes: 256
from sys import stdin, exit
N = int(stdin.readline().rstrip())
A = sorted([int(_) for _ in stdin.readline().rstrip().split()], reverse=True)
sum_A = sum(A)
ans = 1
for a in A:
    sum_A -= a
    if a > sum_A * 2:
        break
    ans += 1
print(ans)

Measured memory_bytes: 63856
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vpi vector<pair<int,int> >
#define ll long long 
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
// #define mod 998244353
#define mod 1000000007
#define MAXN  1000001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void solve()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans = 0;
    ans += min(a,k);
    k -= min(a,k);
    if(k > 0)
    {
        k -= min(k,b);
    }
    if(k > 0)
    {
        ans -= min(k,c);
    }
    cout<<ans<<endl;
}

int main()
{
    fast;
    int t;
    t = 1;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3556
/*
Author:Jenil Mehta
Not yet serious but trying to be serious :)
Coding is lub
*/
 
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#define boostup ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
int main()
{
    ll k;
    cin>>k;
    ll sum=0;
    ll i,j,l;
    for(i=1;i<=k;i++)
    {
        for(j=1;j<=k;j++)
        {
            for(l=1;l<=k;l++)
            {
                sum+=__gcd(i,__gcd(j,l));
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3580
import itertools
m = a = r = c = h = 0
for i in xrange(input()):
    s = raw_input()
    if s[0] == "M":
        m += 1
    elif s[0] == "A":
        a += 1
    elif s[0] == "R":
        r += 1
    elif s[0] == "C":
        c += 1
    elif s[0] == "H":
        h += 1
ans = 0
for i in itertools.combinations((m,a,r,c,h), 3):
    ans += i[0]*i[1]*i[2]
print ans


Measured memory_bytes: 2692
#include<stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

static inline int gcd(int a,int b){
    int armin = min(a,b);
    int armax = max(a,b);
    int r;
    while(armin){
        r = armax;
        r %= armin;
        armax = armin;
        armin = r;
    }
    return armax;
}

int main(void){
    int k;
    scanf("%d",&k);
    long long ans = 0;
    register int i,j,l;
    for(i = 1;i <= k;i++)for(j = 1;j <= k;j++)for(l = 1;l <= k;l++)ans += gcd(i,gcd(j,l));
    printf("%lld",ans);
}

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

bool solve1159(int a[],int n);

int main() {
	int n=0,p=0;
	while(cin >> n >> p){
		if((n|p)==0)	break;
		int a[n];
		memset(a,0,sizeof(a));
		bool f=false;
		while(true){
			f=false;
			for(int i=0; i<n; i++){
				if(p>0){
					p--;	a[i]++;
					int temp=a[i];	a[i]=0;
					if(p==0 && solve1159(a,n)){
						cout << i << endl;
						f=true;
						break;
					}
					a[i]=temp;
				}else{
					p+=a[i];
					a[i]=0;
				}
			}
			if(f)	break;
		}
	}
	return 0;
}

bool solve1159(int a[],int n){
	for(int i=0; i<n; i++)	if(a[i]!=0)	return false;
	return true;
}

Measured memory_bytes: 864
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,W;
    cin>>n>>W;
    ll w[n+1],v[n+1];
    ll profit=0;
    for(ll i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
        profit+=v[i];
    }
    ll a[n+1][profit+1];
    for(ll i=0;i<=n;i++)
    {
        for(ll j=0;j<=profit;j++)
        {
            if(i==0 && j==0){
                a[i][j]=0;
                continue;
            }
            if(i==0){
                a[i][j]=1e11;
                continue;
            }
            if(j-v[i]<0)
            {
                a[i][j] = a[i-1][j];
            }
            else{
                a[i][j] = min(a[i-1][j],w[i]+a[i-1][j-v[i]]);
            }
            
        }
    }
    ll ans=0;
    for(ll i=0;i<=profit;i++)
    {
        if(a[n][i]<=W)
        {
            ans=i;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
 
int main(){
    int n;
    string s, ans;

    cin >> n >> s;

    for(int i=0; i < s.length(); i++){
        s[i] = s[i]+n;
        if(s[i] > 'Z') s[i] -= 26;
    }

    cout << s << endl;
}

Measured memory_bytes: 256
_, m = map(int, input().split())

mi, mx = map(int, input().split())
flag = False
for i in range(m-1):
    l, r = map(int, input().split())
    if mi < l <= mx:
        mi = l
    if mi <= r < mx:
        mx = r
    if mx < l or r < mi:
        flag = True
        break

if flag:
    print(0)
else:
    print(mx - mi + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
set<string>s;
string p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    ll t,i,j,n,m,l,r,x;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>p;
        s.insert(p);
    }
    cout<<(int)s.size()<<"\n";
    return 0;
}


Measured memory_bytes: 19284
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>

int dat[100005];
int t, n, k;

int main(){
	std::cin >> t;
	for (int i = 0; i < t; ++i){
		std::cin >> n >> k;
		int ans = 0, before;
		std::cin >> before;
		ans = -before;
		for (int j = 0; j < n - 1; ++j){
			int x;
			std::cin >> x;
			dat[j] = x - before;
			before = x;
		}
		ans += before;
		std::sort(dat, dat + n - 1, std::greater<int>());
		for (int j = 0; j < k - 1; ++j)ans -= dat[j];
		std::cout << (ans < 0 ? 0 : ans) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1564
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int f[200001];
int fi[200001];
int N = 200000;
int fp(int x,int y) {
	int res=1;
	while(y){
		if(y&1) res = res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res%mod;
}
int iv(int x){
	return fp(x, mod - 2);
}
int m(int x,int y){
	return (x * y) %mod;
}
int P(int x, int y){
	return m(f[y],fi[y - x]);
}
vector<int> g[100005];
int n,k;
int dfs(int u,int p){
	int res;
	if(g[u].size() == 1 && u != 1) res = 1;
	else{
		int ch = g[u].size() - (u != 1);
		res = P(ch, k - 1 - (u != 1));
		for(int v: g[u])
			if(v != p) res = m(res, dfs(v, u));
	}
	//cout << u << " " << res << endl;
	return res;
}
signed main(){
	f[0] = 1;
	for(int i = 1 ; i <= N ; i ++) f[i] = m(f[i - 1], i);
	fi[N] = iv(f[N]);
	for(int i = N - 1 ; i >= 0 ; i --) fi[i] = m(fi[i + 1], (i + 1));
	cin >> n >> k;
	for(int i = 1 ; i < n ; i ++){
		int u,v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i = 1 ; i < n ; i ++)
		if(g[i].size() + 1 > k){
			cout << 0;
			return 0;
		}
	cout << m(k,dfs(1, 0));
}

Measured memory_bytes: 13568
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,i = map(int, input().split())
    print(n+1-i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    int A[n];
    repi(i, n, 0)
    {
        cin >> A[i];
    }
    int ans = 0;
    int target = 1;
    repi(i, n, 0)
    {
        if (target != A[i])
        {
            ans++;
        }
        else
        {
            target++;
        }
    }
    if (ans == n)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;



int main()
{
    ll ar[3];
    ll sum=0;
    for(ll i=0;i<3;i++)
    {
        cin>>ar[i];
        sum+=ar[i];
    }

    if(sum>=22) cout<<"bust"<<nn;
    else cout<<"win"<<nn;




}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define REP(i, n) for(int i = 0; i < (n); 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 A first
#define B second
#define MOD 1000000007

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;
}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res, x);
        y = y >> 1;
        x = mulmd(x, x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a - b;
    if(ret < 0){
        ret += MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int invPow(ll a){
    return power(a, MOD - 2, MOD);
}

const int N = 1e5 + 5;

int arr[N];
int ans[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    FOR(i, 1, n - 1) cin >> arr[i];
    FOR(i, 1, n - 1){
        if(i == 1) {
            ans[i] = arr[i];
            ans[i + 1] = arr[i];
        }
        else {
            ans[i] = min(arr[i], ans[i]);
            ans[i + 1] = arr[i];
        }
    }
    int s = 0;
    FOR(i, 1, n) s += ans[i];
    cout << s;
}

/**
    Check out for boundary cases, (n = 1 or n = 0)
    check for integer overflow

**/


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

//FILE *in = freopen("input.txt", "r", stdin);

int data[40000];
int ddd[300200];

int n, m;

void init(){
	for(int i = 1; i*7 < 300100; i++) {
		{
			int t = i * 7 - 1;
			if(!ddd[t]) {
				ddd[t] = 1;
				for(int j = 2; j*t < 300100; j++) {
					ddd[j*t] = -1;
				}
			}
		}
		{
			int t = i * 7 + 1;
			if(!ddd[t]) {
				ddd[t] = 1;
				for(int j = 2; j*t < 300100; j++) {
					ddd[j*t] = -1;
				}
			}
		}
	}
	for(int i = 1; i<= 300100; i++) {
		if(ddd[i] == 1) {
			data[m++] = i;
		}
	}
}

int main() {
	init();
	while(true){
		scanf("%d", &n);
		if( n == 1) break;
		printf("%d:", n);
		bool flag = false;
		for(int i = 0 ; data[i] <= n; i++) {
			if(n % data[i] == 0) {
				printf(" %d", data[i]);
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2324
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,K;
    cin>>N>>K;
    if(K==1){
        cout<<0<<endl;
        return 0;
    }
    cout<<N-K<<endl;
}

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

namespace B
{
    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 kx = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var result = new List<int>();
            for (var i = kx[1] - (kx[0] - 1); i < kx[1] + kx[0]; i++)
            {
                result.Add(i);
            }
            Console.WriteLine(string.Join(" ", result));
        }
    }
}


Measured memory_bytes: 13396
a,b,k=map(int,input().split())
c=i=0
l=[]
while i<min(a,b):
    while i<min(a,b)and(a%-~i or b%-~i):
        i+=1
    i+=1
    if a%i<1and b%i<1:
        l.append(i)
print(l[-k])

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

using namespace std;

int n,k,a[100001];long long f[100001];

long long minn(int n)
{
    int i;
    if(n>k)i=n-k;
    else i=0;
    long long nn=f[i]+abs(a[i]-a[n]);
    i++;
    while (i<n)
    {
        nn=min(nn,f[i]+abs(a[i]-a[n]));
        i++;
    }
    return nn;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    memset(f,0,sizeof(f));
    a[0]=1000000001;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    for (int i=2; i<=n; i++)
    {
        f[i]=minn(i);
    }
    cout<<f[n];
    return 0;
}


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

int main() {
	int a, b;
	int ans = -10001;
	cin >> a >> b;
	if (a+b > ans)ans = a+b;
	if (a-b > ans)ans = a-b;
	if (a*b > ans)ans = a*b;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

int main() {
    ll n, t;
    cin >> n >> t;
    ll a[n];
    rep(i, n) cin >> a[i];
    vector<ll> v;
    rep(i, n) v.push_back(a[i]);
    sort(v.begin(), v.end());

    ll Max_diff = 0;
    ll cnt = 0;

    rep(i, n - 1) {
        v.erase(lower_bound(v.begin(), v.end(), a[i]));
        ll last = *(v.end() - 1);
        if (last - a[i] > Max_diff) {
            cnt = 1;
            Max_diff = last - a[i];
        } else if (last - a[i] == Max_diff) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int> 
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, -1, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == -1) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = p; 
        } 
    } 
    
} 
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}
 
ll power(unsigned ll x,unsigned  ll y) 
{ 
    ll res = 1;     
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1;
        x = x*x;  
    } 
    return res; 
}

//to calculate p1^x  *  p2^x2  *p3^x3 ----------
//i.e. prime factorization and store pi and xi in vector 
vector<pair<ll, ll>> pFactor;

void factorize(long long n) 
{ 
    int count = 0; 
  
    // count the number of times 2 divides  
    while (!(n % 2)) { 
        n >>= 1; // equivalent to n=n/2; 
        count++; 
    } 
  
    // if 2 divides it 
    if (count) 
        pFactor.pb({2,count}); 
  
    // check for all the possible numbers that can  
    // divide it 
    for (long long i = 3; i <= sqrt(n); i += 2) { 
        count = 0; 
        while (n % i == 0) { 
            count++; 
            n = n / i; 
        } 
        if (count) 
            pFactor.pb({i,count});
    } 
  
    // if n at the end is a prime number. 
    if (n > 2) 
        pFactor.pb({n,1}); 
} 



int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
  int n;
  cin>>n;
  pii a[n];
  lp(0,n) cin>>a[i].ff>>a[i].ss;
  bool fl=false;
  lp(0,n-2){
      if(a[i].ff==a[i].ss and a[i+1].ff == a[i+1].ss and a[i+2].ff==a[i+2].ss){
          fl=true;
          break;
      }
  }
  if(fl){
      cout<<"Yes\n";
  }else{
      cout<<"No\n";
  }
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
#define ll long long

int main () {
  ll k, a, b;
  cin >> k >> a >> b;
  if (a + 1 >= b) {
    cout << k + 1 << endl;
    return 0;  
  }  
  ll num = 1;
  if (a >= k) {
    cout << k + 1 << endl;
    return 0;   
  }
  k = k - a;
  num = 0;
  if (k % 2 == 1) {
    cout << a + (b - a) * (k + 1) / 2 << endl; 
  }
  else {
    cout << a + (b - a) * k / 2 + 1 << endl;  
  }

}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
using namespace std;
int main() {
	int X, Y;
	cin >> X >> Y;
	int N = Y / 2;
	cout << X + N << endl;
	
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  ll N, T; cin >> N >> T;
  ll t[N];
  rep(i,N) cin >> t[i];
  
  ll retval = 0;
  rep(i,N){
    if (i==0) retval += T;
    else retval += min<ll>(T, t[i]-t[i-1]);
  }

  cout << retval << endl;

  // cout << fixed << setprecision(6);
  return 0;
}



Measured memory_bytes: 1792
from fractions import*
n,*a=map(int,open(0).read().split())
b=a[:]
for i in range(1,n):
    a[i]=gcd(a[i],a[i-1])
    b[n-i-1]=gcd(b[n-i-1],b[n-i])
a=[0]+a
b+=0,
print(max(gcd(a[i],b[i+1])for i in range(n)))

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<ll> a(n);
    vector<ll> b(n);
    
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    
    ll c = 0;
    
    for(int i = n - 1;; i--){
  
        if(a[i] % b[i] == 0);
        else if(a[i] > b[i]) c += b[i] - (a[i] % b[i]);
        else c += b[i] - a[i];
        
        if(i == 0) break;
        else a[i-1] += c;
    }
    cout << c << endl;
}

 



Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
		if(a*a==b*b+c*c) System.out.println(b*c/2);
		else if(a*a+b*b==c*c)System.out.println(a*b/2);
		else System.out.println();
		sc.close();
	}
}

Measured memory_bytes: 24788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    string s;
    cin >> s;
    bool flag1 = true;
    for (ll i = a; i < max(b - 1, d - 1); i++) {
        if (s.substr(i, 2) == "##") flag1 = false;
    }
    if(c<d){
        if (flag1) cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else {
        bool flag2 = false;
        for (ll i = b - 1; i < min(n - 2, d);i++) {
            if (s.substr(i, 3) == "...") flag2 = true;
        }
        if (flag1 and flag2) cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010];
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int f=0;
	for(int i=n-1;i>=0;i--){
		f=a[i]-f;
	}
	cout<<f<<' ';
	for(int i=1;i<n;i++){
		f=(a[i-1]-f/2)*2;
		cout<<f<<' ';
	}
    return 0; 
}

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

int main(){
    
    int a,b;
    char op;
    
    while(1){
        cin >> a >> op >> b;
        if(op == '+') cout << a + b << endl;
        if(op == '-') cout << a - b << endl;
        if(op == '*') cout << a * b << endl;
        if(op == '/') cout << a / b << endl;
        if(op == '?') break;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;

int main(){
    int N; 
    cin >> N;
    int A[200000];
    int B[200000];
    int restA[200000];
    int restB[200000];
    for(int i = 0; i < N + 1; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        cin >> B[i];
    }
    for(int i = 0; i < N; i++){
        restA[i] = A[i];
        restB[i] = B[i];
    }
    long long counter = 0;
    for(int i = 0; i < N; i++){

        counter += min(restA[i] , B[i]);
        restB[i] -= min(restA[i], B[i]);
        counter += min(A[i + 1], restB[i]);
        restA[i + 1] -= min(A[i + 1], restB[i]);
    }

    cout << counter << endl;
}

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-12;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////



int main(){fastio
    string s;cin>>s;
    ll c=0;
    rep(i,0,2)if(s[i]=='R')c++;
    if(s=="RSR")cout<<1<<endl;
    else cout<<c<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3636