akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int parent(int);
int left(int);
int right(int);

int main(){
  int a,l,r,*A;
  int i;

  scanf("%d",&a);
  A = (int *)malloc(sizeof(int)*(a+1));
  for(i=1;i<=a;i++){
    scanf("%d",&A[i]);
  }

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

  return 0;
}

int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 2e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

ll dp[110][100010];
void solve(long long N, long long W, std::vector<long long> w, std::vector<long long> v)
{
    for (int i = 0; i < 110; i++)
    {
        for (int j = 0; j < 100010; j++)
        {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for (int i = 1; i <= N; i++)
    {
        for (int j = 0; j <= 100010; j++)
        {
            if (j >= v[i - 1])
            {
                dp[i][j] = min({dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1], dp[i - 1][j]});
            }
            else
            {
                dp[i][j] = min({dp[i][j], dp[i - 1][j]});
            }
        }
    }


    ll ans = 0;
    for (int i = 0; i < 100010; i++)
    {
        if (dp[N][i] <= W)
        {
            ans = i;
        }
    }

    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long W;
    scanf("%lld", &W);
    std::vector<long long> w(N);
    std::vector<long long> v(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &w[i]);
        scanf("%lld", &v[i]);
    }
    solve(N, W, std::move(w), std::move(v));
    return 0;
}


Measured memory_bytes: 86144
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

struct node{
	int parent_id;
	int left_child_id;
	int right_child_id;
};

int get_root(node* b, int num);
void print_preorder(node* b, int root_id);
void print_inorder(node* b, int root_id);
void print_postorder(node* b, int root_id);

int main(){
	int n;
	cin >> n;
	node* b = (node*)calloc(n, sizeof(node));
	for(int i = 0; i < n; ++i){
		b[i].parent_id  = -1;
	}
	//input data
	for(int i = 0; i < n; ++i){
		int id;
		int left_child_id;
		int right_child_id;
		cin >> id;
		cin >> left_child_id;
		cin >> right_child_id;
		b[id].left_child_id  = left_child_id;
		b[id].right_child_id = right_child_id;
		if(left_child_id  != -1) b[left_child_id].parent_id  = id;
		if(right_child_id != -1) b[right_child_id].parent_id = id;
	}
	int root_id = get_root(b, n);
	printf("Preorder\n");
	print_preorder(b, root_id);
	putchar('\n');
	printf("Inorder\n");
	print_inorder(b, root_id);
	putchar('\n');
	printf("Postorder\n");
	print_postorder(b, root_id);
	putchar('\n');
	return 0;
}

void print_preorder(node* b, int root_id){
	printf(" %d", root_id);
	if(b[root_id].left_child_id  != -1) print_preorder(b, b[root_id].left_child_id);
	if(b[root_id].right_child_id != -1) print_preorder(b, b[root_id].right_child_id);
}

int get_root(node* b, int num){
	for(int i = 0; i < num; ++i){
		if(b[i].parent_id == -1) return i;
	}
	return -1;
}
void print_inorder(node* b, int root_id){
	if(b[root_id].left_child_id  != -1) print_inorder(b, b[root_id].left_child_id);
	printf(" %d", root_id);
	if(b[root_id].right_child_id != -1) print_inorder(b, b[root_id].right_child_id);
}
void print_postorder(node* b, int root_id){
	if(b[root_id].left_child_id  != -1) print_postorder(b, b[root_id].left_child_id);
	if(b[root_id].right_child_id != -1) print_postorder(b, b[root_id].right_child_id);
	printf(" %d", root_id);
}

Measured memory_bytes: 1184
count = [0, 0, 0, 0]
for i in range(3):
    a, b = map(int, input().split())
    count[a-1] += 1
    count[b-1] += 1
res = True
for a in count:
    if a>2:
        res = False
