akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int x = sc.nextInt();
        int y = sc.nextInt();
        int ret = 0;
        if (x>=0&&y==0) {
            ret = x+1;
        } else if (x<0&&y==0) {
            ret = Math.abs(x);
        } else if (x>=0&&y>=0) {
            if (x>y) {
                ret = x-y+2;
            } else {
                ret = y-x;
            }
        } else if (x<0&&y<0) {
            if (x>y) {
                ret = x-y+2;
            } else {
                ret = y-x;
            }
        } else {
            ret = Math.abs(Math.abs(x)-Math.abs(y))+1;
        }
        
        System.out.println(ret);
    }
}


Measured memory_bytes: 9044
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        if (n == 2) {
            System.out.println(s);
            return;
        }
        for (int i = n - 1; i >= 0; i--) {
            System.out.print(s.charAt(i));
        }
        System.out.println();
    }
}


Measured memory_bytes: 21844
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;



#[fastout]
fn main() {
    input!{
        n: usize,
    }

    if n % 2 != 0 {
        println!("0");
    } else {
        let mut ans = 0;
        let mut denominator = 10;

        while n >= denominator {
            ans += n/denominator;
            denominator *= 5;
        }
        println!("{}", ans)
    }
}


Measured memory_bytes: 2152
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

long long cnt;
int l;
int a[1000000];
int n;
vector<int>G;

void insertionSort(int a[], int n, int g)
{
	for (int i = g; i < n; i++)
	{
		int v = a[i];
		int j = i - g;
		while (j >= 0 && a[j] > v)
		{
			a[j + g] = a[j];
			j -= g;
			cnt++;
		}
		a[j + g] = v;
	}
}

void shellSort(int a[], int n)
{
	for (int h = 1;;)
	{
		if (h > n)
			break;
		G.push_back(h);
		h = h * 3 + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--)
	{
		insertionSort(a, n, G[i]);
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	cnt = 0;

	shellSort(a, n);
	cout << G.size() << endl;
	for (int i = G.size()-1; i >=0; i--)
	{
		cout << G[i];
		if (i)
			cout << ' ';
	}
	cout << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
	{
		cout << a[i] << endl;
	}
	return 0;
}


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

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

using namespace std;

int main(){
	string s;cin>>s;
	int mid = s.size()-2;
	cout<<s.front()<<mid<<s.back()<<endl;
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
r, s, p = LI()
D = {'r': p, 'p': s, 's': r}
t = S()
flag = [1] * n
ans = 0
for i in range(n):
    if i <= k - 1:
        ans += D[t[i]]
    else:
        if t[i - k] == t[i] and flag[i - k]:
            flag[i] = 0
        else:
            ans += D[t[i]]



print(ans)

Measured memory_bytes: 41456
#include<stdio.h>

int main(void) {

	int H;		//モンスターの体力H
	int A;		//サーバルが1回攻撃したときに減る体力A
	int N = 0;	//攻撃回数N

	//モンスターの体力Hを入力
	//サーバルの1回攻撃したときに減る体力Aを入力
	scanf("%d %d", &H,&A);

	N = H / A;

	if (H - A * N > 0) {
		N = N + 1;
	}

	printf("%d \n", N);



	return 0;
}

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

namespace multiset
{

class multiset
{
  private:
    std::vector<int> tree;
    int MSB;

    void add(int i, int x)
    {
        for (; i < tree.size(); i += i & -i) {
            tree[i] += x;
        }
    }

    int sum(int i)
    {
        int res = 0;
        for (; i > 0; i -= i & -i) {
            res += tree[i];
        }
        return res;
    }

    int bisect(int w)
    {
        int i = 0;
        for (int k = MSB; k > 0; k /= 2) {
            if (i + k < tree.size() && tree[i + k] < w) {
                w -= tree[i + k];
                i += k;
            }
        }
        return i + 1;
    }

    int get_MSB(int N)
    {
        int i = 1;
        while (i < N) {
            i *= 2;
        }
        return i / 2;
    }

  public:
    multiset(int N) : tree(N + 1), MSB(get_MSB(N)) {}
    void insert(int x) { add(x, 1); }
    void erase(int x) { add(x, -1); }
    int lower_bound(int x)
    {
        int s = sum(x);
        return (s == 0) ? 0 : bisect(s);
    }

    size_t size() { return sum(tree.size() - 1); }
};

} // namespace multiset

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

    int N;
    std::cin >> N;

    std::vector<int> A(N);
    for (auto &&a : A) {
        std::cin >> a;
    }

    std::vector<int> B = A;
    std::sort(begin(B), end(B));
    B.erase(std::unique(begin(B), end(B)), end(B));

    std::transform(begin(A), end(A), begin(A), [&](int val) -> int {
        return std::lower_bound(begin(B), end(B), val) - begin(B) + 1;
    });

    multiset::multiset ms(B.size());
    for (auto a : A) {
        auto i = ms.lower_bound(a - 1);
        if (i != 0) {
            ms.erase(i);
        }
        ms.insert(a);
    }

    std::cout << ms.size() << '\n';
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

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

    int n; cin>>n;
    cout<<n*800-n/15*200<<endl;
    
}

Measured memory_bytes: 256
N = int(input())
a = [int(x) for x in input().split()]

candidates = []

for i in range(N // 2) :
    d = N - 1 - 2*i
    candidates.append(d)
    candidates.append(d)
    
if N % 2 != 0: 
    candidates.append(0)
    
if sorted(candidates) != sorted(a) :
    print(0)
else :
    c_dict = {}
    for c in candidates :
        if c in c_dict.keys() :
            c_dict[c] += 1
        else: 
            c_dict[c] = 1
            
    prod = 1
    for v in c_dict.values() :
        prod *= v
        
    print(prod % (10**9 + 7))
    

Measured memory_bytes: 15496
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll X = 0;
	ll M = 0;
	ll Q = 0;
	//ll x[1000001] = {};
	//ll c[100000] = {};
	//ll v[100] = {};
	ll *x, *c, *d;
	string S[100],T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	

	//char p;
	cin >>N >> X;
	x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));

	rep(i, 0, N) {
		cin >> x[i];
	}
	x[N] = X;
	sort(x,x+N+1);

	//rep(i, 0, N+1) {
	//	cout << x[i] << endl;
	//}
	//cout << endl;

	
	rep(i, 1, N+1) {
		x[i-1] = x[i] - x[i-1];
	}

	/*rep(i, 0, N) {
		cout << c[i] << endl;
	}
	cout << endl;*/

	ll r = gcd(x[0], x[1]);
	rep(i, 1, N-1) {
		 r = gcd(r, x[i + 1]);
	}
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(is.begin(), is.end());
	
	//c = (ll *)malloc(D * sizeof(ll));
	//d = (ll *)malloc(D * sizeof(ll));

	if (N == 1)
		cout << x[0] << endl;
	else
		cout << r << endl;

	
	//sort(l,l+N);


	return 0;

}

