akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n), b(n); rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	int sum = 0; int sum2 = 0;
	vector<int>tmp;
	int cnt = 0;
	rep(i, n) {
		if (a[i] < b[i]) {
			sum += b[i] - a[i]; cnt++;
		}
		else {
			sum2 += a[i] - b[i]; 
			tmp.push_back(a[i] - b[i]);
		}
	}
	if (sum > sum2) {
		cout << -1 << endl; return 0;
	}
	int ans = 0;
	sort(ALLR(tmp));
	rep(i, n) {
		if (sum > 0) {
			sum -= tmp[i];
			ans++;
		}
	}
	cout << ans + cnt << endl;
	return 0;
}

Measured memory_bytes: 2936
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    string nap;
    cin >> nap;
    int n = nap.size();
    int l = 0, p = n - 1;
    int odp = 0;
    while (l < p)
    {
        if (nap[l] == nap[p])
        {
            ++l;
            --p;
        }
        else
        {
            if (nap[l] != 'x' && nap[p] != 'x')
            {
                cout << "-1";
                return 0;
            }
            else
            {
                if (nap[l] == 'x')
                {
                    ++l;
                    ++odp;
                }
                else
                {
                    --p;
                    ++odp;
                }
            }
        }
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define rep(i, a, b) for(int i=a; i<b; i++)
#define per(i, a, b) for(int i=b-1; i>=a; i--)
#define ifor(n) for(int i=0;i<n;i++) 
#define jfor(n) for(int j=0;j<n;j++)
#define Ifor(n) for(int i=1;i<n;i++) 
#define Jfor(n) for(int j=1;j<n;j++)
const int inf=0x3f3f3f3f;
double a[200004],b[200004];
int main(){
	memset(b,0,sizeof(b));
  int n,k;
  cin>>n>>k;
  ifor(n)cin>>a[i];
  ifor(k){
    b[0]+=(a[i]+1)/2;
  }
  double max=b[0];
  for(int i=k;i<n;i++){
  	b[i-k+1]=b[i-k]-(a[i-k]+1)/2+(a[i]+1)/2;
  	if(b[i-k+1]>max)max=b[i-k+1];
  }
  printf("%lf",max);
}


Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
	int InpNum = 0, l = 0;


	while (cin >> InpNum >> l)
	{
		int TempNum1[10] = { 0 };
		int TempNum3[30] = { 0 };

		int tmp1 = 0, tmp2 = 0, tmp3 = 0;


		if (InpNum == 0 && l == 0) { break; }

		tmp1 = InpNum;
		TempNum3[0] = InpNum;

		for (int i = 0; i < 10; i++)
		{
			tmp2 = (int)(tmp1 / 10) * 10;
			tmp3 = tmp1 - tmp2;

			TempNum1[i] = tmp3;

			tmp1 = (int)(tmp1 / 10);
			if (tmp1 == 0) { break; }
		}


		for (int j = 0; j <= 20; j++)
		{

			int TempNum2[10] = { 0 };
			int n = 0;


			sort(TempNum1, TempNum1 + l);

			for (int i = l; i > 0; i--)
			{
				TempNum2[i] = TempNum2[i] + TempNum1[n] - TempNum1[i - 1];

				if (TempNum2[i] < 0)
				{
					TempNum2[i] = TempNum2[i] + 10;
					TempNum2[i - 1] = TempNum2[i - 1] - 1;
				}

				n = n + 1;
			}

			for (int i = 0; i<l; i++)
			{
				int h = 1;
				TempNum1[i] = TempNum2[i + 1];
				TempNum3[j + 1] = TempNum3[j + 1] + TempNum2[i + 1] * (int)pow(10.0, (double)(l - i - 1));
			}
		}

		int cnt = 0;

		for (int j = 0; j <= 20; j++)
		{
			if (cnt == 1) { break; }

			for (int i = 0; i <= 20; i++)
			{
				if (i == j) {}
				else
				{
					if (TempNum3[j] == TempNum3[i])
					{
						printf("%d %d %d\n", j, TempNum3[i], i - j);
						cnt = cnt + 1;
						break;
					}
				}
			}
		}
	}

	return 0;
}

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

using namespace std;

#define sp << " " <<
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define int long long
#define double long double
#define INF 1e18
#define PI 3.14159265359

