akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  int water = 0, sugar = 0;
  for (int k = 0; 100*k*a <= f; ++k) 
    for (int l = 0; 100*l*b <= f; ++l) {
      int w = 100 * (k*a + l*b);
      for (int r = 0; r*c + w <= f; ++r) 
        for (int u = 0; u*c + w <= f; ++u) {
          int s = r*c + u*d;
          if (w + s <= f) {
            if (s <= w/100 * e) {
              if (s * (water + sugar) >= sugar * (w + s)) {
                water = w;
                sugar = s;
              }
            }
          }
        }
    }


  cout << water+sugar << " " << sugar << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 2005
using namespace std;

int h, w, c, mx, s[N][N];
char a[N][N];
int main()
{
	int i, j;
	cin >> h >> w;
	for (i = 0; i < h; i++) scanf("%s", &a[i]);
	for (i = 0; i < h; i++) {
		c = 0;
		for (j = 0; j < w; j++) {
			if (a[i][j] == '.') c++;
			else c = 0;
			s[i][j] += c;
		}
		c = 0;
		for (j = w - 1; j >= 0; j--) {
			s[i][j] += c;
			if (a[i][j] == '.') c++;
			else c = 0;
		}
	}
	for (j = 0; j < w; j++) {
		c = 0;
		for (i = 0; i < h; i++) {
			if (a[i][j] == '.') c++;
			else c = 0;
			s[i][j] += c;
		}
		c = 0;
		for (i = h - 1; i >= 0; i--) {
			s[i][j] += c;
			if (a[i][j] == '.') c++;
			else c = 0;
		}
	}
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			mx = max(mx, s[i][j] - 1);
		}
	}
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 19968
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <tuple>
#include <stdlib.h>
using namespace std;

int main()
{
	int N, K,h,ans=0;
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		cin >> h;
		if (h >= K)ans++;
	}
	cout << ans;
}

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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000

ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<ll>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
    ll n, k = 1, a, b;
    string s;
    cin>>n;
    vector<ll>p(n), q(n), r(n);
    for(ll i=0;i<n;i++) r[i] = i+1;
    for(ll i=0;i<n;i++) cin>>p[i];
    for(ll i=0;i<n;i++) cin>>q[i];
    do{
        bool f = true;
        for(ll i=0;i<n;i++)
        {
            if(p[i] != r[i])
            {
                f = false;
                break;
            }
        }
        if(f)
            a = k;
        f = true;
        for(ll i=0;i<n;i++)
        {
            if(q[i] != r[i])
            {
                f = false;
                break;
            }
        }
        if(f)
            b = k;
        k++;
    }while(next_permutation(r.begin(), r.end()));
    cout<<abs(a-b);
}

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