ll gcd(ll a, ll b) {
	ll c;
	c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}

	return b;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  if(n >= k)
    n %= k;
  cout << min(n, k - n);
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;

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

    std::cin >> N;

    double total = 0;

    for(int i=0;i<N;++i){
        double x;
        std::string u;

        std::cin >> x >> u;

        if(u == "JPY"){
            total += x;
        }else{
            total += x * 380000;
        }
    }

    printf("%.10f\n", total);
}


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

#define df(b, e) ((b) > (e))
#define fore(i, b, e) for(auto i = (b) - df(b, e); i != e - df(b, e); i += 1 - 2 * df(b, e))
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define pb push_back

typedef long long lli;
typedef long double ld;
typedef pair<int, int> ii;

template <class T>
struct rge { T b, e; };

template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}

template <class T> auto dud(T *x) -> decltype(cerr << *x, 0);
template <class T> char dud(...);

struct debug {
#ifdef LOCAL
  ~debug() { cout << endl; }

  template <class T>
  typename enable_if<sizeof dud<T>(0) != 1, debug &>::type operator << (T i) {
    cout << boolalpha << i;
    return *this;
  }

  template <class T>
  typename enable_if<sizeof dud<T>(0) == 1, debug &>::type operator << (T i) {
    return *this << range(begin(i), end(i));
  }

  template <class A, class B>
  debug & operator << (pair<A, B> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }

  template <class T>
  debug & operator << (rge<T> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
      *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
#else
  template <class T> 
  debug & operator << (const T&) {
    return *this; 
  }
#endif
};

#define deb(...) " " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " "

struct treap {
  int x = rand() + (rand() << 15);
  char c;
  treap *left = NULL, *right = NULL;
  int sz = 1, flip = 0;