int power(int p,int y)
{
    int res=1;
    p=p%mod;
    while(y>0)
    {
        if(y&1)
            res=(res*p)%mod;
        y=y>>1;
        p=(p*p)%mod;
    }
    return res;
}

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dice()
{
    uniform_int_distribution<int> uid(0,1);//specify l and r.
    return uid(rng) ;
}

int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int dp = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          dp = dp * 10 + cc - '0';
          cc = getc(stdin);
       }
      return dp;
}

inline void print(int n)
{
  if (n == 0)
  {
    putchar('0');
    putchar('\n');
  }
  else if (n == -1)
  {
    putchar('-');
    putchar('1');
    putchar('\n');
  }
  else
  {
    char buf[20];
    buf[19] = '\n';
    int i = 18;
    while (n)
    {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n')
      putchar(buf[++i]);
  }
}

int n;

vector<vector<int>> mat_mul(vector<vector<int>> a,vector<vector<int>> b)
{
	vector<vector<int>> t(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				t[i][j]+=((a[i][k]*b[k][j])%mod);
				t[i][j]%=mod;
			}
		}
	}
	return t;
}

int n,k;
    double m;
    cin >> n >> m >> k;
    double dp=(double)m/2;
    for(int i=0;i<k;i++)
    {
        double d=floor(dp);
        dp=((d+1)*dp+(m*(m+1))/2-(d*(d+1))/2)/(m+1);
    }
    cout << fixed << setprecision(13) << dp;

vector<vector<int>> pow_mat(vector<vector<int>> mat_a,int p)
{
	if(p==1)
        return mat_a;
	vector<vector<int>> temp=pow_mat(mat_a,p/2);
	vector<vector<int>> res=mat_mul(temp,temp);
	if(p&1)
        res=mat_mul(res,mat_a);
	return res;
}
*/

int n;
int a[16][16];
int p[1<<16];
int dp[1<<16];

void r(int k,int s,int b)
{
    if(b==n)
    {
        dp[k]=max(dp[k],p[s]+dp[k-s]);
    }
    else
    {
        if((1<<b)&k)
            r(k,s+(1<<b),b+1);
        r(k,s,b+1);
    }
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin >> a[i][j];
    for(int i=0;i<(1<<n);i++)
    {
        vector<int> d;
        for(int j=0;j<n;j++)
        {
            if((1<<j)&i)
                d.pb(j);
        }
        int k=d.size();
        for(int j=0;j<k-1;j++)
        {
            for(int l=j+1;l<k;l++)
            {
                p[i]+=a[d[j]][d[l]];
            }
        }
    }
    for(int i=0;i<(1<<n);i++)
    {
        r(i,0,0);
    }
    cout << dp[(1<<n)-1];
    return 0;
}


Measured memory_bytes: 1280
def main():
    from collections import Counter
    n = int(input())
    d = list(map(int, input().split()))
    if d[0] != 0:
        print(0)
        return 0
    for i in range(1, n):
        if d[i] == 0:
            print(0)
            return 0
    mod = 998244353
    m=max(d)
    d = Counter(d)
    ans=1
    for i in range(1, m+1):
        ans = (ans * pow(d[i - 1], d[i], mod)) % mod
    print(ans)
main()

Measured memory_bytes: 19936
from fractions import gcd

read_ints = lambda : map(int, raw_input().strip().split())

n = input()
a = read_ints()

pre = [0] * (n + 1)
for i in xrange(1, n + 1):
    pre[i] = gcd(pre[i - 1], a[i - 1])

suf = [0] * (n + 1)
suf[n - 1] = a[n - 1]
for i in xrange(n - 2, -1, -1):
    suf[i] = gcd(suf[i + 1], a[i])

ans = pre[n]
for i in xrange(n):
    g1 = pre[i]
    g2 = suf[i + 1]
    g = gcd(g1, g2)
    ans = max(ans, g)

print ans

Measured memory_bytes: 45848
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = int(1e9)+10;
const ll INFll = ll(1e18)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;

