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

struct Node {
    int key;
    Node *prev, *next;
};

Node *nil;

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node* listSearch(int key) {
    Node *cur = nil->next;
    while ( cur != nil && cur->key != key) {
        cur = cur->next;
    }

    return cur;
}

void deleteNode(Node *t){
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while (1) {
        if (cur == nil) {
            break;
        }

        if (isf++ > 0) {
            printf(" ");
        }

        printf("%d", cur->key);
        cur = cur->next;
    }

    printf("\n");
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for( i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') {
            insert(key);
            np++;
            size++;
        } else if(com[0] == 'd') {
            if (strlen(com) > 6) {
                if (com[6] == 'F') {
                    deleteFirst();
                } else if (com[6] == 'L') {
                    deleteLast();
                }
            } else {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }

    printList();

    return 0;
}


Measured memory_bytes: 34436
#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 print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

template<typename T>
class TwoDimCumsum {
public:
    int H,W;
    vector<vector<T>> d;
    TwoDimCumsum(T inH, T inW):H(inH),W(inW),d(H+1,vector<T>(W+1,0)){}

    void set_xy(int x, int y){
        d[x][y]++;
    }
    void init(){
        for(int i = 1; i <= H; ++i){
            for(int j = 1; j <= W; ++j){
                d[i][j] += d[i-1][j];
                d[i][j] += d[i][j-1];
                d[i][j] -= d[i-1][j-1];
            }
        }
    }
    T Query(int p, int q){
        return d[q][q] - d[p-1][q] - d[q][p-1] + d[p-1][p-1];
    }
    void display(){
        for(int i = 0;i <= H;++i){
            for(int j = 0; j <= W; ++j){
                cerr<<d[i][j]<<((j == W) ? "\n":" ");
            }
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N,M,Q;
    cin>>N>>M>>Q;
    TwoDimCumsum<int> Cumsum(N,N);
    rep(i,M){
        int l,r;
        cin>>l>>r;
        Cumsum.set_xy(l,r);
    }
    Cumsum.init();
    //Cumsum.display();
    for(int i = 0; i < Q; ++i){
        int p,q;
        cin>>p>>q;
        cout<<Cumsum.Query(p, q)<<endl;
    }
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3968082#2
// bit dpで書いてみる
// dfsをdpで書くということ
// 上のコードは以下を参考にした
// http://kyopro.hateblo.jp/entry/2018/02/12/080534


int m;
int ans;
vector<pii> v(20);

pii incline(int i, int j) {
    pii s;
    s.F = v[j].S - v[i].S;
    s.S = v[j].F - v[i].F;
    int g = gcd(s.F, s.S);
    s.F /= g;
    s.S /= g;
    if (s.S < 0) { s.S = -s.S; s.F = -s.F; }
    return s;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    cin >> m;
    rep(i, m) cin >> v[i].F >> v[i].S;
    
    int dp[1 << 20] = {0};
    
    rep(bit, 1 << m) {
        rep(i, m) {
            if (bit & (1 << i)) continue;
            rep3(j, i + 1, m) {
                if (bit & (1 << j)) continue;
                pii s = incline(i, j);
                int B = bit | (1 << i);
                B |= (1 << j);
                int num = 1;
                rep(k, m) {
                    if (B & (1 << k)) continue;
                    rep3(l, k + 1, m) {
                        if (B & (1 << l)) continue;
                        pii t = incline(k, l);
                        if (s != t) continue;
                        B |= (1 << k); B |= (1 << l);
                        num++;
                        // cout << endl << i << " " << j << " " << k << " " << l << " " << endl << s.F << " " << s.S << " " << t.F << " " << t.S << endl;
                    }
                }
                if (num == 1) continue;
                chmax(dp[B], dp[bit] + num * (num - 1) / 2);
            }
            
        }
    }
    int ans = 0;
    rep(i, 1 << m) chmax(ans, dp[i]);
    cout << ans << endl;
    // rep(i, 1 << m) cout << dp[i] << " "; cout << endl;
}





Measured memory_bytes: 7244
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 50;

long long a[N];

int main() {
	long long k;cin>>k;
	rep(i,50) {
		if(i<k%50) a[i]=51*(k/50+1)+49-k;
		else a[i]=51*(k/50)+49-k;
	}
	cout << 50 << endl;
	rep(i,49) cout << a[i]<<' ';
	cout<<a[49]<<endl;
}


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

int main(){
  ll n; cin >> n;
  ll m = n;
  ll ans = 0;
  for(ll i = 2; i <= pow(m, 0.5); i++){
    ll cnt = 0;
    while(n % i == 0){
      cnt++;
      n /= i;
    }
    if(cnt == 0){continue;}
    else if(cnt < 3){ans++; continue;}
    else if(cnt < 6){ans += 2; continue;}
    else if(cnt < 10){ans += 3; continue;}
    else if(cnt < 15){ans += 4; continue;}
    else if(cnt < 21){ans += 5; continue;}
    else if(cnt < 28){ans += 6; continue;}
    else if(cnt < 36){ans += 7; continue;}
    else if(cnt < 45){ans += 8; continue;}
    
    if(n == 1){break;}
  }
  if(n != 1){ans++;}
  cout << ans << endl;
}




Measured memory_bytes: 4096
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
const int N=2000050;
vector<int> E[N];
struct DSU
{
	int p[N],sz[N];
	ll val[N];
	void init(){ for(int i=0;i<N;i++) p[i]=i,sz[i]=1;}
	DSU(){ init();}
	int Find(int x){ return x==p[x]?x:Find(p[x]);}
	void Union(int x, int y)
	{
		x=Find(x);y=Find(y);
		if(x==y) return;
		if(sz[x]<sz[y]) swap(x,y);
		p[y]=x;
		val[x]+=val[y];
		sz[x]+=sz[y];
		E[x].push_back(y);
	}
} Tree;
bool was[N];
const int inf=1e9+7;
void DFS(int u, int zs)
{
	if(was[u]) return;
	was[u]=1;
	for(int i=0;i<E[u].size() && i<zs;i++)
	{
		int v=E[u][i];
		if(!was[v]) DFS(v,inf);
	}
}
int w[N],u[N],v[N],x[N],id[N],nod[N],zs[N];
ll sum[N];
bool comp(int i, int j){ return w[i]<w[j];}
int main()
{
	int n,m;
	scanf("%i %i",&n,&m);
	for(int i=1;i<=n;i++) scanf("%i",&x[i]),Tree.val[i]=x[i];
	for(int i=1;i<=m;i++) scanf("%i %i %i",&u[i],&v[i],&w[i]),id[i]=i;
	sort(id+1,id+1+m,comp);
	for(int j=1;j<=m;j++)
	{
		int i=id[j];
		Tree.Union(u[i],v[i]);
		nod[i]=Tree.Find(u[i]);
		sum[i]=Tree.val[nod[i]];
		//printf("%i: %lld\n",i,sum[i]);
		zs[i]=E[nod[i]].size();
	}
	int ans=0;
	for(int j=m;j>=1;j--)
	{
		int i=id[j];
		int d=u[i];
		if(u[i]==nod[i]) d=v[i];
		if(sum[i]<w[i] && !was[d])
		{
            ans++;
		}
		else DFS(nod[i],zs[i]);
	}
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 89600
using System;

class Program {
    static void Main( string[] args )
    {
        for ( int i = 1; i < 10001; ++i ) {
            int n = int.Parse( Console.ReadLine() );

            if ( 0 == n ) {
                break;
            }

            Console.WriteLine( "Case {0}: {1}", i, n );
        }
    }
}

Measured memory_bytes: 9196
A,B,K=map(int,input().split())
ANS=[]
for i in range(A,A+K):
    if i<=B:
        ANS.append(i)

for i in range(B,B-K,-1):
    if i>=A:
        ANS.append(i)

for i in sorted(list(set(ANS))):
    print(i)

Measured memory_bytes: 3060
import Control.Monad

main = do
  n <- read <$> getLine
  s <- forM [1..n] $ \t ->
    head <$> getLine
  putStrLn . show . solve $ s

solve :: String -> Int
solve s = 
  let m = length $ filter (== 'M') s
      a = length $ filter (== 'A') s
      r = length $ filter (== 'R') s
      c = length $ filter (== 'C') s
      h = length $ filter (== 'H') s
  in sum $ map product $ comb 3 [m,a,r,c,h]


comb :: Int -> [a] -> [[a]]
comb 0 _ = [[]]
comb _ [] = []
comb m (x:xs) = map (x:) (comb (m-1) xs) ++ comb m xs



Measured memory_bytes: 49532
#include<iostream>
#include<algorithm>
#include<string>
#define INF (1ULL<<20)
using namespace std;
 
int dp[1001][1001];
 
int main()
{
    fill(dp[0], dp[1000],INF);
    string s1, s2;
    cin >> s1 >> s2;
    int s1size = s1.size()+1, s2size = s2.size()+1;
    for (int i = 0; i < s1size; ++i) {
        for (int j = 0; j < s2size; ++j) {
            if (j == 0) {
                dp[i][0] = i;
                continue;
            }
            if (i == 0) {
                dp[0][j] = j;
                continue;
            }
            dp[i][j] = min(min(dp[i - 1][j - 1] + (s1[i - 1] != s2[j - 1]), dp[i][j - 1] + 1), dp[i - 1][j] + 1);
        }
    }
    cout << dp[s1size-1][s2size-1] << endl;
}

Measured memory_bytes: 5104
#include<stdio.h>
int main(void){
    int i,j,x1[4],x2[4];
    while(scanf("%d",&x1[0])!=EOF){
        int h=0,b=0;
        for(i=1;i<4;i++)scanf("%d",&x1[i]);
        for(i=0;i<4;i++)scanf("%d",&x2[i]);
        for(i=0;i<4;i++){
            for(j=0;j<4;j++){
                if(x1[i]==x2[j]){
                    if(i==j)h++;
                    else b++;
                }
            }
        }
        printf("%d %d\n",h,b);
    }

    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

vector<ll> m;
vector<bool> num(10,true);

int N,K;

void rec(int n){
    if(n > N) return;

    rep(i,10){
        if(num[i]){
            if(n*10 + i == 0) continue;
            m.emplace_back(n*10 + i);
            rec(n*10 + i);
        }
    }
}


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


    rep(i,K){
        cin >> a;
        num[a] = false;
    }


    rec(0);

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

    rep(i,m.size()){
        if(m[i] >= N){
            cout << m[i];
            return 0;
        }
    }
}

Measured memory_bytes: 4084
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
int main() {
    int n,m,t,h,p,q,tmp,x;
    int a[102];
    int b[102];
    while(cin>>n>>m&&n!=0){t=0;h=0;
        for(int i=0;i<n;i++){
            cin>>a[i];t+=a[i];}
        for(int i=0;i<m;i++)
        {        cin>>b[i];h+=b[i];}
        x=t-h;tmp=200000;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if((a[i]-b[j])*2==x){
                    if(a[i]<tmp){tmp=a[i];
                        p=a[i];q=b[j];}
                }
            }
        }
        if(tmp!=200000)cout<<p<<" "<<q<<endl;
        else cout<<-1<<endl;}
    }

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

int main(){
    char a;
    cin >> a;

    if(a >= 'a')
        a = 'a';
    else
        a = 'A';

    cout << a << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    string x;
    cin>>x;
    if(x[x.size()-1]=='s') cout<<x<<"es"<<endl;
    else cout<<x<<"s"<<endl;
    return 0;
}


Measured memory_bytes: 3648
<?php

$K = (int) trim(fgets(STDIN));
$mods = [];

$lastMod = 7 % $K;
$mods[1] = $lastMod;

for($i = 2; $i <= $K; $i++) {
  $mod = ($lastMod * 10 + 7) % $K;
  $mods[$i] = $lastMod = $mod;
}

$n = array_search(0, $mods, true);
if($n === false) echo "-1\n";
else echo $n, "\n";


Measured memory_bytes: 49908
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv){
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	string s,t; cin >> s >> t;
	int n=int(s.size());
	int m=int(t.size());
	vvi is(26);
	rep(i,n) is[s[i]-'a'].push_back(i);
	rep(i,n) is[s[i]-'a'].push_back(i+n);
	ll ans = 0;
	int p=0;
	rep(i,m){
		int c = t[i]-'a';
		if(is[c].empty()){
			out(-1); return 0;
		}
		p = *lower_bound(is[c].begin(),is[c].end(),p)+1;
		if(p>=n){
			p -= n;
			ans += n;
		}
	}
	ans += p;
	out(ans);
}




Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define int long long int
#define INF 1000000005
#define MOD 1000000007
#define FF first
#define SS second
#define int long long int

using namespace std;
typedef long long ll;

ll gcd(ll loc, ll b)
{
    if(loc == 0LL)
        return b;
    if(b == 0LL)
        return loc;
    return gcd(b, loc%b);
}

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll modx(ll Base, ll exponent)
{
  ll ans = 1;
  if(Base == 1)
    return Base;
  while(exponent)
  {
    if(exponent & 1)
      ans = (ans * Base)%MOD;
    Base = (Base * Base)%MOD;
    exponent = exponent >> 1;
  }
  return ans;
}

ll inmodx(ll num)
{
  return (modx(num, MOD-2LL));
}

bool cmp(pii loc, pii b)//true for loc before b
{
  if(loc.SS < b.SS)
    return 1;
  if(loc.SS > b.SS)
    return 0;
  if(loc.FF <= b.FF)
    return 1;
  return 0;
}
int dp[105][100005];
pair<int,int> p[1005];
int n,w;
int solve()
{
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;
            }
            else if(p[i-1].FF<=j)
            {
                dp[i][j]=max(dp[i-1][j],p[i-1].SS+dp[i-1][j-p[i-1].FF]);
            }
            else 
                dp[i][j]=dp[i-1][j];

        }
    }
    return dp[n][w];
}
signed main()
{   
    
  
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0); 
    cin.tie(0);
    cout.tie(0);
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        cin>>p[i].FF>>p[i].SS;
    }
    cout<<solve()<<endl;
    return 0;
}

    


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int x;
  cin>>x;
  if(x/10%111==0 || x%10%111==0){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

N, K = inpl()
dp = [False] * N
for i in range(K):
    d = inp()
    A = inpl()
    for a in A:
        dp[a-1] = True
cnt = 0
for bl in dp:
    if not bl:
        cnt += 1
print(cnt)

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

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

const int mod=1e9+7;

int main(){
  int n;
  cin>>n;
  ll ans=1;
  vector<int> res(3);
  rep(i,n){
    int a;
    cin>>a;
    int p=0;
    int q=-1;
    rep(j,3){
      if(res[j]==a){
        p++;
        q=j;
      }
    }
    if(p==0){
      cout<<0<<endl;
      return 0;
    }
    ans*=p;
    ans%=mod;
    res[q]++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n;
  cin >> n;
  int l, r, res = n;
  for (int i = 0; i < n; ++i) {
    cin >> l >> r;
    res += r - l;
  }
  cout << res << endl;
  return 0;
}


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

int cnt[60][60], dp[60][60];
int main() {
	int h, w; scanf("%d%d", &h, &w);
	rep(i, h)rep(j, w)scanf("%1d", &cnt[i][j]);
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = cnt[0][0];
	rep(i, h)rep(j, w) {
		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt[i + 1][j]);
		dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt[i][j + 1]);
	}
	printf("%d\n", dp[h - 1][w - 1]);
}

