akhauriyash/Code-Regression huggingface dataset:
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    F = [int(i) for i in input().split()]
    A.sort()
    F.sort(reverse=True)
    ma = 0
    for a, f in zip(A, F):
        ma = max(ma, a*f)

    def is_ok(mid):
        need = 0
        for a, f in zip(A, F):
            if mid < a*f:
                need += (a - mid//f)
        if need <= K:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = ma + 1
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right
    print(binary_search_meguru())


if __name__ == '__main__':
    main()


Measured memory_bytes: 119500
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
#include <functional>
#include <map>
#include <set>
using namespace std;
const long INF = 1000000009;

long n;
long a[100000];
long b[100000];
long c[100000];

long dp[2][100000];

int main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		scanf("%ld", &a[i]);
	}
	for(int i = 0; i < n; i++){
		scanf("%ld", &b[i]);
	}
	for(int i = 0; i < n; i++){
		scanf("%ld", &c[i]);
	}
	sort(a, a+n);
	sort(b, b+n);
	sort(c, c+n);
	int vis = 0;
	for(int i = 0; i < n; i++){
		while(b[i] > a[vis] && vis < n){
			vis++;
		}
		dp[0][i] = vis;
	}
	vis = 0;
	/*for(int i = 0; i < n; i++){
		printf("%ld ", dp[0][i]);
	}
	printf("\n");*/
	for(int i = 0; i < n; i++){
		if(i != 0){
			dp[1][i] = dp[1][i-1];
		}
		while(c[i] > b[vis] && vis < n){
			//printf("%d\n", vis);
			dp[1][i] += dp[0][vis];
			vis++;
		}
	}
	long ans = 0;
	for(int i = 0; i < n; i++){
		ans += dp[1][i];
	}
	printf("%ld\n", ans);
	return 0;
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p;
  p.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += p[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n, sum = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            sum += a[i] * a[j];
    cout << sum << "\n";
    
    return 0;
}


Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


n=int(input())
a=list(map(int,input().split()))

a.sort()

jd=[True]*(a[-1]+10)

pairwise=True

for i in a:
    if i==1:
        continue
    
    xxx=factorization(i)
    for j in xxx:
        if jd[j[0]]==True:
          jd[j[0]]=False
        else:
            pairwise=False
            break
    
    if pairwise==False:
        break

if pairwise:
    print('pairwise coprime')
    exit()

if 1 in a:
    print('setwise coprime')
    exit()


zzz=factorization(a[0])

for i in zzz:
    pin=i[0]
    flag=True
    cnt=0
    for j in a:
      if j%pin==0:
          cnt+=1
    
    if cnt==n:
        print('not coprime')
        exit()


print('setwise coprime')

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

const int mod = 1000000007;

int N, K;
vector<pair<int, int>> moeb;

long powmod(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return b * powmod(b, e - 1) % mod;
  long t = powmod(b, e / 2);
  return t * t % mod;
}

void pre(int n) {
  vector<int> ps;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      ps.push_back(i);
    }
    while (n % i == 0) {
      n /= i; 
    }
  }
  if (n != 1) {
    ps.push_back(n);
  }
  
  const int m = ps.size();
  for (int s = 0; s < (1 << m); ++s) {
    int prod = 1;
    int val = 1;
    for (int k = 0; k < m; ++k) {
      if (s & (1 << k)) {
        prod *= ps[k];
        val *= -1;
      }
    }
    moeb.push_back(make_pair(prod, val));
  }
}

set<int> divisors(int n) {
  set<int> ret;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.insert(i);
      ret.insert(n / i);
    }
  }
  return ret;
}

long sub(int n) {
  long sum = 0;
  for (auto p : moeb) {
    if (n % p.first != 0) continue;
    int d = n / p.first;
    long sgn = mod + p.second;
    int exp = N % 2 == 0 ? d : (d + 1) / 2;
    sum = (sum + sgn * powmod(K, exp)) % mod;
  }
  return sum;
}

