akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
const int maxn=105;
int n,k,m,a[maxn],sum;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		char a='-',b='1';
		putchar(a);
		putchar(b);
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}

int main()
{
    char ch;
	cin>>ch;
	cout<<(char)((int)ch+1);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,t;
	cin>>n>>t;
	int  x[n+1],c[n+1];
	for(int i=1;i<=n;i++)
	   cin>>c[i]>>x[i];
	int min=10000;
    for(int i=1;i<=n;i++)
       if(x[i]<=t&&c[i]<min)
          min=c[i];
    if(min==10000)
       cout<<"TLE"<<endl;
    else
       cout<<min<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 0;

string s;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
	
	cin >> s;
	if(s == "ABC"){
		cout << "ARC" << '\n';
	}
	else{
		cout << "ABC" << '\n';
	}
}


Measured memory_bytes: 3608
#include<stdio.h>
int main(){
        int a,b,gcd,lcm,x,ch,y;
        int i,j,k;
        while(scanf("%d",&a) != EOF){
                scanf("%d",&b);
                if(a<b){
                        ch=a;
                        a=b;
                        b=ch;
                }
                for(i=1;i<50000;i++){
                        if(a*i%b==0){
                                lcm=a*i;
                                break;
                        }
                }
                for(j=0;j<50000;j++){
                        y=a%b;
                        if(y==0){
                                gcd=b;
                                break;
                        }
                        a=b;
                        b=y;
                }
                printf("%d %d\n",gcd,lcm);
        }
        return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		final String PRINT = "print";
		final String REVERSE = "reverse";
		final String REPLACE = "replace";
		int ord, a, b;
		String str, ordstr, repordstr, cutstr;
		
		str = scan.next();
		ord = scan.nextInt();
		
		for (int i = 0; i < ord; i++) {
			ordstr = scan.next();
			a = scan.nextInt();
			b = scan.nextInt() + 1;
			StringBuilder  newstr = new StringBuilder(str);
			cutstr = str.substring(a, b);
			
			switch (ordstr) {
			case PRINT:	
				System.out.println(cutstr);
				break;
			case REVERSE:
				StringBuffer revordstr = new StringBuffer(cutstr);
				str = newstr.replace(a, b,  revordstr.reverse().toString()).substring(0, newstr.length());
				break;
			case REPLACE:
				repordstr = scan.next();
				str = newstr.replace(a, b, repordstr).substring(0, newstr.length());
				break;
			default:
				break;
			}
			
		}
		
		scan.close();
	}
}


Measured memory_bytes: 29684
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
  double x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  cout<<fixed<<sqrt(pow(x1-x2,2)+pow(y1-y2,2))<<endl;
}

Measured memory_bytes: 3284
N, A, B, C = map(int,input().split())
l = [int(input()) for x in range(N)]
V = [0 for x in range(N)]
ans = 0
minv = float("INF")

def calc(v, trees):
    global minv
    for j, val in enumerate(v):
        trees[val] += l[j]

    if 0 in trees[:3]:
        return float("INF")

    work = abs(trees[0] - A) +  ((v.count(0) - 1) * 10 if v.count(0) > 1 else 0)
    work += abs(trees[1] - B) + ((v.count(1) - 1) * 10 if v.count(1) > 1 else 0)
    work += abs(trees[2] - C) + ((v.count(2) - 1) * 10 if v.count(2) > 1 else 0)
    return work

def dfs(depth, v):
    global minv
    if depth == N:
        w = calc(v, [0, 0, 0, 0])
        if w < minv:
            minv = min(w, minv)
        return

    for i in range(4):
        v[depth] = i
        dfs(depth + 1, v)

dfs(0,V)
print(minv)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var wtr = bufio.NewWriter(os.Stdout)
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	var a, b, c int
	if scanner.Scan() {
		str := scanner.Text()
		cols := strings.Split(str, " ")
		a, _ = strconv.Atoi(cols[0])
		b, _ = strconv.Atoi(cols[1])
		c, _ = strconv.Atoi(cols[0] + cols[1])
	}
	_ = a
	_ = b
	max := 100 * 100
	ans := "No"
	for i := 1; i < max; i++ {
		t := i * i
		if t == c {
			ans = "Yes"
			break
		}
		if t > c {
			break
		}
	}

	fmt.Fprintln(wtr, ans)
	_ = wtr.Flush()
}


Measured memory_bytes: 640
import math
import fractions

n, k = map(int, input().split())
d = [i for i in input().split()]
i = n
while 1:
    flag = 1
    for j in d:
        if j in str(i):
            i += 1
            flag = 0
            break
    if flag:
        print(i)
        break