Measured memory_bytes: 3248
import java.util.*;
public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      String A = sc.next(), B = sc.next();
      String AB = A+B;
      int num = Integer.valueOf(AB);
      int sqrt = (int)Math.pow(num,0.5);
      String ans = (sqrt*sqrt == num)?"Yes" : "No";
      System.out.println(ans);
      
    }
}

Measured memory_bytes: 39328
import java.util.*;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    // int N = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        int N = scanner.nextInt();
        scanner.nextLine();

        List<List<Integer>> edges = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            edges.add(new ArrayList<>());
        }
        for (int i = 0; i < N - 1; i++) {
            int[] e = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            edges.get(e[0] - 1).add(e[1] - 1);
            edges.get(e[1] - 1).add(e[0] - 1);
        }

        int[] zdist = new int[N];
        Queue<Node> q = new ArrayDeque<>();
        Set<Integer> visited = new HashSet<>();
        q.add(new Node(0, 0));
        while (!q.isEmpty()) {
            Node n = q.poll();
            if (visited.contains(n.n)) {
                continue;
            }
            visited.add(n.n);
            zdist[n.n] = n.c;
            for (int e: edges.get(n.n)) {
                q.add(new Node(e, n.c + 1));
            }
        }

        int[] ndist = new int[N];
        q.clear();
        visited.clear();
        q.add(new Node(N - 1, 0));
        while (!q.isEmpty()) {
            Node n = q.poll();
            if (visited.contains(n.n)) {
                continue;
            }
            visited.add(n.n);
            ndist[n.n] = n.c;
            for (int e: edges.get(n.n)) {
                q.add(new Node(e, n.c + 1));
            }
        }

        int b = IntStream.range(0, N).map(i -> zdist[i] <= ndist[i] ? 1 : 0).sum();
        if (b > N - b) {
            System.out.println("Fennec");
        } else {
            System.out.println("Snuke");
        }
    }

    static class Node {
        int n;
        int c;

        public Node(int n, int c) {
            this.n = n;
            this.c = c;
        }
    }

}