ll mulmod(ll a, ll b)
{
    ll res = 0; 
    a = a % MOD;
    while(b > 0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
 
        a = (a * 2) % MOD; 
        b /= 2;
    } 
    return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a = (a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
    fact[0] = 1;
    ifact[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
        ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
    }
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
    ll res;
    res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
    return res;
}


Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    m = [list(map(lambda x: 1 if x=="#" else 0, input())) for _ in range(H)]
    black = [(i, j, 0) for i in range(H) for j in range(W) if m[i][j] == 1]

    # print(m)
    # print(black)

    queue = deque(black)
    queue_append = queue.append
    ans = 0
    while queue:
        p = queue.popleft()
        if ans < p[2]:
            ans += 1
        for i, j in ((-1, 0), (1, 0), (0, 1), (0, -1)):
            next_p = (p[0] + i, p[1] + j)
            if (0 <= next_p[0] < H) and (0 <= next_p[1] < W):
                if not m[next_p[0]][next_p[1]]:
                    m[next_p[0]][next_p[1]] = 1
                    queue_append((next_p[0], next_p[1], ans+1))
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 142404
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> p(n + 10);
    auto co = make_v<ll>(n + 10, n + 10);  // j番目までの、iより大きい要素数
    for(int i = 1; i <= n; i++) {
        int k;
        cin >> k;
        p[k] = i;
        for(int j = 1; j < k; j++) {
            co[j][i]++;
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            co[i][j] += co[i][j - 1];
        }
    }
    auto dp = make_v<ll>(n + 10, n + 10);
    fill_v(dp, LINF);
    dp[0][0] = 0;
    ll ans = LINF;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            if(j < p[i] - 1) {
                chmin(dp[i][j], dp[i - 1][j] + b);
                chmin(dp[i][p[i]], dp[i - 1][j] + (co[i][p[i]] - co[i][j]) * a);
            } else {
                chmin(dp[i][j], dp[i - 1][j]);
            }
            if(i == n) {
                chmin(ans, dp[i][j]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 392960
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N; cin>>N;
  vector<int> H(N,0);
  for(int i=0;i<N;i++) cin>>H[i];

  int ans=0;

  for(int i=0;i<N;i++){
    bool check=true;
    for(int j=0;j<i;j++){
      if(H[i]<H[j]){
        check=false;
        break;
      }
    }
    if(check) ans++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

int main(){
  
  long long int N;
  scanf("%lld", &N);
  std::cout << N*N*N << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

S = input()
ans = 0
for i in range(len(S)//2):
    if S[i] == S[len(S)-(i+1)]:
        continue
    else:
        ans += 1

print(ans)

Measured memory_bytes: 4336
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define fi first
#define se second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define RFor(i,b,a) for(ll i = b;i>=a;i--)
#define sz size()
#define PQ priority_queue
#define len length()
#define mll map<ll,ll>
#define mpll map<pll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pair<ll,ll> >
#define mp(x,y)  make_pair(x,y)
#define pll pair<ll,ll>
#define pb push_back
#define pf push_front
#define ALL(v) v.begin(),v.end()
#define LAPAK ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 2e18;
const ll MAX = 1e7;


int main() {
    
    ll tc;
    tc = 1;
    //cin>>tc;
    while(tc--){
        ll n;
        cin>>n;
        string s;
        cin>>s;
        ll cntr = 0;
        For(i,0,n){
            cntr += (s[i]=='R');
        }
        ll ans = 0;
        For(i,0,cntr){
            ans += (s[i] == 'W');
        }
        cout<<ans;
    }
    
    return 0;
}

Measured memory_bytes: 3732
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int n;cin>>n;
  V<ll> v(n);rep(i,0,n)cin>>v[i];
  ll ans=LINF;
  rep(i,0,101){
    ll cnt=0;
    rep(j,0,n){
      cnt+=(v[j]-i)*(v[j]-i);
    }
    chmin(ans,cnt);
  }
  cout<<ans<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 892
#include<stdio.h>

int main(void){
        int n;
        scanf("%d", &n);
        int mx=0, mn=2000, i;
        for(i=0; i<n; i++){
                int tmp;
                scanf("%d", &tmp);
                mx = tmp>mx? tmp:mx;
                mn = tmp<mn? tmp:mn;
        }
        printf("%d\n", (mx-mn+1)/2);
        return 0;
}


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

using namespace std;
struct data {
	string s;
	int p;
	int idx;
};


bool cmp (data a, data b) {
	if (a.s == b.s) return a.p > b.p;
	return a.s < b.s;
}

data arr[121];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i].s >> arr[i].p;
		arr[i].idx = i + 1;
	}
	sort (arr, arr + n, cmp);
	for (int i = 0; i < n; i++) {
		cout << arr[i].idx << "\n";
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)  
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

long long dp[31];

void init() {
  dp[0] = 1;
  dp[1] = 1;
  dp[2] = 2;
  for (int i = 3; i <= 30; i++)
    dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
}

int solve(int x) {
  int days = (dp[x] + 9) / 10;
  return (days + 364) / 365;
}

int main(int argc, char *argv[])
{
  ios::sync_with_stdio(false);
  init();
  int n;
  while (cin >> n) {
    if (!n) break;
    cout << solve(n) << endl;
  }
  
  return 0;
}

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

namespace Contest
{
	class Program
	{
		static void Main()
		{
			long[] NAB = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long N = NAB[0], A = NAB[1], B = NAB[2];
			if (A > B)
			{
				Console.WriteLine(0);
			}
			else if (N == 1)
			{
				Console.WriteLine(A == B ? 1 : 0);
			}
			else
			{
				Console.WriteLine((B - A) * (N - 2) + 1);
			}
#if DEBUG
			Console.ReadKey();
#endif
		}
	}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include<iostream>
#include<set> 
#include<queue> 
#include<stack> 
#include<vector> 
#include<string> 
#include<numeric> 
#include<algorithm> 
#include<math.h> 
#include<iomanip>
using namespace std;
int main()
{
	int n,a[55]={0},b[55]={0},x=0,y=0;
	cin>>n;
	int j=1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]!=i)
		{
			b[j]=a[i];
			j++;
			if(j==2)
			x=i;
			if(j==3)
			y=i;
		}
		if(j>3)
	    {
		    cout<<"NO";
		    return 0;
	    }
	}
	a[x]=b[2];
	a[y]=b[1];
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=i)
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	


	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int sum[1111][1111];
int main(void)
{
  while(1){
    int n; 
    cin >> n;
    if(!n) break;
    for(int i = 1; i <=n; i++){
      for(int j = 1; j <=n; j++){
	char c;
	cin >> c;
	sum[j][i] = (c == '*')?1:0;
      }
    }

    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= n; j++){
	sum[j][i] += sum[j-1][i];
      }
    }

    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= n; j++){
	sum[i][j] += sum[i][j-1];
      }
    }    

    int best = 0;
    for(int i = 1; i + best <= n; i++){
      for(int j = 1; j + best <= n; j++){
	for(int k = best ; i + k <= n && j + k <= n && !(sum[i+k][j+k] - sum[i+k][j-1] - sum[i-1][j+k] + sum[i-1][j-1]); k++){
	  best = k + 1;
	}
      }
    }
    cout << best << endl;
  }
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int x, a;
  cin >> x >> a;
  cout << (x < a ? 0 : 10) << endl;
  return 0;
}


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