  treap(char c): c(c){}
};

int gsz(treap* t) {
  return t ? t->sz: 0;
}

void push(treap* t) {
  if (!t || !t->flip)
    return;
  swap(t->left, t->right);
  if (t->left)
    t->left->flip ^= 1;
  if (t->right)
    t->right->flip ^= 1;
  t->flip = 0;
}

treap* pull(treap* t) {
  push(t->left), push(t->right);
  t->sz = 1 + gsz(t->left) + gsz(t->right);
  return t;
} 

pair<treap*, treap*> split(treap *t, int sz) {
  if (!t)
    return {t, t};
  push(t);
  if (sz <= gsz(t->left)) {
    auto p = split(t->left, sz);
    t->left = p.s;
    return {p.f, pull(t)};
  }
  auto p = split(t->right, sz - gsz(t->left) - 1);
  t->right = p.f;
  return {pull(t), p.s};
}

treap* merge(treap* l, treap* r) {
  if (!l || !r)
    return l ? l: r;
  push(l), push(r);
  if (l->x > r->x) {
    l->right = merge(l->right, r);
    return pull(l);
  }
  r->left = merge(l, r->left);
  return pull(r);
}

void print(treap *t, int dep = 0) {
  if (!t)
    return;
  push(t);
  print(t->left, dep + 1);
  cout << t->c;
  print(t->right, dep + 1);
  if (dep == 0)
    cout << '\n';
}

treap* t;
string s;
char c;
int q, type, side;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s;
  for (char c: s)
    t = merge(t, new treap(c));
  cin >> q;
  while (q--) {
    cin >> type;
    if (type == 1) 
      t->flip ^= 1;
    else {
      cin >> side >> c;
      if (side == 1)
        t = merge(new treap(c), t);
      else
        t = merge(t, new treap(c));
    }
  }
  print(t);
  return 0;
}


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

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; }

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main(){
    string S,T;
    cin>>S>>T;
    int N = S.size();
    int ans = 0;
    rep(i,N){
        if(S[i]!=T[i]) ans++;
    }
    cout<<ans<<endl;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

bool comPair(const P &firstElof, const P &secondElof) {
    return firstElof.first < secondElof.first;
}

int main() {
    int n;
    vector<P> v;
    cin >> n;
    rep(i, n) {
        int temp;
        cin >> temp;
        v.emplace_back(temp, i + 1);
    }
    sort(all(v), comPair);
    rep(i, n) out(v[i].second);
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 333;
int N,M;
int A[MC][MC];
int x[MC];
bool b[MC];
int c[MC];
int p,ans;

int main(){
	scanf("%d%d" , &N , &M);
	repp(i,0,N){
		repp(j,1,M+1){
			scanf("%d" , A[i]+j);
		}
		x[i] = 1;
		++c[A[i][1]];
	}
	repp(j,1,M+1) if(c[p] < c[j]) p = j;
	ans = c[p];
	repp(k,1,M){
		b[p] = 1;
		repp(i,0,N){
			while(b[A[i][x[i]]]){
				--c[A[i][x[i]]];
				++x[i];
				++c[A[i][x[i]]];
			}
		}
		p = 0;
		repp(j,1,M+1) if(c[p] < c[j]) p = j;
		ans = min(ans , c[p]);
	}
	printf("%d\n" , ans);
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		string ans = "";
		for(var i=0;i<str.Length;i++){
			if(str.Substring(i,1)=="1"){
				ans += "9";
			} else {
				ans += "1";
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#define MAX 100000000
using namespace std;
 
string di[4]={"dream","dreamer","erase", "eraser"};
 
int main (void) {
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  for (int i=0; i<=3; i++){
    reverse(di[i].begin(), di[i].end());
  }
  bool can = true;
  for (int i=0; i<S.size();){
    bool can2 =false;
    for (int j=0; j<=3; j++){
      string d=di[j];
      if (d==S.substr(i,d.size())){
        can2 =true;
        i=i+d.size();
      }
    }
    if (!can2){
      can =false;
      break;
    }
  }
  if (can) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 512
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        mut a: [usize; n]
    }
    a.sort();
    let mut prev = 0;
    let mut subed = true;
    let mut div = [false; 1000001];
    let mut ans = 0;
    for i in a {
        if prev == i {
            if !subed {
                ans -= 1;
                subed = true;
            }
            continue;
        }

        if !div[i] {
            for j in (i..=1000000).step_by(i) {
                div[j] = true;
            }
            ans += 1;

            subed = false;
        } else {
            subed = true;
        }

        prev = i;
    }
    println!("{}", ans);
}


Measured memory_bytes: 5964
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int D;
  cin>>D;
  cout<<"Christmas";
  REP(i,25-D)cout<<" Eve";
  cout<<endl;
  return 0;
}


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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    int h, w;
    cin >> h >> w;
    char field[h][w];

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> field[i][j];
        }
    }

    int cnt = 0;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (field[i][j] == '#'){
                cnt++;
            }
        }
    }

    if(cnt == h+w-1){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}


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