Measured memory_bytes: 5432
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define re(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
int n;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    cin>>n;
    if(n<10){
        cout<<n<<endl;
    }
    else if(n<100){
        cout<<9<<endl;
    }
    else if(n<1000){
        cout<<n-100+1+9<<endl;
    }
    else if(n<10000){
        cout<<909<<endl;
    }
    else if(n<100000){
        cout<<n-10000+1+909<<endl;
    }
    else{
        cout<<90909<<endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
int l=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int d=sc.nextInt();
int ja=a/c; if(a%c!=0)ja++;
int ma=b/d;if(b%d!=0)ma++;
System.out.println(l-Math.max(ma, ja));
}
}

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

struct Dice{
  vector<int> v;
  Dice():v(6,0){
  }
};

int EW[4]={0,2,5,4};
int NS[4]={0,1,5,3};

Dice rotate(int dir,Dice& x){
  Dice res;
  for(int i=0;i<6;i++) res.v[i]=x.v[i];
  switch(dir){
  case 0:
    for(int i=0;i<4;i++){
      res.v[EW[i]]=x.v[EW[(i+3)%4]];
    }
    break;
  case 1:
    for(int i=0;i<4;i++){
      res.v[NS[i]]=x.v[NS[(i+3)%4]];
    }
    break;
  case 2:
    for(int i=0;i<4;i++){
      res.v[NS[i]]=x.v[NS[(i+1)%4]];
    }

    break;
  case 3:
    for(int i=0;i<4;i++){
      res.v[EW[i]]=x.v[EW[(i+1)%4]];
    }
    break;
  };
  res.v[5]++;
  return res;
}

string dirstr[4]={"E","N","S","W"};
int t[6];


bool check(Dice x){
  vector<int> perm(6);
    iota(perm.begin(),perm.end(),0);
  do{
    bool isok=true;
    vector<int> buf(6);
    int ma=0;
    int inde=0;
    int sum=0;
    for(int i=0;i<6;i++){
      buf[i]=t[perm[i]]-x.v[i];
      sum+=buf[i];
      if(ma>=buf[i]){
	if(i!=5 || ma>buf[i]){
	   ma=buf[i];
	   inde=i;
	}
      }
      if(buf[i]<0) isok=false;
    }

    if(!isok) continue;
    isok&=(buf[0]+buf[5]<=buf[1]+buf[2]+buf[3]+buf[4]);
    isok&=(buf[1]+buf[3]<=buf[0]+buf[2]+buf[5]+buf[4]+1);
    isok&=(buf[2]+buf[4]<=buf[0]+buf[1]+buf[5]+buf[3]+1);
    if(isok){
      return true;
    }
  }while(next_permutation(perm.begin(),perm.end()));
  
  return false;
}

int main(){
  ios_base::sync_with_stdio(false);
  while(true){
    int sum=0;
    for(int i=0;i<6;i++){
      cin>>t[i];
      sum+=t[i];
    }
    if(sum==0) break;
    int p,q;
    cin>>p>>q;
    p--;
    string res;
    bool isok=true;

    Dice x;
    while(sum && isok){
      for(int i=0;i<=4;i++){
	if(i==4){
	  isok=false;
	  break;
	}
	Dice y=rotate(i,x);





	if(check(y)){
	  sum--;
	  x=y;
	  res+=dirstr[i];
	  break;
	}
      }
    }
    if(isok){
      for(int i=p;i<q;i++){
	cout<<res[i];
      }
      cout<<"\n";
    }
    else{
      cout<<"impossible\n";
    }

  }
  return 0;
}


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

int main() {
  int N;
  cin>>N;
  
  vector<int> h(N);
  for(int i=0;i<N;++i){
    cin>>h[i];
  }
  
  int count=0;
  
  for(int i=1;i<N;++i){
    int x=0;
    for(int j=0;j<i;++j){
      x=max(x,h[j]);
    }
    if(x<=h[i])
      ++count;
  }
  
  cout<<count+1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <limits>
#define int long long

signed main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, k;
  std::cin >> n >> k;
  std::vector<int> pts(n), positive(n);
  for (int i = 0; i < n; i++) {
    std::cin >> pts[i];
    positive[i] = std::max(0ll, pts[i]);
  }
  std::vector<int> accum = {0}, pos_accum = {0};
  std::partial_sum(std::begin(pts), std::end(pts), std::back_inserter(accum));
  std::partial_sum(std::begin(positive), std::end(positive), std::back_inserter(pos_accum));
  int result = std::numeric_limits<int>::min() / 2;
  for (int i = 0; i < n - k + 1; i++) {
    int range_sum = accum[i + k] - accum[i],
        other_sum = pos_accum[n] - pos_accum[i + k] + pos_accum[i];
    result = std::max({result, range_sum + other_sum, other_sum});
  }
  std::cout << result << std::endl;
}


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