using namespace std;

int main(void) {
	int a, b, c, x, y, ans;
	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
	ans = min(a + b, c + c) * min(x, y);
	if (x > y)
		ans += min(a, c + c) * (x - y);
	else if (x < y)
		ans += min(b, c + c) * (y - x);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> c(b);
  rep(i,b)
    cin>>c[i];
  rep(i,b){
  a-=c[i];
  }
  if(a<0)
    cout<<-1;
  else
    cout<<a;
}

Measured memory_bytes: 3664
from collections import deque, namedtuple

class BinaryTree:
    def __init__(self, t):
        self.t = t

    def setDepth(self, u, d):
        if u == -1:
            return
        self.t[u] = self.t[u]._replace(d = d)
        self.setDepth(self.t[u].l, d + 1)
        self.setDepth(self.t[u].r, d + 1)

    def setHeight(self, u):
        h1 = 0
        h2 = 0
        if self.t[u].l != -1:
            h1 = self.setHeight(self.t[u].l) + 1
        if self.t[u].r != -1:
            h2 = self.setHeight(self.t[u].r) + 1
        self.t[u] = self.t[u]._replace(h = max(h1, h2))
        return self.t[u].h

    def getSibling(self, u):
        if self.t[u].p == -1:
            return -1
        if self.t[self.t[u].p].l not in (u, -1):
            return self.t[self.t[u].p].l
        if self.t[self.t[u].p].r not in (u, -1):
            return self.t[self.t[u].p].r
        return -1

    def printNode(self, i):
        p_ = self.t[i].p
        s_ = self.getSibling(i)
        deg_ = 0
        if self.t[i].l != -1:
            deg_ += 1
        if self.t[i].r != -1:
            deg_ += 1
        dep_ = self.t[i].d
        h_ = self.t[i].h
        if p_ == -1:
            t_ = "root"
        elif deg_ == 0:
            t_ = "leaf"
        else:
            t_ = "internal node"
        print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(i, p_, s_,  deg_, dep_, h_, t_))

if __name__ == '__main__':
    n = int(input().rstrip())
    Node = namedtuple('Node', ['p', 'l', 'r', 'd', 'h'])
    t = [Node(-1, -1, -1, -1, -1)] * n
    r = -1
    for i in range(n):
        v, l, r = [int(i) for i in input().rstrip().split(" ")]
        t[v] = t[v]._replace(l = l, r = r)
        if l != -1:
            t[l] = t[l]._replace(p = v)
        if r != -1:
            t[r] = t[r]._replace(p = v)
    for i in range(n):
        if (t[i].p == -1):
            r = i
    x = BinaryTree(t)
    x.setDepth(r, 0)
    x.setHeight(r)
    for i in range(n):
        x.printNode(i)

Measured memory_bytes: 8224
#include<cstdio>
#include<cstring>
#define mod 1000000007
#define maxn 5005
int n,len,dp[maxn][maxn];
char s[maxn];
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	len=strlen(s);
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
		{
			if(!j) dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
			if(j!=i) dp[i][j]=1ll*(dp[i][j]+2ll*dp[i-1][j+1])%mod;
			if(j) dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
		}
	printf("%d\n",1ll*dp[n][len]%mod);
}

Measured memory_bytes: 96384
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;



namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int L = int.Parse(s[1]);

            int ans = 0;
            int eat = int.MaxValue;
            int eat2 = 0;

            for (int i = 0; i < N; i++)
            {
                ans += L + i;
                if ( eat > Math.Abs(L+i))
                {
                    eat = Math.Abs(L + i);
                    eat2 = L + i;
                }
            }

            Console.WriteLine(ans - eat2);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int s1[4],s2[2];
	for(int i=0;i<4;i++){
		scanf("%d",&s1[i]);
	}
	for(int i=0;i<2;i++){
		scanf("%d",&s2[i]);
	}
	sort(s1,s1+4);
	sort(s2,s2+2);
	printf("%d\n",s1[3]+s1[2]+s1[1]+s2[1]);
}

Measured memory_bytes: 3280
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>

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

using namespace std;

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

	cout << s.substr(0, s.size() - 8) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int r;
   cin >> r;
   if(r < 1200){
      cout << "ABC" << endl;
   }
   else if(r >= 1200 && r < 2800){
      cout << "ARC" << endl;
   }
   else{
      cout << "AGC" << endl;
   }

   return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp;
use std::collections::BTreeSet;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


fn into_code(name: &String, k: usize) -> Vec<char> {
    let boin : BTreeSet<char> = "aeiou".chars().collect();
    let mut cs = (*name).chars().collect::<Vec<char>>();
    let mut ret = Vec::<char>::new();
    ret.push(*(cs.first().unwrap()));
    for wd in cs.as_slice().windows(2) {
        let (prev, now) = (wd[0], wd[1]);
        if ret.len() == k {break;}
        if boin.contains(&prev) {
            ret.push(now);
        }
    }
    ret
}


fn main(){
	let cin = stdin();
	let cin = cin.lock();
	let mut sc = Scanner::new(cin);
    loop{
        let n : usize = sc.read();
        if n == 0 { break; }
        let mut names = Vec::new();
        let mut msize = 0;
        for _ in 0..n {
            names.push(sc.read::<String>());
            if msize < names.last().unwrap().len(){
                msize = names.last().unwrap().len();
            }
            //println!("{}", names.last().unwrap());
        }
        //println!("s:{}", msize);
        let mut ended = false;
        for k in 1..msize {
            let mut nms = BTreeSet::new();
            for name in &names {
                if !nms.insert(into_code(name, k)) {
                    break;
                }
            }
            if nms.len() == n {
                //for i in nms {
                    //println!("{:?}", i);
                //}
                println!("{}", k);
                ended = true;
                break;
            }
        }
        if !ended {
            let mut nms = BTreeSet::new();
            for name in &names {
                if !nms.insert(into_code(name, msize)) {
                    break;
                }
            }
            if nms.len() == n {
                //for i in nms {
                    //println!("{:?}", i);
                //}
                println!("{}", msize);
            } else {
                println!("-1");
            }
        }
    }
}




Measured memory_bytes: 5052
#include<stdio.h>

void solve(int a, int b, int c);
int my_sqrt(int a);
int abs(int a);

int main()
{
    char buf[64];
    int a, b, c;
    while(1){
        fgets(buf, sizeof(buf), stdin);
        sscanf(buf, "%d %d %d", &a, &b, &c);
        if(a == 0) break;
        solve(a, b, c);
    }
    return 0;
}

void solve(int a, int b, int c)
{
    int p, q, r, s;
    int i, j;
    int root_a = my_sqrt(a);
    int max_s;

    for(r = 1; r <= root_a; r++){
        if(a%r != 0) continue;
        p = a/r;
        max_s = (p == r ? my_sqrt(abs(c)) : abs(c));
        for(s = -abs(c); s <= max_s; s++){
            if(s == 0 && c != 0) continue;
            if(s == 0 && c == 0){
                if(p == r){
                    if(b > 0) printf("%d %d %d %d\n", p, b, r, 0);
                    else printf("%d %d %d %d\n", p, 0, r, b);
                }else printf("%d %d %d %d\n", p, b, r, 0);
                return;
            }
            if(c%s != 0) continue;
            q = c/s;
            if(p*s + q*r == b){
                printf("%d %d %d %d\n", p, q, r, s);
                return;
            }
        }
    }

    printf("Impossible\n");
}

int abs(int a)
{
    return a >= 0 ? a : -a;
}

int my_sqrt(int a)
{
    int res;
    for(res = 0; res * res <= a; res++);
    return --res;
}



Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <set>
using namespace std;