Measured memory_bytes: 176904
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int R=stdIn.nextInt();
		int G=stdIn.nextInt();
		int B=stdIn.nextInt();
		int N=stdIn.nextInt();
		int z=0,y=0,x=0,ans=0,max=B+1;
		while(true){
			while(true){
				max=(z*R)+(y*G);
				if(max>N)
					break;
				max=N-max;
				if(max%B==0)
					ans++;
				y++;
			}
			z++;y=0;
			if(z*R>N)
				break;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
n = int(input())
line = list(input())

# 各地点の人について，背を向けている人を数える。無駄が多い？
back = [0] * n
wester, easter = 0, 0
for i, p in enumerate(line):
    back[i] = wester

    if p == 'W':
        wester += 1
i = n
for p in line[::-1]:
    i -= 1
    back[i] += easter

    if p == 'E':
        easter += 1

print(min(back))


Measured memory_bytes: 20044
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <queue>

#define MAX 100005
#define ll long long int
using namespace std;

int main(void)
{
	vector <pair <int, int>> ans; //?????????
	int i, j;
	int n;
	int temp1, temp2;
	int temp = 0;
	int xo = 0, yo = 0; //?????¨
	vector <pair <int, int>> xy, nyu;
	int xa, ya;

	int len = 0;
	int max = 0;
	cin >> n;
	
	for (i = 0; i < n; i++) {
		int x = 0, y = 0;
		xa = 0;
		ya = 0;
		max = 0;
		len = 0;


		while (1) {
			cin >> temp1 >> temp2;
			nyu.push_back(make_pair(temp1, temp2));
			if (temp1 == 0 && temp2 == 0) {
				break;
			}

			x = x + temp1;
			y = y + temp2;

			len = x * x + y * y;

			if (len > max) {
				max = len;
			}
		}

		j = 0;
		x = 0;
		y = 0;

		while (1) {
			
			temp1 = nyu[j].first;
			temp2 = nyu[j].second;

			if (temp1 == 0 && temp2 == 0) {
				break;
			}

			x = x + temp1;
			y = y + temp2;
			len = x * x + y * y;

			if (max == len) {
				xy.push_back(make_pair(x, y));
			}
			j++;
		}

		sort(xy.rbegin(), xy.rend());

		xa = xy[0].first;
		ya = xy[0].second;


		ans.push_back(make_pair(xa, ya));

		nyu.clear();
		xy.clear();



	}


	for (i = 0; i < n; i++) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}


	return (0);
}