int main(void){
    int n;
    cin >> n;
    vector<int>l;
    rep(i,n){
        int x;
        cin >> x;
        l.push_back(x);
    }
    int check = 0;
    sort(l.begin(), l.end(),greater<int>());
    for(int i=1;i<l.size();i++){
        check += l[i];
    }
    if(l[0] >= check){
        cout << "No";
    }
    else{
        cout << "Yes";
    }
    
    
    
    
    return 0;
}













































Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

int a[2][2] = {{0,1},{2,3}};

void mainmain(){
	int H,W,d;
	cin>>H>>W>>d;
	// assert(d%2);
	if(d%2){
		vvint vv;
		initvv(vv, H, W);
		rep(i,H){
			rep(j,W){
				int x = i;
				int y = j;
				vv[i][j] = a[x%2][y%2];
				// cout<<vv[i][j]<<" ";
			}
		}
		// cout<<endl;
		rep(i,H){
			rep(j,W){
				cout<<"RYGB"[vv[i][j]];
			}
			cout<<endl;
		}
	}
	else{
		rep(i,H){
			rep(j,W){
				int x = i+j;
				int y = i-j+W;
				cout<<"RYGB"[a[(x/d)%2][(y/d)%2]];
				// if(d%4==2) cout<<"RYGB"[(2*H-2*i+j)%4];
				// else cout<<"RYGB"[(H-i+j)%4];
			}
			cout<<endl;
		}
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 1536
import itertools

n, m = map(int, input().split())
d = []
for _ in range(m):
    a, b, c = map(int, input().split())
    d.append((a - 1, b - 1, c))

wf = [[float('inf')] * n for _ in range(n)]
for a, b, c in d:
    wf[a][b] = wf[b][a] = c
for i in range(n):
    wf[i][i] = 0

for k, i, j in itertools.product(range(n), repeat=3):
    wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])

ans = 0
for a, b, c in d:
    used = False
    for i in range(n):
        for j in range(i + 1, n):
            if wf[i][a] + c + wf[b][j] == wf[i][j] \
                    or wf[i][b] + c + wf[a][j] == wf[i][j] \
                    or wf[j][a] + c + wf[b][i] == wf[j][i] \
                    or wf[j][b] + c + wf[a][i] == wf[j][i]:
                used = True
            
    if not used:
        ans += 1

print(ans)


Measured memory_bytes: 51164
s=input()
x,y=map(int,input().split())
#s='FT'*4
#x,y=2,2
if 'T' not in s:
  if len(s)==x and y==0:
    print('Yes')
  else:
    print('No')