int main(void) {
	long long A, B, C, K, Ans;

	scanf("%lld %lld %lld %lld", &A, &B, &C, &K);

	Ans = A - B;
	if (K % 2 == 1) Ans *= -1;
	
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d,k,sum,i,j;
    cin>>a>>b>>c>>d;
    vector <long long> v;
    sum = a*c;
    v.push_back(sum);
    sum =0;
    sum = a*d;
    v.push_back(sum);
    sum =0;
    sum = b*c;
    v.push_back(sum);
    sum =0;
    sum = b*d;
    v.push_back(sum);
    cout<<*max_element(v.begin(),v.end());

    return 0;
}


Measured memory_bytes: 3624
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
using namespace std;
vector<int> adj[200005];
bool vis[200005]={0};
int parent[200005]={0};
int ans[200005]={0};
void bfs(int n){
	queue<int> que;
	que.push(1);
	vis[1]=true;
	while(!que.empty()){
		int x=que.front();
		int cost=ans[x];
		que.pop();
		for(int i=0LL;i<adj[x].size();i++){
			int b=adj[x][i];
			if(!vis[b]){
				que.push(b);
				vis[b]=true;
				parent[b]=x;
				ans[b]+=cost;
			}
		}
	}
	
}
int solve()
{
	int n,q;	cin>>n>>q;
	for(int i=1LL;i<n;i++){
		int x,y;
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	for(int i=1;i<=q;i++){
		int x,p;
		cin>>x>>p;
		ans[x]+=p;
	}
	bfs(n);
	for(int i=1LL;i<=n;i++){
		cout<<ans[i]<<" ";
	}
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}

Measured memory_bytes: 20732
import heapq
N,M = map(int, input().split())
A = list(map(lambda x:-int(x), input().split()))
heapq.heapify(A)
for i in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A,-(-a//2))
print(-sum(A))

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

using namespace std;

const int N = 100;
vector<int> arr[N];

int main(){
	int n, d, m, c, tmax, e;
	bool f;
	while(cin >> n >> d, n){
		vector<int> sum(n, 0);
		for(int i = 0;i < n;++i){
			cin >> m;
			arr[i].clear();
			for(int j = 0;j < m;++j){
				cin >> c;
				arr[i].emplace_back(c);
				sum[i] += c;
			}
			reverse(arr[i].begin(), arr[i].end());
		}
		while(1) {
			tmax = *(max_element(sum.begin(), sum.end()));
			f = false;
			if(!tmax) break;
			for(int i = 0;i < n;++i){
				if(arr[i].empty()) continue;
				e = sum[i] - arr[i][0];
				if(tmax == sum[i]){
					int s = 0;
					for(int j = 0;j < n;++j){
						if(i == j) continue;
						s = max(s, sum[j]);
					}
					if((s - e) <= d){
						sum[i] = e;
						arr[i].erase(arr[i].begin());
						f = true;
						break;
					}
				}
				else if((tmax - e) <= d){
					sum[i] = e;
					arr[i].erase(arr[i].begin());
					f = true;
					break;
				}
			}
			if(!f) break;
		}
		cout << (!tmax ? "Yes" : "No") << endl;
	}
}



Measured memory_bytes: 3220
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
MOD = 1000000007


def main():
    N, *A = map(int, read().split())
    M = 60

    ans = 0
    p = 1
    for _ in range(M):
        n = 0
        for i, a in enumerate(A):
            if not a:
                continue
            A[i], d = a // 2, a % 2
            if d:
                n += 1
        ans = (ans + n * (N - n) * p) % MOD
        p = p * 2 % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


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

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

    bool flag = true;

    const int n = s.length();
    rep(i, 0, n / 2) {
        if (s[i] != s[n - i - 1]) flag = false;
    }

    string s1;
    rep(i, 0, (n - 1) / 2) {
        s1 += s[i];
    }

    string s2;
    rep(i, (n + 3) / 2 - 1, n) {
        s2 += s[i];
    }

    int n1 = s1.length();
    rep(i, 0, n1 / 2) {
        if (s1[i] != s1[n1 - i - 1]) flag = false;
    }

    int n2 = s2.length();
    rep(i, 0, n2 / 2) {
        if (s2[i] != s2[n2 - i - 1]) flag = false;
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
n = 0
ans = 0
for n in range( 1 << len(s) -1):
    p = 0
    for i in range(len(s) - 1):
        if n & (1 << i):
            ans += int(s[p:i + 1])
            p = i + 1
    if p < len(s):
        ans += int(s[p:])
print(ans)

Measured memory_bytes: 3064
Module Program
  Sub Main
    Dim s = GetInts()
    Dim a=s(0),b=s(1)
    Dim ans=If((a*b)Mod 2=0,"No","Yes")
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22352
n=int(input())
S=input()

ans=0
for x in range(1000):
  x=str(x).zfill(3)
  p1=S.find(x[0])
  if p1==-1: continue
  p2=S.find(x[1],p1+1)
  if p2==-1: continue
  p3=S.find(x[2],p2+1)
  if p3==-1: continue
  ans+=1
print(ans)

Measured memory_bytes: 3188
N = int(input())
h = list(map(int, input().split())) + [0]*100010

dp = [float("inf")]*100010
dp[0] = 0

for i in range(N):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
    dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]))
    # print(dp)
