akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N;cin >> N;
	set<string> ss;
	while(N--){
		string s;cin >> s;
		ss.insert(s);
	}
	cout << ss.size() << '\n';
}

Measured memory_bytes: 19276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse -> greater<long long>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

const int dx[2]={1,0},dy[2]={0,1};
ll dp[110][110];
char s[110][110];
int main(){
   int h,w;cin>>h>>w;
   rep(i,h)rep(j,w)cin>>s[i][j];
   rep(i,110)rep(j,110)dp[i][j]=INFTY;
   if(s[0][0]=='#')dp[0][0]=1;
   else dp[0][0]=0;

   rep(i,h){
      rep(j,w){
         rep(dir,2){
            int ni=i+dx[dir],nj=j+dy[dir];
            if(ni>=h || nj>=w)continue;
            if(s[ni][nj]=='#'){
               if(s[i][j]=='#')chmin(dp[ni][nj],dp[i][j]);
               else chmin(dp[ni][nj],dp[i][j]+1);
            }
            else{
               chmin(dp[ni][nj],dp[i][j]);
            }
         }
      }
   }
   cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;
using namespace std;

int dp[100000],a[100000];
int main(){
    int n;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        dp[i]=1000100010;
    }
    rep(i,n) *lower_bound(dp,dp+n,a[i])=a[i];
    cout<<lower_bound(dp,dp+n,1000100010)-dp<<endl;
    return 0;
}

Measured memory_bytes: 3872
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int main(void) {
    int N,K;
    cin >> N >> K;
    bool dp[110000];//K個の時先手が行動して勝てるか？,初期値はfalseなのでこのままでいい
    vi a(N);
    rep(i,N) cin >> a[i];
    
    dp[0] = false;//0個のとき先手はもう取れないのでfalse
    rrep(i,K){
        rep(j,N){
           if(i - a[j] >= 0){
               //今の山の数からこちらの手番で相手をgrundy数0の状態に持って行けたなら
               dp[i] |= ! dp[i-a[j]];//dp[i-a[j]]の中に一つでもfalseがあれば反転してtrue、|=　falseは何もしないのでfalse,true、falseでもtrueになる
           }
        }
    }

    if(dp[K]) fin("First");
    else fin("Second");
}

Measured memory_bytes: 384
import collections, math

local = False
if local:
    file = open("inputt.txt", "r")

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


N, M = ints()

A = ints()

totalvotes = sum(A)
popitems = 0
ratio = 1/(4*M)
border = ratio*totalvotes

for a in A:
    if a>=border:
        popitems+=1

if popitems>=M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a)  (a).begin(),(a).end()
 
const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;
 
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
 
template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main(){
  ll k,x;

  cin >> k >> x;
    

  for (ll i = -k+1; i < k; i++){
    ll ans=0;
    ans = x + i;


    if (i>-k+1)cout << " ";
    cout <<ans ;
  }
  

}


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

void dfs(int v, int prev, int color, vector<int> &used, vector<vector<int>> &g, bool &can) {
        used[v] = color;
        for (auto u : g[v]) if (u != prev) {
                if (used[u] == -1) dfs(u, v, 1 - color, used, g, can);
                else if (used[u] != 1 - color) can = true;
        }
}