else:
  move=s.split('T')
  xmove=[len(move[2*i+2]) for i in range((len(move)-1)//2)]
  ymove=[len(move[2*i+1]) for i in range(len(move)//2)]
  import numpy as np
  # 8000を0とする
  ablex=np.full(16001,False)
  abley=np.full(16001,False)
  ablex[8000+len(move[0])]=True
  abley[8000]=True
  for xi in xmove:
    if xi==0:continue
    ax=np.full(16001,False)
    ax[xi:]+=ablex[:-xi]
    ax[:-xi]+=ablex[xi:]
    ablex=ax
  for yi in ymove:
    if yi==0:continue
    ay=np.full(16001,False)
    ay[yi:]+=abley[:-yi]
    ay[:-yi]+=abley[yi:]
    abley=ay
  if ablex[8000+x] and abley[8000+y]:
    print('Yes')
  else:
    print('No')
  #print(ablex[8000:8005])
  #print(abley[8000:8005])

Measured memory_bytes: 27424
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,X[100],M,A[100];
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>X[i];
    }
    cin>>M;
    for(int i=0;i<M;i++){
        cin>>A[i];
    }
    for(int i=0;i<M;i++)
    if(X[A[i]-1]+1==X[A[i]]||X[A[i]-1]==2019){
        
    }else{
        X[A[i]-1]++;
    }
    for(int i=0;i<N;i++){
        cout<<X[i]<<endl;
    }
}




Measured memory_bytes: 3092
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
 
(defvar *n* (read))
(defvar *hi* (make-array *n*))
 
;dp[i]→i番目にたどり着くための最小コスト
(defvar *dp* (make-array *n* :initial-element nil))
 
(dotimes (i *n*)
         (setf (aref *hi* i) (read)))
 
(defun cost (now delta)
   (abs (- (aref *hi* now) (aref *hi* (- now delta)))))
 
;dpテーブル初期化
(setf (aref *dp* 0) 0)
(setf (aref *dp* 1) (cost 1 1))
 
(defun ans (i)
  (cond
    ((aref *dp* i) (aref *dp* i))
    (t (setf (aref *dp* i) (min
                            (+ (ans (- i 1)) (cost i 1))
                            (+ (ans (- i 2)) (cost i 2))
                            )))))
                                         
 
(print (ans (1- *n*)))

Measured memory_bytes: 68540
#include <iostream>
#include <functional>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <array>
#include <memory>
#include <set>

using namespace std;

#define Get(ty,...) ty __VA_ARGS__;cins(__VA_ARGS__);
#define GetArray(ty,v,n) vector<ty> v(n);cin_arr(v,n);
#define ci cin
#define co cout
#define en endl;
#define Arr(f, arr,pred) f(arr.begin(),arr.end(),pred)
#define Arr2(f, arr) f(arr.begin(),arr.end())
#define ArrExpr(f, arr,expr) f(arr.begin(),arr.end(),[](auto x){return expr;})
#define Acc(init,arr,pred) accumulate(arr.begin(),arr.end(),init,pred)

void cins(){}

template<class Head,class... Tail>
void cins(Head& head,Tail&... tail) {
	cin >> head;
	cins(tail...);
}

template<class Arr>
void cin_arr(Arr& v,int n) {
	for (int i = 0; i < n; i++)
		cin >> v[i];
}

bool canMove(int tDelta, int x1, int y1 ,int x2, int y2) {
	int a = abs((x1 - x2)) + abs((y1 - y2));
	if (a > tDelta)return false;
	if ((tDelta - a) % 2 == 0)return true;
	return false;
}

int main() {
	Get(int, n);
	int bt = 0;
	int bx = 0;
	int by = 0;
	while (n-- != 0)
	{
		Get(int, t, x, y);
		if (canMove(t - bt, bx, by, x, y) == false) {
			co << "No" << en;
			return 0;
		}
		bx = x;
		by = y;
		bt = t;
	}
	co << "Yes" << en;

}




Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(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 all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){ 
  int n, m;
  cin >> n >> m;
  priority_queue<ll> s;
  forn(i,n){
    ll a;
    cin >> a;
    s.push(a);
  }
  while (m--){
    ll x = s.top();
    s.pop();
    s.push(x/2);
  }
  ll ans = 0;
  while (!s.empty()){
    auto e = s.top();
    s.pop();
    ans += (ll) e;
  }
  cout << ans << endl;

}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 



*/

Measured memory_bytes: 1400
//
//AtCoder Beginner Contest 131
//A - Security
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    string ans = "Good";
    REP(i, s.size()-1){
        if (s[i] == s[i+1]) {
            ans = "Bad";
            break;
        }

    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;


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;}
ll h,w;
vector<vector<char>> a;

ll dx[4]={-1,1,0,0};
ll dy[4]={0,0,-1,1};

bool dfs(ll i,ll j){
    if(i==-1 && j==-1) return false;
    if(a[i][j]=='.') return false;
    ll cnt=0;
    pll pos;
    pos.fi=-1;
    pos.se=-1;
    rep(k,4){
        ll nx=i+dx[k];
        ll ny=j+dy[k];
        
        if(0<=nx && nx<=h-1 && 0<=ny && ny<=w-1 && a[nx][ny]=='#'){
            if(dx[k]==-1 || dy[k]==-1){
                return false;
            }
            cnt++;
            pos.fi=nx;
            pos.se=ny;
        }
        
    }
    if(i==h-1 && j==w-1 && a[i][j]=='#') return true;
    if(cnt==2) return false;
    a[i][j]='.';
    return dfs(pos.fi,pos.se);
}

const ll INF=1e9+7;

int main(){
    
    cin >> h >> w;
    a=vector<vector<char>>(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }
    if(dfs(0LL,0LL)){
        cout << "Possible" << endl;
    }
    else{
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;
import java.io.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main {
	static int[][] dp;
	static int[] p;

	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();

    int[] c = new int[m+1];
    int[][] dp = new int[m+1][n+1];

    for (int i = 1; i <= m; i++) {
      c[i] = sc.nextInt();
    }
    sc.close();

    for (int i = 0; i <= m; i++) {
      dp[i][0] = 0;
    }
    for (int j = 1; j <= n; j++) {
      dp[0][j] = 1000000;
    }

    for (int i = 1; i <= m; i++) {
      dp[i][0] = 0;
      for (int j = 0; j <= n; j++) {
        if(j-c[i] >= 0) dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1);
        else dp[i][j] = dp[i-1][j];
      }
    }

    out.println(dp[m][n]);
	}

}


Measured memory_bytes: 31124
n,m = map(int, input().split())
lst = [[] for i in range(m)]
for i in range(m):
    pi,si = map(str, input().split())
    lst[i] = (int(pi),si)

ac = 0
wa = 0
status = [0 for i in range(n)]

for i in lst:
    if status[i[0]-1]!="AC" and i[1]=="AC":
        ac += 1
        wa += status[i[0]-1]
        status[i[0]-1] = "AC"
    elif status[i[0]-1]!="AC" and i[1]=="WA":
        status[i[0]-1] += 1

print(ac,wa)


Measured memory_bytes: 19720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int a = in.nextInt();
        int b = in.nextInt();

        if (b == 1) {
            out.println(0);
        } else {
            int sockets = a;
            int strips = 1;

            while (sockets < b) {
                sockets = (sockets + a - 1);
                strips++;
            }
            out.println(strips);
        }
    }
}