int main() {
  cin >> N >> K;
  const int n = N % 2 == 0 ? N / 2 : N;
  pre(n);
  long sum = 0;
  for (int d : divisors(n)) {
    sum = (sum + d * sub(d)) % mod;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import sys
mod = 998244353

def solve():
    input = sys.stdin.readline
    N, S = map(int, input().split())
    A = [int(a) for a in input().split()]
    DP = [[0 for _ in range(S + 1)] for i in range(N)]
    DP[0][0] = 2
    if A[0] <= S: DP[0][A[0]] = 1
    ans = 0
    for i, a in enumerate(A[1:]):
        for s in range(S + 1):
            if DP[i][s] > 0:
                DP[i+1][s] += (DP[i][s] * 2) % mod
                DP[i+1][s] %= mod
                if s + a <= S:
                    DP[i+1][s+a] += DP[i][s]
                    DP[i+1][s+a] %= mod         
    print(DP[N-1][S])
    #print(DP)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 146848
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    vector <ll> a;
    ll n;
    cin >> n;
    for (ll i=0;i<n+1;i++){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    ll ans = 0;
    for (ll i=0;i<n;i++){
        ll b;
        cin >> b;
        if(a[i] >= b){
            ans += b;
            continue;
        }else {
            ans += a[i];
            b -= a[i];
            if (a[i + 1] >= b) {
                ans += b;
                a[i + 1] -= b;
            } else {
                ans += a[i + 1];
                a[i + 1] = 0;
            }
        }
    }
    cout << ans << endl;

}

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

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

  bool f = 0;
  for (int i=0; i<3; i++){
      if(a.at(i) == '7'){
          f = 1;
          break;
      }
  }
  if(f == 0){
      cout << "No" << endl;
  }else{
      cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;cin >> n >> k;
    vector<double> p(n),q(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
        q[i]=(p[i]+1)/2;
    }
    double ans=0,sum=0;
    for(int i=0;i<n;i++){
        if(i<k){
            sum+=q[i];
            if(i==k-1){
                ans=sum;
            }
        }
        else{
            sum+=q[i];
            sum-=q[i-k];
            ans=max(ans,sum);
        }
    }
    cout << fixed << setprecision(15)  << ans << endl;
}

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

#define pb push_back
#define mp make_pair
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef long double ld;

const ll inf = 1e18;

ll get(ll n, ll b)
{
    ll ans = 0;
    while (n) {
        ans += (n % b);
        n /= b;
    }
    return ans;
}

int main()
{

    //ifstream cin("input.txt");

    ll n, s;
    cin >> n >> s;

    if (s > n) {
        cout << "-1\n";
        return 0;
    }

    if (s == n) {
        cout << n + 1 << "\n";
        return 0;
    }

    for (ll b = 2; b * b <= n; ++b) {
        ll g = get(n, b);
        if (g == s) {
            cout << b << "\n";
            return 0;
        }
    }

    ll val = n - s;
    ll ans = inf;

    for (ll d = 1; d * d <= val; ++d) {
        if (val % d == 0) {
            ll b = d + 1;
            ll x = val / d;
            if (x <= s && b > max(x, s - x)) {
                ans = min(ans, b);
            }
            if (d * d != val) {
                b = val / d + 1;
                x = d;
                if (x <= s && b > max(x, s - x)) {
                    ans = min(ans, b);
                }
            }
        }
    }

    cout << (ans == inf ? -1 : ans) << "\n";

}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static final long MAX = 1000000000000000000L;
	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		int zero = -1;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
			if(A[i] == 0) zero = i;
		}
		sc.close();
		if(zero > -1) {
			prtln(0);
			return;
		}
		long answer = 1L;
		for(int i = 0; i < N; i++) {
			try {
				answer = Math.multiplyExact(answer, A[i]);
			} catch(ArithmeticException e) {
				prtln(-1);
				return;
			}
			if(answer > MAX) {
				prtln(-1);
				return;
			}
		}
		prtln(answer);
	}

	public static <T> void prtln(T t) { System.out.println(t); }
}

Measured memory_bytes: 50596
#include<stdio.h>
#define N 10000
#define Q 500
int qsort();

int compare(const void*a,const void*b)
{
  return*(int*)a-*(int*)b;
}

int*uniq(int*a,int*n){
  int i,j,prev = a[0];
  for(i = 1,j = 1;i < *n;i++){
    if(prev != a[i]){
      a[j] = a[i];
      prev = a[i];
      j++;
    }
  }
  *n = j;
  return a;
}