print(dp[N-1])

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    mat A(3, vec(3));
    REP(i,0,3) REP(j,0,3) cin >> A[i][j];
    ll N;
    cin >> N;
    vec B(N);
    REP(i,0,N) cin >> B[i];

    bool f;
    REP(i,0,3) REP(j,0,3) {
        f = false;
        REP(k,0,N) {
            if(A[i][j] == B[k]) {
                f = true;
                break;
            }
        }
        A[i][j] = (ll)f;
    }

    f = false;
    if(A[0][0] && A[0][1] && A[0][2]) f = true;
    if(A[1][0] && A[1][1] && A[1][2]) f = true;
    if(A[2][0] && A[2][1] && A[2][2]) f = true;
    if(A[0][0] && A[1][0] && A[2][0]) f = true;
    if(A[0][1] && A[1][1] && A[2][1]) f = true;
    if(A[0][2] && A[1][2] && A[2][2]) f = true;
    if(A[0][0] && A[1][1] && A[2][2]) f = true;
    if(A[0][2] && A[1][1] && A[2][0]) f = true;
    
    if(f) PR("Yes");
    else PR("No");

    return 0;
}

/*



*/

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

int marge(int*, int);

int main(void){
    int n;
    int* a;

    scanf("%d",&n);

    a=(int*)malloc(n*sizeof(int));

    for(int i=0; i<n; i++){
        scanf("%d",a+i);
    }



    int flg=0;

    flg=marge(a, n);




    if(flg == 1){
        printf("NO");
        return 0;
    }

    for(int i = 1; i < n; i++){
        if(a[i]==a[i-1]){
            printf("NO");
            return 0;
        }
    }

    printf("YES");

    return 0;
}

int marge(int* a, int n){


    if(n==1) return 0;

    int* l2, *r2, *tmp;
    l2=(int*)malloc((n/2)*sizeof(int));
    r2=(int*)malloc((n-n/2)*sizeof(int));
    tmp=(int*)malloc((n)*sizeof(int));

    for(int i=0; i<n/2; i++){
        l2[i]=a[i];
    }
    for(int i=0; i<n-n/2; i++){
        r2[i]=a[i+n/2];
    }

    int lflg=0, rflg=0;

    lflg = marge(l2, n/2);
    rflg = marge(r2, n-n/2);

    if(lflg == 1 || rflg == 1) return 1;



    for(int i = 0; i < n/2; i++){
        tmp[i] = l2[i];
    }
    for(int i = n/2; i < n; i++){
        tmp[i] = r2[n-i-1];
    }

    int lp=0, rp=n-1, p=0;
    int l3, r3;
    while(p<n){
        l3=tmp[lp];
        r3=tmp[rp];

        if(l3==r3 && lp!=rp){
            return 1;
        }else if(l3<r3){
            a[p]=l3;
            lp++;
            p++;
        }else{
            a[p]=r3;
            rp--;
            p++;
        }


    }



    return 0;

}