Measured memory_bytes: 21332
use proconio::fastout;
use whiteread::parse_line;

fn helper(a: &[usize], k: usize, max_length: usize) -> bool {
    let mut cut_num = 0;
    for l in a {
        cut_num += (l - 1) / max_length;
    }

    cut_num <= k
}

#[fastout]
fn main() {
    let (_, k): (usize, usize) = parse_line().unwrap();
    let a: Vec<usize> = parse_line().unwrap();

    let mut left = 0;
    let mut right = 1_000_000_000;
    while left + 1 != right {
        let mid = (left + right + 1) / 2;
        if helper(&a, k, mid) {
            right = mid;
        } else {
            left = mid;
        }
    }

    println!("{}", right);
}


Measured memory_bytes: 5684
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <iomanip>

#define rep(i,a,b) for(long long i=a;i<b;i++)

using namespace std;


int main(void) {

	long long N = 0, D = 0;
		
	cin >> D >> N;
	


	if(N==100 && D==2)
		cout << 1010000 << endl;
	else if (N == 100 && D == 1)
		cout << 10100 << endl;
	else if (N == 100 && D == 0)
		cout << 101 << endl;
	else {
		cout << N*pow(100, D) << endl;
	}
	


	return 0;

}

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

using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;

template<typename C>
i64 Size(const C &c) { return static_cast<i64>(c.size()); }

template<typename C>
void Sort(C &c) { std::sort(c.begin(), c.end()); }

template<typename C>
void SortR(C &c) { std::sort(c.rbegin(), c.rend()); }

template<typename T, typename U, typename Comp=std::less<>>
bool ChMax(T &x_max, const U &x, Comp comp={}) {
  if(comp(x_max, x)) {
    x_max = x;
    return true;
  }
  return false;
}

template<typename T, typename U, typename Comp=std::less<>>
bool ChMin(T &x_min, const U &x, Comp comp={}) {
  if(comp(x, x_min)) {
    x_min = x;
    return true;
  }
  return false;
}

struct ProconInit {
  static constexpr int IOS_PREC = 15;
  static constexpr bool AUTOFLUSH = false;

  ProconInit() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(IOS_PREC);
    if (AUTOFLUSH) std::cout << std::unitbuf;
  }
} PROCON_INIT;

void solve() {
  i64 n; std::cin >> n;
  i64 m; std::cin >> m;
  std::vector<i64> a(n); for (auto &i : a) std::cin >> i;

  i64 sum = 0;
  for (auto &i : a) {
    sum += i;
  }

  f80 th = static_cast<f80>(sum) / static_cast<f80>(4 * m);

  i64 count = 0;
  for (auto &i : a) {
    if (static_cast<f80>(i) < th) continue;
    count++;
  }

  std::cout << ((count >= m) ? "Yes" : "No") << "\n";
}