Measured memory_bytes: 3036
import queue
q = queue.Queue()
for i in range(1,10):
    q.put(i)
K = int(input())
for k in range(K):
    x =q.get()
    last = x % 10
    if last != 0:
        q.put(10*x + last - 1)
    q.put(10*x + last)
    if last != 9:
        q.put(10*x + last + 1)
print (x)

Measured memory_bytes: 57172
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define pb push_back
#define endl '\n'
ll solve(){
	ll x;
	cin>>x;
	if(x>=400&&x<600) cout<<"8";
	else if(x>=600&&x<800) cout<<"7";
	else if(x>=800&&x<1000) cout<<"6";
	else if(x>=1000&&x<1200) cout<<"5";
	else if(x>=1200&&x<1400) cout<<"4";
	else if(x>=1400&&x<1600) cout<<"3";
	else if(x>=1600&&x<1800) cout<<"2";
	else cout<<"1";
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int ma=0;
  int mi=1000000001;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    ma=max(a[i],ma);
    mi=min(a[i],mi);
  }
  cout<<ma-mi;
}

Measured memory_bytes: 764
import scala.io.Source

object Main {
  def main(args: Array[String]) = {
    val lines = Source.stdin.getLines.toStream
    val input = lines.drop(1).head.split(' ').map(_.toLong)

    val memo = Array.fill(input.length + 1, input.length + 1, 2)(-1L)
    (1 to input.length).foreach { n =>
      memo(n-1)(n)(0) = input(n-1)
      memo(n-1)(n)(1) = 0
    }

    val res = dp(input, 0, input.length, memo)
    println(res(1))
  }