int main() {
	int N, K; cin >> N >> K;

	ll ans = 0;
	ll x = N / K;
	ans += x * x * x;

	if (K % 2 == 0) {
		ll x = (2*N + K) / (2*K);
		ans += x * x * x;
	}

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


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  string S, T;
  cin >> S >> T;
  ll A, B;
  cin >> A >> B;
  string U;
  cin >> U;

  if (U == S) {
    A--;
  } else {
    B--;
  }

  cout << A << " " << B << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools
from collections import Counter
from collections import defaultdict

d = defaultdict(lambda:-1)
N = int(input())
X = [0]*N
Y = [0]*N
for i in range(N):
    X[i],Y[i] = map(int,input().split())
    d[(X[i],Y[i])] = i

if N == 1:
    print(1)
    exit()

o = []
for i,j in itertools.product(range(N),range(N)):
    if i == j:
        continue
    x = X[i] - X[j]
    y = Y[i] - Y[j]
    o.append((x,y))

p,q = Counter(o).most_common()[0][0]
o = []
for i in range(N):
    a = i
    while True:
        b = d[(X[a]+p,Y[a]+q)]
        if b == -1:
            o.append(a)
            break
        a = b

print(len(set(o)))

Measured memory_bytes: 3956
from decimal import *
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())



def solve(N, K, A):
    def update():
        new_A = [0]*N
        end_idx = [0]*N
        num_act = 0
        num_max = 0
        for i in range(N):
            end_idx[min(i+A[i], N-1)]+=1
            num_act+=1
            new_A[i] = num_act
            num_act-=end_idx[i]
        end_idx = [0]*N
        num_act = 0
        num_max = 0
        for i in range(N-1, -1, -1):
            tmp = A[i]
            new_A[i]+= num_act
            if new_A[i] == N:
                num_max+=1
            if A[i]>0:
                num_act += 1
                end_idx[max(0,i-tmp)]+=1
            num_act -= end_idx[i]
        return new_A, num_max
    for _ in range(K):
        A, num_max = update()
        if num_max == N:
            return [str(n) for n in A]
    return [str(n) for n in A]
    



N, K = rrm()
A = rrm()
ans = solve(N, K, A)
print(' '.join(ans))


Measured memory_bytes: 199172
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    string in; cin >> in;
    int n = in.size();
    rep(i, n-1){
        if(in.substr(i, 2) == "AC"){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 400010;
 
// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}
 
ll inverse(ll a) {
    return modpow(a, mod-2);
}
 
ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];
 
void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}
 