if res:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
//
// Created by yamunaku on 2020/03/21.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    int h, w;
    cin >> h >> w;
    vector<string> f(h);
    rep(i, h) cin >> f[i];
    vector<mti> dp(h, mti(w, vi(2, IINF)));
    if(f[0][0] == '.'){
        dp[0][0][0] = 0;
    }else{
        dp[0][0][1] = 1;
    }
    rep(i, h){
        rep(j, w){
            if(f[i][j] == '.'){
                if(i > 0){
                    dp[i][j][0] = min(dp[i][j][0], min(dp[i - 1][j][0], dp[i - 1][j][1]));
                }
                if(j > 0){
                    dp[i][j][0] = min(dp[i][j][0], min(dp[i][j - 1][0], dp[i][j - 1][1]));
                }
            }else{
                if(i > 0){
                    dp[i][j][1] = min(dp[i][j][1], min(dp[i - 1][j][0] + 1, dp[i - 1][j][1]));
                }
                if(j > 0){
                    dp[i][j][1] = min(dp[i][j][1], min(dp[i][j - 1][0] + 1, dp[i][j - 1][1]));
                }
            }
        }
    }
    cout << min(dp[h - 1][w - 1][0], dp[h - 1][w - 1][1]) << endl;
    return 0;
}

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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

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;
}
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> long long iterate_sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

struct union_find {
    int size;
    vector<int> par;
    union_find(int N) : size(N), par(N) { REP(i, N) par[i] = i; }
    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            par[x] = root(par[x]);
            return par[x];
        }
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        else {
            par[rx] = ry;
            return;
        }
    }
    bool same(int x, int y) { return root(x) == root(y); }
};

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

long long n, q;
long long a, b;
long long p, x;
long long ans[200003];
vector<long long> branchto[200003];

int rec(long long fromthis){
    for (auto&& to : branchto[fromthis]) {
        ans[to]+=ans[fromthis];
        rec(to);
    }
    return 0;
}