  def dp(input: IndexedSeq[Long], left: Int, right: Int, memo: Array[Array[Array[Long]]]): Array[Long] = {
    if (memo(left)(right)(0) != -1L) return memo(left)(right)

    var minCost = Long.MaxValue
    var minTotal = Long.MaxValue
    ((left + 1) to (right - 1)).foreach { split =>
      val leftRes = dp(input, left, split, memo)
      val rightRes = dp(input, split, right, memo)
      val cost = leftRes(0) + rightRes(0)
      val total = leftRes(1) + rightRes(1) + leftRes(0) + rightRes(0)
      if (total < minTotal) {
        minCost =  cost
        minTotal = total
      }
    }
    memo(left)(right)(0) = minCost
    memo(left)(right)(1) = minTotal
    memo(left)(right)
  }
}


Measured memory_bytes: 40204
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

int main(){
	int N,i,j,X,D,min,check,ans,k;
	int *x,*d;

	scanf("%d%d",&N,&X);
	x = new int[N];
	d = new int[N];

	min =-1;
	for(i=0;i<N;i++){
		scanf("%d",&x[i]);
		d[i] = abs(x[i] - X);
		if(min > d[i] || min == -1){
			min = d[i];
		}
	}


	ans=0;
	for(i=1;i<= min && ans ==0;i++){
		if(min%i == 0){
		k = min/i;
		check = 1;
			for(j=0;j<N && check == 1;j++){
				if(d[j] % k != 0){
					check = 0;
				}
			}
			if(check == 1){
				ans = k;
			}
		}
	}
	
	printf("%d\n",ans);

	delete[] x;
	delete[] d;


	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<ll, ll>;

char S[20];
int n;
void input() {
    cin >> S;
    n = strlen(S);
}

void calc() {
    if (n % 2) {
        cout << "No";
        return;
    }
    for (int i = 0; i < n; i += 2) {
        if (S[i] != 'h' || S[i + 1] != 'i') {
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    input();
    calc();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main(){
ll n,a,b;cin>>n>>a>>b;
n-=a;
int x=n/b;
cout<<n-b*x;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

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

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#define Rint register int
#define mem(a,b) memset(a,(b),sizeof(a))
#define Temp template<typename T>
using namespace std;
typedef long long LL;
Temp inline void read(T &x){
    x=0;T w=1,ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
    x=x*w;
}
const int maxn=100000+10;
int p[maxn];
int pri[maxn],cnt;
int a[maxn];
inline void prime(){
	p[1]=1;
	for(Rint i=2;i<=100000+5;i++){
		if(!p[i])pri[++cnt]=i;
		for(Rint j=1;j<=cnt;j++){
			if(i*pri[j]>100000+5)break;
			p[i*pri[j]]=1;
			if(i%pri[j]==0)break;
		}
	}
}

inline bool chk(int x){
	if(p[x]==0)return 1;
	return 0;
}
inline void init(){
	prime();
	for(Rint i=1;i<=100000+5;i++){
		a[i]+=a[i-1];
		if(i%2==0)continue;
		if(chk(i)&&chk((i+1)/2))a[i]++;
	}
}

int main(){
	init();
	int T;
	read(T);
	while(T--){
		int l,r;
		read(l);read(r);
		printf("%d\n",a[r]-a[l-1]);
	}
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a <= c && c <= a + b){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
  return 0;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(1<<20)
h,w=[int(x) for x in input().split()]
ch,cw=[int(x) for x in input().split()]
dh,dw=[int(x) for x in input().split()]
ch-=1
cw-=1
dh-=1
dw-=1

s=[]
for _ in range(h):
    s.append(list(input()))

nxt=[[ch,cw,0]]
#再起
def rcl(y,x,now):
    
    if y==dh and x==dw:
        print(now)
        exit()
    
    if s[y][x]=='#':
        return
    
    s[y][x]='#'
    # 四方を見る
    for i in range(4):
        yy,xx=-1,0
        if i==1:yy,xx=0,1
        if i==2:yy,xx=1,0
        if i==3:yy,xx=0,-1
        
        if y+yy<0 or h<=y+yy or x+xx<0 or w<=x+xx:
            continue
        if s[y+yy][x+xx]=='#':
            continue
        
        rcl(y+yy,x+xx,now)
    #5*5
    for i in range(-2,3):
        for j in range(-2,3):
            if i==0 and j==0:
                continue
            if y+i<0 or h<=y+i or x+j<0 or w<=x+j:
                continue
            if s[y+i][x+j]=='.':
                nxt.append([y+i,x+j,now+1])
                s[y+i][x+j]=now+1


while nxt:
    i=nxt.pop(0)
    if i[0]==dh and i[1]==dw:
        print(i[2])
        exit()
    rcl(i[0],i[1],i[2])
print(-1)

Measured memory_bytes: 173484
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll r[4301],g[4301],b[4301];
int main () {
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='R')
            r[i]=r[i+1]+1;
        else
            r[i]=r[i+1];
        if(s[i]=='G')
            g[i]=g[i+1]+1;
        else
            g[i]=g[i+1];
        if(s[i]=='B')
            b[i]=b[i+1]+1;
        else
            b[i]=b[i+1];

    }
   // for(int i=0;i<n;i++)
      //  cout<<b[i]<<' ';

    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n-1;++j){
            if(s[i]!=s[j]&&i!=j){
                if((s[i]=='R'&&s[j]=='B')||(s[j]=='R'&&s[i]=='B')){
                    ans+=g[j+1];
                    if(2*j-i<n&&s[2*j-i]=='G')
                        ans--;
                }else if((s[i]=='G'&&s[j]=='B')||(s[j]=='G'&&s[i]=='B')){
                    ans+=r[j+1];
                    if(2*j-i<n&&s[2*j-i]=='R')
                        ans--;
                }if((s[i]=='R'&&s[j]=='G')||(s[j]=='R'&&s[i]=='G')){
                    ans+=b[j+1];
                    if(2*j-i<n&&s[2*j-i]=='B')
                        ans--;
                }
            }

        }
    }
    cout<<ans;
}

Measured memory_bytes: 3700
n = int(input())
ls = []
for i in range(n):
    s,t = map(str,input().split())
    ls.append([s,t])

x = input()
ans = 0
p = 0
for i in ls:
    if p == 1:
        ans += int(i[1])
    if i[0]==x:
        p = 1
        
print(ans)
    

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
ll gcd(ll x,ll y){
	if(y==0)return x;
	return gcd(y,x%y);
}
ll absol(ll x)
{
	if (x<0)
	{
		return -x;
	}
	return x;
}
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
ll w1[1002],v[1002];
ll dp[100012][101];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n,w,s=0;
	cin>>n>>w;
	for (int i = 0; i < n; ++i)
	{
		cin>>w1[i]>>v[i];
        s+=v[i];
	}
	for(int i=n-1;i>=0;--i)
	{
		for (int j = 0; j <=s ; ++j)
		{
			dp[j][i]=dp[j][i+1];
			if (j>v[i]&&dp[j-v[i]][i+1]>0)
			{
                if(dp[j][i]>0)
				dp[j][i]=min(dp[j][i],dp[j-v[i]][i+1]+w1[i]);
                    else
                    dp[j][i]=dp[j-v[i]][i+1]+w1[i];
			}
            if (j==v[i])
            {
                if(dp[j][i]==0)
                dp[j][i]=w1[i];
                else
                    dp[j][i]=min(dp[j][i],w1[i]);
            }
		}	
	}
    ll ans=0;
    for (int i = 0; i <= s; ++i)
    {
        if (dp[i][0]<=w&&dp[i][0]>0)
        {
            ans=i;   
        }
    }
	cout<<ans<<"\n";
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;

const int maxn = 5e3 + 10;
const int maxm = 200 + 10;

int n, m;
ll a[maxn];
int b[maxn][maxm][14];
ll answer = 0;

ll get(int s, int t){
	ll A = 0, B = 0;
	int len = log2(t-s+1);
	for (int i = 1; i <= m; i++)
		A += max(b[s][i][len], b[t-(1<<len)+1][i][len]);
	B = a[t-1] - a[s-1];
	return A - B;
}

void dp_cal(int l, int r, int lo, int hi){
	if (r <= l)
		return;
	int mid = (l + r) >> 1;
	int opt = lo;
	for (int i = lo; i <= min(hi,mid); i++)
		if (get(i, mid) > get(opt, mid))
			opt = i;
	answer = max(answer, get(opt, mid));
	dp_cal(l, mid, lo, opt);
	dp_cal(mid+1, r, opt, hi);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n-1; i++){
		cin >> a[i];
		a[i] += a[i-1];
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> b[i][j][0];
	for (int k = 1; k <= 12; k++)
		for (int i = 1; i + (1<<(k-1)) <= n; i++)
			for (int j = 1; j <= m; j++)
				b[i][j][k] = max(b[i][j][k-1], b[i+(1<<(k-1))][j][k-1]);
	dp_cal(1, n+1, 1, n);
	cout << answer << '\n';
}


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

typedef long long LL;
const int N = 105;
const LL inf = 0x3f3f3f3f3f3f3f3f;

int a[N], n, s, t, dis[N], tot = 1, head[N];
LL ans;
struct edge { int to, nxt; LL rem; } e[N * N];
void link(int x, int y, LL z) {
	e[++tot] = (edge) { y, head[x], z }, head[x] = tot;
	e[++tot] = (edge) { x, head[y], 0 }, head[y] = tot;
}
bool bfs() {
	for (int i = s; i <= t; ++i) dis[i] = 0;
	std::queue<int> q; q.push(s), dis[s] = 1;
	while (q.size()) {
		int tmp = q.front(); q.pop();
		for (int i = head[tmp]; i; i = e[i].nxt)
			if (!dis[e[i].to] && e[i].rem)
				dis[e[i].to] = dis[tmp] + 1, q.push(e[i].to);
	}
	return dis[t] > 0;
}
LL dinic(int x, LL low) {
	if (x == t) return low;
	LL t, ans = 0;
	for (int i = head[x]; i; i = e[i].nxt)
		if (e[i].rem && dis[e[i].to] == dis[x] + 1 && (t = dinic(e[i].to, std::min(low, e[i].rem)))) {
			low -= t, ans += t, e[i].rem -= t, e[i ^ 1].rem += t;
			if (!low) break;
		}
	return ans;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> a[i], ans += a[i], a[i] = -a[i];
	s = 0, t = n + 1;
	for (int i = 1; i <= n; ++i)
		if (a[i] > 0) link(s, i, a[i]), ans += a[i]; else link(i, t, -a[i]);
	for (int i = 1; i <= n; ++i)
		for (int j = i + i; j <= n; j += i) link(i, j, inf);
	while (bfs()) ans -= dinic(s, inf);
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,T,t[200001],res=0,un=0;
  cin  >> N >> T;
  REP(i,N)cin >> t[i];
  t[N] = 10E15;
  for(int i=N-1;i>=0;i--){
    if(t[i+1] - t[i] >= T){
      un += T;
    }else
      un += t[i+1] - t[i];
    
  }
  cout << un << endl;
  return 0;
}



Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String line;
		while ((line = reader.readLine()) != null) {
			if (line.isEmpty()) {
				break;
			}
			int a = Integer.parseInt(line);
			int[] num = new int[25];
			int max = 51000;
			int min = 0;
			int m = a - 72 < 2 ? 2 : a - 72;
			for (int i = m; i < a + 72; i++) {
				if (isPrime(i))
					if (i < a) {
						min = Math.max(min, i);
					} else if (i > a) {
						max = Math.min(max, i);
					}
			}
			builder.append(min).append(' ').append(max).append('\n');

		}
		System.out.print(builder);
	}

	private static boolean isPrime(int a) {
		if (a == 2)
			return true;
		if (a % 2 == 0)
			return false;
		if (a < 8)
			return true;
		if (a % 3 == 0)
			return false;
		for (int i = 5; a >= i * i; i += 6) {
			if (a % i == 0)
				return false;
			if (a % (i + 2) == 0)
				return false;
		}

		return true;
	}
}