int main(void)
{
    int n, w;
    vector<ll> ws, vs, dp;
    scanf("%d%d", &n, &w);
    ws.assign(n, 0);
    vs.assign(n, 0);
    dp.assign(w + 1, 0);

    for (int i = 0; i < n; i++)
    {
        scanf("%d%d", &ws[i], &vs[i]);
    }

    ll weight = 0, value = 0;
    for (int i = 0; i < n; i++)
    {
        weight = ws[i];
        value = vs[i];
        for (int ww = w; ww >= weight; ww--)
        {
            dp[ww] = max(value + dp[ww - weight], dp[ww]);
        }
    }

    printf("%lld\n", dp[w]);

    return 0;
}

Measured memory_bytes: 4024
import math
N,K= map(int, input().split())
okasizu = [0] * (N + 1)
for _ in range(K):
    d = int(input())
    nums = list(map(int, input().split()))
    for num in nums:
        okasizu[num] += 1
ans = 0
for i in range(1,N + 1):
    if okasizu[i] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

ll par[213456];//親
ll depth[213456];//木の深さ
ll tree_num[123456];
//n要素で初期化
void init(ll n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		depth[i] = 0;
		tree_num[i] = 1;
	}
}
//木の根を求める
ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(ll x, ll y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (depth[x] < depth[y]) {
		par[x] = y; tree_num[y] += tree_num[x];
	}
	else {
		par[y] = x; tree_num[x] += tree_num[y];
		if (depth[x] == depth[y])depth[x]++;
	}
}
//xとyが同じ集合に属するか否か
bool same(ll x, ll y) {
	return find(x) == find(y);
}

ll a[123456], b[123456];
signed main() {
	ll n, m, cnt = 0; cin >> n >> m; init(n + m);
	rep(i, m) {
		cin >> a[i] >> b[i];
	}
	cnt = n * (n - 1) / 2;
	reverse(a, a + m); reverse(b, b + m);
	vector<ll> ans; ans.push_back(cnt);
	rep(i, m - 1) {
		if (!same(a[i], b[i])) {
			cnt -= tree_num[find(a[i])] * tree_num[find(b[i])];
		}
		ans.push_back(cnt);
		unite(a[i], b[i]);
	}
	reverse(all(ans));
	rep(i, m) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 9964
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
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 H, W, D, A;
int Q, L, R;
vector<int> px(90001), py(90001), d(90001);

int main() {
	cin >> H >> W >> D;
    rep(i,H) rep(j,W) {
        cin >> A;
        px[A] = i;
        py[A] = j;
    }
    for (int i = D+1; i <= H*W; i++) {
        d[i] = d[i-D] + abs(px[i]-px[i-D]) + abs(py[i]-py[i-D]);
    }
    cin >> Q;
    rep(i,Q) {
        cin >> L >> R;
        cout << d[R]-d[L] << endl;
    }   
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int dp[2222];
signed main()
{
	int n;
	cin>>n;
	if (n<3)
		re cout<<0,0;
	dp[3]=dp[4]=dp[5]=1;
	dp[6]=2;
	int sum=3;
	for (int i=7;i<=n;i++){
		dp[i]=sum;
		sum=(sum+dp[i-2])%1000000007ll;
	}
	cout<<dp[n];
	re 0;
}


Measured memory_bytes: 3640
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in xrange(n)]

def make2d_arr(w,h,val =INF):
    return [[val for i in xrange(w)]for i in xrange(h)]

n = int_raw()

edge = make2d_arr(n,n,0)

n_even = n - n%2

comp_edge = [(i,n_even-i-1) for i in xrange(0,n_even)]

for e in comp_edge:
    edge[e[0]][e[1]]=1
    edge[e[1]][e[0]]=1

m = 0
ans = []

for i in xrange(n):
    for j in xrange(i):
        if edge[j][i] == 0:
            m+=1
            ans.append((i,j))
print m
for a in ans:
    print a[0]+1,a[1]+1


Measured memory_bytes: 3076
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, q;
    queue<int> que;
    vector<bool> visited;
    vector<int> value;
    vector<list<int> > graph;
    cin >> n >> q;
    visited.resize(n + 1);
    value.resize(n + 1);
    graph.resize(n + 1);
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for (int i = 0; i < q; i++) {
        int p, x;
        cin >> p >> x;
        value[p] += x;
    }
    visited[1] = true;
    que.push(1);
    while (que.size()) {
        int now = que.front();
        que.pop();
        for (int next : graph[now])
            if (!visited[next]) {
                visited[now] = true;
                value[next] += value[now];
                que.push(next);
            }
    }
    for (int i = 1; i <= n; i++) cout << value[i] << ' ';
    return 0;
}