signed main() {
  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>

#define M 1000000007

using namespace std;

int main(void) {
  int n, m, *s;
  int a;
  
  cin >> n >> m;
  s = new int[n+1];
  s[0] = s[1] = 1;
  for (int i = 0; i < m; i++) {
    cin >> a;
    s[a] = -1;
  }
  
  for (int i = 2; i <= n; i++) {
    if (s[i] < 0) continue;
    s[i] = ((s[i - 1] < 0 ? 0 : s[i - 1]) + (s[i - 2] < 0 ? 0 : s[i - 2])) % M;
    //cout << i << " :" << s[i] << endl;
  }
  
  cout << (s[n] < 0 ? 0 : s[n]) << endl;
  
  return 0;
}
  

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }
const int maxn = 1e6 + 10;
vi pos[maxn];
int a[maxn], pnt[maxn], aft[maxn];
int nxt[45][maxn];
vi vec;
map<int,int> cnt;
void add(int x){
	if(cnt[x]){
		while(vec.size()){
			int y = vec.back();
			cnt[y]--;
			vec.pop_back();
			if(y == x)
				break;
		}
	}
	else{
		cnt[x]++;
		vec.push_back(x);
	}
}
int32_t main(){
	IOS;
	int n;
	ll m;
	cin >> n >> m;
	ll mb = m;
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<n; i++)
		a[i + n] = a[i];
	n *= 2;
	for(int i=0; i<n; i++)
		pos[a[i]].push_back(i);
	for(int i=0; i<n; i++){
		int x = a[i];
		int cur = pnt[x];
		if(cur+1 == pos[x].size())
			aft[i] = pos[x][0] + 1;
		else
			aft[i] = pos[x][cur + 1] + 1;
		aft[i] %= n;
		pnt[x]++;
	}
	for(int i=n-1; i>=0; i--){
		if(aft[i] > i)
			nxt[0][i] = nxt[0][aft[i]];
		else
			nxt[0][i] = aft[i];
	}
	for(int i=1; i<45; i++)
		for(int j=0; j<n; j++)
			nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
	if(m <= 4){
		for(int i=0; i<m; i++){
			for(int j=0; j<n/2; j++){
				add(a[j]);
			}
		}
	}
	else{
		bool have = 0;
		if(m & 1)
			have = 1;
		m >>= 1;
		m--;
		int cur = 0;
		for(int i=0; i<45; i++){
			if(m & (1LL<<i))
				cur = nxt[i][cur];
		}
		add(a[cur]);
		for(int i=cur+1; i<n; i++)
			add(a[i]);
		for(int i=0; i<n/2 && have; i++)
			add(a[i]);
	}
	for(auto i : vec)
		cout << i << " ";
	cout << endl;
}

Measured memory_bytes: 216052
#include <iostream>
#include <vector>
#include <utility>
#include <tuple>
#include <queue>
using namespace std;

struct road {
  int to, len, max_v;
  road(int to, int len, int max_v) : to(to), len(len), max_v(max_v) {}
};

int main(){
  int n, m;
  while(cin >> n >> m, n){
    int s, g;
    cin >> s >> g;
    --s,--g;
    vector<vector<road>> G(n);
    for(int i = 0; i < m; ++i){
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      --x,--y;
      G[x].emplace_back(y,d,c);
      G[y].emplace_back(x,d,c);
    }
    const double INF = 1e9;
    vector<vector<vector<double>>> T(n,vector<vector<double>>(n,vector<double>(31,INF)));
    priority_queue<tuple<double,int,int,int>> Q;
    Q.emplace(0,s,s,0);
    while(Q.size()){
      double t;
      int cur, from, v;
      tie(t,cur,from,v) = Q.top();
      t *= -1;
      Q.pop();
      if(T[cur][from][v] < t) continue;
      T[cur][from][v] = t;
      for(auto e : G[cur]){
        if(e.to == from) continue;
        for(int dv = -1; dv < 2; ++dv){
          int v_ = v+dv;
          if(v_ <= 0) continue;
          if(v_ > e.max_v) break;
          double t_ = t + (double)e.len/v_;
          if(T[e.to][cur][v_] > t_){
            T[e.to][cur][v_] = t_;
            Q.emplace(-t_,e.to,cur,v_);
          }
        }
      }
    }
    double ans = INF;
    for(int i = 0; i < n; ++i){
      ans = min(ans,T[g][i][1]);
    }
    if(ans >= INF) puts("unreachable");
    else printf("%.12lf\n",ans);
  }
}



Measured memory_bytes: 3888
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <queue>

using namespace std;

struct State {
  int x, y, t;
  State(int x, int y, int t): x(x), y(y), t(t) {;};
};

const int OFFSET = 200;
const int dx[6] = {0, 1, 1, 0, -1, -1},
          dy[6] = {1, 1, 0, -1, -1, 0};

int field[1000][1000];
int T, N;

void Solve(int sx, int sy)
{
  bool visit[1000][1000];
  memset(visit, false, sizeof(visit));
  
  queue<State> que;
  que.push(State(sx, sy, T)); 
  int res = 0;
  while (!que.empty()) {
    State s = que.front(); que.pop();
    int x = s.x, y = s.y, t = s.t;
    if (t < 0 || field[y + OFFSET][x + OFFSET] == 1 || visit[y + OFFSET][x + OFFSET])
      continue;
    
    visit[y + OFFSET][x + OFFSET] = true;
    res++;
    for (int k = 0; k < 6; k++) 
      que.push(State(x + dx[k], y + dy[k], t - 1));
  }
  cout << res << endl;
}

