akhauriyash/Code-Regression huggingface dataset:
#coding:utf-8
n,m = map(int,input().split())
List = list(map(int,input().split()))


forest = [i for i in range(n+1)]
rank = [0 for i in range(n+1)]

def unite(x,y):
    x = Find(x)
    y = Find(y)
    a = rank[x]
    b = rank[y]
    forest[x] = y


def Find(x):
    if forest[x] != x:
        rank[x] = 1
        forest[x] = Find(forest[x])
        return forest[x]
    else:
        return x
    
    for xi in Q:
        forest[xi] = x
        rank[xi] = 1
    
    return x

    
cnt = 0
for i in range(m):
    x,y = map(int,input().split())
    unite(x,y)

for i in range(1,n+1):
    x = Find(i)
    y = Find(List[i-1])
    if x == y:
        cnt += 1
print(cnt)
    


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

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

ll n;

void f(ll x)
{
	if(x <= 0)
		return;
	
	f((x - 1) / 26);
	
	if(x % 26 == 0)
		printf("z");
	else
		printf("%c", (x - 1) % 26 + 'a');
}

int main(void)
{
	scanf("%lld", &n);
	
	f(n);
	
	return 0;
}

Measured memory_bytes: 3748
class Dice:
  def __init__(self, state):
    self.state = state

  def vertical(self, direction):
    s = self.state
    state = [s[1], s[5], s[0], s[4]]
    if direction < 0:
      s[0], s[1], s[4], s[5] = state
    elif 0 < direction:
      s[0], s[1], s[4], s[5] = reversed(state)
    return self
  
  def lateral(self, direction):
    s = self.state
    state = [s[2], s[5], s[0], s[3]]
    if direction < 0:
      s[0], s[2], s[3], s[5] = state
    elif 0 < direction:
      s[0], s[2], s[3], s[5] = reversed(state)
    return self

  def north(self):
    self.vertical(-1)
    return self

  def south(self):
    self.vertical(1)
    return self
  
  def east(self):
    self.lateral(1)
    return self

  def west(self):
    self.lateral(-1)
    return self

init_state = input().split()

for i in range(int(input())):
  dice = Dice(init_state)
  up, front = input().split()

  if up == dice.state[0] \
    and front == dice.state[1]:
      print(dice.state[2])
  else:
    for c in list('NNNNWNNNWNNNENNNENNNWNNN'):       
      if c == 'N':
        dice.north()
      elif c == 'S':
        dice.south()
      elif c == 'W':
        dice.west()
      elif c == 'E':
        dice.east()
      if up == dice.state[0] \
        and front == dice.state[1]:
          print(dice.state[2])
          break



Measured memory_bytes: 5608
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 c = sc.nextInt();
	    if(a < b && b < c ){
	        System.out.println("Yes");
	    }else{
	        System.out.println("No");
	    }
	}
}


Measured memory_bytes: 26280
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <time.h>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>
#define print_time()cout<<clock()/CLOCKS_PER_SEC<<" s"<<endl;

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


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

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