Measured memory_bytes: 16864
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a<b){
		printf("a < b\n");
}
	if(a>b){
		printf("a > b\n");
}
	if(a==b){
		printf("a == b\n");
}
	return 0;
}

Measured memory_bytes: 580
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

template<typename T>
class BinaryIndexedTree {
    int N;
    vector<T> data;
public:
    BinaryIndexedTree(int N) : N(N) {
        data.resize(N + 1, 0);
    }

    T sum(int k) {
        T res = 0;
        for (; k > 0; k -= k & -k) {
            res += data[k];
        }
        return res;
    }

    void add(int k, T x) {
        for (; k <= N; k += k & -k) {
            data[k] += x;
        }
    }

    /**
     * v1 + v2 + ⋯ + vx ≧ W となる最小の 𝑥 を求める
     */
    int lowerBound(int w) {
        if (w <= 0) return 0;
        int x = 0;
        int k = 1;
        while (k * 2 <= N) k *= 2;
        for (; k > 0; k /= 2) {
            if (x + k <= N && data[x + k] < w) {
                w -= data[x + k];
                x += k;
            }
        }
        return x + 1;
    }
};

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

    ll l=-1;
    ll r=INF;
    while(r-l>1){
        ll k=(l+r)/2;
        vector<ll> b(N,0);
        REP(i,N){
            if(a[i]<=k) b[i]=1;
        }
        vector<ll> s(N+1,0);
        REP(i,N){
            s[i+1]=s[i]+b[i];
        }
        vector<ll> d(N+1,0);
        REP(i,N+1){
            d[i]=2*s[i]-i;
        }
        reverse(ALL(d));

        BinaryIndexedTree<ll> bit(N+10);
        ll num=0;
        ll m=MIN(d);
        REP(i,N+1){
            d[i]+=(1-m);
        }
        REP(i,N+1){
            num+=i-bit.sum(d[i]);
            bit.add(d[i],1);
            
        }

        if(num>(N+1)*N/4) r=k;
        else l=k;
    }
    cout<<r<<endl;
}