int main()
{
  while (cin >> T >> N && !(T == 0 && N == 0)) {
    memset(field, 0, sizeof(field));
    int x, y, sx, sy;
    for (int i = 0; i < N; i++) {
      cin >> x >> y;
      field[y + OFFSET][x + OFFSET] = 1;
    }
    cin >> sx >> sy;
    Solve(sx, sy);
  }
}

Measured memory_bytes: 5812
#include "bits/stdc++.h"
using namespace std;
#include "atcoder/all"
using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;


using mint = modint998244353;

vector<mint>one(200020, 1), ten(200020, 1);

// モノイドの型S
struct S {
	mint val;
	int size;
};

// S × S -> S を計算する関数
S op(S l, S r) {
	mint ret = l.val * ten[r.size] + r.val;
	return S{ret, l.size + r.size};
}

// e を返す関数
S e() {
	return S{0, 0};
}

// 写像の型
struct F{
	int val;
};

// f(x) を返す関数
S mapping(F l, S r) {
	if(l.val == INF) return r;
	mint ret = one[r.size] * l.val;
	return S{ret, r.size};
}


// f ○ g を返す関数(f(g(x)))
// lの方が後の操作であることに注意
F composition(F l, F r) {
	if(l.val == INF) return r;
	return l;
}

// 恒等写像 id(x) = x
F id() {
	return F{INF};
}

// lazy_segtree<S, op, e, F, mapping, composition, id>seg();

signed main(){
	int N, Q;
	cin >> N >> Q;
	FOR(i, 1, 200019) {
		one[i + 1] = one[i] * 10 + 1;
	}
	REP(i, 200019) {
		ten[i + 1] *= ten[i] * 10;
	}
	lazy_segtree<S, op, e, F, mapping, composition, id>seg(200020);
	REP(i, N) seg.set(i, S{(mint)1, 1});
	REP(i, Q) {
		int l, r, d;
		cin >> l >> r >> d;
		--l;
		seg.apply(l, r, F{d});
		out(seg.prod(0, N).val.val());
	}
}


Measured memory_bytes: 18340
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  k = min(k, n);
  int ans = x * k + y * (n - k);
  cout << ans << endl;
  return(0);
}


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

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = 1; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				int x = 10001 * i + j * 1010 + k * 100;
				if ( a <= x && x <= b ) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n,a,sum=0;
    cin >>n>>a;
    for (int i=0;i<a;i++){
        int e;
        cin >> e;
        sum = sum+e;
    }
  if(sum >= n){
    cout << "Yes";
  }else{
  cout << "No";
  }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

//#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

bool is_prime(int n){
    bool res = true;

    if(n==0) res =  false;
    else if(n == 1) res =  false;

    else{
        for(int i = 2; i*i <= n;i++){
            if(n%i == 0){
                res = false;
                break;
            }
        }
    }

    return res;
}


//Ｎが2017に似た数か判定
bool nita(int n){
    bool res;

    if(n%2 == 0) res = false;
    else if(is_prime(n) && is_prime((n+1)/2) ) res = true;
    else res = false;

    return res;
}


const int MAX_N = 100010;

//0~100000の数が　2017に似た数 かを収納
bool a[MAX_N];

//0~nまでに 2017に似た数　がいくつあるのかをcount
int cnt[MAX_N];

int main(){
    int q; cin >> q;

    rep(i, MAX_N) a[i] = nita(i);
    rep(i, MAX_N) cnt[i+1] = cnt[i] + a[i];


    rep(i, q){
        int l, r; cin >> l >> r;

        cout << cnt[r+1]-cnt[l] << endl;
    }
}

Measured memory_bytes: 1152
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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


int main(){
  ll a,b; cin >> a >> b;
  
  ll pera = a % 4;
  ll perb = (b+1) % 4;
  
  if(pera == 0) a = 0;
  else if(pera == 1) a--;
  else if(pera == 2) a = 1;
  
  if(perb == 0) b = 0;
  else if(perb == 2) b = 1;
  else if(perb == 3) b++;
  
  cout << (a^b) << endl;
  
  
}

