akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;
using boost::math::gcd;
using boost::math::lcm;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){cin.tie(nullptr);ios::sync_with_stdio(false);}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

template<class T> void show_(const T& t) {cout<<t;}
template<class T> void show_(const vector<T>& v) {cout<<joined(v);}
void show_(bool b) {cout<<(b?"Yes":"No");}
void show_(double d) {cout<<fixed<<setprecision(12)<<d;}
template<class T, class... TS> void show_(const T& t, TS... ts) {show_(t);cout<<' ';show_(ts...);}
template<class T> void show(const T& t) {show_(t);cout<<LN;}
template<class T, class... TS> void show(const T& t, TS... ts) {show_(t, ts...);cout<<LN;}


ll K;
ll countK;

bool solve(int digits, int left, ll value) {
    if (digits == 0) {
        countK++;
        dump(value);
        if (countK == K) {
            show(value);
            return true;
        }
        return false;
    }
    for (int d : irange(max(0, left - 1), min(left + 2, 10))) {
        if (solve(digits - 1, d, value * 10 + d)) {
            return true;
        }
    }
    return false;
}

int main() {
    cin >> K;

    countK = 0;
    for (int digits = 1; true; digits++) {
        for (int d : irange(1, 10)) {
            if (solve(digits - 1, d, d)) {
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
L=[]
for i in range(H):
    for j in range(W-1):
        if A[i][j]%2==1:
            A[i][j]-=1
            A[i][j+1]+=1
            L.append((i+1,j+1,i+1,j+2))
for i in range(H-1):
    if A[i][W-1]%2==1:
        A[i][W-1]-=1
        A[i+1][W-1]+=1
        L.append((i+1,W,i+2,W))
print(len(L))
for y,x,y_,x_ in L:
    print(y,x,y_,x_)


Measured memory_bytes: 73052
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string sente = "Fennec";
string gote = "Snuke";

int N;
vector<int> G[210000];


int dist[210000];
int pre[210000];

int num[210000];

int rec(int v, int p) {
  int res = 1;
  for (int i = 0; i < G[v].size(); ++i) {
	int to = G[v][i];
	if (num[to] != -1) continue;
	if (to == p) continue;
	rec(to, v);
	res += num[to];
  }
  return num[v] = res;
}

string solve() {
  memset(dist, -1, sizeof(dist));
  dist[0] = 0;
  memset(pre, -1, sizeof(pre));
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
	int cur = que.front();
	que.pop();
	for (int i = 0; i < G[cur].size(); ++i) {
	  int to = G[cur][i];
	  if (dist[to] != -1) continue;
	  dist[to] = dist[cur] + 1;
	  que.push(to);
	  pre[to] = cur;
	}
  }
  vector<int> load;
  int cur = N-1;
  while (true) {
	load.push_back(cur);
	cur = pre[cur];
	if (cur == -1) break;
  }

  reverse(load.begin(), load.end());
  int res = 0;
  memset(num, -1, sizeof(num));
  for (int i = 0; i < load.size(); ++i) {
	num[load[i]] = 1;
  }
  for (int i = 0; i <= (int)(load.size() - 1) / 2; ++i) {
	res += rec(load[i], -1);
  }

  if (res > N/2) return sente;
  else return gote;
}


int main() {
  while (cin >> N) {
	for (int i = 0; i < 210000; ++i) G[i].clear();
	for (int i = 0; i < N-1; ++i) {
	  int a, b;
	  cin >> a >> b;
	  --a, --b;
	  G[a].push_back(b);
	  G[b].push_back(a);
	}
	cout << solve() << endl;
  }
}


















Measured memory_bytes: 11256
#include<bits/stdc++.h>
using namespace std;
int n,a[100009],b[100009];
long long ans;
int main() {
	scanf("%d",&n);
	for(int i=0;i<n+1;i++) scanf("%d",a+i);
	for(int i=0;i<n;i++) scanf("%d",b+i);
	for(int i=n-1;i>=0;i--) {
		if(a[i+1]<b[i]) {
			b[i]-=a[i+1];
			ans+=1ll*a[i+1];
		}
		else {
			ans+=1ll*b[i];
			continue;
		}
		if(a[i]<b[i]) {
			ans+=a[i];
			a[i]=0;
		}
		else {
			ans+=b[i];
			a[i]-=b[i];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

const int MAXN = 1e5;
const int INF = 1e9;
vector<int> dp(MAXN+5, INF);

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	
	dp[0] = 0;
	for(int i = 1; i < n; i++){
		for(int j = max(0,i-k); j < i; j++){
			dp[i] = min( dp[i], dp[j]+abs(h[i]-h[j]) );
		}
	}
	
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"
import "bufio"
import "os"
import "strings"
import "strconv"

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func main() {
	line := nextLine()
	cols := strings.Split(line, " ")

	month, _ := strconv.Atoi(cols[0])
	day, _ := strconv.Atoi(cols[1])

	if month > day {
		fmt.Println(month - 1)
	} else {
		fmt.Println(month)
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>


using namespace std;

int main()
{
	int n, k;
	int mini, max1, max2;
	cin >> k >> n;
	vector<int> v(n);
	int ans = 2*n;

	for(int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}

	int diff = (k - v[n-1]) +  v[0];	
	for(int i = 1; i < n; ++i)
	{
		diff = max(diff, v[i]-v[i-1]);
        }
	cout << k - diff;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pi 3.14159265358979323846
#define mod 1000000007
int main()
{ 
    ll p;
    //cin>>p;
    p=1;
    while(p--)
    {
        ll a,b,c,d,e,sum=0;
        string A;
        cin>>A;
        for(c=0;c<A.length();c++)
        {
            sum=sum+A[c]-'0';
        }
        if(sum%9==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int result = Math.min(a, b) + Math.min(Math.max(a, b), c);

		System.out.println(result);
	}
}


Measured memory_bytes: 22996
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const int M = 1000000007;
ll qpow(ll a, ll n)
{
    ll re = 1;
    while(n)
    {
        if(n & 1)
            re = (re * a) % M;
        n >>= 1;
        a = (a * a) % M;
    }
    return re % M;
}
ll Combination(ll n, ll m)
{
    ll ans = 1;
    for(ll i=n; i>=(n-m+1); --i){
        ans *= i;
        ans %= M;
    }
    while(m)
    {
        ans *= qpow(m,M-2);
        ans %= M;
        m--;
    }
    return ans;
}
int main()
{
    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    ll sum = 0;
    sum  = qpow(2,n) - 1 - (Combination(n,a) + Combination(n,b)) % M;
    sum = (sum + M) % M;
    printf("%lld\n", sum);
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

int a[N];

void solve() {
  int n, l; scanf("%d%d", &n, &l);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }
  vector<int> v;
  for (int i = 0; i < n-1; ++i) {
    if (a[i]+a[i+1] < l) continue;
    v.push_back(i);
    for (int j = i-1; j >= 0; --j) v.push_back(j);
    for (int j = i+1; j < n-1; ++j) v.push_back(j);
    reverse(v.begin(), v.end());
    puts("Possible");
    for (int e: v) printf("%d\n", e+1);
    return;
  }
  puts("Impossible");
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4328
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

lint table[10000010];

int main(){
    int n;
    scanf("%d", &n);
    For(i, 1, n+1) table[i] = i;
    For(i, 2, n+1)if(table[i] == i){
        for(lint j=1; j*i<=n; ++j){
            lint t = j*i, cnt = 1;
            while(t % i == 0){
                t /= i;
                ++cnt;
            }
            table[j*i] *= cnt;
        }
    }
    printf("%lld\n", accumulate(table+1, table+n+1, 0LL));
}

Measured memory_bytes: 81900
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])

p = [0]*Q
q = [0]*Q
for i in range(Q):
    p0,q0 = II()
    p[i] = p0-1
    q[i] = q0-1

a = [[0]*N for _ in range(N)]
for i in range(M):
    a[x[i][0]][x[i][1]] += 1

c = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if j==0:
            temp = 0
        else:
            temp = c[i][j-1]
        c[i][j] = temp + a[i][j]

for i in range(Q):
    ans = 0
    for j in range(p[i],q[i]+1):
        ans += c[j][q[i]]
    print(ans)

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

using namespace std;

struct circle
{
    int x, y, r, c;
    circle(int _x, int _y, int _r, int _c) : x(_x), y(_y), r(_r), c(_c) {}
};

int N;
int res = 0;
void dfs(int sum, vector<int> in, int state, vector<bool> &used, vector<circle> &cs, vector<vector<int>> &G)
{
    int flag = 1;
    if (used[state])
    {
        return;
    }
    for (int i = 0; i < N; i++)
    {
        if (state & (1 << i))
            continue;
        for (int j = i + 1; j < N; j++)
        {
            if (state & (1 << j))
                continue;

            if (in[i] == 0 && in[j] == 0 && cs[i].c == cs[j].c)
            {
                auto in2 = in;
                auto s = state;
                flag = 0;
                for (int nv : G[i])
                {
                    in2[nv]--;
                }
                for (int nv : G[j])
                {
                    in2[nv]--;
                }
                s |= (1 << i);
                s |= (1 << j);
                dfs(sum + 2, in2, s, used, cs, G);
            }
        }
    }
    if (flag)
        res = max(res, sum);

    used[state] = 1;
}

int main()
{
    while (cin >> N, N)
    {
        res = 0;
        vector<circle> circles(N, circle(0, 0, 0, 0));
        for (int i = 0; i < N; i++)
        {
            int x, y, r, c;
            cin >> x >> y >> r >> c;
            circles[i] = circle(x, y, r, c);
        }
        vector<vector<int>> G(N, vector<int>());
        vector<int> in(N);
        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                auto c1 = circles[i];
                auto c2 = circles[j];
                if ((c1.r + c2.r) * (c1.r + c2.r) > ((c1.x - c2.x) * (c1.x - c2.x) + (c1.y - c2.y) * (c1.y - c2.y)))
                {
                    G[i].push_back(j);
                    in[j]++;
                }
            }
        }
        vector<bool> used(1 << N);
        dfs(0, in, 0, used, circles, G);
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 5112
N = [int(i) for i in input().split()]
n1,n2,n3,n4=0,0,0,0
for n in N:
  if n == 1:
    n1 = 1
  elif n == 9:
    n2 = 1
  elif n == 7:
    n3 = 1
  elif n == 4:
    n4 = 1
if n1==n2==n3==n4==1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1; 
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
const int N=1<<18;
int main()
{IOS;
	int n;cin>>n;
	vector<ll>s(n+1,0);
	auto calc=[&](int l,int o,int r)
	{
		ll t[4]={s[l],s[o]-s[l],s[r]-s[o],s[n]-s[r]};
		sort(t,t+4);
		return t[3]-t[0];
	};
	for(int i=1,x;i<=n;++i)
		cin>>x,s[i]=s[i-1]+x;
	ll ans=1LL<<61;
	for(int l=1,o=2,r=3;o<n-1;++o)
	{
		while(l<o-1&&abs(s[o]-2*s[l])>abs(s[o]-2*s[l+1]))
			++l;
		while(r<n-1&&abs(s[n]-2*s[r]+s[o])>abs(s[n]-2*s[r+1]+s[o]))
			++r;
		ans=min(ans,calc(l,o,r));
	}
	cout<<ans<<Endl;
}

Measured memory_bytes: 1792
size = int(input())

A = input()
B = []
for i in A.split():
    B.append(int(i))

if min(B) == 0:
    mul = 0
else:
    mul = 1
    for i in range(len(B)):

        mul *= B[i]

        if mul > 10**18:
            mul = -1
            break

print(mul)

Measured memory_bytes: 84512
N, M, Q = map(int, input().split())
a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

mx = 0

def dfs(Aary):
    global mx

    if len(Aary) == N + 1:
        scr = score(Q, Aary, a, b, c, d)
        if mx < scr:
            mx = scr
        return

    Aary.append(Aary[-1])
    while Aary[-1] <= M:
        dfs(Aary.copy())
        Aary[-1] += 1

def score(Q, A, a, b, c, d):
    ans = 0
    for i in range(Q):
        if A[b[i]] - A[a[i]] == c[i]:
            ans += d[i]

    return ans

dfs( [1] )

print(mx)


Measured memory_bytes: 9168
char*z,a[2][204];n,m,i,p;main(c){for(;m=scanf("%d %[^\n] %[^\n]",&n,a,a+1)*n;printf(m>n?"NA\n":"%d\n",m))for(i=2;i--;m=c)for(c=p=0;z=p+p+a[c+i&1],c<m&&*z&2|n+~p;)p+=p<n&*z<50?*z-49|z[2]-49?++c,2:1:-1;}

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

const int maxN=2e5+1;

int n,q;
char str[maxN];
char t[maxN];
char d[maxN];

bool good(bool type,int pos){
    for(int i=1;i<=q;i++){
        if(t[i]==str[pos]){
            if(d[i]=='L'){
                pos--;
            } else {
                pos++;
            }
        }
        if(type && pos==n+1){
            return 1;
        } else if(pos==0){
            return 1;
        }
    }

    return 0;
}

int main(){
    cin>>n>>q>>(str+1);
    for(int i=1;i<=q;i++){
        cin>>t[i]>>d[i];
    }

    int st=0,dr=n;
    int sol1=0;
    while(st<=dr){
        int mij=(st+dr)/2;
        if(good(0,mij)){
            sol1=mij;
            st=mij+1;
        } else {
            dr=mij-1;
        }
    }

    int sol2=n+1;
    st=0,dr=n+1;
    while(st<=dr){
        int mij=(st+dr)/2;
        if(good(1,mij)){
            sol2=mij;
            dr=mij-1;
        } else {
            st=mij+1;
        }
    }

    if(sol1<sol2){
        cout<<sol2-sol1-1;
    } else {
        cout<<0;
    }

    return 0;
}

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

int sum(int *save, int n, int p)
{
  int i;
  int sum;
  
  sum = 0;
  i = 0;
  while (i < n)
  {
    sum += (save[i] - p) * (save[i] - p);
    i++;
  }
  return (sum);
}

int ft_min(int *save, int n)
{
  int min;
  int i;
  
  i = 0;
  min = save[0];
  while (i < n)
  {
    if (min > save[i])
       min = save[i];
    i++;
  }
  return (min);
}

int ft_max(int *save, int n)
{
  int max;
  int i;
  
  i = 0;
  max = save[0];
  while (i < n)
  {
    if (max < save[i])
       max = save[i];
    i++;
  }
  return (max);
}

int main()
{
  int n;
  int i;
  int min;
  int *save;
  int p;
  
  scanf("%d", &n);
  
  save = (int *)malloc(sizeof(int) * n);
  
  i = 0;
  while (i < n)
  {
    scanf("%d", &save[i]);
    i++;
  }
  
  if (n == 1)
  {
    printf("%d", 0);
    return (0);
  }  
  p = ft_min(save, n);
  min = sum(save, n, p);
  p++;
  while (p <= ft_max(save, n))
  {
     if (min > sum(save, n, p))
     {
       min = sum(save, n, p);
     }
    p++;
  }
  
  printf("%d", min);
  return (0);
}

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

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

    if (s == "SUN") cout << 7 << endl;
    if (s == "SAT") cout << 1 << endl;
    if (s == "FRI") cout << 2 << endl;
    if (s == "THU") cout << 3 << endl;
    if (s == "WED") cout << 4 << endl;
    if (s == "TUE") cout << 5 << endl;
    if (s == "MON") cout << 6 << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int N;
    vector< pair<int, int> > A;
    cin >> N;
    REP(i, N) {
        int a;
        cin >> a;
        A.push_back(make_pair(a, i+1));
    }
    SORT(A);
    REP(i, N) {
        printf("%lld%c", A[i].second, (i == N-1) ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 2544
#include<stdio.h>

int main(void)
{
	int a, b, c, num;
	scanf("%d %d %d", &a, &b, &c);
	if (a == b&&a == c) num = 1;
	else if (a == b || a == c || b == c) num = 2;
	else num = 3;
	printf("%d\n", num);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
double ans,d,x;
int n;
int main(){
	scanf("%d%lf%lf",&n,&d,&x);
	while (n){
		ans+=d+(2*n-1)*x/2;
		d=(n+1)*d/n+5*x/2/n;
		x=(n+2)*x/n;
		n--;
	}
	printf("%.10lf\n",ans);
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}

class CAttention {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int N;
    string S;
    cin >> N >> S;
    vector<int> cum_sum(N + 1, 0);
    rep(i, S.size()) {
      if (S[i] == 'W') cum_sum[i + 1]++;
      cum_sum[i + 1] += cum_sum[i];
    }
    int ans = INF;
    rep(i, S.size()) {
      ans = min(ans, cum_sum[i] + ((int)S.size() - (i + 1) - (cum_sum[S.size()] - cum_sum[i + 1])));
    }
    cout << ans << endl;
  }
};


signed main() {
  CAttention solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
const ll INF = 1e9, MOD = INF + 7;

/////////////////////////////////////////////////////////////////////

const int N = 3e5 + 5;

int a[N];

int main(){
	
	sync;

	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);

	double ans = a[0];
	for(int i = 1; i < n; i++) {
		ans = (1.0 * (ans + a[i])) / 2.0;
	}

	cout << fixed << setprecision(5) << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int i,m[100],f[100],r[100];
  for(i=1;i<100;i++){
    scanf("%d %d %d",&m[i],&f[i],&r[i]);

    if(m[i]==-1&&f[i]==-1&&r[i]==-1){
      break;
    }
  }
  for(i=1;i<100;i++){
    if(m[i]==-1&&f[i]==-1&&r[i]==-1){
      break;
    }

    if(m[i]==-1||f[i]==-1||m[i]+f[i]<30){
      printf("F\n");
    }
    else if(m[i]+f[i]>=80){
      printf("A\n");
    }
    else if(m[i]+f[i]<80&&m[i]+f[i]>=65){
      printf("B\n");
    }
    else if(m[i]+f[i]<65&&m[i]+f[i]>=50||r[i]>=50){
      printf("C\n");
    }
    else if(m[i]+f[i]<50&&m[i]+f[i]>=30){
      printf("D\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2072
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
point = 0
for i in range(n):
    a= list(map(int, input().split()))
    x = 0
    for j in range(m):
        x += a[j]*b[j]
    x += c
    if x > 0:
        point += 1
print(point)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            if (input[1] <= 500 * input[0]) Console.WriteLine("Yes");
            else Console.WriteLine("No");
            
            //Console.WriteLine(input[1] <= 500 * input[0] ? "Yes" : "No");
        }
    }
}


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

#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol Mod=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
lol sum[100010];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  for(int i=1;true;i++){
    sum[i]=pow(i,5);
    if(sum[i]<sum[i-1]){
      //cout <<i<<'\n';
      break;
    }
  }
  cin >>n;
  for(int i=5000;i>0;i--){
    for(int j=i;j>=0;j--){
      if(sum[i]-sum[j]==n){
	cout <<i<<' '<<j<<'\n';
	return 0;
      }else if(sum[i]+sum[j]==n){
	cout <<i<<' '<<-j<<'\n';
	return 0;
      }
    }
  }
  /*
  int i=0;
  while(sum[i]<n) i++;
  
  for(int j=i;j>=0;j--){
    if(sum[i]-sum[j]==n){
      cout <<i<<' '<<j<<'\n';
      return 0;
    }
  }
  i--;
  for(int j=i;j>=0;j--){
    if(sum[i]+sum[j]==n){
      cout <<i<<' '<<-j<<'\n';
      return 0;
    }
    }*/
  return (0);
}


Measured memory_bytes: 4236
use std::cmp::max;

fn main() {
    let k: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut ans: Vec<i8> = Vec::new();
    for _ in 0..k {
        let mut i = 0;
        while i <= ans.len() {
            if i == ans.len() {
                ans.push(1);
                break;
            } else if ans[i] < 9 {
                if i + 1 == ans.len() || (ans[i] + 1 - ans[i + 1]).abs() <= 1 {
                    ans[i] += 1;
                    break;
                }
            }
            i += 1;
        }
        for j in (0..i).rev() {
            ans[j] = max(0, ans[j + 1] - 1);
        }
    }
    
    let ans = ans.iter().rev().map(|x| x.to_string()).collect::<Vec<_>>().join("");
    println!("{}", ans);
}

Measured memory_bytes: 2120
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <fstream>
#include <tuple>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto& i : a)
#define foraj(a) for(auto& j : a)
#define forak(a) for(auto& k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0);
#define pb(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort(a.begin(), a.end());
#define sortm(a, n) sort(a, a + n);
#define reversi(a) reverse(a.begin(), a.end());
#define fi first
#define se second
#define yes cout << "Yes\n";
#define no cout << "No\n";
#define ans(a) cout << a << '\n';
#define res(a, n) a.resize(n);
#define read(a, n) a.resize(n); fori(n) cin >> a[i];
//#define int long long
//#define double long double

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<int, pair<int, int>>> viii;
typedef pair<int, pair<int, int>> iii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;
typedef vector<bool> vb;
typedef set<int> si;
typedef set<ii> sii;
typedef unsigned long long ull;
typedef pair<ull, ull> ullll;
typedef pair<double, double> dd;
typedef vector<dd> vdd;
typedef vector<pair<ull, ull>> vullll;
typedef pair<bool, bool> bb;
typedef vector<bb> vbb;
typedef vector<vector<ii>> vvii;
typedef vector<vector<iii>> vviii;

const int INF = 2147483647;
const ll LONGINF = 9223372036854775807;
const ll MOD = 1e9 + 7;

void solve()
{
    string s;
    cin >> s;
    if (s[1] == 'R')
    {
        if (s[0] == s[2])
        {
            if (s[0] == 'R') ans(3)
            else ans(1)
        }
        else ans(2)
    }
    else if (s[0] == 'R' || s[2] == 'R') ans(1)
    else ans(0)
}

signed main()
{
    fast
    bool mult = false;
    if (mult)
    {
        int t;
        cin >> t;
        while (t--) solve();
    }
    else solve();
}


Measured memory_bytes: 3184
#include <iostream>
#include <set>
#include <string>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

int main()
{
	ll i,j,k;
	ll N,M,T;
	ll p[200] = {0};
	string S;
	cin >> S;
	ll s_len = S.size();
	ll dp[128][4] = {0};
	for(i = 0; i< s_len; ++ i)
	{
		p[i] = (int)(S[s_len-i-1]-'0');
	}
	cin >> N;
	dp[0][0] = 1;
	dp[0][1] = 9;
	dp[0][2] = 0;
	dp[0][3] = 0;
	for(i=1;i<s_len;++i)
	{
		dp[i][0] = 1;
		dp[i][1] = dp[i-1][1] + dp[i-1][0]*9;
		dp[i][2] = dp[i-1][2] + dp[i-1][1]*9;
		dp[i][3] = dp[i-1][3] + dp[i-1][2]*9;
	}

	ll ans;
	if(s_len > 1)
	{
		ans = dp[s_len-2][N];
		ans += dp[s_len-2][N-1]*(p[s_len-1]-1);
		k = 1;
		for(i=1;i<N;++i,++k)
		{
			if(s_len-2-k < 0)
			{
				if(N-i-1 == 0)
					ans += p[s_len-k-1];
				break;
			}
			if(p[s_len-k-1] == 0)
			{
				--i;
				continue;
			}
			ans += dp[s_len-2-k][N-i];
			ans += dp[s_len-2-k][N-i-1]*(p[s_len-k-1]-1);
		}
		if(i == N)
			ans ++;
	}
	else
	{
		if(N==1)
			ans = p[0];
		else
			ans = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll unsigned long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int n;
ll a[200005],k;
bool check(ll x){
	ll cnt=0;
	FOR(i,1,n){
		cnt+=(a[i]%x!=0)+(a[i]/x);
		cnt--;
		if(cnt>k)RE 0;
	}
	RE 1;
}
signed main(){
	cin>>n>>k;
	FOR(i,1,n){
		cin>>a[i];
	}
	ll l=1,r=1e9,mid,ans=-1;
	while(r>=l){
		mid=(l+r)>>1;
		if(check(mid)){
			ans=mid;
			r=mid-1;
		}else l=mid+1;
	}
	cout<<ans;
	RE 0;
}




Measured memory_bytes: 5028
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    int a, b;
    cin >> a >> b;
    int res = 0;
    for (int i = a; i <= b; i++) {
        string s = to_string(i);
        int flag = 1;
        for (int j = 0; j < s.size() - 1 - j; j++) {
            if (s[j] != s[s.size() - 1 - j]) {
                flag = 0;
                break;
            }
        }
        res += flag;
    }
    cout << res << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mod 1000000007
#define ar array
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

void init() {
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  int mx = -1, cnt = 0;
  for (int i = 0; i <= n - m; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      if (s[i + j] == t[j])
        cnt++;
    }
    mx = max(mx, cnt);
  }
  cout<<m-mx<<endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;


int main(){
    vector<int> a(3);
    for(int i=0;i<3;i++)cin>>a[i];
    sort(a.begin(),a.end());
    cout<<a[1]-a[0]+a[2]-a[1]<<endl;
    
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long a[5005],x,ans,k,sum,n,maxn[5005][5005];
int main()
{
	scanf("%lld%lld",&n,&x);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",a+i);
		a[n+i]=a[i];
		ans+=a[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n+1;j++)
		{
			maxn[i][0]=a[i];
			maxn[i][j]=min(maxn[i][j-1],a[n+i-j]);
		}
	for(int i=0;i<n;i++)
	{
		sum=0;
		for(int j=1;j<=n;j++)
			sum+=maxn[j][i];
		sum+=i*x;
		ans=min(ans,sum);
	}
	printf("%lld\n",ans);
}

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

import sys
def input(): return sys.stdin.readline().strip()
    
from heapq import heappop, heappush

# 今回はダイクストラするので、データの持ち方は隣接リスト
N = int(input())
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, c))
    # 無向グラフなのでこっちも入れる
    nodes[b].append((a, c))

def dijkstra(nodes, start):
    # 最短距離メモ
    memo = [float('inf')] * (len(nodes))
    # スタート位置
    que = [(0, start)]
    memo[start] = 0
    # キューが空になるまで
    while len(que) != 0:
        # startからの距離, 現在のノード
        dist, cur = heappop(que)
        # 出発ノードcurの到着ノードでループ
        for nxt, cost in nodes[cur]:
            # 今回の経路のが短い時
            if memo[cur] + cost < memo[nxt]:
                memo[nxt] = memo[cur] + cost
                # 現在の移動距離をキューの優先度として、早い方から先に処理するようにする
                heappush(que, (memo[nxt], nxt))
    # ノードstartからの最短距離リストを返却
    return memo

Q, K = map(int, input().split())
# 引数：(ノードの隣接リスト, 出発ノード)
memo = dijkstra(nodes, K)

for i in range(Q):
    x, y = map(int, input().split())
    # 今回は全てKを経由するので、Kからの距離さえ分かれば全部出る
    print(memo[x] + memo[y])


Measured memory_bytes: 84912
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    
    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N;
        static int[] C, S, F;
        
        public static void Input()
        {
            var cin = new Solve();

            N = int.Parse(Console.ReadLine());
            if (N == 1) { return; }
            C = new int[N];
            S = new int[N];
            F = new int[N];
            for(var i = 0; i < N-1; i++)
            {
                int[] input = cin.SplitReader();
                C[i] = input[0];
                S[i] = input[1];
                F[i] = input[2];
            }
        }

        static void Main(string[] args)
        {
            
            Input();
            if (N == 1) { Console.WriteLine(0);
                return;
            }
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            int[] ans = new int[N];
            for(var i = 0; i < N; i++)
            {
                ans[i] = 0;
                for(var j = i; j < N; j++)
                {
                    if (i == j) { continue; }
                    if (ans[i] < S[j - 1]) { ans[i] = S[j - 1] + C[j - 1]; }
                    else
                    {
                        int r = ans[i] % F[j - 1];
                        if (r == 0)
                        {
                            ans[i] += C[j - 1];
                        }
                        else
                        {
                            ans[i] += F[j - 1] - r + C[j - 1];
                        }
                    }
                }
            }

            for(var i = 0; i < N; i++)
            {
                Console.WriteLine(ans[i]);
            }

            //Console.Out.Flush();
        }

        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    
}



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

int main() {
  int n;

  cin >> n;

  vector<int> x(n);

  for (int i = 0; i < n; i++) cin >> x[i];

  sort(x.begin(), x.end());

  long ans = -1;

  for (int i = x[0]; i <= x[n - 1]; i++) {
    long tmp = 0;
    for (int j = 0; j < n; j++) {
      tmp += pow(x[j] - i, 2);
    }
    if (ans == -1)
      ans = tmp;
    else if (tmp < ans)
      ans = tmp;
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,ans=0,s;
	scanf("%d",&n);
	for(i=1;i<=n;i+=2)
	{
		s=0;
		for(j=1;j<=i;j++)
			if(i%j==0)
				s++;
		if(s==8)
			ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int solve(int i,int m);
int n,*A;
int main(){
  int *S,i,q,count=0,result;
 scanf("%d\n",&n);
  A=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d\n",&q);
  S=(int *)malloc(q*sizeof(int));
  for(i=0;i<q;i++){
    scanf("%d",&S[i]);
  }


  for(i=0;i<q;i++){
    result=solve(0,S[i]);
    if(result==1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
int solve(int i,int m){
  int res;
  //printf("%d %d\n",i,m);
  if(m==0) return 1;
  if(i>=n) return 0;
  res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
const int N=1e4+5;
int n,idx[N<<1],pos[N<<1],val[N<<1],org[N<<1];

inline int nxi(FILE *fd=stdin){
	int x=0;
	char c;
	while((c=fgetc(fd))>'9'||c<'0');
	while(x=x*10-48+c,(c=fgetc(fd))>='0'&&c<='9');
	return x;
}

inline bool cmp_org(const int a,const int b){
	return org[a]<org[b];
}

template <class T> inline void abs(const T x){
	return x<0?-x:x;
}

template <class T> inline void apn(T &x,const T y){
	x>y?x=y:0;
}

namespace G{
	int cnd,cscc,cnt,fir[N*6],bel[N*6],dfn[N*6],low[N*6];
	struct edge{
		int to,nx;
	}eg[N*100];

	void clear(){
		cnt=cscc=cnd=0;
		memset(fir,0,(n+1)*6*sizeof(int));
		memset(bel,0,(n+1)*6*sizeof(int));
		memset(dfn,0,(n+1)*6*sizeof(int));
	}

	inline void add(const int a,const int b){
		//printf("add: %d -> %d\n",a,b);
		eg[++cnt]=(edge){b,fir[a]};
		fir[a]=cnt;
	}

	void tarjan(const int x){
		static int top,stk[N*6];
		dfn[x]=low[x]=++cnd;
		stk[++top]=x;
		for(int i=fir[x]; i; i=eg[i].nx){
			const int y=eg[i].to;
			if(!dfn[y]) tarjan(y);
			if(!bel[y]) apn(low[x],low[y]);
		}
		if(dfn[x]!=low[x]) return;
		++cscc;
		for(int i=stk[top--]; ; i=stk[top--]){
			bel[i]=cscc;
			if(i==x) break;
		}
	}
}

namespace T{
	int x,y,v;
	inline int idx(const int l,const int r){
		return (l+r)|(l!=r);
	}

	void build(const int l,const int r){
		if(l==r) return;
		const int k=idx(l,r),mid=(l+r)>>1;
		G::add(k+(n<<1),idx(l,mid)+(n<<1));
		G::add(k+(n<<1),idx(mid+1,r)+(n<<1));
		build(l,mid);
		build(mid+1,r);
	}

	void lnk_t(const int l,const int r){
		assert(l<=r);
		if(l>=x&&r<=y){
			G::add(v,idx(l,r)+(n<<1));
			return;
		}
		const int mid=(l+r)>>1;
		if(x<=mid) lnk_t(l,mid);
		if(y>mid) lnk_t(mid+1,r);
	}

	inline void lnk(const int x,const int l,const int r){
		assert(l<=r);
		assert(l>=1&&r<=(n<<1));
		T::x=l,T::y=r,T::v=x;
		lnk_t(1,(n<<1));
	}
}

bool jdg(const int tgt){
	G::clear();
	T::build(1,n<<1);
	for(int i=1; i<n<<1; i+=2){
		const int p1=pos[i],p2=pos[i+1];
		G::add(T::idx(p1,p1)+(n<<1),p2);
		G::add(T::idx(p2,p2)+(n<<1),p1);
	}
	for(int i=1; i<=n<<1; ++i){
		const int l=std::lower_bound(val+1,val+i+1,val[i]-tgt+1)-val;
		if(l<i) T::lnk(i,l,i-1);
		const int r=std::upper_bound(val+i,val+(n<<1)+1,val[i]+tgt-1)-val-1;
		if(r>i) T::lnk(i,i+1,r);
	}
	for(int i=1; i<=n<<1; ++i){
		if(!G::bel[i]) G::tarjan(i);
	}
	for(int i=1; i<n<<1; i+=2){
		if(G::bel[pos[i]]==G::bel[pos[i+1]]) return 0;
	}
	return 1;
}

int solve(){
	int l=0,r=1e9,mid;
	while(l!=r){
		mid=(l+r+1)>>1;
		if(jdg(mid)) l=mid;
		else r=mid-1;
	}
	return l;
}

int main(){
	n=nxi();
	for(int i=1; i<=n; ++i){
		org[(i<<1)-1]=nxi(),org[i<<1]=nxi();
	}
	for(int i=1; i<=n<<1; ++i){
		idx[i]=i;
	}
	std::sort(idx+1,idx+(n<<1)+1,cmp_org);
	for(int i=1; i<=n<<1; ++i){
		pos[idx[i]]=i;
		val[i]=org[idx[i]];
	}
	printf("%d\n",solve());
	return 0;
}


Measured memory_bytes: 11648
#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(){
  int N; cin >> N;
  map<int,int> D;
  int d;
  rep(i,N){
    cin >> d;
    D[d]++;
  }
  int M; cin >> M;
  int t;
  bool flag = (N>=M);
  if (flag){
    rep(i,M){
      cin >> t;
      if (D.count(t) && D.at(t)>0) D[t]--;
      else {
        flag = false;
        break;
      }
    }
  }  

  cout << (flag? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 9600
a,b,c,x,y = gets.split(" ").map(&:to_i)

min_pizza = [x,y].min

c_total = min_pizza * c * 2
ab_total = min_pizza * a + min_pizza * b
total = 0

if c_total < ab_total
  total += c_total
else
  total += ab_total
end

remainder = (x-y).abs

rem_c = remainder * c * 2
rem_ab = x < y ? (remainder * b) : (remainder * a)

if rem_c < rem_ab
  total += rem_c
else
  total += rem_ab
end

puts total

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

int main() {
	int x,a,b,sum;
	vector<long long> afact(1000); 
	long long bfact;
	cin>>x;
	for(int i=1;i<=1000;i++){
		afact[i]=pow(i,5);
	}
	for(int i=-1000;i<1000;i++){
		bfact=x+pow(i,5);
		for(int j=1;j<=1000;j++){
			if(bfact==afact[j]){
				cout<<j<<" "<<i<<endl;
				return 0;
			}
		}
	}
}

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

int main()
{
    string s;
    stack<int> v;
    int a,b;
    while(cin >> s){
        if(s[0] == '+'){
            b = v.top();v.pop();
            a = v.top();v.pop();
            v.push(a+b);
        }
        else if(s[0] == '-'){
            b = v.top();v.pop();
            a = v.top();v.pop();
            v.push(a-b);
        }
        else if(s[0] == '*'){
            b = v.top();v.pop();
            a = v.top();v.pop();
            v.push(a*b);
        }
        else{
            v.push(atoi(s.c_str()));
        }
    }
    cout << v.top() << endl;
}
 


Measured memory_bytes: 3176
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

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

  std::vector<std::string> week={"SUN","MON","TUE","WED","THU","FRI","SAT"};

  std::string s;
  std::cin>>s;

  rep(i,1,8){
    if(s==week[7-i]){
      std::cout<<i<<"\n";
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll k;
    string s;
    cin >> s;
    cin >> k;

    bool is_all_same = true;
    for(int i = 0; i < s.size()-1; i++){
        if(s[i] != s[i+1]){is_all_same = false;}
    }
    if(is_all_same){
        cout << s.size()*k/2 << endl;
        return 0;
    }


    ll top_sequence = 1, rear_sequence = 1;
    int index = 0;
    while(s[index] == s[index+1]){
        top_sequence++;
        index++;
    }
    index = s.size()-1;
    while(s[index] == s[index-1]){
        rear_sequence++;
        index--;
    }
    ll operation = 0;
    ll sequence = 1;
    for(int i = 0; i < s.size()-1; i++){
        if(s[i] == s[i+1]){
            sequence++;
        }else{
            operation += sequence/2;
            sequence = 1;
        }
    }
    operation += sequence/2;
    if(s[0] == s[s.size()-1]){
        if((top_sequence+rear_sequence)%2==0){
            operation++;
            cout << operation*k-1 << endl;
        }else{
            cout << operation*k << endl;
        }
    }else{
        cout << operation*k << endl;
    }




    return 0;
}


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

int ok(string str)
{
    int n = str.length();
    int su = 0;
    for (int i=0; i<n; i++)
        su += (str[i]-'0');
    return (su % 9 == 0);
}
int main()
{
    string str;
    cin>>str;
    ok(str)?  cout << "Yes" : cout << "No ";
    return 0;
}


Measured memory_bytes: 3924