Measured memory_bytes: 7192
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int mod = 1e9 + 7;
int dp[2][401];
int sum[401][401];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	rep(i, 401){
		sum[i][0] = 1;
		rep(j, 400) sum[i][j + 1] = sum[i][j] * (ll)i % mod;
	}
	rep(i, 400) rep(j, 401) (sum[i + 1][j] += sum[i][j]) %= mod;
	
	int n, c; cin >> n >> c;
	vi a(n), b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	
	int cur = 0, next = 1;
	dp[0][0] = 1;
	
	rep(i, n){
		memset(dp[next], 0, sizeof(dp[next]));
		
		for(int s = 0; s <= c; s++){
			for(int k = 0; k + s <= c; k++){
				dp[next][k + s] += dp[cur][s] * ((ll)mod + sum[b[i]][k] - sum[a[i] - 1][k]) % mod;
				dp[next][k + s] %= mod;
			}
		}
		swap(cur, next);
	}
	cout << dp[cur][c] << endl;
	
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    ll sum = 0;
    rep(mask, (1 << n))
    {
        ll tmp = 0;
        rep(i, n)
        {
            if ((mask >> i) & 1)
            {
                tmp *= 10;
                tmp += s[i] - '0';
            }
            else
            {
                sum += tmp;
                tmp = 0;
            }
        }
        sum += tmp;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3596
n = int(input())
d = {}
for i in range(n):
	a, b = map(int, input().split())
	if b in d:
		d[b].append(a)
	else:
		d[b] = [a]
dk = sorted(d)
t, o = 0, "Yes"
for k in dk:
	if t+sum(d[k]) > k:
		o = "No"
		break
	t += sum(d[k])
print(o)


Measured memory_bytes: 47900
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

char c[3][3];

int main () {
  rep(i,3)rep(j,3) cin >> c[i][j];
  rep(i,3) cout << c[i][i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
#define MAX 25
typedef struct {
  int parent;
  int leftc;
  int rightc;
}Node;
Node t[MAX];
int h,max;
void calcHeight(int);

int main() {
  int i,j,n,id,left,right;
  int depth[MAX],height[MAX],sibling[MAX],degree[MAX];

  scanf("%d",&n);
  for(i=0; i<n; i++) {
    t[i].parent=t[i].leftc=t[i].rightc=sibling[i]=NIL;
    degree[i]=0;
  }    
  for(i=0; i<n; i++) {
    scanf("%d%d%d",&id,&left,&right);
    if(left!=NIL) {
      t[left].parent=id;
      degree[id]++;
    }
    if(right!=NIL){
      t[right].parent=id;
      degree[id]++;
    }
    t[id].leftc = left;
    t[id].rightc = right;
    sibling[left]=right;
    sibling[right]=left;
  }

  for(i=0; i<n; i++) {
    depth[i]=height[i]=0;
    j=i;
    while(t[j].parent!=NIL) {
      j=t[j].parent;
      depth[i]++;
    }
    max=h=0;
    calcHeight(i);
    height[i] = max;
  }
  for(i=0; i<n; i++) {
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,t[i].parent,sibling[i],degree[i],depth[i],height[i]);
    if(t[i].parent==-1) printf("root");
    else if(t[i].leftc!=-1 || t[i].rightc!=-1) printf("internal node");
    else printf("leaf");
    printf("\n");
  }
  return 0;
}


void calcHeight(int n)
{
  if(t[n].leftc==NIL || t[n].rightc==NIL)  max = h>max ? h:max;
  if(t[n].leftc!=NIL) {
    h++;
    calcHeight(t[n].leftc);
  }
  if(t[n].rightc!=NIL) {
    h++;
    calcHeight(t[n].rightc);
  }
  h-=1;
}

Measured memory_bytes: 604