Measured memory_bytes: 3608
class UnionFind:
    def __init__(self,n):
        super().__init__()
        self.par = [-1]*n
        self.rank = [0]*n
        self.tsize = [1]*n
    
    def root(self,x):
        if self.par[x] == -1:
            return x 
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x_r = self.root(x)
        y_r = self.root(y)
        
        if self.rank[x_r]>self.rank[y_r]:
            self.par[y_r] = x_r

        elif self.rank[x_r]<self.rank[y_r]:
            self.par[x_r] = y_r

        elif x_r != y_r:
            self.par[y_r] = x_r
            self.rank[x_r] += 1

        if x_r != y_r:
            size = self.tsize[x_r]+self.tsize[y_r]
            self.tsize[x_r] = size
            self.tsize[y_r] = size

    def isSame(self,x,y):
        return self.root(x) == self.root(y)

    def size(self,x):
        return self.tsize[self.root(x)]

def main():

    n= int(input())
    uf = UnionFind(2*(n+1))
    
    for _ in range(n-1):
      x,y,w = tuple([int(t)for t in input().split()])
      if w%2==0:
        uf.unite(2*x,2*y)
        uf.unite(2*x+1,2*y+1)
      else:
        uf.unite(2*x+1,2*y)
        uf.unite(2*x,2*y+1)

    w = uf.root(2)

    for i in range(1,n+1):
      if w == uf.root(2*i):
        print(1)
      else:
        print(0)

if __name__ == "__main__":
    main()

Measured memory_bytes: 15088
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1<<25

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef long long ll;

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}
int N,W;
int w[1001],v[1001];
int dp[101][10001];
int dfs(int i,int j){//pos,weight /value
	if(i>=N)return 0;
	if(dp[i][j]!=-1)return dp[i][j];
	int ret;
	if(w[i]>(W-j))ret = dfs(i+1,j);
	else {
		ret = max(dfs(i+1,j),dfs(i+1,j+w[i])+v[i]);
	}
	return dp[i][j]=ret;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>N>>W;
	rep(i,N)cin>>v[i]>>w[i];
	memset(dp,-1,sizeof(dp));
	P(dfs(0,0));

	return 0;
}

Measured memory_bytes: 7156
// doot diddly donger cuckerino Hahahahahah

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

// @formatter:off
#define F               first
#define S               second
#define all(x)          (x).begin(), (x).end()
#define sz(x)           (long long) (x).size()
#define sim             template<typename T
#define ris             return *this
#define dor             > debug & operator <<
#define eni(x)          sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim> struct rge { T b, e; };
sim> rge<T> rang(T i, T j) { return rge<T>{i, j}; }
sim> auto dud(T *x) -> decltype(cerr << *x, 0);
sim> char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) { cerr << boolalpha << i; ris; }
  eni(==) { ris << rang(all(i)); }
  sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
  sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vb = vector<bool>;

using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template<typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template<typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
template <typename T> T rand(T x, T y) { return rand() % (y - x + 1) + x; }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T, typename U>
std::ostream& operator<<(std::ostream& stream, const pair<T, U>& p) {
  return stream << p.first << " " << p.second;
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const vector<T>& vec) {
  for (const T& x: vec) out << x << ' ';
  return out;
}
template <typename T>
std::istream& operator>>(std::istream& in, vector<T>& vec) {
  for(auto& x: vec) in >> x;
  return in;
}
// @formatter:on


class ANot {
public:

  void solve(std::istream& cin, std::ostream& cout) {
    int x;
    cin >> x;
    cout << (x == 0) << endl;
  }
};

int32_t main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	ANot solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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


using namespace std;
const int maxn = 2e5 + 10;


double deal(int x)
{
	int cnt = 0;
	for(int i = 1 ; i <= x;i++) cnt += i;
	return (cnt * 1.0) / x * 1.0;
}

int main()
{
	int n,k;cin >> n >> k;int a[maxn];int date[maxn];
	int sum = 0;
	for(int i = 1; i <= n ; i++){
		cin >> a[i];sum += a[i];date[i] = sum;
	}
	int ans = date[k];int X = k;
	for(int i = k + 1 ; i <= n ; i++){
		int cur = date[i] - date[i - k];
		if(cur > ans){
			ans = cur;X = i;
		}
	}
	double res = 0;
	for(int i = X - k + 1;i <= X ;i++){
		res += deal(a[i]);
	}
	printf("%.7f\n",res);
}

Measured memory_bytes: 1792
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <bits/stdc++.h>

using namespace std;
int fun(int a[],int n,int k)
{
    int dp[n];
    for(int i=0;i<n;i++)
    {
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {
            if(j<n)
            {
                dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
            }
        }
        
    }
    return dp[n-1];
}
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
cout<<fun(a,n,k)<<endl;
    return 0;
}


Measured memory_bytes: 4400