int main() {
    cin >> n >> q;
    for (int i = 0; i < n-1; i++) {
        cin >> a >> b;
        branchto[a].push_back(b);
    }
    for (int i = 0; i < q; i++) {
        cin >> p >> x;
        ans[p]+=x;
    }
    rec(1);
    for (int i = 1; i <= n; i++) {
        cout<<ans[i]<<' ';
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 21120
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if (x >= r && y >= r && x + r <= w && y + r <= h)
        cout << "Yes";
    else cout << "No";
    cout << endl;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
#define F first
#define S second
signed main(){
  int n,m;
  while(cin>>n>>m,n){
    int h[n];
    for(int i=0;i<n;i++) cin>>h[i];
    int a[m],b[m],c[m];
    for(int i=0;i<m;i++) cin>>a[i]>>b[i]>>c[i];
    priority_queue<P> q1;
    for(int i=0;i<n;i++) q1.emplace(h[i],i);
    vector<P> G[n];
    for(int i=0;i<m;i++){
      a[i]--;b[i]--;
      G[a[i]].push_back(P(b[i],c[i]));
      G[b[i]].push_back(P(a[i],c[i]));
    }
    int INF=1LL<<55LL;
    int cost[n];
    for(int i=0;i<n;i++) cost[i]=INF;
    bool used[n];
    memset(used,0,sizeof(used));
    int root=q1.top().S;
    cost[root]=0;
    used[root]=1;
    int tmp=h[root];
    q1.pop();
    int ans=0;
    while(!q1.empty()){
      priority_queue<P,vector<P>,greater<P> > q2;
      set<int> s,t;
      while(!q1.empty()&&q1.top().F==tmp){
	s.insert(q1.top().S);
	t.insert(q1.top().S);
	q1.pop();
      }
      if(!q1.empty()) tmp=q1.top().F;
      if(ans==0){
	for(int i=0;i<n;i++) cost[i]=INF;
	cost[root]=0;
	for(int i=0;i<n;i++)
	  if(used[i]&&root!=i) s.insert(i);
	for(P p:G[root]){
	  if(cost[p.F]<=p.S) continue;
	  cost[p.F]=p.S;
	}
      }else{
	for(int i=0;i<n;i++){
	  if(!used[i]) continue;
	  for(P p:G[i]){
	    if(cost[p.F]<=p.S) continue;
	    cost[p.F]=p.S;
	  }
	}
      }
      //cout<<tmp<<":";for(int i:s) cout<<i<<" ";cout<<endl;
      for(int i=0;i<n;i++)
	if(s.count(i)) q2.emplace(cost[i],i);
      while(!s.empty()&&!q2.empty()){
	P p=q2.top();q2.pop();
	if(!s.count(p.S)) continue;
	if(p.F==INF) break;
	//cout<<p.S<<endl;
	s.erase(p.S);
	ans+=cost[p.S];
	for(P u:G[p.S]){
	  if(cost[u.F]<=u.S) continue;
	  cost[u.F]=u.S;
	  if(s.count(u.F)) q2.emplace(cost[u.F],u.F);
	}
      }
      if(!s.empty()) ans=0;
      for(int i:t) used[i]=1;
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main() {
    int64_t n; cin >> n;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    vector<int64_t> v;
    for (int64_t i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            int64_t cnt = 0;
            while (n % i == 0) {
                n /= i;
                cnt++;
            }
            v.push_back(cnt);
            if (n == 1) {
                break;
            }
        }
    }
    if (n != 1) {
        v.push_back(1);
    }
    int64_t ans = 0;
    for (auto u: v) {
        int64_t i = 1;
        while (u >= i) {
            u = u - i;
            i++;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
n, m = map(int, input().split())

ans = [0]*(n)

for i in range(m):
    a = list(map(int, input().split()))
    if n>=2:
        if a[0] == 1:
            if a[1] == 0:
                print("-1")
                exit()

    a[0] -= 1
    if ans[a[0]] == 0 or ans[a[0]] == a[1]:
        ans[a[0]] = a[1]
    else:
        print("-1")
        exit()

if n>=2:
    for i in range(n):
        if ans[0] == 0:
            ans[0] = 1
            print(ans[i],end="")

        else:
            print(ans[i],end="")
else:
    print(ans[0])


Measured memory_bytes: 9224
/**
*    author:  boutarou
*    created: 10.06.2020 19:36:42
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const long long MOD = 998244353;
const long long INF = 3e18;
const double PI = 3.1415926535897932;

long long mod_pow(long long n, long long p, long long m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		long long t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}

class BIT {
private:
	vector<int>bit;
	int n;
public:
	BIT() {
		n = 0;
	}
	void set(int _n) {
		bit.resize(_n + 1);
		rep(i, _n + 1) bit[i] = 0;
		n = _n;
	}
	//i 1-indexed
	int sum(int i) {
		int s = 0;
		while (i > 0) {
			s += bit[i];
			i -= (i & -i);
		}
		return s;
	}
	void add(int i, int x) {
		while (i <= n) {
			bit[i] += x;
			i += (i & -i);
		}
	}
};

int n;
P p[200005];
vector<int>y_data;
BIT bit;
int exist[200005][4];
lint ans;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n;
	rep(i, n) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n);

	rep(i, n) {
		y_data.push_back(p[i].second);
	}
	sort(y_data.begin(), y_data.end());
	rep(i, n) {
		p[i].second = lower_bound(y_data.begin(), y_data.end(), p[i].second) - y_data.begin();
	}

	bit.set(n);
	rep(i, n) {
		exist[i][1] = bit.sum(p[i].second + 1);
		exist[i][0] = i - exist[i][1];
		bit.add(p[i].second + 1, 1);
	}
	bit.set(n);
	for (int i = n - 1; i >= 0; i--) {
		exist[i][2] = bit.sum(p[i].second + 1);
		exist[i][3] = (n - 1 - i) - exist[i][2];
		bit.add(p[i].second + 1, 1);
	}

	ans = (mod_pow(2, n, MOD) - 1) * n;
	//cout << ans << endl;
	ans %= MOD;
	if (ans < 0) ans += MOD;
	rep(i, n) {
		lint minus = 0;
		minus += mod_pow(2, exist[i][0] + exist[i][1], MOD) - 1;
		minus += mod_pow(2, exist[i][1] + exist[i][2], MOD) - 1;
		minus += mod_pow(2, exist[i][2] + exist[i][3], MOD) - 1;
		minus += mod_pow(2, exist[i][3] + exist[i][2], MOD) - 1;
		minus -= mod_pow(2, exist[i][0], MOD) - 1;
		minus -= mod_pow(2, exist[i][1], MOD) - 1;
		minus -= mod_pow(2, exist[i][2], MOD) - 1;
		minus -= mod_pow(2, exist[i][3], MOD) - 1;
		minus %= MOD;
		ans -= minus;
		ans %= MOD;
		if (ans < 0) ans += MOD;
	}
	ans %= MOD;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6644
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
int main(){
  int N;cin>>N;
  vector<double>X(N);
  vector<string>U(N);
  for (int i=0;i<N;++i){
    cin>>X[i]>>U[i];
  }
  double sum=0.0;
  for (int i=0;i<N;++i){
    if (U[i]=="JPY"){
      sum+=X[i];
    }
    else sum+=X[i]*380000;
  }
  cout<<setprecision(16)<<sum<<endl;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }

int main() {
  int n;
  vector<string> x;
  vector<string> u;

  cin >> n;
  each(i, n) {
    string t1;
    string t2;
    cin >> t1 >> t2;
    x.push(t1);
    u.push(t2);
  }

  double summary = 0;
  each(i, n) {
    if (u[i] == "JPY") {
      summary += std::stod(x[i]);
    } else {
      summary += std::stod(x[i]) *  380000.0;
    }
  }

  cout << summary << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
if n < 600: exit(print(8))
if n < 800: exit(print(7))
if n < 1000: exit(print(6))
if n < 1200: exit(print(5))
if n < 1400: exit(print(4))
if n < 1600: exit(print(3))
if n < 1800: exit(print(2))
if n < 2000: exit(print(1))

Measured memory_bytes: 9188
module Main where
import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List                      ( unfoldr )
import           Control.Monad
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.Tuple
import qualified Data.IntMap                   as Map
import qualified Data.Set                      as Set

main :: IO ()
main = do
  [n, m] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  hs     <- VU.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  abs    <-
    replicateM m $ unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let es = map (\[a, b] -> (a, b)) abs
  let es' =
        Map.fromListWith Set.union
          $  map (\(x, y) -> (x, Set.singleton y))
          $  es
          ++ map swap es
  let trues = map (isHighest hs es') [1 .. n]
  print $ length $ filter id trues

-- lookups x xs = map snd $ filter ((== x) . fst) xs
isHighest :: VU.Vector Int -> Map.IntMap (Set.Set Int) -> Int -> Bool
isHighest hs es i = case es Map.!? i of
  Just rs ->
    let hs' = Set.map (\r -> hs VU.! (r - 1)) rs
    in  Set.findMax hs' < hs VU.! (i - 1)
  Nothing -> True

Measured memory_bytes: 62820
#include<iostream>
using namespace std;
int main(){
  bool cards[4][14];
  int n,rank;
  char suit;
  for(int s=0;s<4;s++){
    for(int r=1;r<=13;r++){
      cards[s][r]=0;
    }
  }cin>>n;
  for(int i=0;i<n;i++){
    cin>>suit>>rank;
    if(suit=='S') cards[0][rank]=1;
    if(suit=='H') cards[1][rank]=1;
    if(suit=='C') cards[2][rank]=1;
    if(suit=='D') cards[3][rank]=1;
  }
  for(int s=0;s<4;s++){
    for(int r=1;r<=13;r++){
      if(cards[s][r]) continue;
      if(s==0)suit='S';
      if(s==1)suit='H';
      if(s==2)suit='C';
      if(s==3)suit='D';
      cout<<suit<<" "<<r<<endl;
    }
  } return 0;
}



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

int main(){
    int n;
    cin>>n;
    string s = to_string(n);
    int tmp=0;
    for(int i=0;i<s.size();i++){
        tmp+=s[i]-'0';
    }
    if(n%tmp) cout << "No" << endl;
    else cout << "Yes" << endl;
    
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

char ch, d;

int main()
{
  while(scanf("%c", &ch) != EOF){
    if(ch != '@'){
      cout << ch;
      continue;
    }
    scanf("%c%c", &d, &ch);
    rep(i, d-'0') cout << ch;
  }

  return 0;
}

Measured memory_bytes: 1112
#include<stdio.h>

int main(){
 
  int x, y, r, tmp;
 
  scanf("%d %d", &x,&y);
 
  if(x<y){
    tmp = x;
    x = y;
    y = tmp;
  }
 
  r = x % y;
  while(r!=0){
    x = y;
    y = r;
    r = x % y;
  }
 
  printf("%d\n", y);
 
  return 0;
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, X, D;
  cin>>N>>X>>D;

  if(D < 0) X = -X, D = -D;

  if(D == 0){
    if(X == 0)cout<<1<<endl;
    else cout<<N+1<<endl;
    return 0;
  }

  //S - T = S - (U - S) = 2 * S - U
  map<Int, vector<P> > A;
  for(Int k=0;k<=N;k++){
    Int d = (k * X) / D;
    Int x = (k * X) % D;
    while(x < 0) x += D, d--;
    Int l = (0 + k-1) * k / 2 + d;
    Int r = (N-k + N-1) * k / 2 + d;
    //U = x + I * D, l <= I <= r;
    A[x].emplace_back(l, r);
  }

  Int ans = 0;
  for(auto p:A){
    Int x;
    vector<P> B;
    tie(x, B) = p;
    sort(B.begin(), B.end());
    Int L = -INF;
    for(auto p:B){
      Int l, r; tie(l, r) = p;
      Max(L, l);
      ans += max<Int>(0, r - L + 1);
      Max(L, r+1);
    }
  }

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


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

using namespace std;

void Main() {
    int N;
    cin >> N;
    map<string, int> judge;
    judge.insert(make_pair("AC", 0));
    judge.insert(make_pair("WA", 0));
    judge.insert(make_pair("TLE", 0));
    judge.insert(make_pair("RE", 0));
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        ++judge[s];
    }

    cout << "AC x " << judge["AC"] << endl;
    cout << "WA x " << judge["WA"] << endl;
    cout << "TLE x " << judge["TLE"] << endl;
    cout << "RE x " << judge["RE"] << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n, k;
    cin >> n >> k;
    n =  n % k;
    if(k >= n)
         cout << min(abs(k - n), n) << "\n";
    else
        cout << n << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> > 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 2e5 + 5;
map <pii, int> mp;
vpii v(MAX);
void work(int val)
{
	int x = val;
	int fr = -1, ls = -1, cnt = 0;
	while(x){
		if(cnt == 0){
			cnt++;
			fr = x % 10;
		}
		ls = x % 10;
		x /= 10;
	}
	mp[{fr, ls}]++;
	v[val] = {fr, ls};
}
int main()
{
	boost;
	int n, i;
	cin >> n;
	foe(i, 1, n)
	work(i);
	ll ans = 0;
	foe(i, 1, n){
		int x = v[i].f, y = v[i].s;
		ans += mp[{y, x}];
	}
	cout << ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int c[26],i,n; long long ans; char s[100010];
int main(){
	scanf("%d",&n); scanf("%s",s+1); for (i=1;i<=n;i++)c[s[i]-'a']++;
	ans++; for (i=0;i<26;i++)ans=ans*(c[i]+1)%1000000007;ans--;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
	rtn 0;
}

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

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<pair<ll, ll>> P(N);
  for (ll i = 0; i < N; i++) {
    ll x, y;
    cin >> x >> y;
    P[i] = make_pair(x, y);
  }

  ll ans = -1;
  for (ll l = 0; l < N; l++) {
    for (ll r = 0; r < N; r++) {
      for (ll u = 0; u < N; u++) {
        for (ll d = 0; d < N; d++) {
          pair<ll, ll> pl = P[l], pr = P[r], pu = P[u], pd = P[d];
          ll cnt = 0;
          for (ll i = 0; i < N; i++) {
            if (P[i].first >= pl.first && P[i].first <= pr.first
                && P[i].second >= pd.second && P[i].second <= pu.second) {
                  cnt++;
                }
          }
          if (cnt >= K) {
            ll temp = (P[r].first - P[l].first) * (P[u].second - P[d].second);
            if (temp == 0) continue;
            else if (ans == -1) ans = temp;
            else ans = min(ans, temp);
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int cntfact[1010];

void primeFactorization(int n) {
    int k = n;
    repq(i,2,sqrt(n)) {
        while(k % i == 0) {
            cntfact[i]++;
            k /= i;
        }
    }
    if(k > 1) {
        cntfact[k]++;
    }
}

signed main() {
    int n; cin >> n;
    memset(cntfact, 0, sizeof(cntfact));
    repq(i,2,n) {
        primeFactorization(i);
    }

    int ans = 1;
    repq(i,2,n) {
        ans = (ans * (cntfact[i] + 1)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF=1000000000;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n;i++)
ll n,dp[100005][3];
int main(){
   cin>>n;
   ll happy[n][3];
   rep(i,n) cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
    rep(i,n)
        rep(j,3) dp[i][j] = -INF;
    rep(j,3)  dp[0][j] = 0;
    rep(i, n){
        rep(j, 3){
            rep(k, 3){
                if (j == k) continue;
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + happy[i][j]);
            }
        }
    }
    ll ans = -INF;
    rep(i, 3) ans = max(ans, dp[n][i]);
    cout << ans << endl;
    return 0;
}

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

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

int main()
{
	ll N, M;
	ll ans = 0;

	cin >> N >> M;

	if (N == 1 && M != 1)
		ans = M - 2;
	else if (M == 1 && N != 1)
		ans = N - 2;
	else
		ans = (N - 2) * (M - 2);

	cout << ans << endl;

	return 0;
}

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

int main(){

    long long n; cin >> n;
    vector<vector<long long> > c(n, vector<long long> (n));
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> c[i][j];
    long long ans = 0;    
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            ans += min(c[i][j], c[j][i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3236
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll mod=998244353;
vector<ll> fact;
ll pot(ll a,ll b){
  if(b==0)return 1;
  ll x=pot(a,b/2);
  if(b%2)return x*x%mod*a%mod;
  return x*x%mod;
}
ll binom(ll a,ll b){
  return fact[a]*pot(fact[a-b],mod-2)%mod*pot(fact[b],mod-2)%mod;
}
int main(){
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
    ll N,M,K;
    cin>>N>>M>>K;
    ll tot=0;
    fact.push_back(1);
    for(ll i=0;i<200010;i++)fact.push_back(fact.back()*(i+1)%mod);
    for(ll i=0;i<=K;i++){
      tot+=M*pot(M-1,N-i-1)%mod*binom(N-1,i)%mod;
      tot%=mod;
    }
    cout<<tot;
    return 0;
}

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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MAX = 1e5 + 5;

int main()
{
	IOS
	int t = 1;
	//cin >> t;
	while(t--)
	{
		int a, b, c, k;
		cin >> a >> b >> c >> k;
		ll sum = 0;
		if(a >= k)
		{
			sum += k;
			k = 0;
		}
		else
		{
			sum += a;
			k -= a;
		}
		if(b >= k)
		{
			k = 0;
		}
		else
		{
			k -= b;
		}
		if(c >= k)
		{
			sum -= k;
			k = 0;
		}
		else
		{
			sum -= c;
			k -= c;
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3616
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = myconv(next(),4);
  var N = one[0];
  var M = one[1];
  var R = one[2];
  var max = Math.pow(10,12);
  var kyori = new Array(N);
  for(var i = 0; i < N; i++){
    kyori[i] = new Array(N);
  }
  
  //移動パターンの全探索用
  var travel = myconv(next(),4);
  for(var i = 0; i < R; i++){
    travel[i]--;
  }
  
  for(var i = 0; i < M; i++){
    var tmp = myconv(next(),4);
    kyori[tmp[0] - 1][tmp[1] - 1] = tmp[2];
    kyori[tmp[1] - 1][tmp[0] - 1] = tmp[2];
  }
  
  for(var i = 0; i < N; i++){
    for(var j = 0; j < N; j++){
      /*if(i == j){
         kyori[i][j] = 0;
        continue;
      }*/
      if(kyori[i][j] == null){
         kyori[i][j] = max;
      }
    }
  }
  for(var k = 0; k < N; k++){
    for(var i = 0; i < N; i++){
      for(var j = 0; j < N; j++){
        if(kyori[i][j] > kyori[i][k] + kyori[k][j]){
           kyori[i][j] = kyori[i][k] + kyori[k][j];
        }
      }
    }
  }
  var output = max;
  for(var i = 0; i < R; i++){
    dfs(travel[i],new Set(travel),0);
  }
  myout(output);
  function dfs(parent,set,moved){
    var tmpSet = new Set(set);
    tmpSet.delete(parent);
    if(tmpSet.size == 0){
      output = Math.min(output,moved); 
      return;
    }
    var nextTravel = Array.from(tmpSet);
    for(var i = 0; i < nextTravel.length; i++){
      if(nextTravel[i] == parent){
         continue;
      }
      dfs(nextTravel[i],tmpSet,(moved + kyori[parent][nextTravel[i]]));
    }
  }
}

Measured memory_bytes: 17424
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let q: usize = input();
    let lr: Vec<(usize, usize)> = (0..m).map(|_| (input(), input())).collect();
    let pq: Vec<(usize, usize)> = (0..q).map(|_| (input(), input())).collect();

    let mut lrx = vec![vec![0; n + 1]; n + 1];
    for (l, r) in lr {
        lrx[l][r] += 1;
    }
    let mut sum = vec![vec![0; n + 1]; n + 1];
    for i in 1..n + 1 {
        for j in 1..n + 1 {
            sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + lrx[i][j];
        }
    }

    with_stdout_lock(|mut w| {
        for (p, q) in pq {
            let a = sum[q][q] - sum[q][p - 1] - sum[p - 1][q] + sum[p - 1][p - 1];
            writeln!(w, "{}", a).unwrap();
        }
    });
}


Measured memory_bytes: 10492
N,K,Q=map(int,input().split())
A=[int(input())for _ in range(Q)]

count=[0]*N
i=0
while i<Q:
    count[A[i]-1]+=1
    i+=1

for c in count:
    if c+K-Q>0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 8592
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する

void next(ll &num) {
    if (num == 0) {
        num++;
        return;
    }
    num *= 3ll;
    num %= MOD;
}

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

    string s;
    cin >> s;

    vector<ll> lAbase(s.size(), 1ll), lQbase(s.size(), 0ll);
    vector<ll> lANum(s.size()), lQNum(s.size());

    vector<ll> rCbase(s.size(), 1ll), rQbase(s.size(), 0ll);
    vector<ll> rCNum(s.size()), rQNum(s.size());

    for (int i = 0; i < s.size(); ++i) {
        if (i != 0) {
            lAbase[i] = lAbase[i - 1];
            lQbase[i] = lQbase[i - 1];
            lANum[i] = lANum[i - 1];
            lQNum[i] = lQNum[i - 1];
        }
        if (s[i] == 'A') {
            lANum[i]++;
        } else if (s[i] == '?') {
            next(lAbase[i]);
            next(lQbase[i]);
            lQNum[i]++;
        }
    }

    reverse(all(s));
    for (int i = 0; i < s.size(); ++i) {
        if (i != 0) {
            rCbase[i] = rCbase[i - 1];
            rQbase[i] = rQbase[i - 1];
            rCNum[i] = rCNum[i - 1];
            rQNum[i] = rQNum[i - 1];
        }
        if (s[i] == 'C') {
            rCNum[i]++;
        } else if (s[i] == '?') {
            next(rCbase[i]);
            next(rQbase[i]);
            rQNum[i]++;
        }
    }

    reverse(all(rCbase));
    reverse(all(rQbase));
    reverse(all(rCNum));
    reverse(all(rQNum));
    reverse(all(s));

    ll ans = 0;
    for (int i = 1; i < s.size() - 1; ++i) {
        if (s[i] == 'B' || s[i] == '?') {
            ll tmp = (lAbase[i - 1] * lANum[i - 1] + lQbase[i - 1] * lQNum[i - 1]) % MOD;
            tmp *= (rCbase[i + 1] * rCNum[i + 1] + rQbase[i + 1] * rQNum[i + 1]) % MOD;
            tmp %= MOD;
            ans += tmp;
            ans %= MOD;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 6720
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    int res=0;
    rep(i,n){
        cin>>a[i];
        int m;
        m=min(a[i],abs(k-a[i]));
        res+=2*m; 
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;typedef vector<int> vi;typedef vector<ll> vll;
typedef pair<int,int> ii;typedef map<int,int> mii;
inline void rvi(vi &v, int n){int temp; rep(i,n){cin>>temp;v.pb(temp);}}
inline void rvll(vll &v, int n){ll temp;rep(i,n){cin>>temp;v.pb(temp);}}
inline void prvi(vi &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline void prvll(vll &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline vll prefixsum(vi &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vi &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
inline vll prefixsum(vll &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vll &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
void solve();int main(){ios;solve();return 0;}
//--------SOLVE--------------------------------------------------------------------
void solve()
{
	int n;cin>>n;
	vi h;
	rvi(h,n);
	int count=0,j,k,ti,l=0;
	bool flag=true;
	while(flag)
	{
		j=0;
		l=j;
		while(j<n && l<n)
		{
			while(l<n && h[l]==0) l++;
			if(l>=n) break;
			// cout<<"l="<<l<<endl;
			j=l;
			while(j<n && h[j]!=0) j++;
			j--;
			// cout<<"j="<<j<<endl;
			count++;
			// cout<<"count="<<count<<endl;
			for(ti=l;ti<=j;ti++)
			{
				h[ti]--;
			}
			l=j+1;
		}
		flag=false;
		for(k=0;k<n;k++)
		{
			if(h[k]!=0) flag=true;
		}
	}
	cout<<count<<endl;
}

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

using namespace std;

#define int long long
#define PB push_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;

pii go[100005];

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

  int n;
  while (cin >> n, n) {
    fill(go, go + 100005, pii(-1, -1));
    int head = 0, a;
    cin >> a;
    go[0] = pii(a, 1);
    for (int i = 2; i <= n; ++i) {
      cin >> a;

      if (i % 2 == 1 || go[head].first == a) {
	if (go[head].first != a) {
	  head++;
	  go[head] = pii(a, 1);
	  continue;
	}
	go[head].second++;
	continue;
      }

      if (0 < head && go[head - 1].first == a) {
	go[head - 1].second += go[head].second + 1;
	go[head] = pii(-1, -1);
	head--;
      } else {
	go[head] = pii(a, go[head].second + 1);
      }
    }

    int ans = 0;
    for (int i = 0; i <= head; ++i) {
      if (go[i].first == 0) ans += go[i].second;
    }
    
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2752
import java.io.BufferedReader;
import java.io.InputStreamReader;

//üÍÍ¡ñ éÌÅAæÉfóâð·×ÄoµÄ¨­B
//public class Problem0009_PrimeNumber {
public class Main {
	public static void main(String[] args) {
		try {
		//	Problem0009_PrimeNumber test = new Problem0009_PrimeNumber();
			Main test = new Main();
			test.setPrimeArray();
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String line;
			
			while((line = reader.readLine()) != null) {
				int number = Integer.parseInt(line);
				
				System.out.println(test.getAnswer(number));
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	int[] primeArray = new int[0];
	int getAnswer(int num) {
		int number = num;
		
		int high = primeArray.length - 1;
		int low = 0;
		while(low <= high) {
			int middle = (high + low) / 2;
			if(number == primeArray[middle]) {
				return middle + 1;
			} else if(number < primeArray[middle]) {
				high = middle - 1;
			} else {
				low = middle + 1;
			}
		}
		return high + 1;
	}
	void setPrimeArray() {	
		primeArray = new int[78498];
		int count = 0;
		for(int i = 2; i < 1000000; i++) {
			if(isPrime(i)) {
				primeArray[count] = i;
				count++;
			}
		}
		if(primeArray[primeArray.length-1] == 0) {
			System.err.println("fÌª¨©µ¢");
		}
	}
	boolean isPrime(int num) {
		if(num < 2) {
			return false;
		} else if(num == 2 || num == 3 || num == 5) {
			return true;
		} 
		if(num % 2 == 0 || num % 3 == 0) {
			return false;
		}
		int primeCandidate = 5;
		for(int i = 0; primeCandidate <= Math.sqrt(num); i++) {
			if(num % primeCandidate == 0) {
				return false;
			}
			if(i % 2 == 0) {
				primeCandidate += 2;
			} else {
				primeCandidate += 4;
			}
		}
		return true;
	}
}

Measured memory_bytes: 9856
f=lambda:map(int,input().split())
n,q=f()
g=[[] for _ in range(n)]
for i in range(n-1):
  a,b=f()
  g[a-1]+=[b-1]
  g[b-1]+=[a-1]
c=[0]*n
for i in range(q): v,x=f(); c[v-1]+=x
b=[1]*n
s=[0]
b[0]=0
while s:
  t=s.pop()
  for i in g[t]:
    if b[i]: c[i]+=c[t]; s+=[i]; b[i]=0
print(*c)

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

int main() {
	int x, count500, count5;
	cin >> x;
	count500 = 0; count5 = 0;
	while(x >= 500)
	{
		x -= 500;
		count500++;
	}
	while(x >= 5)
	{
		x -= 5;
		count5++;
	}
	cout << 1000*count500 + 5*count5 << endl;
}

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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	if (N == 1){
		cout << "Hello World" << endl;
	}else{ // if (N == 2)
		int A, B; cin >> A >> B;
		int res = A + B;
		cout << res << endl;
	} // end if

	return 0;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back

int bexp(int a, int b, int mod)
{
    int res = 1;
    if (mod <= 0)
        return 0;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

#define N 200010
#define MOD 1000000007

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

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n, k;
    cin >> n >> k;

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

    int l = 1, r = *max_element(a, a + n);

    while (l < r)
    {
        int mid = l + r >> 1;

        int cost = 0;
        for (int i = 0; i < n; ++i)
        {
            cost += (a[i] - 1) / mid;
        }

        if (cost > k)
            l = mid + 1;
        else
            r = mid;
    }

    cout << l << endl;
    return 0;
}


Measured memory_bytes: 5140