akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int x;
  cin >> x;
  cout << (x ? 0 : 1);
}
#endif


Measured memory_bytes: 3644
import sys
input = sys.stdin.readline
from collections import defaultdict,deque
N,M= map(int,input().split())

g = defaultdict(list)
for i in range(M):
    A,B = map(int,input().split())
    g[A].append(B)
    g[B].append(A)

pre = defaultdict(int)
pre[1] = 0
d = [10**6]*(N+1)

dq = deque([1])
d[1] = 0

while dq:
    v = dq.popleft()
    for nv in g[v]:
        if d[v] + 1 < d[nv]:
            d[nv] = d[v] + 1
            pre[nv] = v
            dq.append(nv)

print('Yes')
for i in range(2,N+1):
    print(pre[i])



Measured memory_bytes: 110372
#include <cstdio>

int count[42];
int d[42];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n * m; i++) {
    int c = getchar();
    while (c <= 32) c = getchar();
    count[c - 'a']++;
  }
  if (n % 2 == 1 && m % 2 == 1) {
    d[0] = 1;
    d[1] = n / 2 + m / 2;
  } else if (n % 2 == 1) {
    d[0] = 0;
    d[1] = m / 2;
  } else if (m % 2 == 1) {
    d[0] = 0;
    d[1] = n / 2;
  } else {
    d[0] = 0;
    d[1] = 0;
  }
  for (int i = 0; i < 26; i++) {
    if (count[i] % 2 == 1) {
      --d[0];
      count[i]--;
    }
    if (count[i] % 4 == 2) {
      --d[1];
    }
  }
  puts(d[0] == 0 && d[1] >= 0 && d[1] % 2 == 0 ? "Yes" : "No");
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll n;
ll a[100010];
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i+1);
	ll s=0;
	rep(i,0,n+1)s+=llabs(a[i]-a[i+1]);
	rep(i,1,n+1){
		printf("%lld\n",s-llabs(a[i-1]-a[i])-llabs(a[i]-a[i+1])+llabs(a[i-1]-a[i+1]));
	}
}

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

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int n;
   vector<int> d;
   cin >> n;
   for(int i = 0;i < n;i++) {
      int x;
      cin >> x;
      d.push_back(x);
   }
   sort(d.begin(), d.end());
   int count = 0;
   int stock = -1;
   for(int i = 0;i < d.size();i++) {
      if(stock==d[i]) {
         count++;
      }
      stock = d[i];
   }
   cout << n-count << endl;
}



Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt(); 
        int r;       
        
       
        while( (r = a % b) != 0 ) {
            a = b;
            b = r;
        }
        System.out.println( b );
     
   

      
    }
}


Measured memory_bytes: 26172
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  string S;
  cin>>S;
  cout<<S[0];
  cout<<S[1];
  cout<<S[2]<<endl;
}

Measured memory_bytes: 3596
#include <stdio.h>

void depth(int,int);

int d[100000],k[100000],c[100000][1000],g[100000],root,id;

int main()
{
  int i,n,id,j,p[100000],type[100000];

  scanf("%d",&n);

  for(j=0;j<n;j++) d[j]=0;

  for(j=0;j<n;j++){
    scanf("%d",&id);
    scanf("%d",&k[id]);

    for(i=0;i<k[id];i++){
      scanf("%d",&c[id][i]);

	d[c[id][i]]= d[id] + 1;
  
      p[c[id][i]] = id;
    }

    if(d[id]==0){
 p[id] =-1;
    }
  }

  /*type*/
  for(j=0;j<n;j++){
    if(p[j]==-1) {
type[j] = 0;
 root = j;
    }
    else if(k[j]==0) type[j] = 1;
    else type[j] = 2;
  }

  depth(root,0);

  for(j=0;j<n;j++){
    printf("node %d: parent = %d, depth = %d, ",j,p[j],g[j]);

    if(type[j]==0) printf("root, ");
    else if(type[j]==1) printf("leaf, ");
    else printf("internal node, ");

    printf("[");
    for(i=0;i<k[j];i++){
      printf("%d",c[j][i]);  
      if(i!=k[j]-1) printf(", ");
    }
    printf("]\n");
  }

  return 0;
}

void depth(int v,int dep){
  int i;
  g[root]=0;
  if(k[v]==0) return;
  dep++;
  for(i=0;i<k[v];i++){    
    g[c[v][i]]=dep;
  }

  for(i=0;i<k[v];i++){
    depth(c[v][i],dep);
  }

}