int main() {
        int n, m;
        cin >> n >> m;
        vector<vector<int> > g(n);
        for (int i = 0; i < m; i ++) {
                int a, b;
                cin >> a >> b;
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        vector<int> used(n, -1);
        bool can = false;
        dfs(0, -1, 0, used, g, can);
        if (can) {
                long long ans = (long long) n * (n - 1) / 2;
                cout << ans - m << endl;
        } else {
                int black = 0;
                for (int i = 0; i < n; i ++) black += used[i];
                long long ans = (long long) black * (n - black);
                cout << ans - m << endl;
        }
        return 0;
}


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

// #define multitest 1
#define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

void solve()
{
	int n;
	cin >> n;
	vector<int> v(n);
	int lsum = 0, rsum = 0;
	for (auto &x : v)
	{
		cin >> x;
		rsum += x;
	}
	int ans = rsum - lsum;
	for(int i=0;i<n;++i)
	{
		lsum += v[i];
		rsum -= v[i];
		ans = min(ans,abs(rsum - lsum));
	}
	cout << ans ;
	// db("ou");
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	char x;
	cin >> x;
	x++;
	cout << x;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



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

constexpr int P = 1000000007;

struct Graph {
    struct Edge {
        bool operator<(const Edge& o) const {
            return c > o.c; // 逆
        }
        int i;
        int64_t c;
    };
    Graph(int n) : v(n), e(n) {}
    void add_edge(int i, int j, int c) {
        e[i].push_back({ j, c });
    }
    void dijkstra(int i, int j) {
        priority_queue<Edge> q;
        fill(v.begin(), v.end(), (int64_t)1 << 60);
        q.push({ i, v[i] = 0 });
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            a.push_back(p.i);
            if (p.i == j) break;
            if (p.c > v[p.i]) continue;
            for (const auto& o : e[p.i]) {
                int64_t c = p.c + o.c;
                if (c < v[o.i]) q.push({ o.i, v[o.i] = c });
            }
        }
    }
    int64_t solve() {
        int n = v.size();
        int k = a.size();
        vector<int> b0(n), b1(n);
        b0[a.front()] = 1;
        for (int j = 1; j < k; j++) {
            int i = a[j];
            int64_t t = 0;
            for (Edge& o : e[i]) {
                if (v[i] == v[o.i] + o.c) t += b0[o.i];
            }
            b0[i] = t % P;
        }
        b1[a.back()] = 1;
        for (int j = k - 1 - 1; j >= 0; j--) {
            int i = a[j];
            int64_t t = 0;
            for (Edge& o : e[i]) {
                if (v[i] + o.c == v[o.i]) t += b1[o.i];
            }
            b1[i] = t % P;
        }
        int64_t r = 0;
        int64_t d = v[a.back()];
        for (int i = 0; i < n; i++) {
            if (v[i] * 2 == d) {
                int64_t t = (int64_t)b0[i] * b1[i] % P;
                r += t * t;
                r %= P;
            }
            if (v[i] * 2 < d) {
                for (Edge& o : e[i]) {
                    if (v[i] + o.c == v[o.i] && v[o.i] * 2 > d) {
                        int64_t t = (int64_t)b0[i] * b1[o.i] % P;
                        r += t * t;
                        r %= P;
                    }
                }
            }
        }
        int64_t t = b0[a.back()];
        r = t * t - r;
        r %= P;
        if (r < 0) r += P;
        return r;
    }
    vector<int> a;
    vector<int64_t> v;
    vector<vector<Edge>> e;
};

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

    int n, m;
    cin >> n >> m;

    int s, t;
    cin >> s >> t;
    s--; t--;

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;

        g.add_edge(a, b, c);
        g.add_edge(b, a, c);
    }

    g.dijkstra(s, t);

    cout << g.solve() << endl;

    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) cin >> A.at(i);
    vector <int> A_CP(N);
    for(int i = N - 1; i >= 0; --i) {
        if (i == 0) 
        {
            A_CP.at(0) = K - A.at(N - 1) + A.at(0);
            continue;
        }
        A_CP.at(i) = A.at(i) - A.at(i - 1);
    } 
    sort(A_CP.begin(), A_CP.end());
    A_CP.at(N - 1) = 0;
    ll ans = accumulate(A_CP.begin(), A_CP.end(), 0ll);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int partition(int A[], int p, int r) {
    int x = A[r];
    int i = p - 1;
    for(int j = p; j < r; j++) {
        if(A[j] <= x) {
            i = i + 1;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

int main() {
    int n, ind;
    int A[100001];
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> A[i];
    }
    ind = partition(A, 0, n - 1);
    for(int i = 0; i < n; i++) {
        if( i != 0 ) cout << " ";
        if( i == ind) {
            cout << "[" << A[i] << "]";
        } else {
            cout << A[i];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3392
s = int(input())

items = [s]
while True:
    if s % 2 == 0:
        s = s // 2
        if s not in items:
            items.append(s)
        else:
            print(len(items) + 1)
            break
    else:
        s = 3 * s + 1
        if s not in items:
            items.append(s)
        else:
            print(len(items)+ 1)
            break

Measured memory_bytes: 3060
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  _  <- getLine 
  as <- readInts
  print $ minimum $ map f as 

f :: Int -> Int
f = g 0
 
g acc n
  | even n = g (acc+1) (n `div` 2)
  | odd  n = acc


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    cout << (n * n * n) << endl;
}

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

#define MAX 251
#define NIL -2000000001

struct Node{
    int key;
    int right;
    int left;
    int parent;
};

int main(){
    int n;
    int key[MAX];
    struct Node node[MAX];

    scanf("%d",&n);

    for(int i = 1;i <= n;i++){
        scanf("%d",&key[i]);
        node[i].right = node[i].left = node[i].parent = NIL;
    }

    for(int i = 1;i <= n;i++){
        node[i].key = key[i];
        if((i * 2 + 1) <= n){
            node[i].right = key[i * 2 + 1];
        }
        if((i * 2) <= n){
            node[i].left = key[i * 2];
        }
        if(i >= 2){
            node[i].parent = key[i / 2];
        }
    }

    for(int i = 1;i <= n;i++){
        printf("node %d: key = %d, ",i,node[i].key);
        if(node[i].parent != NIL){
            printf("parent key = %d, ",node[i].parent);
        }
        if(node[i].left != NIL){
            printf("left key = %d, ",node[i].left);
        }
        if(node[i].right != NIL){
            printf("right key = %d, ",node[i].right);
        }
        printf("\n");
    }

    return 0;
}


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

int main() {
	int N;
	long long M = 0, A = 0, R = 0, C = 0, H = 0;
	long long cnt = 0;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		string s;
		cin >> s;

		if (s[0] == 'M') {
			M++;
		}
		else if (s[0] == 'A') {
			A++;
		}
		else if (s[0] == 'R') {
			R++;
		}
		else if (s[0] == 'C') {
			C++;
		}
		else if (s[0] == 'H') {
			H++;
		}
	}

	cnt += M * R * C;
	cnt += M * R * A;
	cnt += M * R * H;
	cnt += M * C * A;
	cnt += M * C * H;
	cnt += M * A * H;
	cnt += H * A * C;
	cnt += H * R * C;
	cnt += A * R * H;
	cnt += A * R * C;

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
n,a,b = map(int, input().split())

mod = 10**9+7
ans = pow(2,n,mod)-1

nca = 1
ncb = 1

for i in range(b):
    ncb = ncb*(n-i)%mod
    ncb *= pow(i+1,mod-2,mod)
    if i+1==a:
        nca = ncb

ans -= nca+ncb
print(ans%mod)

Measured memory_bytes: 40556
n=int(input())
ca=0
cw=0
ct=0
cr=0
for x in range(n):
    a=input()
    if a=='AC':
        ca+=1
    elif a=="WA":
        cw+=1
    elif a=="TLE":
        ct+=1
    else:
        cr+=1
ca='AC x '+str(ca)
cw='WA x '+str(cw)
ct='TLE x '+str(ct)
cr='RE x '+str(cr)
print(ca)
print(cw)
print(ct)
print(cr)

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

// vector<int> dp(100000, 1e9);

int main()
{
    string S;
    cin >> S;
    rep(i,S.length()){
    printf("x");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;

    if(a >= 13)
        cout << b << endl;
    else if(a <= 12 && a >= 6)
        cout << b/2 << endl;
    else 
        cout << 0 << endl;

    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

ll n,c,k;
ll t[101001];

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>c>>k;
  rep(i,n)cin>>t[i];
  sort(t,t+n);
  ll res=0,maxt=t[0]+k,cnt=1;
  for(int i=0;i<n;){
    int j;
    for(j=i+1;j<n&&t[j]<=maxt&&cnt<c;j++){
      cnt++;
    }
    cnt=1;
    maxt=t[j]+k;
    i=j;
    res++;
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1024
object Main extends App {
  def buildFrame(x: (Int, Int)): String = {
    (List("#" * x._2) ::: List.fill(x._1 - 2)(s"#${"." * (x._2 - 2)}#") ::: List("#" * x._2)).mkString("\n")
  }

  scala.io.Source.stdin.getLines.toList.init
    .map(_.split(" ").map(_.toInt))
    .map(x => (x(0), x(1)))
    .map(buildFrame)
    .map(x => println(x + "\n"))
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 3e6 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, ans = -1;

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

	cin >> n;
	for (int i = 0; i < maxn; i++)
	{
		int now = i * 108 / 100;
		if (now == n)
			ans = i;
	}
	if (ans == -1)
		cout << ":(" << endl;
	else
		cout << ans << endl;
}



Measured memory_bytes: 384
# ABC093B - Small and Large Integers
a, b, k = list(map(int, input().rstrip().split()))
ans = []

if k >= b - a:
    for i in range(a, b + 1):
        print(i)
else:
    for i in range(k):
        ans.append(a + i)
    for j in range(k):
        if b - j not in ans:
            ans.append(b - j)
    ans = sorted(ans)
    for k in ans:
        print(k)

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

fn solve(n: u32, a: Vec<u32>) -> u32{
    let sum = a.iter().sum();
    a.into_iter().filter(|x| x*n <= sum).count() as u32
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    loop {
        let n: u32 = iter.next().unwrap().parse().unwrap();
        if n == 0  {
            return;
        }
        let a: Vec<u32> = (0..n)
            .map(|_| {iter.next().unwrap().parse().unwrap()})
            .collect();
        println!("{}", solve(n, a));
    }
}



Measured memory_bytes: 5024
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>

using namespace std;

int main() {
	int T,i,j,a[11];

	for(i=1;i<11;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<11;i++)
    {
        for(j=1;j<11;j++)
        {
            if(a[i]>a[j])
            {
                T=a[i];
                a[i]=a[j];
                a[j]=T;
            }

        }
    }
    for(i=1;i<4;i++)
    {
        printf("%d\n",a[i]);
    }

	return 0;
}

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

using namespace std;

double sqr(double x) { return x * x; }

int n, m;
double l[22], a[22], b[22];

double d[22][22];

double ans;

double eval(int t) {
	double ret = 0.0;
	for (int i = 0; i < n; i++) {
		if (!(t >> i & 1)) continue;
		for (int j = i + 1; j < n; j++) {
			if (!(t >> j & 1)) continue;
			ret += d[i][j];
		}
	}
	return ret;
}

void rec(int i, int s, int t) {
	if (s == m) {
		ans = max(ans, eval(t));
		return;
	}
	
	if (i == n) return;
	
	rec(i + 1, s, t);
	t |= 1 << i;
	rec(i + 1, s + 1,t);
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> l[i]>> a[i] >> b[i];
	
	memset(d, 0, sizeof(d));
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			double dist = sqr(l[i] - l[j]) + sqr(a[i] - a[j]) + sqr(b[i] - b[j]);
			d[i][j] = d[j][i] = dist;
		}
	}
	
	ans = 0;
	rec(0, 0, 0);
	printf("%lf\n", ans);
	
	return 0;
}

Measured memory_bytes: 1248
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t N;
    int32_t a[100];
    int32_t aMin = INT32_MAX;
    int32_t aMax = INT32_MIN;

    scanf("%zu\n", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%zu", &(a[i]));
        if (i < N - 1) {
            scanf(" ");
        }

        if (a[i] < aMin) {
            aMin = a[i];
        }
        if (aMax < a[i]) {
            aMax = a[i];
        }
    }

    size_t costMin = (size_t)100000000;

    for (int32_t t = aMin; t <= aMax; t++) {
        size_t cost = 0;
        for (size_t i = 0; i < N; i++) {
            cost += (size_t)((t - a[i]) * (t - a[i]));
        }

        if (cost < costMin) {
            costMin = cost;
        }
    }

    printf("%zu", costMin);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>



int solve (int ,int );
int res;
int n ,arr[20] ,m[200];
int main() 
{


int i ,j , q;

scanf("%d",&n);

for (i = 0; i < n; i++){
scanf("%d",&arr[i]);
}
scanf("%d",&q);
for (i = 0; i < q; i++){
scanf("%d",&m[i]);
}
for ( i = 0; i < q;i++){
if (( solve( 0 , m[i] ) )   > 0){printf("yes\n");}
else{printf("no\n");}
}
	return 0;

}

int solve (int i,int m ){
   if (m == 0){ return 1;}
   if (i >= n){return 0;}

    res = solve(i + 1, m ) + solve(i + 1, m - arr[i]  );
   return res;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;
    cout << string(dx, 'R') << string(dy, 'U');
    cout << string(dx, 'L') << string(dy, 'D');
    cout << 'D' << string(dx + 1, 'R') << string(dy + 1, 'U') << 'L';
    cout << 'U' << string(dx + 1, 'L') << string(dy + 1, 'D') << 'R';
    cout << endl;
    return 0 ;

}

 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

int main(int argc, char const* argv[])
{
    int n;
    std::cin >> n;

    auto data = std::vector<std::pair<std::string, std::pair<int, int>>>(n);
    auto line = 1;
    for(auto &p: data)
    {
        std::cin >> p.first >> p.second.first;
        p.second.second = line;
        line++;
    }

    std::sort(data.begin(), data.end(),
            [](std::pair<std::string, std::pair<int, int>> &a, std::pair<std::string, std::pair<int, int>> &b) -> bool {
                if(a.first != b.first)
                {
                    return a.first < b.first;
                }
                else
                {
                    return a.second.first > b.second.first;
                }
            });

    for(auto &p: data)
    {
        std::cout << p.second.second << std::endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int INF = 1e8;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h+2);
    s[0]=string(w+2,'#');
    for(int i=1; i<h+1; i++){
        string t;
        cin>>t;
        s[i]="#"+t+"#";
    }
    s[h+1]=string(w+2,'#');
    
    int dot = 0;
    for(int i=1; i<h+1; i++){
        for(int j=1; j<w+1; j++){
            if(s[i][j]=='.') dot++;
        }
    }
    
    queue<P> que;
    vector<vector<int>> d(h+2,vector<int>(w+2,INF));
    que.push(P(1,1));
    d[1][1]=1;
    vector<int> dx={1,-1,0,0};
    vector<int> dy={0,0,1,-1};
    while(!que.empty()){
        P q=que.front();que.pop();
        int y=q.first,x=q.second;
        for(int i=0; i<4; i++){
            int ny=y+dy[i],nx=x+dx[i];
            if(s[ny][nx]=='#'||d[ny][nx]!=INF)continue;
            d[ny][nx]=d[y][x]+1;
            que.push(P(ny,nx));
        }
    }
    if(d[h][w]==INF)cout<<-1;
    else cout<<dot-d[h][w];

    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
  int N;
  cin >> N;
  int L[2*N];
  for(int i = 0;i<2*N;i++) cin >> L[i];
  sort(L,L+2*N);
  int sum=0;
  for(int i = 0;i<N;i++) sum += L[2*i];
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int maxn = 100000 + 5;
const int maxm = 105;
const int mod = 1e9 + 7;
const ll inf = 1e15 + 7;
int main() {
    int a, b;
    cin >> a >> b;
    if((a*b) & 1) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
int main(){
	char s[10];
	scanf("%s", s);
	int ans=0, sum=0;
	for (int i=0;s[i];i++)
		if (s[i]=='R') sum++;
		else ans=max(ans, sum), sum=0;
	ans=max(ans, sum);
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n, k;
  string s;
  cin >> n >> s >> k;
  char c = s[k-1];
  for(int i=0;i<s.size();i++){
    if(s[i] != c){
      s[i] = '*';
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
import itertools
k = int(input())
cnt = 0
lists = list(range(1,k+1))
for i,j in itertools.combinations(lists,2):
    if i % 2 == 1:
        if j % 2 == 0:
            cnt += 1
    elif i % 2 == 0:
        if j % 2 == 1:
            cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    int n;
    cin >> n;
    int x = 0;
    vii a(n);
    map<int, int> cnt;
    vii ruijo(32);
    ruijo[0] = 1;
    rep(i, 31) { ruijo[i + 1] = ruijo[i] * 2; }
    rep(i,n){
        cin >> a[i];
        x ^= a[i];
        cnt[a[i] ^ (a[i] - 1)]++;
    }
    int ans = 0;
    repr(i,31,-1){
        if ((x>>i)&1){
            if (cnt[ruijo[i+1]-1]==0){
                cout << -1 << endl;
                return 0;
            }
            ans++;
            x ^= (ruijo[i + 1] - 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b){
		cout << c << endl;
	}else if(a == c)
		cout << b << endl;
	else
		cout << a << endl;
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <queue>

using namespace std;


int main() {
	int N; cin >> N;
	long* P = new long[N];
	long* a = new long[N + 1];
	a[0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> P[i];
		a[P[i]] = i;
	}

	set<long> st;
	st.insert(-1);
	st.insert(N);
	st.insert(a[N]);

	long sum = 0;

	for (long i = N - 1; i > 0; i--) {
		auto itrR = st.lower_bound(a[i]);
		auto itrL = itrR; itrL--;

		if (*itrL != -1) {// 左側を含む場合
			long x, y;

			auto itrLL = itrL; itrLL--;
			x = *itrL - *itrLL;
			y = *itrR - a[i];

			sum += x * y * i;
		}
		if (*itrR != N) {// 右側を含む場合
			long x, y;

			auto itrRR = itrR; itrRR++;
			x = a[i] - *itrL;
			y = *itrRR - *itrR;

			sum += x * y * i;
		}

		st.insert(a[i]);
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 6528
n = int(input())
s = input()
cnt = 0

for i in range(1000):
    p = str(i).zfill(3)
    p1 = s.find(p[0])
    if p1 == -1: continue
    p2 = s.find(p[1], p1 + 1)
    if p2 == -1: continue
    p3 = s.find(p[2], p2 + 1)
    if p3 == -1: continue
    cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
	int N, T;
	cin >> N >> T;
	int i = N;
	int c_min = 1001;
	while (i--) {
		int c, t;
		cin >> c >> t;
		if (t <= T) {
			if (c < c_min) {
				c_min = c;
			}
		}
	}

	if (c_min > 1000) {
		cout << "TLE";
	}
	else {
		cout << c_min;
	}
	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

template <typename T>
struct BellmanFord
{
    struct edge
    {
        int u, v;
        T w;
        edge() {}
        edge(int u, int v, T w) : u(u), v(v), w(w) {}
    };

    int n;
    vector<vector<int>> G;
    vector<int> used, reach;
    BellmanFord(int n) : n(n), G(n), used(n, 0), reach(n, 0) {}

    vector<edge> es;
    void add_edge(int u, int v, T c)
    {
        es.emplace_back(u, v, c);
        G[u].emplace_back(v);
    }

    void dfs(int v)
    {
        if (used[v])
            return;
        used[v] = 1;
        for (int u : G[v])
            dfs(u);
    }

    T build(int from, int to, int &neg_loop)
    {
        for (int i = 0; i < n; i++)
        {
            fill(used.begin(), used.end(), 0);
            dfs(i);
            reach[i] = used[to];
        }
        vector<T> ds(n, INF);
        ds[from] = 0;
        for (int j = 0; j < n; j++)
        {
            bool update = 0;
            for (auto e : es)
            {
                if (!reach[e.u] || !reach[e.v] || ds[e.u] == INF)
                    continue;
                if (ds[e.v] > ds[e.u] + e.w)
                {
                    ds[e.v] = ds[e.u] + e.w;
                    update = 1;
                }
            }
            if (!update)
                break;
            if (j == n - 1)
            {
                neg_loop = 1;
                return INF;
            }
        }
        neg_loop = 0;
        return ds[to];
    }
};

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

    int n, m, p;
    cin >> n >> m >> p;
    BellmanFord<int> G(n);
    rep(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        c = p - c;
        G.add_edge(a, b, c);
    }
    int f, res = G.build(0, n - 1, f);
    res = max(-res, 0LL);
    cout << (f ? -1 : res) << endl;
}

Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	double t[] = { 1.1, 0.6, 0.2, 0 };
	int n[8];
	memset(n, 0, sizeof(n));
	double e[2];
	while (scanf("%lf %lf", e, e+1) != EOF)
	{
		for (int i = 0; i < 2; ++i)
		{
			int j;
			for (j = 0; e[i] < t[j]; ++j)
				;
			++n[i*4 + j];
		}
	}
	for (int i = 0; i < 4; ++i)
		printf("%d %d\n", n[i], n[4 + i]);

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <typeinfo>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <set>
#include <map>
#include <cstring>

using namespace std;

int N;
int mod = 1e9 + 7;


bool Ok(string last4) {
    for (int i = 0; i < 4; i++) {
        string tmp = last4;
        if (i > 0) {
            swap(tmp[i], tmp[i-1]);
        }
        if (tmp.find("AGC") != -1) {
            return false;
        }
    }
    return true;
}


int DFS(int cnt, string last3, vector<map<string, int> >& memo) {
    if (memo[cnt].count(last3)) {
        return memo[cnt][last3];
    }
    if (cnt == N) {
        return 1;
    }
    int ret = 0;
    string s = "ACGT";
    for (char i : s) {
        if (Ok(last3 + i)) {
            ret = (ret + DFS(cnt + 1, last3.substr(1, 2) + i, memo)) % mod;
        }
    }
    memo[cnt][last3] = ret;
    return ret;
}



int main() {
    ios::sync_with_stdio(false);
    cin >> N;
    vector<map<string, int> > memo(N+1);
    cout << DFS(0, "TTT", memo);
    return 0;
}


Measured memory_bytes: 896
// id: ALDS1_3_C
// CPU: 00:sec
#include <cstdio>
#include <list>
#include <string>

using std::list;
using std::string;

static const int MAX_LEN = 11;

void remove(list<int> &ilst, int x);
void print_list(list<int> &ilst);

int main()
{
	int n;
	list<int> dlist;

	scanf("%d", &n);

	for ( int i = 0; i < n; ++i ) {
		char command[MAX_LEN + 1];
		int key;

		scanf("%s", command);
		string cmd(command);

		if ( cmd == "insert" ) {
			scanf("%d", &key);
			dlist.push_front(key);
		}
		else if ( cmd == "delete" ) {
			scanf("%d", &key);
			remove(dlist, key);
		}
		else if ( cmd == "deleteFirst" )
			dlist.pop_front();
		else
			dlist.pop_back();
	}

	print_list(dlist);

	return 0;
}

void remove(list<int> &ilst, int x)
{
	list<int>::iterator it = ilst.begin();

	while ( it != ilst.end() ) {
		if ( *it == x ) {
			ilst.erase(it);
			break;
		}

		++it;
	}
}

void print_list(list<int> &ilst)
{
	list<int>::iterator it = ilst.begin();

	if ( it != ilst.end() ) {
		printf("%d", *it);
		++it;
	}

	while ( it != ilst.end() ) {
		printf(" %d", *it);
		++it;
	}

	printf("\n");
}


Measured memory_bytes: 34088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

template <typename T>
class SegmentTree{
  public:
    int n;
    T element;
    vector<T> dat;
    function<T(T,T)> operate;

    SegmentTree(){}
    SegmentTree(int n_,T element_,function<T(T,T)> operate_){
        element = element_;
        operate = operate_;
        n = 1;
        while(n < n_) n *= 2;
        dat = vector<T>(n*2,element);
    }

    void update(int k,T a){
        k += n-1;
        dat[k] = a;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = operate(dat[k*2+1],dat[k*2+2]);
        }
    }

    T query(int a,int b,int k,int l,int r){
        if(r<=a || b<=l) return element;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a,b,k*2+1,l,(l+r)/2);
        T vr = query(a,b,k*2+2,(l+r)/2,r);
        return operate(vl,vr);
    }

    T query(int a,int b) { return query(a,b,0,0,n);}
};



ll solve(vector<ll> x,vector<ll> v,ll n, ll c){
    SegmentTree<ll> st(n,0LL, [](ll a,ll b){return max(a,b);});
    ll sumV = 0;
    rep(i,n){
        sumV += v[i];
        st.update(i, sumV-x[i]*2);
    }

    reverse(all(x));
    reverse(all(v));
    sumV = 0;
    ll res = 0;
    rep(i,n){
        sumV += v[i];
        ll dist = c-x[i];
        res = max((sumV-dist) + max(st.query(0,n-i-1),0LL), res);
    }

    return res;
}

int main(void){
    ll n,c;
    cin>>n>>c;
    vector<ll> x(n),v(n);
    rep(i,n){
        cin>>x[i]>>v[i];
    }
    vector<ll> rx = x, rv = v;
    ll res1 = solve(x,v,n,c);
    reverse(all(rx));
    reverse(all(rv));
    rep(i,n){
        rx[i] = c-rx[i];
    }
    ll res2 = solve(rx,rv,n,c);
    cout<<max(res1,res2)<<endl;
    return 0;
}


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

int main()
{
    ll A,B,C;
    cin >> A >> B >> C;
    ll K;
    cin >>K;
    ll sum=0;
    if (A<=K)
    {
        K-=A;
        sum+=A;
        if (K>0 && B<=K)
        {
            K-=B;
            if (K>0 && C<=K)
            {
                sum-=C;
            }
            else
            {
                sum-=K;
            }
            
        }
    }
    else
    {
        sum+=K;
        K=0;
    }
    cout << sum << endl;
    return 0;
   
}

Measured memory_bytes: 3632
N = int(input())

def factoring(M,n=2):
    if M==1: return {}
    for i in range(n,int(M**0.5)+1):
        if M%i==0:
            ret = factoring(M//i,i)
            ret[i] = ret.get(i,0)+1
            return ret
    return {M:1}

F = factoring(N)

ans = 0
for n in F.values():
    tmp = 1
    while n >= tmp:
        n -= tmp
        ans += 1
        tmp += 1

print(ans)

Measured memory_bytes: 9464
#include<bits/stdc++.h>
using namespace std;
void bell(int a,int b, int c){
    if(a==b && a==c){
        cout<<(a+b)<<endl;
    }
    else{
       int x,y,z;
       x=a+b;
       y=a+c;
       z=b+c;
       if(x<y && x<z){
          cout<<x<<endl;
       }
      else if(y<x && y<z){
        cout<<y<<endl;
       }
       else if(z<x && z<y){
        cout<<z<<endl;
       }
    }
}
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  bell(a,b,c);
  return 0;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (lint i = 0; i < lint(n); ++i)
#define Rep(i, n) for (lint i = lint(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { lint to, cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3e18;

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

lint modpow(lint x, lint n) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

lint fact[10000000];
void f_init(lint n) {
	if (10000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(lint p) {
	for (lint i = 2LL; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1LL;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

lint x, y, ans;
int main() {
	cin >> x >> y;
	f_init(x + 10);
	if ((x + y) % 3 != 0) cout << "0\n";
	else {
		rep(i, x+1) {
			if ((x - i) % 2 == 0) {
				if (2 * i + (x - i) / 2 != y) continue;
				ans += comb(i + (x - i) / 2, i);
				ans %= mod;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
ll n, k;
int main(){
	scanf("%lld %lld", &n, &k);
	ll chk1 = 0, chk2 = 0, c1 = 0, c2 = 0;
	for(int i = 1; i < k; i++){
		chk1 += i;
		c1  = i;
	}
	for(int i = n; i > n - k; i--){
		chk2 += i;
		c2 = i;
	}
	ll sum = 0;
	while(k <= n + 1){
		sum += (chk2 + 1 - chk1);
		c1++;
		c2--;
		chk2 += c2;
		chk1 += c1;
		k++;
	}
	cout << sum % mod <<endl;
	return 0;
}


Measured memory_bytes: 3724
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m,a,b;
    cin >> n >> m;
    vector<int> c(n+1,0);
    for(int i=0;i<m;i++){
        cin >> a >> b;
        c[a]++;
        c[b]++;
    }
    for(int i=1;i<=n;i++){
        cout << c[i] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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


int main()
{
  string S;
  cin >> S;
  int ans = INF;
  for (int i = 0; i <= S.size() - 3; i++) {
    int num = 100*(S[i] - '0') + 10*(S[i+1] - '0') + S[i+2] - '0';
    ans = min(ans, abs(753 - num));
  }
  cout << ans << endl;
	return 0;
}



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

const int MAXN = 100010;
int fa[MAXN], n, dep[MAXN], ans, K;
int head[MAXN], nxt[MAXN];
int dfs(int u) {
	int res = dep[u];
	for (int i = head[u]; i; i = nxt[i]) {
		dep[i] = dep[u] + 1;
		res = std::max(dfs(i), res);
	}
	if (res - dep[u] == K - 1 && fa[u] != 1) fa[u] = 1, ++ans, res = 0;
	return res;
}
void dfs2(int u) {
	for (int i = head[u]; i; i = nxt[i])
		dep[i] = dep[u] + 1, dfs2(i);
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> K;
	for (int i = 1; i <= n; ++i) std::cin >> fa[i];
	for (int i = 2; i <= n; ++i)
		nxt[i] = head[fa[i]], head[fa[i]] = i;
	for (int i = head[1]; i; i = nxt[i]) dfs(i);
	memset(head, 0, n + 1 << 2);
	memset(dep, 0, n + 1 << 2);
	for (int i = 2; i <= n; ++i)
		nxt[i] = head[fa[i]], head[fa[i]] = i;
	for (int i = head[1]; i; i = nxt[i]) dep[i] = 1, dfs2(i);
	bool flg = true;
	for (int i = 1; i <= n; ++i) flg &= (K - dep[i]) % (dep[fa[1]] + 1) == 0;
	ans += !flg;
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 4992
N = int(input())
A = [[int(_) for _ in input().split()] for i in range(N)]

dp = [[0] * ((1 << 21) + 10) for _ in range(N + 1)]
dp[0][0] = 1
MOD = 10**9+7
for i in range(N):
    # i 番目の男性に着目
    for s in range(1 << N):  # sのbit が立っている女子はマッチ済み
        if dp[i][s] == 0: continue

        for j in range(N):
            jb = 1 << j
            if not (s & jb) and A[i][j]:
                # i, j をマッチさせる
                dp[i + 1][s | jb] += dp[i][s]
print(dp[N][(1 << N) - 1] % MOD)


Measured memory_bytes: 430344