int main(void)
{
  int i,j,n,q,c = 0;
  int S[N],T[Q];

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&T[i]);
  }

  qsort(S,n,sizeof(int),compare);
  uniq(S,&n);

  for(i = 0;i < n;i++){
    for(j = 0;j < q;j++){
      if(S[i] == T[j]){
        c++;
      }
    }
  }
  printf("%d\n",c);

  return 0;
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(exp, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = 2505;
int N, M, P, dist[MAXN];
vector<pii> v[MAXN];

bool path_exists(int v1, int v2)
{
    bool seen[MAXN];
    for(int i=0; i<N; i++)
    {
        seen[i] = false;
    }
    queue<int> q;
    q.push(v1);
    while(!q.empty())
    {
        int x = q.front();
        //cout << x << "\n";
        q.pop();
        seen[x] = true;
        for(auto e : v[x])
        {
            if(!seen[e.f])
            {
                q.push(e.f);
            }
        }

    }
    return seen[v2];
}

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M >> P;
    for(int i=0; i<M; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        z-=P;
        v[x].PB({y, z});
    }

    //bellman-ford
    for(int i=1; i<N; i++)
    {
        dist[i] = -INF;
    }

    for(int i=0; i<N-1; i++)
    {
        for(int j=0; j<N; j++)
        {
            for(auto edge : v[j])
            {
                dist[edge.f] = max(dist[edge.f], dist[j] + edge.s);
            }
        }
    }

    //check cycle
    for(int j=0; j<N; j++)
    {
        for(auto edge : v[j])
        {
            if((dist[edge.f] < dist[j] + edge.s) && path_exists(0, edge.f) && path_exists(edge.f, N-1))
            {
                //cout << "\n" << j << " " << edge.f << " " << edge.s;
                cout << -1;
                return 0;
            }
        }
    }

    cout << max(0, dist[N-1]);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define iiii pair<ii,ii>
#define f(i,a,b) for(long long i = a;i < b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define w(t) while(t--)
#define c(n); cin>>n;
#define p(n) cout<<n;
#define pl(n) cout<<n<<endl;
#define ps(n); cout<<n<<" ";
#define F first
#define S second
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define ull unsigned long long
#define vll vector<ll>
#define vii vector<ii>
#define mkp make_pair
#define ld long double
#define arrin(a,n) f(i,0,n){cin>>a[i];}
#define arrout(a,n) f(i,0,n){cout<<a[i]<<" ";}
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define PI (2*acos(0))
const long long N = 1e6+5;
vll visit,dist,taken;
vector<vll> adj;
vector<vii> adj2;
priority_queue<ii,vector<ii>, greater<ii> > pq;
ll bit[N]={0};
ll siz;
ll res = 0;
ll lcm(ll a,ll b){return (a * b) / __gcd(a,b);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll power(ll a,ll b){if(b == 0)return 1;if(b == 1)return a;ll ans = power(a,b/2) % MOD;ans *= ans;ans %= MOD;if(b % 2 == 1)ans *= a;return ans%MOD;}
ll inverse(ll x){x%=MOD;return power(x,MOD-2);}
void BITup(ll k, ll x){while(k <= siz){bit[k]+=x;k += k & -k;}}
ll BITq(ll k){ll s=0;while(k>=1){s+=bit[k];k -= k &-k;}return s;}
struct node{ll lazy,val;}seg[4000000];
struct point{ll x,y;};
void dfs(ll v){visit[v] = 1;for(auto x:adj[v]){if(!visit[x])dfs(x);}}
void bfs(ll s){visit[s] = 1;queue<ll>q;q.push(s);while(!q.empty()){ll u = q.front();ps(u);q.pop();for(auto x:adj[u]){if(!visit[x]){visit[x] = 1;q.push(x);}}}}
void dijkstra(ll s){pq.push(ii(0,s));dist[s] = 0;while(!pq.empty()){ii f = pq.top();pq.pop();ll w = f.F;ll u = f.S;if(w > dist[u]){continue;}for(auto v:adj2[u]){if(dist[u] + v.S < dist[v.F]){dist[v.F] = dist[u] + v.S;pq.push(ii(dist[v.F],v.F));}}}}
void prim(ll edge) {taken[edge] = 1;for(auto v:adj2[edge]) {if (taken[v.first]==0)pq.push(ii(v.second, v.first));}}
ll mst(ll s){taken.assign(N, 0);prim(s);ll cost = 0;while(!pq.empty()){ii front = pq.top();pq.pop();ll w = front.first;ll u = front.second;if(taken[u]==0)cost += w;prim(u);}return cost;}
void YESNO(ll a){if(!!a){pl("YES");}else{pl("NO");}}
void filesin(void){freopen("input.in","r",stdin);}
void filesout(void){freopen("output.out","w",stdout);}
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Educational DP Contest
int main(void){
    fastio;
    ll n,w;
    c(n);
    c(w);
    ll we[n],v[n];
    ll sum = 0;
    f(i,0,n){
        cin>>we[i]>>v[i];
    }
    ll dp[n+1][w+1];
    f(i,0,n+1){
        f(j,0,w+1){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else if(j >= we[i-1]){
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-we[i-1]] + v[i-1]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    pl(dp[n][w]);
}


Measured memory_bytes: 79232
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

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

int main() {
    int i, q;
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);
    q = partition(0, n -1);
    
    for (i = 0; i < n; i++) {
        if(i) printf(" ");
        if (i == q) printf("[");
        printf("%d", A[i]);
        if (i == q) printf("]");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2108
/*
        FFFFFFFFFFFFFFFFFFFFFF
        F::::::::::::::::::::F
        F::::::::::::::::::::F
        FF::::::FFFFFFFFF::::F
          F:::::F       FFFFFF
          F:::::F
          F::::::FFFFFFFFFF
          F:::::::::::::::F
          F:::::::::::::::F
          F::::::FFFFFFFFFF
          F:::::F
          F:::::F
        FF:::::::FF
        F::::::::FF
        F::::::::FF
        FFFFFFFFFFF
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(...) cout<<__FUNCTION__<<":"<<__LINE__<<": ";debugger(#__VA_ARGS__, __VA_ARGS__);
template<typename arg>
void debugger(const char* varname, arg&& var) { cout<<varname<<" = "<<var<<endl; }
template<typename arg, typename... args>
void debugger(const char* varnames, arg&& var, args&&... vars) {
    const char* comma = strchr(varnames + 1, ',');
    cout.write(varnames, comma - varnames)<<" = "<<var<<" | ";
    int sz = 1; if(isspace(comma[sz])) sz++;
    debugger(comma + sz, vars...);
}
#define forr(i, s, n) for(ll i=(ll)(s); i<(ll)(n); ++i)
#define forn(i, n) forr(i, 0, n)
#define eb(n) emplace_back(n)
#define endl '\n'
#define fst first
#define snd second
using ll = long long;
using ii = pair<ll,ll>;
using vi = vector<ll>;
extern const int INF = INT_MAX - 5;
extern const ll LINF = LLONG_MAX - 5;
extern const int MOD = 1e9 + 7;
extern const int N = 2e5 + 200;
int n;
int main() {
    string s;
    cin>>s;
    bool ok = (s[2] == s[3]) and (s[4] == s[5]);
    if(ok) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
char x;
int main()
{
	cin >> x;
	if(x == 'A'){
		cout << 'T';
	}
	else if(x == 'T'){
		cout << 'A';
	}
	else if(x == 'C'){
		cout << 'G';
	}
	else{
		cout << 'C';
	}

    return 0;
}


Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

const int mod = 1e9 + 7;
signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt[26] = {0};
  for (int i = 0; i < n; i++) {
    cnt[s[i] - 'a']++;
  }
  int ans = 1;
  for (int i = 0; i < 26; i++) {
    ans *= cnt[i] + 1;
    ans %= mod;
  }
  ans = (ans + mod - 1) % mod;
  cout << ans << "\n";
}



Measured memory_bytes: 512
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    cout<<A*B/2<<endl;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code


int main()
{
  ll h, w;
  cin>>h>>w;
  ll a1 = (h%3==0?0:1)*w;
  ll a2 = (w%3==0?0:1)*h;
  ll x = min(h, w);
  ll xx = x / 2;
  ll y = max(h, w);
  ll yy = y / 2;
  ll a3 = LONG_MAX;
  rep(i, 1, y)
  {
    ll a = x * i;
    ll b = xx * (y - i);
    ll c = (x - xx)*(y - i);
    ll aa = max(a, max(b, c));
    ll bb = min(a, min(b, c));
    ll area = abs(aa - bb);
    a3 = min(a3, area);
  }
  rep(i, 1, x)
  {
    ll a = y*i;
    ll b = yy*(x-i);
    ll c = (y - yy)*(x - i);
    ll aa = max(a, max(b, c));
    ll bb = min(a, min(b, c));
    ll area = abs(aa - bb);
    a3 = min(a3, area);
    //cout<<i<<" "<<area<<endl;
  }
  cout<<min(a3, min(a1, a2))<<endl;
  return 0;
}


Measured memory_bytes: 12160
// 及时当勉励，岁月不待人！
//当前状态 : attempted
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<cmath>
#include<string>
#include<iomanip>
#define MP make_pair
using namespace std;
typedef long long ll;

const int inf=0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
inline int read(){int ret = 0, sgn = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')sgn = -1;ch = getchar();} while (ch >= '0' && ch <= '9'){ret = ret*10 + ch - '0';ch = getchar();}return ret*sgn;}
struct MN{int a;int b;};
ll MOD=1e9+7;

//结构体
//全局变量
const int maxn=1005;
//函数
ll qp(ll a,ll b)
{
	ll cnt=1;
	while(b)
	{
		if(b&1)
		{
			cnt*=a;
			cnt%=MOD;
		}
		b>>=1;
		a*=a;
		a%=MOD;
	}
	cnt%MOD;
	return cnt;
}

int main()
{
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  //freopen("d:\\desk\\in.txt","r",stdin);
  //freopen("d:\\desk\\out.txt","w",stdout);
  ll n;cin>>n;
  ll ans=qp(10,n);
  ll tmp=qp(8,n);
  ll ttt=qp(9,n);
  ll a=(ans-(ttt*2)%MOD+tmp)%MOD;
  cout<<(a+MOD)%MOD<<endl;
  return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k, ans = 0, x;
	cin >> n >> k;
	vector <int> v;
	while(n--){
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	for(int i = 0; i < k; i++) ans+=v[i];
	cout << ans << "\n";
}

Measured memory_bytes: 3664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var raw = ReadLine().Split().Select(int.Parse).ToArray();
            var A = raw[0];
            var B = raw[1];

            WriteLine(B % A == 0 ? A + B : B - A);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,m;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s.at(i);
    cin >> m;
    vector<string> t(m);
    rep(i,m) cin >> t.at(i);
    // sが青, tが赤
    vector<bool> counted(n,false);
    vi res;
    for(int i=0; i<n; i++){
        if(counted.at(i)) continue;
        counted.at(i) = true;
        int64_t point = 1;
        for(int j=i+1; j<n; j++){
            if(s.at(i) == s.at(j)){
                point++;
                counted.at(j) = true;
            }
        }
        for(int j=0; j<m; j++){
            if(s.at(i) == t.at(j)) point--;
        }
        res.push_back(point>0 ? point : 0);
    }
    sort(res.begin(), res.end(), greater<>());
    cout << res.at(0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdint.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long int
using namespace std;

int32_t main(){
	int n;
	string s;
	cin>>n>>s;
	if(n<3200){
		cout<<"red\n";
	}
	else cout<<s<<"\n";
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, yen): (usize, usize) = read();
    let x = yen / 1000;
    let y = yen / 5000;
    let z = yen / 10000;

    if let Some((x, y, z)) = possible(n, yen, x, y, z) {
        println!("{} {} {}", z, y, x);
    } else {
        println!("-1 -1 -1");
    }
}

fn possible(n: usize, yen: usize, x: usize, y: usize, z: usize) -> Option<(usize, usize, usize)> {
    if x < n {
        return None;
    }
    if n < z {
        return None;
    }
    let want_dec = x-n;

    // 4 and 9
    for yi in 0..y+1 {
        if want_dec < 4*yi {
            break;
        }

        let want_dec_1man = want_dec-4*yi;
        if want_dec_1man % 9 != 0 {
            continue;
        }

        let zi = want_dec_1man / 9;
        if zi > z {
            continue;
        }
        if yi * 5000 + zi * 10000 > yen {
            continue;
        }
        let xi = (yen - yi * 5000 - zi * 10000) / 1000;
        if xi + yi + zi != n {
            continue;
        }
        return Some((xi, yi, zi))
    }
    None
}


Measured memory_bytes: 4352
#include <stdio.h>

int K,X;
int i,j;

int main(){
    scanf("%d %d", &K,&X);
    i=X-K+1;
    j=X+K-1;
    for(i=i; i<j; i++){
        printf("%d ", i);
    }
    printf("%d", i);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

int main()
{
	int n, cnt = 0;
	std::cin >> n;
	std::vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		std::cin >> a[i];
	}

	int m = 0;
	while (m < n)
	{
		if (a[m] % 2 == 0)
		{
			a[m] /= 2;
			cnt++;
		}
		else
		{
			m++;
		}
	}

	std::cout << cnt << std::endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

#ifdef ZERO_IQ
ios_base::sync_with_stdio ( false ), cin.tie ( 0 ), cout.tie ( 0 );
#endif

int main() {
    ll n;
    cin>>n;
    ll q=ceil(double(n)/2.0);
    cout<<q;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double PI  = acos(-1.0);
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    string S;
    cin >> S;
    if (S[0] >= 'A' && S[0] <= 'Z'){
        cout << "A";
    } else {
        cout << "a";
    }
    return 0;
}



Measured memory_bytes: 3628
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <memory>        // unique_ptr, shared_ptr, weak_ptr
#include <cstring>
#include <cmath>

using namespace std;

using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;

#define _LIBCPP_DEBUG 0
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
	long long a, b, c, cube1=0, cube2=0;
	cin >> a >> b >> c;

	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		cout << 0 << endl;
	} else if (max(a, max(b, c)) == a) {
		cube1 = (a/2+1) * b * c;
		cube2 = (a/2) * b * c;
		cout << cube1 - cube2 << endl;
	} else if (max(a, max(b, c)) == b) {
		cube1 = a * (b/2+1) * c;
		cube2 = a * (b/2) * c;
		cout << cube1 - cube2 << endl;
	} else if (max(a, max(b, c)) == c) {
		cube1 = a * b * (c/2+1);
		cube2 = a * b * (c/2);
		cout << cube1 - cube2 << endl;
	}

	return 0;
}


Measured memory_bytes: 3160
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll n;  cin >> n;
  vector<pair<ll,ll> >v(n);
  rep0(i,n){
    cin >> v[i].second >> v[i].first;
  }
  sort(all(v));

  ll check = 0;  //締切日
  ll task = 0;   //仕事
  rep0(i,n){
    check = max(check,v[i].first);
    task += v[i].second;
    if(check < task){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>

using namespace std;

class DICE{
public:
    int top;
    int bottom;
    int right;
    int left;
    int front;
    int back;
    void South();
    void North();
    void East();
    void West();
};

void DICE::South(){
    int temp = back;
    back = top;
    top = front;
    front = bottom;
    bottom = temp;
}

void DICE::North(){
    int temp = front;
    front = top;
    top = back;
    back = bottom;
    bottom = temp;
}

void DICE::West(){
    int temp = left;
    left = top;
    top = right;
    right = bottom;
    bottom = temp;
}

void DICE::East(){
    int temp = right;
    right = top;
    top = left;
    left = bottom;
    bottom = temp;
}

int main(){
    DICE d;
    cin>>d.top>>d.back>>d.right>>d.left>>d.front>>d.bottom;
    string str;
    cin>>str;
    for(int i = 0;i<str.size();i++){
        if(str[i]=='S')d.South();
        if(str[i]=='N')d.North();
        if(str[i]=='E')d.East();
        if(str[i]=='W')d.West();
    }
    cout<<d.top<<endl;
    return 0;
}

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

int main() {
	int n, c, k;
	cin >> n >> c >> k;
	int t[n];
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}

	sort(t, t + n);
	
	int ans = 0;

	int start = -1;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (start == -1) {
			ans++;
			start = t[i];
			cnt = 1;
		}
		else {
			cnt++;
			if (cnt > c || t[i] - start > k) {
				start = -1;
				i--;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3924
from collections import defaultdict
import Queue

def npk(n,k,mod):
	temp = 1
	for i in xrange(n,n-k,-1):
		temp *= i
		temp %= mod
	return temp

mod = 10**9+7
n,k = map(int,raw_input().split())
g = defaultdict(list)
for i in xrange(n-1):
	a,b = map(int,raw_input().split())
	g[a].append(b)
	g[b].append(a)

#arbitrarily start from vertex 1
res = k
q = Queue.Queue()
q.put((1,0))
while not q.empty():
	node = q.get()
	children = g[node[0]]
	c = len(children)
	if node[0] == 1:
		res *= npk(k-1,c,mod)
	else:
		res *= npk(k-2,c-1,mod)
	res %= mod
	for x in children:
		if x != node[1]:
			q.put((x,node[0]))
print res

Measured memory_bytes: 36000
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using i64=long long int;

int main() {
    string S;
    cin >> S;
    const string ref = "keyence";
    int l = S.size()-ref.size();
    if (l <= 0 && S != ref) {
        cout << "NO" << endl;
        return 0;
    }

    for (int i = 0; i < S.size()-l; ++i) {
        string str = S.substr(0, i) + S.substr(i+l);
        if (str == ref) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
while(n=gets.to_i)>0
a=[x=0]*n*2+[0]
n.times{*l,_=a
a=[w=0]
l.each_slice(2){|i,j|s=STDIN.getc<?.?(h=w=0):[h=j+1,w+=1,i+1].min;a<<h;a<<s;x<s&&x=s}
gets}
p x
end 

Measured memory_bytes: 6240
num, max_kind = [int(i) for i in input().split()]

data = []
for i in range(num):
    taste = [int(i) for i in input().split()]
    del taste[0]
    data.append(taste)


result = 0
if len(data) == 1:
    result = len(data[0])
else:
    for num1 in data[0]:
        trueNum = 0
        for i in range(1, len(data)):
            if num1 in data[i]:
                trueNum += 1
                if trueNum == len(data) - 1:
                    result += 1

print(result)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const ll INF = 1e18;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

const int mxV = 1e5 + 8;
ll dist[mxV];
vector<pair<int, int>> adj[mxV];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, r;
    cin >> n >> m >> r;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back(make_pair(b, c));
    }
    fill(dist, dist + mxV, INF);
    dist[r] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;
    Q.push(make_pair(0, r));
    while(!Q.empty()) {
        pair<int, int> p = Q.top();
        Q.pop();
        int dis = p.first;
        int v = p.second;
        if(dist[v] < dis) continue;

        for(auto u : adj[v]) {
            if(chmin(dist[u.first], dist[v] + u.second)) {
                Q.push(make_pair(dist[u.first], u.first));
            }
        }
    }
    rep(i, n) {
        if(dist[i] == INF) cout << "INF" << endl;
        else cout << dist[i] << endl;
    }
}


Measured memory_bytes: 13412
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;
use std::cmp::max;

fn main() {
    input!{
        n: usize,
        m: usize,
        es: [(usize1, usize1); m]
    }
    let mut tree: Vec<Vec<usize>> = vec![Vec::new(); n];
    for (u, v) in es {
        tree[u].push(v);
    }
    let mut tab: HashMap<(usize, usize), usize> = HashMap::new();
    let mut ans = 0;
    for i in 0..n {
        ans = max(ans, dfs(&tree, i, i, &mut tab));
    }
    println!("{}", ans - 1);
}

fn dfs(t: &Vec<Vec<usize>>, r: usize, p: usize, tab: &mut HashMap<(usize, usize), usize>) -> usize {
    if let Some(&x) = tab.get(&(p, r)) {
        return x;
    }
    let mut tmp = 0;
    for &c in t[r].iter() {
        if c == p {
            continue;
        }
        tmp = max(tmp, dfs(t, c, r, tab));
    }
    tab.insert((p, r), tmp + 1);
    tmp + 1
}


Measured memory_bytes: 40616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;
using P = pair<int,int>;

int main(void) 
{
   int x, y;
   cin >> x >> y;

   if(y%2 != 0)
   {
       cout << "No" << endl;
       return 0;
   }

   if(y <= (4 * x) && y >= 2*x){
       cout <<"Yes" <<endl;
   }
   else cout << "No" << endl;
   
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
typedef long long ll;
ll n,a[20],b[20],c,ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>c;
        ans+=c;
    }
    for(int i=0;i<n-1;i++)cin>>b[i];
    for(int i=0;i<n-1;i++){
        if(a[i]+1==a[i+1])ans+=b[a[i]-1];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

long long n, x;

long long lenOfTotal[60];	//面包的总个数
long long lenOfPatty[60];	//对应肉饼的总个数

void init()

{
	lenOfTotal[0] = 1;	//面包的总个数
	lenOfPatty[0] = 1;	//对应肉饼的总个数	
	
	for (int i = 1 ; i <= 50 ; i++)
	{
		lenOfTotal[i] = lenOfTotal[i - 1] * 2 + 3;
		lenOfPatty[i] = lenOfPatty[i - 1] * 2 + 1;
	}
} 

void solve(long long &numOfPatty, long long &leftLayer, int d)
{
	if (leftLayer >= lenOfTotal[d])
	{
		leftLayer = leftLayer - lenOfTotal[d];
		numOfPatty = numOfPatty + lenOfPatty[d];
		
		return;
	}
	
	leftLayer--;	//first bun
	if (leftLayer <= 0) return;
		
	solve(numOfPatty, leftLayer, d - 1);
	if (leftLayer <= 0) return;
	
	leftLayer--;
	numOfPatty++;
	if (leftLayer <= 0) return;
	
	solve(numOfPatty, leftLayer, d - 1);
	if (leftLayer <= 0) return;
	
	leftLayer--;	//last bun
	if (leftLayer <= 0) return;
	return ;
}

int main()
{
	long long leftLayer;
	long long numOfPatty;
	init();

	scanf("%lld%lld", &n, &x);
	
	leftLayer = x;
	numOfPatty = 0;
	
	solve(numOfPatty, leftLayer, n);
	
	printf("%lld\n", numOfPatty);
	
	return 0;
}

Measured memory_bytes: 128
use proconio::input;
use std::collections::BinaryHeap;
 
fn main() {
  input! {
    n: usize,
    m: usize,
    mut abs: [(usize,usize);n]
  }
  abs.sort_by(|a, b| a.0.cmp(&b.0));
  abs.reverse();
  
  let mut p_queue = BinaryHeap::new();
  let mut result = 0;
  let mut index = m;
  for index in 1..=m {
    while !abs.is_empty() {
      let last = abs.last().unwrap();
      if last.0 > index {
        break
      }
      p_queue.push(abs.pop().unwrap().1);
    }
    
    if let Some(v) = p_queue.pop() {
      result += v;
    }
  }
  
  println!("{}", result);
}

Measured memory_bytes: 5848
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
      Scanner scanner = new Scanner(System.in);
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      int c = scanner.nextInt();
      if (a < b && b<c) {
    	  System.out.println("Yes");
      } else {
    	  System.out.println("No");
      }
      scanner.close();
  }
}


Measured memory_bytes: 26228
#include<stdio.h>

int n, A[50];

int solve(int i, int m) {
	if (m == 0)
		return 1;
	if (i >= n)
		return 0;
	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}

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


Measured memory_bytes: 2108
import queue
q = queue.Queue()
N,K = map(int,input().split())
ds = list(map(int,input().split()))

sm = sum(ds[:K])
out = sm
for i in range(N-K):
    sm = sm-ds[i]+ds[i+K]
    out = max(out,sm)

print((out+K)/2)

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

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


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int X; cin >> X;
	cout << 10 - X / 200 << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<deque>
#include<string>

int n;
std::string s;
int cnt, pnt;
std::deque<bool> deq;

int main()
{
	std::cin >> n;

	while( std::cin >> s )
	{
		if( s == "HIT" )
		{
			deq.push_back( true );
			
			if( deq.size() > 3 )
			{
				deq.pop_back();
				++pnt;
			}
		}
		else if( s == "HOMERUN" )
		{
			pnt += deq.size() + 1;
			deq.clear();
		}
		else
			++cnt;

		if( cnt == 3 )
		{
			std::cout << pnt << std::endl;
			cnt = pnt = 0;
			deq.clear();
		}
	}

	return 0;
}

Measured memory_bytes: 1212
#include"bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main(){

   fast
   ll a,b,c,k;
   cin>>a>>b>>c>>k;

   if(a >= k) cout<<k<<endl;
   else{
    if(a+b >= k) cout<<a<<endl;
    else cout<<a-(k-(a+b))<<endl;
  }
}


Measured memory_bytes: 3652
N = int(input())
alice = 0
bob = 0
a = [int(i) for i in input().split()] 
while len(a) != 0:
    alice += max(a)
    a.remove(max(a))
    while len(a) != 0:
        bob += max(a)
        a.remove(max(a))
        break
print(alice - bob)

Measured memory_bytes: 3060
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int i,j;
		int count,num;
		boolean flag;
		
		while(scan.hasNextInt()){
			count = 0;
			num = scan.nextInt();
			if(num < 2){
				count = 0;
			}else if(num == 2){
				count = 1;
			}else{
				count = 1;
				
				for(i=3;i<=num;i+=2){
					flag = true;
					for(j=3;j<=Math.sqrt(i);j+=2){
						if(i%j == 0){
							flag = false;
							break;
						}
					}
					if(flag)
						count++;
				}
			}
			System.out.println(count);
		}
		scan.close();
	}
}

Measured memory_bytes: 18992