Measured memory_bytes: 41344
# include <bits/stdc++.h>
using namespace std; 
int main(){
  int n,x,i,j,k,sum; 
  cin>>n; 
  int ar[n];
  for(i=0;i<n;i++){
    cin>>ar[i];
  }
  sort(ar,ar+n);
  sum=0;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(k=j+1;k<n;k++){
        if(ar[i]!=ar[j] && (ar[j]!=ar[k] && ar[i]!=ar[k])){
          if(ar[i]+ar[j]>ar[k]){
            sum++;
          }
        }
      }
    }
  }
  cout<<sum; 
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
int n,q,a[100010];
signed main(){
    cin>>n>>q;
    a[0]=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a,a+n+1);
    rep(_,q){
        int l,r;
        cin>>l>>r;
        cout<<upper_bound(a,a+1+n,r)-lower_bound(a,a+1+n,l)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,count=1,sum=0;
    cin>>n;
    string arr[n];
    for(i=0;i<n;i++){
        cin>>arr[i];
        sort(arr[i].begin(),arr[i].end());
    }
    sort(arr,arr+n);
    for(i=0;i<n-1;i++){
        if(arr[i]==arr[i+1])
            count+=1;
        else{
            sum=sum+(count*(count-1))/2;
            count=1;
        }
    }
    sum=sum+(count*(count-1))/2;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 5760
//I am so vegetable
//#define _LOCAL_
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#define _for(i,a,b) for(ll i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 1e5 + 5;
const int MOD = 998244353;
const double eps = 1e-6;
const double pi = acos(-1);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
int c[2*N];
int main() {
	FIO;
	int x,y,A,B,C;cin>>x>>y>>A>>B>>C;
	vector<int>a(A),b(B);
	_for(i,0,A)cin>>a[i];
	_for(i,0,B)cin>>b[i];
	_for(i,0,C)cin>>c[i];
	sort(a.begin(),a.end(),greater<int>());
	sort(b.begin(),b.end(),greater<int>());
	sort(c,c+C,greater<int>());
	a.resize(x),b.resize(y);
	a.IN(a.end(),b.begin(),b.end());
	sort(a.begin(),a.end());
	ll ans = 0;
	_for(i,0,a.size()){
		if(a[i]<c[i])ans+=c[i];
		else ans += a[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		String[] S = new String[] {A,B,C};
		sc.close();
		int num = 0;
		while(S[num].length() != 0) {
			int cnt = S[num].charAt(0) - 'a';
			S[num] = S[num].substring(1);
			num = cnt;
		}
		System.out.println((char)('A' + num));
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int INF = 1000000000; // 10^9
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int R;
    cin >> R;
    double ans = 0;
    ans = 2 * R * 3.14;
    cout << ans << endl;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;


vector<int> v, w;


vector<int> getvec(int p) {
    int lim = 100010;
    vector<int> vv, ww;
    for (int j = p; ; j = (j - 1) >> 1) {
        vv.push_back(v[j]);
        ww.push_back(w[j]);
        if (j == 0) break;
    }

    int m = vv.size();
    vector<int> lis(lim);
    for (int i = 0; i < (1 << m); ++i) {
        int vs = 0, ws = 0;
        for (int j = 0; j < m; ++j) {
            if ((i >> j) & 1) {
                vs += vv[j];
                ws += ww[j];
            }
        }
        if (ws < lim) {
            lis[ws] = max(lis[ws], vs);
        }
    }
    for (int i = 1; i < lim; ++i) {
        lis[i] = max(lis[i], lis[i - 1]);
    }
    return lis;
}

vector<P> getvec(int p, int par) {
    int lim = 100010;
    vector<int> vv, ww;
    for (int j = p; ; j = (j - 1) >> 1) {
        vv.push_back(v[j]);
        ww.push_back(w[j]);
        if (j == par) break;
    }

    int m = vv.size();
    vector<P> lis;
    for (int i = 0; i < (1 << m); ++i) {
        int vs = 0, ws = 0;
        for (int j = 0; j < m; ++j) {
            if ((i >> j) & 1) {
                vs += vv[j];
                ws += ww[j];
            }
        }
        if (ws < lim) {
            lis.push_back({ ws, vs });
        }
    }
    return lis;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    v = vector<int>(n);
    w = vector<int>(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i] >> w[i];
    }
    int q;
    cin >> q;
    vector<vector<P>> que(n, vector<P>());
    for (int i = 0; i < q; ++i) {
        int u, l;
        cin >> u >> l;
        --u;
        que[u].push_back({ l, i });
    }
    vector<vector<int>> memo(1 << 10);
    vector<int> ans(q);
    for (int i = 0; i < n; ++i) {
        if (i < (1 << 10)) {
            vector<int> lis = getvec(i);
            memo[i] = lis;
            for (auto& p : que[i]) {
                int l = p.first;
                ans[p.second] = lis[l];
            }
        }
        else {
            int pp = i;
            while (((pp - 1) >> 1) >= (1 << 10)) {
                pp = (pp - 1) >> 1;
            }
            const vector<int>& lis1 = memo[(pp - 1) >> 1];
            vector<P> lis2 = getvec(i, pp);

            for (auto& p : que[i]) {
                int l = p.first;
                int ma = 0;
                for (auto& j : lis2) {
                    if (j.first <= l) {
                        ma = max(ma, lis1[l - j.first] + j.second);
                    }
                }
                ans[p.second] = ma;
            }
        }
    }
    for (auto& i : ans) {
        cout << i << '\n';
    }


    return 0;
}


Measured memory_bytes: 415660
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

template <int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

const int mod = 998244353;
using mint = ModInt<mod>;

const int N = 200002;
mint f[N];

mint C(int n, int r) { return f[n] * f[r].inverse() * f[n - r].inverse(); }

int main() {
    f[0] = 1;
    for (int i = 1; i < N; ++i) f[i] = f[i - 1] * i;

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

    vector<mint> pw(n);
    pw[0] = 1;
    rep(i, n - 1) pw[i + 1] = pw[i] * (m - 1);

    mint ans = 0;
    rep(i, k + 1) ans += C(n - 1, i) * m * pw[n - 1 - i];
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;




int main(){FIN
    
    ll n;cin>>n;
    vll a(n); REP(i,n) cin>>a[i];
    VSORT(a);
    vll ok(1000001,1);
    vll doub(1000001, 1);
    REP(i,n){
        if (i+1<n && a[i]==a[i+1]) doub[a[i]] = 0;
        else if (i-1>=0 && a[i]==a[i-1]) doub[a[i]]=0;
    }
    

    ll ans=0;
    REP(i,n){
        bool cnt=true;
        if (doub[a[i]]==0) cnt=false;
        if (ok[a[i]]==0) {
            cnt=false;
            continue;
        }
        if (cnt) ans++;

        ll cp=a[i];
        ll idx=1;
        if (ok[a[i]]!=0){
            while(cp*idx<=a[n-1]){
                ok[cp*idx] = 0;
                idx++;
            }
        }
    }

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

Measured memory_bytes: 20356
#include<bits/stdc++.h>
using namespace std;
int ans = 0;
vector<int> v;
int m;
int DP[10009][2][101][2];
int N = 1000000007;
int dp(int pos,int isSmall,int mod,int leadingZero)
{

    if(DP[pos][isSmall][mod][leadingZero]!=-1)
    {
        return DP[pos][isSmall][mod][leadingZero];
    }
    //cout<<pos<<" "<<isSmall<<" "<<mod<<" "<<leadingZero<<endl;
    if(pos==v.size())
    {
        if(mod==0 && leadingZero==1)
            return DP[pos][isSmall][mod][leadingZero] = 1;
        else return DP[pos][isSmall][mod][leadingZero] = 0;

    }
    DP[pos][isSmall][mod][leadingZero] = 0;
    if(isSmall==0)
    {
        for(int i=0;i<v[pos];i++)
        {
            if(i==0)
                DP[pos][isSmall][mod][leadingZero] = (DP[pos][isSmall][mod][leadingZero] +dp(pos+1,1,(mod+i)%m,leadingZero|0))%N;
            else
                DP[pos][isSmall][mod][leadingZero] = (DP[pos][isSmall][mod][leadingZero]+dp(pos+1,1,(mod+i)%m,1))%N;
        }
        if(v[pos]==0)
            DP[pos][isSmall][mod][leadingZero] = (DP[pos][isSmall][mod][leadingZero]+dp(pos+1,0,(mod+v[pos])%m,leadingZero|0))%N;
        else
            DP[pos][isSmall][mod][leadingZero] = (DP[pos][isSmall][mod][leadingZero]+dp(pos+1,0,(mod+v[pos])%m,1))%N;
    }
    else
    {
        DP[pos][isSmall][mod][leadingZero] = (DP[pos][isSmall][mod][leadingZero]+dp(pos+1,1,(mod+0)%m,leadingZero|0))%N;
        for(int i=1;i<10;i++)
            DP[pos][isSmall][mod][leadingZero] = (DP[pos][isSmall][mod][leadingZero]+ dp(pos+1,1,(mod+i)%m,1))%N;
    }
    return DP[pos][isSmall][mod][leadingZero];
}
int main()
{
    string n;
    cin>>n>>m;
    memset(DP,-1,sizeof DP);
    for(int i=0;i<n.size();i++)
        v.push_back(n[i]-48);

    cout<<dp(0,0,0,0)<<endl;

}


Measured memory_bytes: 17152