Measured memory_bytes: 42744
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main() {
    int N,K;
    string S;
    cin >> N >> K;
    cin >> S;
    if(S.at(K-1) == 'A'){
        S.at(K-1) = 'a';
    }
    else if(S.at(K-1) == 'B'){
        S.at(K-1) = 'b';
    }
    else if(S.at(K-1) == 'C'){
        S.at(K-1) = 'c';
    }
    cout << S << endl;
}



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

def main():
    N = int(input())
    A = list(map(int,input().split()))
    INF = 10**9+7
    
    c = collections.Counter(A)
    ans = True
    if N%2 == 0:
        for i in range(N//2):
            if c[2*i+1] != 2:
                ans = False
    else:
        for i in range(N//2):
            if c[2*i+2] != 2:
                ans = False
        if c[0] != 1:
            ans = False
            
    if ans:
        print(pow(2,(N//2),INF))
    else:
        print(0)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 14800
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static int n = int.Parse(Console.ReadLine());
static long[] nums = new long[n];
static long[] dp = new long[n];

	static void Main()
	{
    for(int i = 0; i < n; i++)
    {
      nums[i] = long.Parse(Console.ReadLine());
      dp[i] = -1;
    }

    for(int i = 0; i < n; i++)
    {
      long position = Search(0,n-1,-1,nums[i]);
      dp[(int)position] = nums[i];
    }

    int answer = 0;
    for(int i = 0; i < n; i++)
    {
      if(dp[i] == -1) break;
      else answer++;
    }
    
		Console.WriteLine(answer);
	}

  static long Search(long min, long max, int MinorMax, long checkNum)//二分探索法で最小値-1最大値1を求める
  {
    while (true)
    {
      long mid = min + (max - min) / 2;
      if(MinorMax == 1)
      {
        if(Check(mid,checkNum)) min = mid;//さらに大きくても成り立つかも
        else max = mid;
      }else
      {
        if(Check(mid,checkNum)) max = mid;//さらに小さくても成り立つかも
        else min = mid;
      }

      if(max - min <= 1)
      {
        if(MinorMax == 1)
        {
          if(Check(max,checkNum)) return max;//最大値で成り立つかの確認を優先
          else return min;
        }else
        {
          if(Check(min,checkNum)) return min;//最小値で成り立つかの確認を優先
          else return max;
        }

      break;
      }  
    }
  }

  static bool Check(long testNum, long checkNum)
  {
    if(dp[testNum] < checkNum) return true;

    return false;
  }  

  
}

Measured memory_bytes: 18896
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/

/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lng a,b,x;
    cin >> a >> b >> x;
    if(a==0) cout << b/x+1 << endl;
    else cout << b/x-(a-1)/x << endl;
}


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

int main() {
	string s,t;cin >> s >> t;
	int cnt_ch = 0;
	for (int i=0;i<s.size();++i){
		if(s[i]!=t[i]) ++cnt_ch;
	}
	cout << cnt_ch << endl;
	return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, T t){return v2<T>(r, vector<T>(c, t));}

void solve(){
    int x, n;
    cin >> x >> n;
    set<int> s;
    for(int i = -105; i <= 105; i++){
        s.insert(i);
    }

    for(int i = 0; i < n; i++){
        int a; cin >> a;
        s.erase(s.find(a));
    }

    int ans = -200;
    for(int i : s){
        if(abs(x-i) < abs(x-ans)){
            ans = i;
        }
    }

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 3668
import java.util.Scanner;


public class Main {
	private	static	Scanner	stdin = null;

	static {
		stdin = new Scanner(System.in);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int	nMax = stdin.nextInt();

		for (int n = 0; n < nMax; n++) {
			parseParallel();
		}
	}

	private static void parseParallel() {
		double[]	da   = { stdin.nextDouble(), stdin.nextDouble() };
		double[]	db   = { stdin.nextDouble(), stdin.nextDouble() };
		double[]	dc   = { stdin.nextDouble(), stdin.nextDouble() };
		double[]	dd   = { stdin.nextDouble(), stdin.nextDouble() };
		double[]	v1   = { db[0] - da[0], db[1] - da[1] };
		double[]	v2   = { dd[0] - dc[0], dd[1] - dc[1] };

		if (isParallel(v1, v2)) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}

	private static boolean isParallel(double[] v1, double[] v2) {
		div(v1);
		div(v2);
		
		return (v1[0] == v2[0]) & (v1[1] == v2[1]);
	}

	private static void div(double[] d1) {
		if (d1[0] != 0.0) {
			d1[1] /= d1[0];
			d1[0] /= d1[0];
		}
		else {
			if (d1[1] != 0.0) {
				d1[1] /= d1[1];
			}
		}
	}
}

Measured memory_bytes: 20488
#include<stdio.h>
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    int p[100005];
    int count[100005];
    int x, y;
    int i;
    for (i = 0; i < n; i++)
    {
        count[i] = 1;
        p[i] = 0;
    }
    p[0] = 1;
    for (i = 0; i < m; i++)
    {
        scanf("%d %d", &x, &y);
        x--;
        y--;
        if (p[x] == 1)
            p[y] = 1;
        count[x]--;
        count[y]++;
        if (count[x] == 0)
            p[x] = 0;
    }
    int ans = 0;
    for (i = 0; i < n; i++)
        if (p[i] == 1)
            ans++;
    printf("%d\n", ans);
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

struct UnionFind {
  vector<int> data;

  UnionFind(int n){
    data.resize(n+1);
    fill(data.begin(), data.end(), -1);
  }

  int root(int x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);

    if(rx!=ry){
      if(data[ry] < data[rx])swap(rx, ry);

      data[rx]+=data[ry];
      data[ry]=rx;
    }
  }

  bool same(int x, int y){
    return root(x)==root(y);
  }

  int size(int x){
    return -data[root(x)];
  }
};

int main(){
  ll n, m;cin>>n>>m;
  vector<int> a(m), b(m);
  rep(i, m)cin>>a[i]>>b[i];
  UnionFind uf(n);
  ll unc=n*(n-1)/2;
  vector<ll>results;
  rrep(i, m){
    results.push_back(unc);
    if(!uf.same(a[i], b[i])){
      unc -= (ll)uf.size(a[i]) * (ll)uf.size(b[i]);
      uf.unite(a[i], b[i]);
    }
  }
  rrep(i, m)cout<<results[i]<<endl;

  return 0;
}


Measured memory_bytes: 3444
def main():
    H = map(int, open(0).read().split()[:0:-1])
    pre = None
    for h in H:
        if pre is None:
            pre = h
        elif h <= pre:
            pre = h
        elif pre + 1 == h:
            continue
        else:
            # pre + 1 < h
            print("No")
            return

    print("Yes")
    return


main()


Measured memory_bytes: 11200
N,K = map(int,input().split())
if K % 2 == 0:
	n = N // (K // 2)
	n_odd = (n + 1) // 2
	n_even = n // 2
	print(n_odd ** 3 + n_even ** 3)
else:
	n = N // K
	print(n ** 3)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007


void solve(void)
{
   int A,B,C;
   cin>>A>>B>>C;
   if(A+B+C >= 22)
   {
     cout<<"bust"<<endl;
   }
   else
   {
     cout<<"win"<<endl;
   }
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

def main():
    N, K, Q = map(int, input().split())
    d = defaultdict(int)
    for _ in range(Q):
        A = int(input())
        d[A] += 1

    for i in range(1,N+1):
        if K - (Q - d[i]) > 0:
            print('Yes')
        else:
            print('No')


main()

Measured memory_bytes: 62680
N = int(input())
union_find = [i for i in range(N)]
def find(n, P):
	if P[n] == n:
		return n
	else:
		x = find(P[n], P)
		P[n] = x
		return x

def append(n, P):
	P[n] = n - 1
	find(n, P)

P = []
for i in range(N):
	p = int(input()) - 1
	P.append(p)

appeared = [False for i in range(N)]
for i in range(N):
	n = P[i]
	appeared[n] = True
	if n != 0 and appeared[n - 1]:
		append(n, union_find)

cont = 0

for i in range(N):
	cont = max(cont, i - find(i, union_find) + 1)
print(N - cont)

Measured memory_bytes: 22560
#!/usr/bin/env python3
import sys

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    A, B, C, K = map(int, input().split())
    score = min(K, A) * 1
    K -= A + B
    if K > 0:
        score -= K
    print(score)
if __name__ == '__main__':
    main()


Measured memory_bytes: 8920
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>

#define DEBUG 0
#define fi first
#define se second
#define pb push_back
#define INF 1000000000
#define fore(i,a,b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i,a,b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i,a,b) for (int i = (a), _b = (b); i >= (_b); --i)
#define MAXN 103
#define MAXW 100003

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;

LL N, W, w[MAXN], v[MAXN], f[MAXN][MAXW];

void input() {
    cin >> N >> W;
    fort(i, 1, N) cin >> w[i] >> v[i];
}

void solve() {
    fort(i, 0, N) fort(j, 0, W) {
        if (i == 0 || j == 0) f[i][j] = 0;
        else if (w[i] <= j) f[i][j] = max(f[i - 1][j], f[i - 1][j - w[i]] + v[i]);
        else f[i][j] = f[i - 1][j];
    }
    cout << f[N][W] << '\n';
}

int main() {
    if (DEBUG) {
        freopen("CP.inp", "r", stdin);
        //freopen("CP.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(0);
    input();
    solve();
    return 0;
}


Measured memory_bytes: 80128
#include <stdio.h>

int main(){
	int n, q, i, j, num;
	int a[2001] = {1};
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &num);
		for(j = 2000-num; j >= 0; j--){
			if(a[j]) a[j + num] = 1;
		}
	}
	
	scanf("%d", &q);
	for(i = 0; i < q; i++){
		scanf("%d", &num);
		if(a[num]) printf("yes\n");
		else printf("no\n");
	}
	return 0; 
}

Measured memory_bytes: 588
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
  long long n, k;
  cin >> n >> k;
  long long h[n];
  for(long long i = 0; i < n; i++)cin >> h[i];
  sort(h, h+n);
  for(long long i = 0; i < k; i++){
    h[max(n-1-i, (long long)0)]=0;
  }
  long long sum = 0;
  for(long long i = 0; i < n-k; i++){
    sum+=h[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll N;
  string c;
  cin>>N>>c;
  ll r=0,w=0;
  rep(i,N){
    
    if(c[i]=='R'){
      r++;
    }
  }
  rep(i,N){
    if(r==w){
      cout<<r;break;
    }
    if(c[i]=='R'){
      r--;
    }
    else{
      w++;
    }
    if(r==w){
      cout<<r;break;
    }
  }
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
    IOS;
 	int x,y,a,b,c;
 	cin>>x>>y>>a>>b>>c;
 	int A[a],B[b],C[c];
 	for(int i=0;i<a;i++) cin>>A[i];
 	for(int i=0;i<b;i++) cin>>B[i];
 	for(int i=0;i<c;i++) cin>>C[i];
 	sort(A,A+a,greater<int>());
 	sort(B,B+b,greater<int>());
 	sort(C,C+c,greater<int>());
 	int res1=x-1;
 	int res2=y-1;
 	int res3=0;
 	while(1){
 		if((res1==-1&&res2==-1)||res3==c){
 			break;
 		}
 		else if(res1==-1){
 			if(B[res2]>=C[res3]){break;}
 			B[res2]=C[res3];
 			res2--;
 			res3++;
 			continue;
 		}
 		else if(res2==-1){
 			if(A[res1]>=C[res3]){break;}
 			A[res1]=C[res3];
 			res1--;
 			res3++;
 			continue;
 		}
 		else{
 			if(A[res1]>=C[res3]&&B[res2]>=C[res3]){break;}
 			int X=C[res3]-A[res1];
 			int Y=C[res3]-B[res2];
 			if(X>=Y){
 				A[res1]=C[res3];
 				res1--;
 				res3++;
 			}
 			else{
 				B[res2]=C[res3];
 				res2--;
 				res3++;
 			}
 		}
 	}   
 	int sum=0;
 	for(int i=0;i<x;i++) sum+=A[i];
 	for(int i=0;i<y;i++) sum+=B[i];
 	cout<<sum<<endl;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;
void min_self(ll& a,ll b){
  a = min(a,b);
}

int main() {
  ll n,w;
  cin>>n>>w;
  vector<ll> wt(n);
  vector<ll> val(n);
  for (int i = 0; i < n; i++)
  {
    cin>>wt[i]>>val[i];
  }
  ll sum_value=0;
  for(auto x:val){
    sum_value += x;
  }
  vector<ll> dp(sum_value+1,INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = sum_value-val[i]; j >= 0; j--)
    {
      min_self(dp[j+val[i]],wt[i]+dp[j]);
    }
  }
  ll answer = 0;
  for(int i=0;i<=sum_value;i++){
    if(dp[i]<=w){
      answer = max(answer,(ll)i);
    }
  }
  cout<<answer<<endl;
  
    
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int tmp=(a%2)+(b%2)+(c%2);
    cout<<(tmp>=2 ? "Hom" : "Tem")<<endl;
    
    return 0;
}


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

int power(int x,int y)
{
    int res=1;
    while(y>0)
    {
        if(y%2!=0)
            res=res*x;
        y/=2;
        x=x*x;
    }
    return res;
}
int A[1005]={0};
int main()
{
    A[1]=1;
    for(int i=2;i*i<=1000;i++)
    {
        int j=2;
        //cout<<i<<": \n";
        while(power(i,j)<=1000)
        {
            int in=power(i,j);
            A[in]=1;
            j++;
            //cout<<i<<" "<<j-1<<" "<<in<<" , ";
        }
        //cout<<endl;
    }
    /*for(int i=1;i<=1000;i++)
    {
        if(A[i]==1)
            cout<<i<<" ";
    }*/
    //cout<<endl;
    int n;
    cin>>n;
    while(A[n]==0)
    {
        n--;
    }
    cout<<n<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<iterator>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define SIZE 100001
 

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=0,w=0,t=0,r=0;
   int T;
   cin>>T;
   while(T--){
   	string S;
   	cin>>S;
   	if(S =="AC")a++;
   	if(S=="WA")w++;
   	if(S=="TLE")t++;
   	if(S=="RE")r++;
   	
   	
   }
   cout<<"AC x "<<a<<"\n";
   	cout<<"WA x "<<w<<"\n";
   	cout<<"TLE x "<<t<<"\n";
   	cout<<"RE x "<<r<<"\n";
	
	return 0;
}

 
 

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<vi>
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  ll A,B,C; cin>>A>>B>>C;
  ll ans=0;
  if(A%2==1&&B%2==1&&C%2==1){
    ans=min({B*C,A*C,A*B});
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 998244353, INF = 1e16;

lint N, K, C;
string s;
lint L[200000];
lint R[200000];
int main() {
	cin >> N >> K >> C;
	cin >> s;
	lint idx = 0;
	REP(i, K) {
		while (s[idx] == 'x') idx++;
		L[i] = idx;
		idx += C + 1;
	}
	set<lint> ans;
	idx = N - 1;
	IREP(i, K) {
		while (s[idx] == 'x') idx--;
		R[i] = idx;
		idx -= (C + 1);
	}
	REP(i, K) {
		if (L[i] == R[i]) cout << L[i] + 1 << endl;
	}
}


Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
 
int main() {
     ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> dp(n + 1);
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 3; j <= n; j++) {
            if (i - j >= 0) {
                (dp[i] += dp[i - j]) %= mod;
            }
        }
    }
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 3648
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

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

    std::vector<int> U;
    for (int i = 0; i < N; ++i) {
        int t;
        std::cin >> t;
        U.push_back(t);
    }
    std::vector<int> D;
    for (int i = 0; i < N; ++i) {
        int t;
        std::cin >> t;
        D.push_back(t);
    }

    int u = 0;
    int d = std::accumulate(D.begin(), D.end(), 0);

    int ma = 0;
    for (int i = 0; i < N; ++i) {
        u = u + U[i];
        ma = std::max(ma, u+d);
        d = d - D[i];
    }

    std::cout << ma << std::endl;

    return 0;
}


Measured memory_bytes: 256
H, W = map(int,input().split())
dp = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

def warshallFloyd(dp):
    for k in range(10):
        for i in range(10):
            for j in range(10):
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])

ans = 0
warshallFloyd(dp)
for i in range(H):
    for j in range(W):
        a = A[i][j]
        if a == -1:
            continue
        else:
            ans += dp[a][1]
print(ans)


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

int main()
{
    int N, X;
    cin >> N >> X;

    vector<int> data(N);
    for (int i = 0; i < N; i++)
    {
        cin >> data.at(i);
    }
       int count = 1;
        int total = 0;
    for (int i = 0; i < N; i++)
    {
     
        total += data.at(i);
    if (total <= X)
    {
        count++;
    }
    }
    

cout << count << endl;
}



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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n,a[100001],mp[100001],z,ans;

main() {
    cin >> n;
    rep1(i,n) cin >> a[i];
    z=a[1];
    ans++;
    while(1) {
        if (z==2) {
            ct(ans)
            return 0;
        }
        if (mp[z]) {
            ct(-1)
            return 0;
        }
        mp[z]++;
        z=a[z];
        ans++;
    }
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

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

int main(){
	int n, m; scanf("%d %d", &n, &m);
	int a[50], b[50];
	rep(i, n) scanf("%d %d", &a[i], &b[i]);
	int c[50], d[50];
	rep(i, m) scanf("%d %d", &c[i], &d[i]);
	int r[50], res[50];
	fill(r, r + n, INF);
	rep(i, n) rep(j, m){
		int t = abs(a[i] - c[j]) + abs(b[i] - d[j]);
		if(t < r[i]){ r[i] = t; res[i] = j + 1; }
	}
	rep(i, n) printf("%d\n", res[i]);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define INF 100000000
typedef long long ll;

using namespace std;

int main()
{
    int n, x;
    vector<int> v;
    cin >> n;
    REP(i, n) {
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    cout << v.size() << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < n; i++)
#define Rep(i,n) for (int i = n; i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define cend cout<<endl;
#define P pair<int, int>
#define prique priority_queue<P, vector<P>, greater<P>>
struct edge { int to, cost; };
using namespace std;

signed main() {
	int n, k;
	string s;
	cin >> n >> k >> s;
	k--;
	if (s[k] == 'A') s[k] = 'a';
	else if (s[k] == 'B') s[k] = 'b';
	else if (s[k] = 'C') s[k] = 'c';
	cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  ll n;
  cin >> n;
  ll x = sqrt(n);
  RFOR(i, x, 1) {
    if (n % i == 0) {
      cout << (i - 1) + (n / i - 1) << endl;
      return;
    }
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


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



int main(void){
    double t,x;
    cin >> t >> x;
    double ans = t/x;
    cout << ans <<endl;
    
    
    
    
    
    return 0;
}












































Measured memory_bytes: 256
def pgcd(m,n): 
    while m%n: 
        r=m%n 
        m=n 
        n=r 
    return n 
 
def ppcm(m,n): 
    return m*n//pgcd(m,n)


a,b,c,d=map(int,input().split())

mx=max(c,d)
mn=min(c,d)
e=ppcm(c,d)

x=b//mx-(a-1)//mx
y=b//mn-(a-1)//mn
z=b//e-(a-1)//e
print(b-a+1-x-y+z)


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

using Graph = vector<vector<Pll>>;
ll dp[1024][9];

void solve() {
    ll N, M, R;
    cin >> N >> M >> R;
    Vl visit(R);
    for (ll i = 0; i < R; i++) {
        cin >> visit[i];
        --visit[i];
    }

    Graph g(N);
    vector<Vl> cost(N, Vl(N, L_INF));
    for (ll i = 0; i < N; i++) {
        cost[i][i] = 0;
    }
    for (ll i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
        cost[a][b] = c;
        cost[b][a] = c;
    }

    for (ll k = 0; k < N; k++) {
        for (ll i = 0; i < N; i++) {
            for (ll j = 0; j < N; j++) {
                if (cost[i][k] != L_INF && cost[k][j] != L_INF) {
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
                }
            }
        }
    }

    fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), L_INF);
    for (ll i = 0; i < R; i++) {
        dp[(1LL << i)][i] = 0;
    }

    for (ll mask = 0; mask < (1LL << R); mask++) {
        for (ll i = 0; i < R; i++) {
            if (!((mask >> i) & 1)) continue;
            for (ll j = 0; j < R; j++) {
                if (!((mask >> j) & 1)) continue;
                ll pmask = mask & ~(1LL << i);
                if (dp[pmask][j] != L_INF && cost[visit[j]][visit[i]] != L_INF)
                    dp[mask][i] = min(dp[mask][i], dp[pmask][j] + cost[visit[j]][visit[i]]);
            }
        }
    }

    ll ans = L_INF;
    for (ll i = 0; i < R; i++) {
        ans = min(ans, dp[(1LL << R) - 1][i]);
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 1536
/*
 * SmallLargeorEqual.c
 *
 *  
 */

#include <stdio.h>

int main(void){
	int i,j;

	scanf("%d %d",&i,&j);

	if(i<j){
		printf("a < b\n");
	}
	else if(i >j){
		printf("a > b\n");
	}
	else if(i == j){
		printf("a == b\n");
	}


	return 0;
}

Measured memory_bytes: 580
list_all=list(map(int,input().split()))
if list_all[0]>=list_all[3]:
    print(list_all[3])
elif list_all[0]+list_all[1]>=list_all[3]:
    print(list_all[0])
else:
    print(list_all[0]-(list_all[3]-list_all[0]-list_all[1]))


Measured memory_bytes: 9116
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;
const double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

void Calculate_Depth(vector<vector<int>>&edge, vector<int>&depth, int stnode) {
	depth[stnode] = 0;
	queue<int>Q;
	Q.push(stnode);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (auto i : edge[cn]) {
			if (depth[i] > depth[cn] + 1) {
				depth[i] = depth[cn] + 1;
				Q.push(i);
			}
		}
	}
	return;
}

void Search(vector<vector<int>>&edge, vector<long long int>&dp, vector<int>&depth, int node, vector<vector<long long int>>&l, vector<vector<long long int>>&r) {
	l[node].resize(edge[node].size(), 1);
	r[node].resize(edge[node].size(), 1);
	for (int i = 0; i < edge[node].size(); i++) {
		if (depth[edge[node][i]] > depth[node]) {
			Search(edge, dp, depth, edge[node][i], l, r);
			dp[node] *= dp[edge[node][i]] + 1;
			dp[node] %= M;
			l[node][i] = dp[edge[node][i]] + 1;
			r[node][i] = dp[edge[node][i]] + 1;
		}
	}
	for (int i = 1; i < edge[node].size(); i++) {
		l[node][i] *= l[node][i - 1];
		l[node][i] %= M;
	}
	for (int i = ((int)edge[node].size()) - 2; i >= 0; i--) {
		r[node][i] *= r[node][i + 1];
		r[node][i] %= M;
	}
	return;
}

void Search(vector<vector<int>>&edge, vector<long long int>&dpa, vector<long long int>&dpb, vector<int>&depth, int node, vector<vector<long long int>>&l, vector<vector<long long int>>&r, long long int box = 1) {
	for (int i = 0; i < edge[node].size(); i++) {
		if (depth[edge[node][i]] > depth[node]) {
			if (i)dpb[edge[node][i]] *= l[node][i - 1];
			if (i + 1 < edge[node].size())dpb[edge[node][i]] *= r[node][i + 1];
			dpb[edge[node][i]] %= M;
			dpb[edge[node][i]] *= box;
			dpb[edge[node][i]]++;
			dpb[edge[node][i]] %= M;
			long long int nx = dpb[edge[node][i]];
			dpb[edge[node][i]] *= dpa[edge[node][i]];
			dpb[edge[node][i]] %= M;
			Search(edge, dpa, dpb, depth, edge[node][i], l, r,nx);
		}
	}
	return;
}

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

	cin >> N >> M;
	vector<vector<int>>edge(N);
	for (int i = 1; i < N; i++) {
		cin >> L >> R;
		L--;
		R--;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<vector<long long int>>l(N);
	vector<vector<long long int>>r(N);
	vector<int>depth(N, MOD);
	Calculate_Depth(edge, depth, 0);
	vector<long long int>dpa(N, 1);
	vector<long long int>dpb(N, 1);
	Search(edge, dpa, depth, 0, l, r);
	dpb[0] = dpa[0];
	Search(edge, dpa, dpb, depth, 0, l, r);
	for (int i = 0; i < N; i++)cout << dpb[i] << endl;
}

Measured memory_bytes: 27264
#include <iostream>
using namespace std;

const int maxm = 10010;

int n, m;
int ans;
int temp;

int num[maxm];

int main(void) {
    cin >> n >> m;
    for (int i = 0; i < m; i ++) {
        cin >> num[i];
        temp += num[i];
    }
    ans = n - temp;
    if (ans < 0) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    string s;
    int k;
    cin >> s >> k;

    set<string> st;
    rep(i, s.size()){
        for(int j=1; j < s.size()-i+1 && j <= k; ++j){
            st.insert(s.substr(i, j));
        }
    }
    int i = 1;
    for(auto itr = st.begin(); itr != st.end(); ++itr, ++i) {
        if(i == k)
            cout << *itr;
    }

    return 0;
}

Measured memory_bytes: 1664
n, a, b = map(int, input().split())
ans = 0
lis = []

for i in range(1, n+1):
  y = str(i)
  w = 0
  for x in range(len(y)):
    w += int(y[x])
  if a <= w <= b:
    ans += i

print(ans)
    


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


using namespace std;
int min(int a,int b)
{
    if(a<b)
    return a;
    return b;
    
    
    
}
int max(int  a,int b)
{
    if(a>b)
    return a;
    return b;
}


int main() {
int n,m;
cin>>n>>m;
int mini,maxi;
cin>>mini>>maxi;
int flag=0;
for(int i=1;i<m;i++)
{
int x,y;
cin>>x>>y;
if((mini>y)||(maxi<x))
{
    flag=1;
break;
}


else
{mini=max(mini,x);
maxi=min(maxi,y);
}

}

if(flag)
cout<<0;
else if(flag==0) cout<<maxi-mini+1;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define x first
#define y second
#define PII pair < int , int >
#define PLL pair < ll , ll >
#define mod 1000000007
#define maxn 100100

using namespace std;

ll n, a[300100], dp[300100], dp2[300100], sum, mn = 1e17;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
    for (int i = 1; i <= n; i++) dp[i] = dp[i-1] + a[i];
    for (int i = 1; i < n; i++) mn = min(mn, abs(sum - 2*dp[i]));
    cout << mn;
        
}

Measured memory_bytes: 4480
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
M = 10**9+7
v1 = pow(9, n, M)
v2 = pow(8, n, M)
ans = pow(10, n, M) - v1*2 + v2
print(ans%M)

Measured memory_bytes: 61828
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').let {
        it[0].toInt() to it[1].toLong()
    }
    val a = readLine()!!.split(' ').map { it.toLong() }.sorted().toLongArray()
    val f = readLine()!!.split(' ').map { it.toLong() }.sortedDescending().toLongArray()

    var l = 0L
    var r = 1e12.toLong()
    while (l < r) {
        val m = l + (r - l) / 2

        var x = 0L
        for (i in 0 until n) {
            x += Math.max(a[i] - (m / f[i]), 0)
        }

        if (x <= k) {
            r = m
        } else {
            l = m + 1
        }
    }

    println(l)
}


Measured memory_bytes: 112816
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;

    vector<vector<char>> C(H, vector<char>(W));
    for (int h = 0; h < H; ++h){
        for (int w = 0; w < W; ++w){
            cin >> C[h][w];
        }
    }
    for (int h = 0; h < 2*H; ++h){
        for (int w = 0; w < W; ++w){
            cout << C[h / 2][w];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define L_T_S_K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std; 

const int N = 1e6 + 7;
 
vector <int> spf(N);

bool isprime[N];
 
 void seive(){
  iota(spf.begin() , spf.end() , 0);
  for(int i = 2 ; i < N ; i+= 2){
    spf[i] = 2;
    isprime[i] = 0;
  }
  isprime[2] = 1;
  for(int i = 3 ; i * i < N ; i+= 2){
    if(spf[i] == i){
        isprime[i] = 1;
      for(int j = i * i ; j < N ; j+=i){
        isprime[j] = 0;
        if(spf[j] == j) spf[j] = i;
      }
    }
  }
 }

int check(int n){
    for(int i = 2 ; i <= sqrt(n) ; i++){
        if(n % i == 0){
            return 0;
        }
    }
    return 1;
}

int32_t main(){
    L_T_S_K;
    int n ;
    cin >> n ;
    
    if(n == 1){
        cout << 0 << "\n";
        return 0;
    }

    int ans = 0;
    int f = 0;
    for(int i = 2 ; i <= sqrt(n) ; i++){
        if(n % i == 0){
            f = 1;
            break;
        }
    }

    if(!f){
        cout << 1 << "\n";
        return 0;
    }
   
    for(int i = 2 ; i < 1000007  ; i ++){
        if(n == 1) break;
        if(n % i == 0){
            int c = 0;
            while(n % i == 0 ){
                n /=i;
                c++;
            }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
            int u = 1;
            while(c - u >= 0){
                c -= u;
                ans++;
                ++u;
            }
            if(n == 1) break;
        }
    }

    if(n > 1)ans++;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11028
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String line = null;
		List<String> tmpList = new ArrayList<>();
		try (Scanner sc = new Scanner(System.in)) {
			line = sc.nextLine();

			String[] tmpArray = line.split(" ");
			int letterNum = Integer.parseInt(tmpArray[0]);
			//int letterLength = Integer.parseInt(tmpArray[1]);

			for(int i = 0;i<letterNum;i++){
				tmpList.add(sc.nextLine());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		tmpList.stream().sorted().forEach(i -> System.out.print(i));
	}
}

Measured memory_bytes: 26708
#include <stdio.h>

int table[105][105];
int breadth_list[105];

void breadth_search(int breadth, int id, int col) {
	int i;
	int j;
	int queue[1005];
	int wp = 0;
	int rp = 0;
	int now_id;
	
	table[id][0] = 0;
	breadth_list[id] = breadth;

	queue[wp] = id;
	wp++;

	while(wp > rp) {
		now_id = queue[rp%1000];
		rp++;
		for(i=1;i<=col;i++) {
			if(table[now_id][i] == 1 && table[i][0] == 1) {
				for(j=0;j<=col;j++) table[j][i] = 0;
				breadth_list[i] = breadth_list[now_id] + 1;
				queue[wp%1000] = i;
				wp++;
			}
		}
	}
}

int main(void) {
    int i, j, n, q;
    int id, t;
    char buff[1024];

    scanf("%d\n", &n);
    for(i=0;i<=n;i++) {
    	breadth_list[i] = -1;
    	table[i][0] = 1;
        for(j=1;j<=n;j++) {
            table[i][j] = 0;
        }
    }
   
    for(i=0;i<n;i++) {
        scanf("%d %d", &id, &q);
        for(j=0;j<q;j++) {
            scanf("%d", &t);
            table[id][t] = 1;
        }
        gets(buff);
    }
	
	breadth_search(0, 1, n);

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

    return 0;
}

Measured memory_bytes: 648