const int maxn = 2e5 + 10;
long long sum[maxn];

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> sum[i];
		sum[i] += sum[i - 1];
	}
	long long res = LONG_LONG_MAX;
	for (int i = 1; i < n; i++) {
		res = min(res, abs(sum[n] - 2 * sum[i]));
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1792
import itertools

n,m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
graph = [list() for i in range(n)]
ans = 0
for a,b in ab:
  a -= 1
  b -= 1
  graph[a].append(b)
  graph[b].append(a)
for i in itertools.permutations(range(1,n)):
  now = 0
  for j in i:
    if not (j in graph[now]):
      break
    now = j
  else:
    ans += 1
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 45
int A[MAX];
int Fibonacci(int);

int main(){
  int i,n,ans;

  for(i = 0; i < MAX; i++){
    A[i] = 0;
  }
  scanf("%d",&n);
  ans = Fibonacci(n);
  printf("%d\n",ans);

  return 0;
 }

int Fibonacci(int n){
  if(n == 0){
    A[n] = 1;
    return A[n];
  }

  if(n == 1){
    A[n] = 1;
    return A[n];
  }

  else if(A[n] != 0) return A[n];
  else{
    A[n] =  Fibonacci(n - 1) + Fibonacci(n - 2);
    return A[n];
  }
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,n;
    cin>>x>>n;
    vector<int> p(n);
    unordered_map<int,bool> isPresent;
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
        isPresent[p[i]] = true;
    }
    int ans=x;
    for(int i=0;i<1000;i++)
    {
        int right = x+i;
        int left = x-i;
        if(isPresent.find(left)==isPresent.end())
        {
            ans = left;
            break;
        }
        if(isPresent.find(right)==isPresent.end())
        {
            ans = right;
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<iterator>

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

using namespace std;

int main(){
	long hoge[2501][51];
	long hoge2[2501][51];
	int N,A;
	vector<int> x;
	cin >> N >> A;
	rep(i, N){
		int temp; cin>>temp;
		x.push_back(temp);
	}

	rep(i,2501){
		rep(j,51)
			hoge[i][j] = 0;
	}
	hoge[0][0] = 1;

	for(int i = 1; i <= N; i++){
		rep(j,2501){
			rep(k,51){
				int iter = j - x[i-1];
				if(iter >= 0 && k > 0)
					hoge2[j][k] = hoge[j][k] + hoge[iter][k-1];
				else
					hoge2[j][k] = hoge[j][k];
			}
		}
		rep(j, 2501){
			rep(k,51)
				hoge[j][k] = hoge2[j][k];
		}
	}

	long long res = 0;
	for(int i = 1; i <= N; i++){
		res += hoge[A*i][i]; 
	}

	cout << res << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

// 回数, 残る数
pair<ll, ll> f(int a, int b) {
  if (a + b < 10) return {1, a+b};
  auto p = f(1, a+b-10);
  p.first += 1;
  return p;
}

ll solve(const vector<ll>&d, const vector<ll>& c) {

  int M = d.size();
  if (M == 1 && c[0] == 1) {
    return 0;
  }

  ll ans = 0;
  vector<ll> d2, c2;
  REP(i, M) {
    if (c[i] >= 2) {
      auto p = f(d[i], d[i]);
      ans += p.first * (c[i]/2);
      d2.push_back(p.second);
      c2.push_back(c[i]/2);
      if (c[i] % 2 == 1) {
        d2.push_back(d[i]);
        c2.push_back(1);
      }
    } else {
      d2.push_back(d[i]);
      c2.push_back(c[i]);
    }
  }
  vector<ll> d3, c3;
  for (int i = 0; i < (int)d2.size(); i++) {
    if (i + 1 < (int)d2.size() && c2[i] == 1 && c2[i+1] == 1) {
      auto p = f(d2[i], d2[i+1]);
      ans += p.first;
      d3.push_back(p.second);
      c3.push_back(1);
      i++;
    } else {
      d3.push_back(d2[i]);
      c3.push_back(c2[i]);
    }
  }
  return ans + solve(d3, c3);
}

int main2() {
  int M = nextInt();
  vector<ll> d(M), c(M);
  REP(i, M) {
    d[i] = nextInt();
    c[i] = nextLong();
  }
  ll ans = solve(d, c);
  cout << ans << endl;
  return 0;
}


int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 490720
#include<bits/stdc++.h>
#define Set(a,b) memset(a,b,sizeof(a))
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
template <typename T> inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
typedef long long ll;
typedef unsigned long long ull;
typedef __uint128_t uLL;
typedef double db;
typedef long double ldb;
template <typename T>inline void Inc(T&x,int y){x+=y;if(x>=mod) x-=mod;return;}
template <typename T>inline void Dec(T&x,int y){x-=y;if(x <  0) x+=mod;return;}
template <typename T>inline int fpow(int x,T k){int ret=1;for(;k;k>>=1,x=(ll)x*x%mod) if(k&1) ret=(ll)ret*x%mod;return ret;}
ll k,A,B;
ll ans=0;
int main()
{
	init(k),init(A),init(B);
	if(A>=B) printf("%lld\n",k+1);
	else {
		ll K=k;ll now=A;k-=A-1;
		if(k<0) {printf("%lld\n",K+1);return 0;}
		ll d=B-A;
		if(d>2) {
			if(k&1) ++now,--k;
			now+=(ll)(k>>1)*d;
			printf("%lld\n",now);
		}
		else printf("%lld\n",K+1);
	}
	return 0;
}


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

const ll MOD = 1e9 + 7;
ll F[1009], M[1009][1009], X[1009][1009], I[1009];
int N, A, B, C, D;

ll pw(ll X, ll Y) {
	if(Y == 0LL) return 1;
	ll t = pw(X, Y >> 1);
	if(Y&1) return t*t%MOD*X%MOD;
	return t*t%MOD;
}

ll inv(ll X) {
	return pw(X, MOD-2);
}

ll ncr(ll N, ll R) {
	if(N < 0 || N < R) return 0;
	if(N == R || R == 0) return 1;
	if(X[N][R]) return X[N][R];
	return X[N][R] = (ncr(N-1, R-1) + ncr(N-1, R)) % MOD;
}

int main() {
	F[0] = 1; I[0] = inv(1);
	for(int i=1; i<=1000; i++) {
		F[i] = F[i-1] * i % MOD;
		I[i] = inv(F[i]);
	}
	scanf("%d%d%d%d%d",&N,&A,&B,&C,&D);
	for(int i=0; i<=B; i++) M[0][i] = 1;
	for(int i=1; i<=N; i++) {
		for(int j=A; j<=B; j++) {
			M[i][j] = M[i][j-1];
			long long s = 1;
			for(int k=1; k<=D; k++) {
				s *= ncr(i - (k-1)*j, j); s %= MOD;
				if(k < C) continue;
				if(i - k*j >= 0) {
					M[i][j] += (M[i - k*j][j-1] * s % MOD * I[k] % MOD);
					// printf("i: %d, j: %d, k: %d, i-k*j: %d, M[i][j]: %lld, C: %lld\n", i, j, k, i-k*j, M[i][j], s * inv(F[k]) % MOD);
				}
				else break;
				M[i][j] %= MOD;
			}
		}
	}
	printf("%lld", M[N][B]);
	return 0;
}

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

int main() {
  int n, i, sum = 0, bob = 0;
  cin >> n;
  
  vector<int> a(n);
  for (i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  for (i = 1; i < n; i += 2) {
    bob += a.at(i);
  }
  
  cout << sum - 2 * bob << endl;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    if (A >= 13) cout << B << endl;
    else if (6 <= A && A <= 12) cout << B/2 << endl;
    else cout << 0 << endl;
    return 0;
}

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

template<typename T, typename E> struct LazySegmentTree {
  using F = function<T(T, T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;
  using P = function<E(E, int)>;

  int n;
  T ti;
  E ei;
  F f;
  G g;
  H h;
  P p;
  vector<T> data;
  vector<E> lazy;

  LazySegmentTree(int n_, F f, G g, H h, T ti = INT_MAX, E ei = INT_MAX,
                  vector<T> v = vector<T>(), P p = [](E a, int b) { return a; })
      : f(f), g(g), h(h), ti(ti), ei(ei), p(p) {
    init(n_);
    if (n_ == (int)v.size()) build(v);
  }
  void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    data.assign(n * 2 - 1, ti);
    lazy.assign(n * 2 - 1, ei);
  }
  void build(vector<T> v) {
    for (int i = 0; i < v.size(); ++i) data[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; --i) {
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  inline void eval(int len, int k) {
    if (lazy[k] == ei) return;
    if (k * 2 + 1 < n * 2 - 1) {
      lazy[k * 2 + 1] = h(lazy[k * 2 + 1], lazy[k]);
      lazy[k * 2 + 2] = h(lazy[k * 2 + 2], lazy[k]);
    }
    data[k] = g(data[k], p(lazy[k], len));
    lazy[k] = ei;
  }
  T update(int a, int b, E x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return data[k];
    if (a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      return g(data[k], p(lazy[k], r - l));
    }
    T vl = update(a, b, x, k * 2 + 1, l, (l + r) / 2);
    T vr = update(a, b, x, k * 2 + 2, (l + r) / 2, r);
    return data[k] = f(vl, vr);
  }
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return ti;
    if (a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
};

const ll INF = 1e12;

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

  LazySegmentTree<ll, ll>::F f = plus<ll>();
  LazySegmentTree<ll, ll>::G g = [](ll a, ll b) { return (b == INF) ? a : b; };
  LazySegmentTree<ll, ll>::H h = [](ll a, ll b) { return (b == INF) ? a : b; };
  LazySegmentTree<ll, ll>::P p = [](ll a, int b) { return (a == INF) ? a : a * b; };

  int n, q; cin >> n >> q;
  LazySegmentTree<ll, ll> seg(n, f, g, h, 0, INF, vector<ll>(), p);

  while (q--) {
    int com; cin >> com;
    if (com) {
      int s, t; cin >> s >> t;
      cout << seg.query(s, t + 1) << endl;
    } else {
      int s, t, x; cin >> s >> t >> x;
      seg.update(s, t + 1, x);
    }
  }
  return 0;
}



Measured memory_bytes: 7060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> os;
int t[200005], a[200005], b[200005];

struct fenwick{
    LL ft[200005];
    void update(int i, int v){
        for(;i<=200000;i+=(i&-i)) ft[i] += v;
    }
    LL query(int i){
        LL res = 0;
        for(;i>0;i-=(i&-i)) res+=ft[i];
        return res;
    }
}ft1, ft2, ftc;

int main(){
    vector<int> v;
    int q;
    scanf("%d", &q);
    for(int i=0;i<q;i++){
        scanf("%d", &t[i]);
        if(t[i] == 1) scanf("%d%d", &a[i], &b[i]), v.push_back(a[i]);
    } 
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    int cnt = 0;
    LL val = 0;

    os s;
    for(int i=0;i<q;i++){
        if(t[i] == 1){
            int x = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
            ftc.update(x, 1);
            ft1.update(x, a[i]-(-1e9));
            ft2.update(x, 1e9-a[i]);
            val += b[i];
            cnt++;
            s.insert(a[i]);
        }
        else{
            // int lo = 1, hi = 200000, x = 1;
            int w = (cnt+1)/2;
            // while(lo <= hi){
            //     int mid = (lo+hi)/2;
            //     if(ftc.query(mid) >= w) x = mid, hi = mid-1;
            //     else lo = mid+1;
            // }
            int y = *s.find_by_order(w-1);
            int x = lower_bound(v.begin(), v.end(), y) - v.begin() + 1;

            LL val1 = ft1.query(200000) - ft1.query(x);
            int c1 = ftc.query(200000) - ftc.query(x);
            LL val2 = ft2.query(x);
            int c2 = ftc.query(x);

            LL ans = val1 - c1*1ll*(y-(-1e9)) + val2 - c2*1ll*(1e9-y);
            printf("%d %lld\n", y, ans + val);

        }
    }
}

Measured memory_bytes: 15476
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
long long dp[300000] = {};
int main() {
	iostream::sync_with_stdio(false);
	cin.tie(0);
	long long n, w;
	cin >> n >> w;
	REP(i, 300000) {
		dp[i] = w + 1;
	}
	dp[0] = 0;
	REP(i, n) {
		long long a, b;
		cin >> a >> b;
		for (int q = 100000; q >= 0; --q) {
			dp[q + b] = min(dp[q + b], dp[q] + a);
		}
	}
	long long ans = 0;
	for (int q = 100000; q >= 0; --q) {
		if (dp[q] <= w) {
			cout << q << endl;
			return 0;
		}
	}
	cout << ans << endl;
}

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

struct UnionFind {
    static const int Max = 100010;
    int par[Max];
    int rank[Max];

    void init(int n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

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

const int MAXE = 100010 * 2;
struct edge { int u, v, cost; };

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

edge es[MAXE];
int V, E;

ll kruskal() {
    sort(es, es+E, comp);
    UnionFind uf;
    uf.init(V);
    ll res = 0;
    for (int i=0; i<E; ++i) {
        edge e = es[i];
        if (!uf.same(e.u, e.v)) {
            uf.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> V;

    using P = pair< pair<int, int>, int>;
    vector< P > v(V);

    rep(i, V) {
        P a; int x, y;
        cin >> x >> y;
        a = { {x, y}, i };
        v[i] = a;
    }

    sort(v.begin(), v.end(), [](P& a, P& b) {
        return a.first.first < b.first.first;
    });

    rep(i, V-1) {
        es[E++] = { v[i].second, v[i+1].second, min((int)abs(v[i].first.first - v[i+1].first.first), (int)abs(v[i].first.second - v[i+1].first.second)) };
    }

    sort(v.begin(), v.end(), [](P& a, P& b) {
        return a.first.second < b.first.second;
    });

    rep(i, V-1) {
        es[E++] = { v[i].second, v[i+1].second, min((int)abs(v[i].first.first - v[i+1].first.first), (int)abs(v[i].first.second - v[i+1].first.second)) };
    }

    cout << kruskal() << endl;

}


Measured memory_bytes: 4608
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

//for A以上B未満でI探索 for (int I = A; i <= B; i++)
//string s = to_string(i);
int a = 0, b = 0, x = 0, y = 0, z = 0, n = 0, sum = 0;
string s = ""; asas; cncn;

int main(void) {
	llint n;
	cin >> n;
	llint ans = 1;
	for(llint i=1;i<=n;i++){
		ans *= i;
		ans %= 1000000007;
	}
	cout << ans << rt;
	please AC;
}

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

int main(void){
    int n, cnt=0, tmp;
    cin >> n;
    for (int i=1; i<=n; i+=2){
        tmp = 0;
        for (int j=1; j<=i; j++){
            if (i%j == 0) tmp += 1;
        }
        if (tmp == 8) cnt += 1;
    }
    cout << cnt << endl;
    return 0;
}


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


int main(void){
    
    string S;
    cin >> S;
    
    map<string,int> mp;
    
    mp["SUN"] = 7;
    mp["MON"] = 6;
    mp["TUE"] = 5;
    mp["WED"] = 4;
    mp["THU"] = 3;
    mp["FRI"] = 2;
    mp["SAT"] = 1;
    

    
    cout << mp[S] <<endl;
    
}


Measured memory_bytes: 256
<?php
  $s = str_split(trim(fgets(STDIN)));
  $n=count($s);

  for($i=0;$i<($n-1)/2;$i++){
    if($s[$i]!=$s[$n-1-$i]){
      echo "No";
      exit;
    }
  }
  
  $x = intdiv(($n-1)/2, 2);

  if(($n-1)/2%2==0){
    for($i=0;$i<$x;$i++){
      if($s[$i]!=$s[$x*2-1-$i]){
        echo "No";
        exit;
      }
    }
  }else{
    for($i=0;$i<$x;$i++){
      if($s[$i]!=$s[$x*2-$i]){
        echo "No";
        exit;
      }
    }
  }

  echo "Yes";

Measured memory_bytes: 4856
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

class Node
{
    internal int key, id;
    public int parentid
    {
        get { return id / 2; }
    }
    public int leftid
    {
        get { return 2 * id; }
    }
    public int rightid
    {
        get { return 2 * id + 1; }
    }
    public Node(int id, int key) {
        this.id = id;
        this.key = key;
    }
}

class A
{
    public static void Main() {
        int n = int.Parse(Console.ReadLine());
        Node[] nodes = new Node[n+1];
        int[] data = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        for(int i = 0; i < n; i++) {
            nodes[i + 1] = new Node(i + 1, data[i]);
        }
        for (int i = 1; i <= n; i++) {
            StringBuilder output = new StringBuilder();
            output.Append("node " + nodes[i].id + ": key = " + nodes[i].key + ", ");
            if (nodes[i].parentid >= 1) {
                output.Append("parent key = " + nodes[nodes[i].parentid].key + ", ");
            }
            if (nodes[i].leftid <= n) {
                output.Append("left key = " + nodes[nodes[i].leftid].key + ", ");
            }
            if (nodes[i].rightid <= n) {
                output.Append("right key = " + nodes[nodes[i].rightid].key + ", ");
            }
            Console.WriteLine(output);
        }
    }
    
}


Measured memory_bytes: 9216
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc158_a solver = new abc158_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc158_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            if (S.contains("AB") || S.contains("BA")) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll INF = 1LL << 58;

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<string> str(3);
    rep(i,3){
        cin>>str[i];
    }
    cout<<str[0][0]<<str[1][1]<<str[2][2]<<endl;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    vector<ll> p;
    p.push_back(a * x + b * y);
    // dump(a * x + b * y);
    p.push_back(c * max(x, y) * 2);
    // dump(c * max(x, y) * 2);
    ll tmp = 0;
    if (x < y)
    {
        tmp += 2 * x * c;
        tmp += (y - x) * b;
    }
    else
    {
        tmp += 2 * y * c;
        tmp += (x - y) * a;
    }
    // dump(tmp);
    p.push_back(tmp);
    cout << *min_element(ALL(p)) << endl;
    return 0;
}


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

int main(){
  int a,z;
  string S;
  cin >> S;
  int N = S.size();
  for(int i = 0; i < N; ++i){
    if(S[i] == 'A'){
      a = i;
      break;
    }
  }
  reverse(S.begin(),S.end());
  for(int i = 0; i < N; ++i){
    if(S[i] == 'Z'){
      z = i;
      break;
    }
  }
  cout << N - z - a << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> v(n+1,0);
    vector<int> ans(n+1,0);
    FOR(i,1,n+1) cin >> v[i];

    int count = 0;
    for(auto i = n;i > 0; i--) {
        //cerr << i << endl;
        if (i > n/2) {
            if (v[i] == 1) {
                ans[i] = 1;
                count++;
            }
        } else  {
            int c = 0;
            for(auto j = i;j < n+1;j += i) {
                c += ans[j];
            }
            if (c % 2 != v[i]) {
                ans[i] = 1;
                count++;
            }
        }
    }

    cout << count << endl;
    FOR(i,1,n+1) {
        //cerr << cnt[i] << endl;
        if(ans[i] == 1) cout << i << " ";
    }


    return 0;
}

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

using namespace std;
	
const int maxn=1e5+20;
int b[maxn];

int main()
{
	long long a,c,d,e,ans=1;
	cin >> a >> c >> d;
	for(int i=0;i<a;i++)
		cin >> b[i];
		
	sort(b,b+a);
	e=0;
	int p=0;
	for(int i=0;i<a;i++)
	{
		e+=b[i+1]-b[i];
		p++;
		if(p==c && i!=a-1)
		{
			ans++;
			p=0;
			e=0;
		}
		else if(e>d)
		{
			ans++;
			p=0;
			e=0;
		}
	}
	
	
	
	
	cout << ans;
}

 



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

int main(){

 for(int i=0;i<3;i++){
 
  int h1, m1, s1, h2, m2, s2;
  cin>>h1>>m1>>s1>>h2>>m2>>s2;
  
  

  int s3 = h1 * 3600 + m1 * 60 + s1;
  int s4 = h2 * 3600 + m2 * 60 + s2;
  int x = s4 - s3;

  int h3 = x / 3600;
  int m3 = (x / 60) % 60;
  int s5 = x % 60;

  cout<<h3<<" "<<m3<<" "<<s5<<endl;
 }



  return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner;

//Eye Test
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] e = new int[4][2];
		while(sc.hasNext()){
			for(int i=0;i<2;i++){
				double x = sc.nextDouble();
				if(x<0.2)e[3][i]++;
				else if(x<0.6)e[2][i]++;
				else if(x<1.1)e[1][i]++;
				else e[0][i]++;
			}
		}
		for(int i=0;i<4;i++)System.out.println(e[i][0]+" "+e[i][1]);
	}
}

Measured memory_bytes: 0
#くじ引き

import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	n = input()
	a = list(map(int, input().split()))
	ans = float("inf") #無限大を挿入
	for i in a:
		# 2値で変換した際の右に並ぶ0の数が2で割ることのできる回数
		# rfindで1の値を持つ最大インデックスを求め、その分だけ引く
		# 計算した回数の最小値を求める
		ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
	print(round(ans))

if __name__ == '__main__':
	main()


Measured memory_bytes: 12508
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			final int N = 100001;
			int n = in.nextInt();
			int[] a = new int[N];
			for (int i = 0; i < n; i++) {
				++a[in.nextInt()];
			}
			int ans = 0;
			int numEven = 0;
			for (int i = 0; i < N; i++) {
				if (a[i] == 0) {
					continue;
				}
				++ans;
				a[i] %= 2;
				if (a[i] == 0) {
					++numEven;
				}
			}
			if (numEven % 2 == 1) {
				--ans;
			}
			out.println(ans);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



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

int main() {
    int w, a, b;
    cin >> w >> a >> b;
    int ans;
    if (a <= b) {
        ans = max(0, b - a - w);
    } else {
        ans = max(0, a - b - w);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N,a,A[200000]={0};
	cin>>N;
	for(int i=0;i<N-1;i++){
		cin>>a;
		A[a-1]++;
	}
	for(int i=0;i<N;i++){
		cout<<A[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4412
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

class unionfind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.size = [1 for i in range(n)]
    def find(self,a):
        if a == self.parent[a]: return a
        else: self.parent[a] = find(self,self.parent[a]); return self.parent[a]
    def unite(self,a,b):
        pa,pb = self.find(self,a), self.find(self,b)
        if pa == pb: return
        else: self.parent[pb] = pa; self.size[pa] += self.size[pb]
    def same(self,a,b): return find(self,a) == find(self,b)

n,r = imap()
ans = r if n>=10 else r + 100*(10-n)
print(ans)


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

using ll = long long;

const int MAX = 510000;
static const int INF = 1e9;
static const int MOD = 1e9 + 7;

// 組合せを素数で割った値を求める
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k || n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 順列計算
long long PER(int n, int k) {
  if (n < k || n < 0 || k < 0) return 0;
  return fac[n] * (finv[n - k] % MOD) % MOD;
}

int k;

// 隣接リストを用いた幅優先探索 O(|V|+|E|)
vector<int> G[MAX], d(MAX, INF); // 始点sから頂点iまでの最短距離をd[i]に記録
// main関数からこれらを削除すること

ll bfs(int s) {
  ll ret = k;
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    int count = 0, painted = 1;
    for (int v = 0; v < G[u].size(); v++) {
      if (d[G[u][v]] == INF) {
        count++;
        d[G[u][v]] = d[u] + 1;
        q.push(G[u][v]);
      }
      else painted++;
    }
    ret *= PER(k - painted, count);
    ret %= MOD;
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n; // n:頂点数
  cin >> n >> k;
  
  // vector<int> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  int u, v;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではこの行をコメントアウト
  }
  
  COMinit();
  
  cout << bfs(0) << '\n';
}

Measured memory_bytes: 30200
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#include <queue>
#include <stack>
// #define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void chmax(string &a,string b){
  if(a=="-")a=b;
  if(a.size()<b.size())a=b;
  if(a.size()==b.size()&&a<b)a=b;
}

void run(){
  int n,m;
  cin>>n>>m;
  vi a(m);
  rep(i,m)cin>>a[i];
  const int NUM[]={0,2,5,5,4,5,6,3,7,6};
  string dp[10010];
  rep(i,10010)dp[i]="-";
  dp[0]="";
  rep(i,n+1){
    if(dp[i]=="-")continue;
    rep(j,m){
      chmax(dp[i+NUM[a[j]]],dp[i]+(char)('0'+a[j]));
    }
  }
  cout<<dp[n]<<endl;
}


Measured memory_bytes: 30336
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/
 
 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */
 
#include <bits/stdc++.h>
using namespace std;
 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,w;
    cin >> n >> w;
    
    int v[n],wt[n];
    for(int i=0;i<n;i++){
      cin >> wt[i] >> v[i];
    }

    long long dp[n+1][w+1];
    for(int i=0;i<w+1;i++)
    {
        dp[0][i]=0;
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<w+1;j++)
        {
           if(j>=wt[i]) 
           dp[i+1][j] = max(dp[i][j] , dp[i][j-wt[i]]+v[i]);
           else
           dp[i+1][j] = dp[i][j];
        }
    }
    cout<<dp[n][w];
    return 0;
}

Measured memory_bytes: 79232
#include <iostream>
using namespace std;
 
int main(){
    int h, w;
    while(true){
        cin >> h >> w;
        if(h==0) break;
        for(int i=0;i<h;i++){
            for(int i=0;i<w;i++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

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

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	string s;
	cin >> s;
	string p = "RGB";
	vector<vi> v(3, vi(n + 1));
	rep(i, 3) rep(j, n) {
		v[i][j + 1] = v[i][j] + (s[j] == p[i]);
	}

	ll ans = 0;
	for(int i = 0; i < n - 2; i++) {
		for(int j = i + 1; j < n - 1; j++) {
			if(s[i] == s[j]) continue;
			int c = 0;
			for(c = 0; c < 3; c++) if(p[c] != s[i] && p[c] != s[j]) break;
			ll _ans = v[c][n] - v[c][j + 1];
			if(j + (j - i) < n && s[j + (j - i)] == p[c]) _ans--;
			ans += _ans;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3684
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define pb push_back
    #define sz size()
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using Vl = vector<ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;

ll dp1[3010][2], dp2[3010][2];
int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vector<vector<int>> res(h, vector<int> (w));
    rep(i, b){
        rep(j, w){
            if(j < a)res[i][j] = 1;
            else res[i][j] = 0;
        }
    }
    REP(i, b, h - 1){
        rep(j, w){
            if(j < a)res[i][j] = 0;
            else res[i][j] = 1;
        }
    }
    rep(i, h){
        rep(j, w)cout << res[i][j];
        cout << endl;
    }
}



Measured memory_bytes: 7096
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		PriorityQueue<Integer> list = new PriorityQueue<>();
		int n = sc.nextInt();
		
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		int size = list.size();
		
		int prev = 0;
		for (int i = 0; i < size / 2; i++) {
			prev = list.poll();
		}
		System.out.println(list.peek()-prev);
		
	}

}


Measured memory_bytes: 60964
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define INF 1000000000000000000
#define EPS 0.0000000001
#define CHAINS 18
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
bool possible[MAX];
int balls[MAX];
int main()
{
    int n,m,i,u,v;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)
    {
        balls[i]=1;
    }
    possible[1]=true;
    for(i=0;i<m;i++)
    {
        scanf("%d %d",&u,&v);
        possible[v]=(possible[v]||possible[u]);
        balls[u]--;
        balls[v]++;
        if(possible[u]&&balls[u]==0)
        {
            possible[u]=false;
        }
    }
    int ans=0;
    for(i=1;i<=n;i++)
    {
        if(possible[i]) ans++;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 4196
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  string s;
  cin >> s;
  int ans = 700;
  for(char c : s) {
    if(c == 'o') ans += 100;
  }
  cout << ans << endl;

  return 0;
}

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


int main()
{
	LL n;cin>>n;
	vector<LL> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++){
		if(a[i]==0){
			cout<<0<<"\n";
			return 0;
		}
	}
	LL ans=1,k = 1e18;
	for(int i=0;i<n;i++){
		if(a[i]>k/ans){
			ans = -1;break;
		}
		ans*=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4036
def LI():
    return list(map(int, input().split()))

_ = int(input())
a = LI()
ans = 1
mod = pow(10, 18)

def main(ans):
    if 0 in a:
        ans = 0
    else:
        for i in a:
            ans *= i
            if ans > mod:
                ans = -1
                break
    print(ans)

if __name__ == "__main__":
    main(ans)

Measured memory_bytes: 21784
#include <stdio.h>
int main()
{
	int a [100][100];
	int b [100];
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}
	for(int i = 0; i < m; i++)
	{
		scanf("%d", &b[i]);
	}
	int c[100] = {0};
	for (int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j ++)
		{
			c[i] += a[i][j]*b[j];
		}
	}
	for(int i = 0; i < n; i++)
	{
		printf("%d\n", c[i]);
	}
	return 0;
} 


Measured memory_bytes: 2716
object Main extends App {
  def check(s:Set[Char]) = {
    val s_ = (for(c <- 'a' to 'z' if !s.contains(c)) yield c).toArray
    if (s_.length == 0) None
    else Some(s_(0))
  }
  val s = readLine.toSet
  println(check(s) match {
    case Some(c) => c
    case None => "None"
  })
}

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

int main() {
	int64_t N;
	cin >> N;

	int64_t n3 = N / 3;
	int64_t fizz = n3 * (n3 + 1) / 2 * 3;

	int64_t n5 = N / 5;
	int64_t bazz = n5 * (n5 + 1) / 2 * 5;

	int64_t n15 = N / 15;
	int64_t fizzbazz = n15 * (n15 + 1) / 2 * 15;

	int64_t nSUM = N * (N + 1) / 2;

	int64_t ans = nSUM - fizz - bazz + fizzbazz;

	cout << ans << endl;
}

Measured memory_bytes: 3636