//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll n, k;
    cin >> n >> k;
 
    init();
    
    if(n-1 <= k) {
        out(Comb(2*n-1, n-1));
        re0;
    }
 
    // 以下 k <= n-2 
    ll ans = 1;
    exrep(i, 1, k) {
      ans += (Comb(n, i)*Comb(n-1, i))%mod;
      ans %= mod;
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <set>
#include <map>
#include <array>
#include <cassert>
#include <cstring>
#include <vector>
#include <list>
#include <algorithm>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define mp make_pair

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef list<int> li;
typedef vector<li> vli;
typedef vector<vpi> vvpi;
typedef long long i64;

const int inf = 1e9;

void solve_a() {
  int a,b,c;
  cin >> a >> b >> c;
  i64 k;
  cin >> k;
  // a, b, c = a-b
  // b+c, a+c, a+b = b-a
  // 2a+b+c, 2b+a+c, 2c+a+b = a-b
  // 2a+3b+3c, 3a+2b+3c, 3a+3b+2c = b-a
  a = (k & 1) ? b - a : a - b;
  cout << a << endl;
}

void solve_b() {
  int n; cin >> n;
  vi a(n); forn(i, n) cin >> a[i];
  vi b(n + 1, 0);
  for(int x: a) b[x] = b[x-1] + 1;
  cout << n - *max_element(all(b)) << endl;
}

void solve_c() {
  int n; cin >> n;
  vi a(n); forn(i, n) cin >> a[i];
  i64 r = -1;
  if (a[0] == 0) {
    r = 0;
    ford(i, n) {
      int d = a[i] - a[i-1];
      if (d > 1) {
        r = -1;
        break;
      } else if (d == 1) {
        r += 1;
      } else r += a[i];
    }
  }
  cout << r << endl;
}

void solve_d() {
  int n; cin >> n;
  vvi g(n);
  forn(i, n - 1) {
    int v,u; cin >> v >> u;
    --v; --u; g[v].pb(u); g[u].pb(v);
  }
  vi d(n, n);
  vi dp(n, -1);
  auto dfs = [&](auto dfs, int v, int p) -> void {
    dp[v] = p;
    for (int u: g[v]) if (u != p) {
      d[u] = d[v] + 1;
      dfs(dfs, u, v);
    }
  };
  d[0] = 0; dfs(dfs, 0, -1);
  int v = max_element(all(d)) - d.begin();
  fill(all(d), n);
  d[v] = 0; dfs(dfs, v, -1);
  int u = max_element(all(d)) - d.begin();
  cout << (d[u] + 2) / 2 << ' ';
  vi path; {
    int i = u;
    while (i != -1) { path.pb(i); i = dp[i]; }
  }
  auto go = [&] (int v, int u) -> i64 {
    vi used(n, 0);
    vi e(1, v);
    if (u != -1) e.pb(u);
    for (int i: e) used[i] = 1;
    i64 ans = e.size();
    while (!e.empty()) {
      vi ne;
      int mst = 0;
      for (int i: e) {
        uax(mst, (int)g[i].size() - (e.size() == 1 ? 0 : 1));
        for (int j: g[i]) {
          if (used[j]) continue;
          used[j] = 1;
          ne.pb(j);
        }
      }
      e = ne;
      if (mst > 0) ans *= mst;
    }
    return ans;
  };
  if (d[u] & 1) {
    cout << go(path[d[u]/2], path[d[u]/2+1]) << endl;
  } else {
    v = path[d[u]/2];
    i64 r = go(v, -1);
    for (int u: g[v]) uin(r, go(v, u));
    cout << r << endl;
  }
}

int main() {
#ifdef HOME
  freopen("input.txt", "rt", stdin);
#endif
  solve_d();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    for(ll i=1;i<=n;i++)
        cin>>a[i];
    ll dp[n+1];
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    ll mi=1;
    for(ll i=3;i<=n;i++)
    {

        dp[i]=INT_MAX;
        for(ll j=i-1;j>=max(i-k,mi);j--)
        dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,A,B;

bool check(int x,priority_queue<ll> Q){
  ll X=x;
  while(!Q.empty()){
    ll t = Q.top()-X*B;Q.pop();

    if(t<=0)break;
    x-= (t-1)/(A-B)+1;
    if(x<0) return 0;

  }
  return 1;
}

int main(){

  cin>>n>>A>>B;

  priority_queue<ll>Q;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    Q.push(a);
  }
  ll L=0,R=(1e9)+10;
  while(L<R){
    ll M = (L+R)/2;
    if(check(M,Q)) R = M;
    else L = M+1;
  }
  cout<<L<<endl;
  return 0;
}


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

using namespace std;
const int N = 1e5 + 5;
int mark[N], cnt[2], node, val;
vector <int> g[N];

void dfs(int v, int col = 1) {
    mark[v] = col, node++;
    for (int u : g[v]) {
        if (!mark[u]) dfs(u, 3 - col);
        else if (col == mark[u]) val = 0;
    }
    return ;
}

int main() {
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    long long ans = 0, res = 0;
    for (int i = 1; i <= n; i++) if (!mark[i]) {
        val = 1, node = 0, dfs(i);
        if (node == 1) {res++; continue ;}
        if (val == 1) ans += 4 * cnt[1] + 2 * cnt[0] + 2;
        else ans += 2 * (cnt[0] + cnt[1]) + 1;
        cnt[val]++;
    }
    cout << ans + 2 * n * res - res * res << "\n";
}


Measured memory_bytes: 9984
import itertools
 
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
 
l = [i for i in range(1,n+1)] 
 
x = 0
y = 0
 
m = list(itertools.permutations(l))
 
for i in range(len(m)):
	if m[i] == p:
  		x = i+1
	if m[i] == q:
 		y = i+1
        
print(abs(x-y))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define hell 1000000007
        using namespace std;
        const int N=500;
        void solve()
        {
            ll i,j,k,n,m,c=0,ans=0;
            string s;
            cin>>k>>n;
            if(k==0 and n<100)
                cout<<n;
            else if(k==0 and n==100)
                    cout<<101;
            else if(k==1 and n<100)
            cout<<n*100;
            else if(k==1 and n==100)
                cout<<101*100;
            else if(k==2 and n<100) cout<<n*10000;
            else cout<<101*10000;




    }

        int main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define watch(x); cout<<#x<<"="<<x<<endl;
#define watch2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define endl "\n"
#define int long long
using namespace std;        
 

int arr[15][15];
int32_t main(){

    fast
    int n,m,x;
    int price[15];
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        cin>>price[i];
        for(int j=0;j<m;j++){
            cin>>arr[i][j];
        }
    }
    int isPoss[15];
    int mini=INT_MAX;
    for(int i=0;i<(1<<n);i++){
        memset(isPoss,0,sizeof isPoss);
        int cost=0;
        for(int j=0;j<n;j++){
            if((i&(1<<j))!=0){
                for(int k=0;k<m;k++){
                    isPoss[k]+=arr[j][k];
                }
                //watch(j);
                cost+=price[j];
            }
        }
        bool b=true;
        for(int j=0;j<m;j++){
            if(isPoss[j]<x)b=false;
        }
        if(b){
            mini=min(cost,mini);
        }
    }
    if(mini==INT_MAX){
        cout<<-1;
    }
    else{
        cout<<mini;
    }




    return 0;
}



Measured memory_bytes: 3660
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    long long num,day,move,town=1,temp,road[100000]={0},sum=0,i;
    scanf("%lld %lld",&num,&day);
    sum=0;
    for (i=0; i<num-1; i++) {
        scanf("%lld",&temp);
        road[i+1]=road[i]+temp;
    }
    for (i=0; i<day; i++) {
        scanf("%lld",&move);
        sum+=abs(road[town+move-1]-road[town-1]);
        sum%=100000;
        town+=move;
    }
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 1388
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      int n = int.Parse(Console.ReadLine());
      List<int> a1 = Console.ReadLine().Split().ToList().ConvertAll(x=>int.Parse(x));
      List<int> a2 = Console.ReadLine().Split().ToList().ConvertAll(x=>int.Parse(x));
      List<List<int>> a = new List<List<int>>();
      a.Add(a1);
      a.Add(a2);
      int ans =0;
      int hantei=0;
      
      for (int i=1;i<=n;i++)
      {
        hantei=0;
        hantei+=a[0].GetRange(0,i).Sum();
        hantei+=a[1].GetRange(i-1,a[0].Count+1-i).Sum();
        //Console.WriteLine(string.Join(" ",a[0].GetRange(0,i)));
        //Console.WriteLine(string.Join(" ",a[1].GetRange(i-1,a[0].Count+1-i)));
        //Console.WriteLine(hantei);
        if (hantei>ans)
        {
          ans=hantei;
        }
      }
      Console.WriteLine(ans);
    }
}


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