Measured memory_bytes: 19456
#include <iostream>
#include <vector>
#include <set>

using namespace std;

void fill(vector<int> &res, int prefix, const set<char> &elems) {
    if (elems.empty()) {
        res.push_back(prefix);
        return;
    }
    for (auto e: elems) {
        set<char> left(elems);
        left.erase(e);
        int new_prefix = (prefix << 3) + e;
        fill(res, new_prefix, left);
    }
}

int bs(const vector<int> &all, int v) {
    int a = 0;
    int b = all.size();
    while (b - a > 1) {
        int c = (b + a) / 2;
        if (all[c] > v)
           b = c;
        else
           a = c; 
    }
    return a;
}

int read(int n) {
    int c;
    int a = 0;
    for (auto i = 0; i < n; ++i) {
        cin >> c;
        a <<= 3;
        a += c - 1;
    }
    return a;
}

int main(int argc, char* argv[]) {
    int n, c;
    cin >> n;
    int a = read(n);
    int b = read(n);
    vector<int> p;
    set<char> elems;
    for (auto i = 0; i < n; ++i)
        elems.insert(i);
    fill(p, 0, elems);
    cout << abs(bs(p, b) - bs(p, a)) << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
ll b[1000005];
int main()
{
    int n;
    scanf("%d",&n);
    
    ll a[100005],i;
    
    for(i=0; i<n; i++)
        scanf("%lld",&a[i]),b[i]=0;
    if(n>=1e5)
        a[-2]=0;
    if(a[0]!=0)
            printf("0\n");
    else
    {
        ll ans=1;
        for(i=0;i<n;i++)
            b[a[i]]++;
        for(i=1;i<n;i++)
        {
            ans*=b[a[i]-1];
            ans%=998244353;
        }

        printf("%lld\n",ans);
    }
    return 0;
}


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

int main() {
    long long int k, renzoku = 1, renzoku_ = 2, right, renzoku_right = 0, renzoku_left = 0, left, ans = 0, ans_ = 0;
    string s;
    cin >> s >> k;
    left = 0;
    right = s.size() - 1;
    if(s.size() == 1) {
        cout << k/2 << '\n';
        return 0;
    } else if(k == 1) {
        for(int i = 1; i < s.size(); ++i) {
            if(s[i-1] == s[i]) {
                renzoku++;
            } else {
                ans += renzoku/2;
                renzoku = 1;
            }
        }
        ans += renzoku/2;
        cout << ans << '\n';
        return 0;
    } else {
        //両端が同じとき
        if(s[0] == s[s.size()-1]) {

            //右端から
            for(int i = s.size() - 2; i >= 0; --i) {
                if(s[i+1] == s[i]) {
                    renzoku_++;
                } else {
                    right = i+1;
                    renzoku_right = renzoku_-1;
                    break;
                }

                // 全部同じ
                if(i == 0) {
                    cout << s.size()*k/2 << '\n';
                    return 0;
                }
            }

            //左端から
            for(int i = 1; i < right; ++i) {
                if(s[i-1] == s[i]) {
                    renzoku_++;
                } else {
                    left = i;
                    ans_ += renzoku_/2;
                    renzoku_left = renzoku_ - renzoku_right;
                    break;
                }
            }

            //続き
            for(int i = left; i < right; ++i) {
                if(s[i-1] == s[i]) {
                    renzoku++;
                } else {
                    ans += renzoku/2;
                    renzoku = 1;
                }
            }
            ans += renzoku/2;
        } else {
            for(int i = 1; i < s.size(); ++i) {
                if(s[i-1] == s[i]) {
                    renzoku++;
                } else {
                    ans += renzoku/2;
                    renzoku = 1;
                }
            }
            ans += renzoku/2;
        }
        ans = ans*k + ans_*(k-1) + renzoku_left/2 + renzoku_right/2;
        cout << ans << '\n';
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n,k;
  cin >> n >> k;
  vl a(n,0);
  rep(i,n) {
    cin >> a.at(i);
  }

  rep(i,n-k) Yes(a.at(i) < a.at(k+i));

  return 0;
}


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

int main() {
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;
	cout << max(E, F) + max({ A + B + C, A + B + D, A + C + D, B + C + D }) << endl;
}


Measured memory_bytes: 3096
from sys import stdin
import sys

MAX_N = 100;

X, N = [int(x) for x in stdin.readline().rstrip().split()]
if N==0:
  print(X)
  sys.exit()
p = [int(x) for x in stdin.readline().rstrip().split()]

for i in range(MAX_N//2+1):
  a=X-i
  if not a in p:
    print(a)
    break
  a=X+i
  if not a in p:
    print(a)
    break

Measured memory_bytes: 9188
h,w,m = map(int,input().split())
hw = [[int(i) for i in input().split()] for j in range(m)]

tate = [0]*(w+1)
yoko = [0]*(h+1)

for i in range(m):
    yoko[hw[i][0]] += 1
    tate[hw[i][1]] += 1
    
ans = 0

t_max = -1


for i in range(1,w+1):
    if t_max < tate[i]:
        t_max = tate[i]
        t_max_idx = []
        t_max_idx.append(i)
    elif t_max == tate[i]:
        t_max_idx.append(i)

y_max = -1

for i in range(1,h+1):
    if y_max < yoko[i]:
        y_max = yoko[i]
        y_max_idx = []
        y_max_idx.append(i)
    elif y_max == yoko[i]:
        y_max_idx.append(i)
        
s_y = set(y_max_idx)
s_t = set(t_max_idx)

if len(y_max_idx)*len(t_max_idx) > m:
    print(t_max+y_max)
else:
    ans = 0
    for i in range(m):
        if hw[i][0] in s_y and hw[i][1] in s_t:
            ans += 1
    if ans < len(y_max_idx)*len(t_max_idx):
        print(t_max+y_max)
    else:
        print(t_max+y_max-1)

Measured memory_bytes: 110196
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    while(true){
		int K = Integer.valueOf(sc.readLine());
		if(K==0)
		    break;
		String[] st = sc.readLine().split(" ");
		int sum = 0;
		for(int i=0; i<K*(K-1)/2; i++)
		    sum+=Integer.valueOf(st[i]);
		System.out.println(sum/(K-1));
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 31356
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"

const ll MOD = 1000000007;

int hsh[100005];
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    quickio
    int n;
    cin >> n;
    
    ll sum = 0;
    rep(i, 0, n){
        int inp;
        cin >> inp;
        hsh[inp]++;
        sum += inp;
    }

    int q;
    cin >> q;
    while(q--){
        int b, c;
        cin >> b >> c;
        sum += hsh[b]*c - hsh[b]*b;
        hsh[c] += hsh[b];
        hsh[b] = 0;
        cout << sum << endl;
    }
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 4004
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define INF 999999999999
const double PI = acos(-1.0);
const ll m = (1e9+7);
ll ans;
int n;

ll compute(ll a, ll b){
    ll ret = 1;
    for(int i = 0; i < b; i++){
        ret = (1LL * ret * a) % m;
    }
    return ret;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> n;
    ans = compute(10,n);
    ans -= 2LL * compute(9,n);
    ans += compute(8,n);
    ans %= m;
    if(ans < 0) ans += m;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int d;
  cin >> d;
  ll k[26];
  ll c[26];
  rep(i,26)cin >> c[i];
  rep(i,26)k[i]=0;
  ll ans=0;
  ll s[d][26];
  rep(i,d)rep(j,26)cin >> s[i][j];
  ll  anss[d];
  rep(i,d){
    ll tmp=ans;
    ll p=0;
    ans=-1000000000;
    rep(o,26){
      ll w=tmp;
      w+=s[i][o];
      rep(j,26){
        if(j==o)continue;
        w-=(i+1-k[j])*c[j];
      }
      if(ans<w){
        ans=w;
        p=o;
      }
    }
    anss[i]=p+1;
    k[p]=i+1;
  }
  rep(i,d)cout << anss[i] << endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  if (a >= 13) cout << b << '\n';
  else if (a >= 6) cout << b / 2 << '\n';
  else cout << 0 << '\n';
}

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

int main() {
	int r,D,x;
	cin >> r>>D>>x;
	vector<int>Ans(11); 
	Ans[0] = x;
	for (int n = 0; n < 10; ++n) {
		Ans[n + 1] = r * Ans[n] - D;
	}	
	for (int n = 0; n < 10; ++n) {
		cout << Ans[n+1] <<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		boolean flag = false;
		for (int i = A; i <= B; i++) {
			if (i%K==0) {
				System.out.println("OK");
				flag = true;
				break;
				
			}	
			
		}	
		if(!flag){
			System.out.println("NG");
		}
      	sc.close();
    }
		
		
}


Measured memory_bytes: 27088
from collections import Counter
from fractions import gcd

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

g = gcd(a,b)

def sosuu(a):
    sosuu_list = set()
    sosuu_list.add(1)
    i = 2
    while 1:
        flag = True
        while a >= i*i:
            if a % i == 0:
                # print(a,i)
                a = a//i
                sosuu_list.add(i)
                flag = False
            else:
                i += 1
        if flag:
            sosuu_list.add(a)
            return sosuu_list
        i += 1

a = sosuu(g)
print(len(a))

Measured memory_bytes: 5056
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b,n;
    string s,s1;
    cin >> s;
    rep(i,3){ if(s[i] == '1') a++; }
    cout << a << endl;
    return 0;
} 

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  vector<int> xs(5);
  for (int i = 0; i < 5; i++) {
    cin >> xs[i];
    if (xs[i] == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3644
X = int(input())
Food = [100,101,102,103,104,105]
dp = [False] * (X+1)
dp[0] = True
for i in range(X+1):
    for f in Food:
        if i - f >= 0:
            #print(i,i-f)
            dp[i] = dp[i - f] | dp[i]
print('1' if dp[X] else '0')


Measured memory_bytes: 41324
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

struct dsu {
	public:
		dsu() : _n(0) {}
		dsu(int n) : _n(n), parent_or_size(n, -1) {}

		int merge(int a, int b) {
			assert(0 <= a && a < _n);
			assert(0 <= b && b < _n);
			int x = leader(a), y = leader(b);
			if (x == y) return x;
			if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
			parent_or_size[x] += parent_or_size[y];
			parent_or_size[y] = x;
			return x;
		}

		bool same(int a, int b) {
			assert(0 <= a && a < _n);
			assert(0 <= b && b < _n);
			return leader(a) == leader(b);
		}

		int leader(int a) {
			assert(0 <= a && a < _n);
			if (parent_or_size[a] < 0) return a;
			return parent_or_size[a] = leader(parent_or_size[a]);
		}

		int size(int a) {
			assert(0 <= a && a < _n);
			return -parent_or_size[leader(a)];
		}

		std::vector<std::vector<int>> groups() {
			std::vector<int> leader_buf(_n), group_size(_n);
			for (int i = 0; i < _n; i++) {
				leader_buf[i] = leader(i);
				group_size[leader_buf[i]]++;
			}
			std::vector<std::vector<int>> result(_n);
			for (int i = 0; i < _n; i++) {
				result[i].reserve(group_size[i]);
			}
			for (int i = 0; i < _n; i++) {
				result[leader_buf[i]].push_back(i);
			}
			result.erase(
				std::remove_if(result.begin(), result.end(),
						   [&](const std::vector<int>& v) { return v.empty(); }),
				result.end());
			return result;
		}

	private:
		int _n;
		// root node: -1 * component size
		// otherwise: parent
		std::vector<int> parent_or_size;
};

int main() {
	int N, Q;
	cin >> N >> Q;
	dsu d(N);
	vector<int> ans;
	for (int i = 0; i < Q; ++i) {
		int t, u, v;
		cin >> t >> u >> v;
		if (t) { ans.emplace_back(d.same(u, v)); }
		else { d.merge(u, v); }
	}
	for (auto v : ans) { cout << v << "\n"; }

	return 0;
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 2e5 + 12;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;



int n, k, a[N];

bool check (int x) {
	int sum = 0;
	for (int i = 1; i <= n; ++i)
		sum += (a[i] + x - 1) / x - 1;

	return sum <= k;
}


main () {
	fastio
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) 
		cin >> a[i];
	
	int l = 1, r = inf, res = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (check(mid)) {
			r = mid - 1;
			res = mid;
		} else
			l = mid + 1;
	}

	cout << res << endl;
}

	

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

static class Program
{
    static IEnumerable<long> Solve(int N, int[] A)
    {
        var dict = new Dictionary<int, int>();
        foreach (int a in A)
        {
            if (!dict.ContainsKey(a)) { dict[a] = 0; }
            ++dict[a];
        }
        long sum = 0;
        foreach (var value in dict.Values)
        {
            sum += Math.BigMul(value, value - 1) / 2;
        }
        var values = new long[N];
        for (int i = 0; i < N; ++i)
        {
            int value = dict[A[i]];
            values[i] = sum - Math.BigMul(value, value - 1) / 2 + Math.BigMul(value - 1, value - 2) / 2;
        }
        return values;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var values = Solve(N, A);
        foreach (var value in values) { Console.WriteLine(value); }
    }
}


Measured memory_bytes: 39840
#include <bits/stdc++.h>
using namespace std;
int N,K,p[1001],x;
int main() {
	cin>>N>>K;
	for(int i=1;i<=N;i++) {
		cin>>p[i];
	}
	sort(p+1,p+N+1);
	for(int i=1;i<=K;i++) {
		x+=p[i];
	}
	cout<<x<<endl;
}


Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0141

"""
import sys
from sys import stdin
input = stdin.readline
from itertools import cycle


def guruguru(n):
    line = 0
    dirs = cycle([(0, -1), (1, 0), (0, 1), (-1, 0)])

    M = [[' '] * n for _ in range(n)]
    cx = 0
    cy = n - 1

    while line < n:
        line += 1
        dx, dy = dirs.__next__()
        while True:
            M[cy][cx] = '#'
            nx = cx + dx
            ny = cy + dy
            nnx = nx + dx
            nny = ny + dy

            if nx < 0 or nx >= n:
                break
            if ny < 0 or ny >= n:
                break
            if nny < 0 or nny >= n or nnx < 0 or nnx >= n:
                pass
            else:
                if M[nny][nnx] != ' ':
                    break
            cx = nx
            cy = ny

    for l in M:
        print(''.join(map(str, l)))


def main(args):
    n = int(input())
    for i in range(n):
        size = int(input())
        guruguru(size)
        if i != (n - 1):
            print()


if __name__ == '__main__':
    main(sys.argv[1:])
    

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

int main()
{
    long long int x, y;
    int count = 0;
    long long int p, q;
    
    cin >> x >> y;
    
    p = x;
    q = 2 * x;

    count = 1;
    
    while(q <= y) {
        count++;
        p = q;
        q = q * 2;
    }
    
    cout << count << "\n";
    
    return 0;
}

Measured memory_bytes: 256
trump = {
        "S": list(range(1,14)),
        "H": list(range(1,14)),
        "C": list(range(1,14)),
        "D": list(range(1,14)),
        }
for i in range(0, int(input())):
    a,b = input().split()
    trump[a].remove(int(b))
for k in ["S","H","C","D"]:
    for e in trump[k]:
        print("{0} {1}".format(k, str(e)))

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

using namespace std;

const int ATOZ = 26;

void Main() {
    int D;
    cin >> D;
    vector<int> c(ATOZ, 0);
    for (int i = 0; i < ATOZ; ++i) {
        cin >> c[i];
    }
    vector<vector<int> > s(D, vector<int>(ATOZ, 0));
    for (int i = 0; i < D; ++i) {
        for (int j = 0; j < ATOZ; ++j) {
            cin >> s[i][j];
        }
    }

    vector<int> t(D, 0);
    for (int i = 0; i < D; ++i) {
        cin >> t[i];
        t[i] -= 1;
    }

    map<int, int> last;
    for (int i = 0; i < ATOZ; ++i) {
        last.insert(make_pair(i, -1));
    }

    vector<int> v(D, 0);
    for (int d = 0; d < D; ++d) {
        v[d] = v[d - 1] + s[d][t[d]];
        last[t[d]] = d;
        for (int i = 0; i < ATOZ; ++i) {
            v[d] -= c[i] * (d - last[i]);
        }
    }

    for (int d = 0; d < D; ++d) {
        cout << v[d] << endl;
    }
}


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


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d)cout << "Yes";
	else if (abs(c - b) <= d && abs(a - b) <= d)cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*
#ifndef ONLINE_JUDGE
    #define cin f
    #define cout g
    ifstream cin("a.in");
    ofstream cout("a.out");
#endif
*/
long long n,w,x,y,dp[1<<17];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>w;
    for(int i=1;i<=n;++i)
    {
        cin>>x>>y;
        for(int j=w-x;j>=0;--j) dp[j+x]=max(dp[j+x],dp[j]+y);
    }
    long long ans=0;
    for(int i=1;i<=w;++i) ans=max(ans,dp[i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024