int main() {
  int N, X, e, ans = 0;
  vector<int> m;
  cin >> N >> X;

  ans += N;

  while (cin >> e) {
    m.push_back(e);
  }

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

  ans += (X - accumulate(m.begin(), m.end(), 0)) / m.at(0);

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int n,a,b; cin>>n>>a>>b;
    int k;
    int ans=0;
    for(int i=1;i<=n;i++){
        k=0;
        int m=i;
        while(m>0){
            k+=m%10;
            m=m/10;
        }
        if(a<=k&&k<=b){
            ans+=i;
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3644
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		
		System.out.println(koya(Math.max(x, y),Math.min(x, y)));
	}
	
	public static int koya(int a,int b){
		
		if(b == 0){
			return a;
		}else{
			return koya(b,a%b);
		}
	}
}


Measured memory_bytes: 26148
N=int(input())
total=0
A=list(map(int,input().split()))
for i in range(N):
    total+=A[i]
for i in range(N):
    if i%2==1:
        total-=A[i]*2
print(int(total),end=" ")
for i in range(N-1):
    print(int(A[i]*2-total),end=" ")
    total=A[i]*2-total


Measured memory_bytes: 14092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.HashMap;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int T=sc.nextInt();
		HashMap<Integer,Integer> nedan=new HashMap<Integer,Integer>();	//多分Longしか使わない
		int[] ary=new int[N];
		for(int i=0; i<N; i++) {
			ary[i]=sc.nextInt();
			nedan.put(ary[i],i);
		}
		int min=114514810;
		int diff=0;
		min=ary[0];
		for(int i=1; i<N; i++) {
			diff=Math.max(diff, ary[i]-min);
			min=Math.min(min,ary[i]);
		}
		int kaisu=0;
		for(int i=1; i<N; i++) {
			int tmp=ary[i];
			if(tmp-diff>0) {
				if(nedan.containsKey(tmp-diff)) {
					if(nedan.get(tmp-diff)<i) {
						kaisu++;
					}
				}
			}
		}
		pl(kaisu);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	public static void pl() {
		System.out.println();
	}
}


Measured memory_bytes: 49932
#include <iostream>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N; cin>>N;
  ll ans = 0;
  for(int i=1;i<=N;++i){
    if(i%3!=0 && i%5!=0){
      ans += i;
    }
  }
  cout << ans <<"\n";
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(i,4){
        char res[n+2];    
        if(i%2 == 0) res[0] = 'S';
        else res[0] = 'W';
        if(i/2 == 0) res[1] = 'S';
        else res[1] = 'W';
        rep(j,n){
            char bs = res[j];
            char ns = res[j+1];
            if(bs == 'S' && ns == 'S' ){
                if(s[j] == 'o') res[j+2] = 'S';
                else res[j+2] = 'W'; 
            }else if(bs == 'S' && ns == 'W'){
                if(s[j] == 'o') res[j+2] = 'W';
                else res[j+2] = 'S';                 
            }else if(bs == 'W' && ns == 'S'){
                if(s[j] == 'o') res[j+2] = 'W';
                else res[j+2] = 'S'; 
            }else if(bs == 'W' && ns == 'W'){
                if(s[j] == 'o') res[j+2] = 'S';
                else res[j+2] = 'W'; 
            }    
        }
        if (res[n] == res[0] && res[n+1] == res[1]){
            for(int j = 1; j< n+1; j++) cout << res[j] ;
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int Check(char S[16]){
  int i, Y, M, D, y, m, d;
  Y = 2019;
  M = 4;
  D = 30;
  y = 0;
  for(i = 0;i < 4;i++) y = y * 10 + S[i] - '0';
  if(Y < y) return 0;
  else if(Y > y) return 1;
  m = 0;
  for(i = 0;i < 2;i++) m = m * 10 + S[i+5] - '0';
  if(M < m) return 0;
  else if(M > m) return 1;
  d = 0;
  for(i = 0;i < 2;i++) d = d * 10 + S[i+8] - '0';
  if(D < d) return 0;
  else return 1;
}
  
int main(void){
  char S[16];
  scanf("%s", S);
  if(Check(S) == 0) printf("TBD\n");
  else printf("Heisei\n");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define res register int
#define N 100005
using namespace std;
int n,ans,a[100100];
inline int read()
{
  int X=0,w=0;
  char ch=0;
  while(!isdigit(ch))
  {
    w|=ch=='-';
    ch=getchar();
  }
  while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
  return w?-X:X;
}
inline bool cmp(int x,int y)
{
  return x>y;
}
int main()
{
  n=read();
  for(res i=1; i<=n; i++)
    a[i]=read();
  sort(a+1,a+n+1,cmp);
  for(res i=1; i<=n; i++)
    if(i+1>a[i+1])
    {
      for(res j=i+1; a[j]==i; j++) ans^=1;
      ans|=(a[i]-i)&1;
      puts(ans? "First":"Second");
      return 0;
    }
  return 0;
}

Measured memory_bytes: 640
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int H,W;
	cin >> H >> W;
	string str;
	for(int r=0;r<H;++r){
		for(int c=0;c<W;++c){
			cin >> str;
			if( str == "snuke" ){
				cout << (char)('A'+c);
				cout << r+1 << endl;
			}
		}
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    int b[n-1];
    rep(i,n-1)cin >> b[i];
    int ans = 0;
    ans += b[0];
    ans += b[n-2];
    for(int i=1;i<n-1;i++){
        ans += min(b[i],b[i-1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
int main(int argc, char** argv)
{
    using namespace std;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, a, b, sum_d, sum=0;
    cin >> n >> a >> b;
    for (int i = 1; i <= n; ++i)
    {
        int i_ = i;
        sum_d = 0;
        while (i_ != 0)
        {
            sum_d += i_ % 10;
            i_ /= 10;
        }
        if (a <= sum_d&&sum_d <= b)
        {
            sum += i;
        }
    }
    cout << sum;
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long K, long long X){
    if (500 * K >= X)
        cout << YES << endl;
    else
    {
        
        cout <<NO << endl;
    }
    
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long X;
    scanf("%lld",&X);
    solve(K, X);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		int[] b = new int[m];
		int[][] a = new int[n][m];
		for(int i = 0; i < m; i++) {
			b[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for(int i = 0; i < n; i++) {
			int sum = 0;
			for(int j = 0; j < m; j++) {
				sum += a[i][j]*b[j];
			}
			if(sum + c > 0) {
				ans ++;
			}
		}
		System.out.println(ans);
		sc.close();
	}
}



Measured memory_bytes: 22100
a=list(input())
b=list(input())
c=list(input())

now="a"
while 1:
    if now=="a":
        
        if len(a)==0:
            print("A")
            break
        now=a[0]
        del a[0]
        
    elif now=="b":
        if len(b)==0:
            print("B")
            break
        now=b[0]
        del b[0]
        
    else:
        
        if len(c)==0:
            print("C")
            break
        now=c[0]
        del c[0]
       

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  vector<int> a(n);
  for (int &i : a) in >> i;
  vector<int> st;
  int64_t ans = 0;
  a.push_back(0);
  n++;
  for (int i = 0; i < n; ++i) {
    while (!st.empty() && a[st.back()] > a[i]) {
      int ind = st.back();
      int val = a[st.back()];
      st.pop_back();
      int r = i, l = st.empty() ? -1 : st.back();
      ans += (int64_t) val * (int64_t) (ind - l) * (r - ind);
    }
    st.push_back(i);
  }
  out << ans << '\n';
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}


int main() {
    int N; cin >> N;
    vector<int> a(N); REP(i, N) cin >> a[i];

    map<int, int> tmp;
    sort(all(a));
    REP(i, N) {
        tmp[a[i]]++;
    }

    ll res = 1;

    for(int i = 1; i < N - 1; ++i) {
        int t = 0;
        t = tmp[i - 1] + tmp[i] + tmp[i + 1];
        if(res < t) res = t;
    }

    cout << res << endl;
}

Measured memory_bytes: 5376
r, c = map(int, input().split())
lines = []
for i in range(r):
    lines.append(list(map(int, input().split())))

for line in lines:
    line.append(sum(line))

lines.append([sum([line[i] for line in lines]) for i in range(c  + 1)])

for line in lines:
    print(*line)



Measured memory_bytes: 6232
N=int(input())
W=list(map(int,input().split()))
ans=float("inf")
for i in range(1,N):
    w_f=W[:i]
    w_l=W[i:]
    dif=abs(sum(w_f)-sum(w_l))
    if dif<ans:
        ans=dif
print(ans)   

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

using namespace std;       

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	assert(n > 0);
	assert(m > 0);
	string s, t;
	cin >> s >> t;
	int g = __gcd(n, m);
	for (int i = 0; i < g; i++) {
		if (s[i * n / g] != t[i * m / g]) {
		 	cout << -1 << endl;
			return 0;
		} 	
	}
	cout << (long long) n * m / g << endl;
	return 0;
}



Measured memory_bytes: 640
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec a(N);
  llvec c(3, 0);
  rep(i, N){
    cin >> a[i];
    if(a[i]%4==0){
      c[0]++;
    }else if(a[i]%2==0){
      c[1]++;
    }else{
      c[2]++;
    }
  }
  DUMP(i, c);cerr << endl;
  if(c[2]==0){
    cout << "Yes";
  }else{
    if(c[2]<=c[0]){
      cout << "Yes";
    }else if(c[2]==(c[0]+1) and c[2]+c[0]==N){
      cout << "Yes";
    }else{
      cout << "No";
    }
  }
  return 0;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  ll q;cin>>q;
  bool rev = false;
  deque<char>que;
  for(auto c:s)que.push_back(c);
  while(q--){
    ll t;cin>>t;
    if(t == 1){
      if(rev)rev=false;
      else rev = true;
    }else{
      ll f;char c;
      cin>>f>>c;
      if(f == 1){
	if(rev){
	  que.push_back(c);
	}else{
	  que.push_front(c);
	}
      }else{
	if(rev)que.push_front(c);
	else que.push_back(c);
      }
    }
  }
  while(!que.empty()){
    if(rev == false){
      char hoge = que.front();
      cout<<hoge;
      que.pop_front();
    }else{
     char hoge = que.back();
      cout<<hoge;
      que.pop_back();
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 976
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
v_list=list(map(int,input().split()))
v_list.sort(reverse=True)
x=v_list[a-1]
print(sum(v_list[:a])/a)
import math
if v_list[0]==x:
    count=0
    for i in range(n):
        if v_list[i]==x:
            count+=1
    ans=0
    for i in range(a,min(b,count)+1):
        ans+=math.factorial(count)//(math.factorial(i)*math.factorial(count-i))
    print(ans)
else:
    counta=0
    for i in range(a):
        if v_list[i]==x:
            counta+=1
    count=0
    for i in range(n):
        if v_list[i]==x:
            count+=1
    ans=math.factorial(count)//(math.factorial(counta)*math.factorial(count-counta))
    print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 998244353
using namespace std;


int main(){
    string s;
    cin >> s;
    
    ll minidx=0;
    ll temp=0;
    ll ans[500000]={};
    for(int i=0; i<s.length(); i++){
        if(s[i]=='<'){
            ans[i+1]=max(ans[i+1],ans[i]+1);
        }
    }
    for(int i=s.length()-1; i>=0; i--){
        if(s[i]=='>'){
            ans[i]=max(ans[i],ans[i+1]+1);
        }
    }
    
    ll sum=0;
    
    for(int i=0; i<s.length()+1; i++){
        //cout<<ans[i]<<" ";
        sum+=ans[i];
    }
    
    cout<<sum<<endl;
    return 0;
    
}


Measured memory_bytes: 4740
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

int main() {
  ll n, a[200100], x[200100], ans = 0;
  bool stat = true;
  a[0] = 0; x[0] = 0;
  scanf("%lld", &n);
  for(int i = 1; i <= n; ++i) {
    x[i] = 0;
    scanf("%lld", &a[i]);
    if(a[i] >= i) stat = false;
    if(i > 0 && a[i] - a[i - 1] > 1) stat = false;
  }
  if(stat) {
    //int check = 0;
    //while(stat && check < n) {
      //check = 0;
      /*
      for(int i = n; i > 1; --i) {
        while(stat && a[i - 1] <= a[i] && i > 1) {
          if((i < n && a[i] >= a[i + 1]) || i == n) ans += a[i];
          //cout << i << " " << ans << endl;
          --i;
        }
      }
      */
      int i = 2;
      while(i <= n) {
        /*
        while(a[i + 1] >= a[i] && i < n) {
          if(a[i] >= a[i+1]) ans += a[i];
          //cout << ans << i << endl;
          ++i;
        }
        */
        if(a[i - 1] + 1 == a[i]) ++ans;
        else ans += a[i];
        ++i;
      }
      /*
      for(int i = n; i > 0; --i) {
        if(x[i] < a[i]) {
          x[i] = a[i];
          ++ans;
          int temp = x[i];
          while(stat && a[i - 1] <= a[i] && i > 0) {
            --temp;
            --i;
            if(temp > x[i]) ++ans;
            x[i] = max(0, temp);
            //cout << i << " tete\n";
          }
        }
        if(x[i] > a[i]) {
          stat = false;
          break;
        }
      }
      */
      //cout << ans << endl;
      /*
      for(int i = 1; i <= n; ++i) {
        if(x[i] == a[i]) ++check;
        if(x[i] > a[i]) {
          stat = false;
          break;
        }
        */
        //cout << check << endl;
        //cout << x[i] << " " << a[i] << endl;
      //}
    //}
  }
  if(!stat) printf("-1\n");
  else {
    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int MAXN = 1e5 + 100;

char a[MAXN];

int main()
{
    cin >> a;
    int ans = 0;
    for(int i = 0; i <= 2; i++)
    {
        if(a[i] == 'o') ans++;
    }
    cout << 700 + ans * 100 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a[51],k,m,x=0;
	cin>>m>>k;
	for(int i=1;i<=m;i++)
	cin>>a[i];
	for(int i=1;i<=m;i++)
		for(int j=1;j<=i;j++)
			if(a[i]>a[j])
			swap(a[i],a[j]);
	for(int i=1;i<=k;i++)
	x=x+a[i];
	cout<<x;
}

Measured memory_bytes: 256