akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int maxN = 510;
const char ch[8] = "RYGB";

int h, w;
char str[maxN][maxN];

inline void mark(int x, int y, int k){
	if(0 <= x && x < h && 0 <= y && y < w)
	if(!str[x][y])
		str[x][y] = ch[k];
}

int main (){
	int d, i, j;
	//freopen("out.txt", "w", stdout);
	scanf("%d%d%d", &h, &w, &d);
	if(d & 1){
		for(i = 0; i < h; ++i){
			for(j = 0; j < w; ++j)
				printf("%c", ch[(i + j) & 1]);
			puts("");
		}
	}
	else{
		if(d & 2){
			for(i = 0; i < h; ++i){
				for(j = 0; j < w; ++j)
					printf("%c", ch[((i & 3) + (j & 2)) & 3]);
				puts("");
			}
		}
		else{
			int s, t, p, q, k, dm = d / 2;
			for(p = -1; p <= max(1, h / dm + 1); ++p){
			for(q = -1; q <= max(1, w / dm + 1); ++q){
				s = p * dm, t = q * d;
				if(p & 1) t += dm;
				k = (p & 1) + ((p / 2 + q) & 1) * 2;
				for(i = 0; i < dm; ++i){
					for(j = 0; j < dm - i; ++j){
						mark(s + i, t + dm - j - 1, k);
						mark(s + i, t + dm + j, k);
						mark(s - i, t + dm - j - 1, k);
						mark(s - i, t + dm + j, k);
					}
				}
			}}
			for(i = 0; i < h; ++i){
				for(j = 0; j < w; ++j){
if(!str[i][j]) assert(0);
					printf("%c", str[i][j]);
}
				puts("");
			}
		}
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int a[200000];
    set<int> s;
    for(int i=0;i<n;i++) {
        cin >> a[i];
        int b = a[i];
        s.insert(b);
    }
    if(s.size()==n)
    {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 10368
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    x = I()
    ans = x//11*2
    num = x%11
    if num==0:
        pass
    elif num<=6:
        ans += 1
    else:
        ans += 2

    print(ans)
main()


Measured memory_bytes: 74540
#include <iostream>
#include <cstdio>
using namespace std;
int n,c[100005],ans,x;
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        if(c[a]==0)ans++;
        else x++;
        c[a]++;
    }
    if(x%2)ans--;
    printf("%d\n",ans);
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();
        String s = sc.next();
        int count = 0;
        for (int i = 0; i < 1000; i++) {
            int[] c = new int[] { i / 100, (i / 10) % 10, i % 10 };
            int f = 0;
            for (int j = 0; j < n; j++) {
                if ((s.charAt(j) + "").equals(("" + c[f]))) {
                    f++;
                }
                if (f == 3) {
                    break;
                }
            }
            if (f == 3) {
                count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 345696
h,w = map(int,input().split())
data_t = []
for _ in range(h):
    list_ = str(input())
    data_t.append(list_)

data = []
for i in range(h):
    data.append([])
    for  j in range(w):
        data[i].append(data_t[i][j])
    
for i in range(h):
    contw=True
    line = ""
    for j in range(w):
        c = data[i][j]
        if c == "#":
            contw = False
            line+="#"
        elif c == ".":
            pre = True
            for k in range(h):
                if data[k][j] == "#":
                    pre = False
            if pre == True:
                for k in range(h):
                    data[k][j] = "_"
            else:
                line+="."
    if contw == False:
        print(line)

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

int main()
{
  int sum = 1;
  int N, K;
  cin >> N >> K;

  for (int i = 0; N > i; i++){
    if (K > sum){
      sum *= 2;
    } else {
      sum += K;
    }
  }
  cout << sum << endl;
}

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

ll mod = 1e9+7;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

vector<ll> fact;
vector<ll> invfact;

void set_fact(int n){
    fact.resize(n+1, 1);
    invfact.resize(n+1, 1);
    for (int i = 2; i <= n; i++) {
        fact[i] = fact[i-1] * i % mod;
    }
    invfact[n] = modinv(fact[n]);
    for (int i = n-1; i >= 2; i--) {
        invfact[i] = invfact[i+1] * (i+1) % mod;
    }
    return;
}

ll comb(int n, int k) {
    if (k > n || k < 0) return 0;
    if (k == n || k == 0) return 1;
    return fact[n] * invfact[n-k] % mod * invfact[k] % mod;
}

int main(){
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    ll ans = 0;
    set_fact(2000000);
    ans = comb(r1+c1, c1);
    if (r2 != r1 || c2 != c1) {
        ans += comb(r2+c2, c2);
    }
    if (r2-r1 > 0 && c2-c1 > 0) {
        ans += comb(r2+c2, c2);
    }
    ans %= mod;
    for (int i = r2-1; i > r1; i--) {
        ans += comb(i+c2, c2);
        ans %= mod;
    }
    for (int i = c2-1; i > c1; i--) {
        ans += comb(i+r2, r2);
        ans %= mod;
    }
    cout << ans%mod << endl;
    return 0;
}


Measured memory_bytes: 31488
#include <iostream>
using namespace std;
int main(){
	long long int n, m;
	cin >> n >> m;
	if(n == 1 && m == 1){
		cout << 1 << endl;
	}else if(n == 1){
		cout << (m - 2) << endl;
	}else if(m == 1){
		cout << (n - 2) << endl;
	}else{
		cout << (n - 2) * (m - 2) << endl;
	}
	return 0;
}

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

int hit(string a,string b){
	int res = 0;
	for(int i=0;i<4;i++) if(a[i] == b[i]) res++;
	return res;
}

int blow(string a,string b){
	int res = 0;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(i == j) continue;
			if(a[i] == b[j]){
				res++;
				break;
			}
		}
	}

	return res;
}

int main(void){
	while(1){
		string a="",b="";

		for(int i=0;i<4;i++){
			char ch;
			if(!(cin>>ch)) return 0;
			a += ch;
		}

		for(int i=0;i<4;i++){
			char ch;
			cin>>ch;
			b += ch;
		}

		cout<<hit(a,b)<<" "<<blow(a,b)<<endl;
	}

	return 0;
}

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

int main() {
    // input
    int A, B;
    string S;
    cin >> A >> B >> S;

    // solve
    bool flag = true;
    for (int i = 0; i < A; ++i) {
        if (S[i] < '0' || S[i] > '9') flag = false;
    }
    if (S[A] != '-') flag = false;
    for (int i = A + 1; i <= A + B; ++i) {
        if (S[i] < '0' || S[i] > '9') flag = false;
    }

    // output
    cout << (flag ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
using System;

class Pratice
{
    public static void Main()
    {
        while (true)
        {
            string[] str = Console.ReadLine().Split(' ');
            int m = int.Parse(str[0]), f = int.Parse(str[1]), r = int.Parse(str[2]);
            if (m == -1 && f == -1 && r == -1) break;
            Console.WriteLine(m == -1 || f == -1 ? 'F' : m + f >= 80 ? 'A' : m + f >= 65 ? 'B' : m + f >= 50 ? 'C' : m + f >= 30 ? (r >= 50 ? 'C' : 'D') : 'F');
        }
    }
}


Measured memory_bytes: 15964
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int x = nextInt();
		int a = nextInt();

		out.println(x < a ? 0 : 10);
	}

	private void solveB() {
		int n = nextInt();

		out.println("");
	}

	private void solveC() {
		int n = nextInt();

		out.println("");
	}

	private void solveD() {
		int n = nextInt();

		out.println("");
	}

	private void solveE() {
		int n = nextInt();

		out.println("");
	}

	private void solveF() {
		int n = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE 
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  int n;
  cin >> n;
  std::vector<int> v(n), cnt(int(1e6 + 5));
  for(int i = 0; i < n; i++){
    cin >> v[i];
    cnt[v[i]] = n;
  }
  sort(v.begin(), v.end());

  for(auto x : v){
    for(int j = x; j <= v[n - 1]; j += x) cnt[j]--;
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(cnt[v[i]] == n - 1) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8012
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}
bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
    
int main(){
    int N, M; cin >> N >> M;
    ll pinv = 1 << M;
    cout << pinv * ((N - M) * 100 + M * 1900) << endstr;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  bool ok = true;
  string t = s;
  reverse(t.begin(),t.end());
  if(s!=t) ok = false;
  int n = s.size();
  string u = s.substr(0,(n-1)/2);
  string v = u;
  reverse(v.begin(),v.end());
  if(u!=v) ok = false;
  string w = s.substr((n+3)/2-1);
  string x = w;
  reverse(x.begin(),x.end());
  if(w!=x) ok = false;

  cout << (ok? "Yes" : "No") << endl;
}


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

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

struct Problem {

	void Solve() {
		UL N, M; cin >> N >> M;
		vector<UL> C(M);
		rep(i, N) {
			UL K; cin >> K;
			rep(j, K) {
				UL c; cin >> c; c--;
				C[c]++;
			}
		}
		UL ans = 0;
		rep(i, M) if (C[i] == N) ans++;
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
sum = 0
 
for n in range(N+1):
  N1 = int(n/10000)
  N2 = int((n-10000*N1)/1000)
  N3 = int((n-10000*N1-1000*N2)/100)
  N4 = int((n-10000*N1-1000*N2-100*N3)/10)
  N5 = n-10000*N1-1000*N2-100*N3-10*N4
  if A <= N1+N2+N3+N4+N5 <= B:
    sum = sum + n
 
 
print(sum)

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

using namespace std;

const int MOD = 1e9 + 7;

long long dp[2][100005];
char s[100005];

int main() {
	scanf("%s", s + 1);
	
	//0 smaller, 1 = equal
	
	dp[1][0] = 1LL;
	
	int l = strlen(s + 1);
	
	for (int i = 1; i <= l; i++) {
		if (s[i] == '0') {
			dp[0][i] = (dp[0][i - 1] * 3) % MOD;
			dp[1][i] = dp[1][i - 1];
		}
		else {
			dp[0][i] = (dp[0][i - 1] * 3 + dp[1][i - 1]) % MOD;
			dp[1][i] = (dp[1][i - 1] * 2) % MOD;
		}
	}
	
	printf("%lld\n", (dp[1][l] + dp[0][l]) % MOD);
}


Measured memory_bytes: 1920
open Printf open Scanf
open Array

let () = scanf " %d %d %d %d" @@ fun n a b c ->
  let l = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  let rec solve i p q r s =
    if i=n then (
      if p>0 && q>0 && r>0 then
        (n-s-3) * 10
        + abs (p-a) + abs (q-b) + abs (r-c)
      else max_int
    )
    else
      let v = l.(i) in
      fold_left min max_int [|
        solve (i+1) (p+v) q r s;
        solve (i+1) p (q+v) r s;
        solve (i+1) p q (r+v) s;
        solve (i+1) p q r (s+1)
      |]
  in print_int @@ solve 0 0 0 0 0




Measured memory_bytes: 1280
#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     bit_1(a)       __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front
#define     mpr            make_pair
#define     ins            insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     vstr           vector<string>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))
#define     orderset1      tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define     orderset2      tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));
/// lcm(a,b)=a/gcd(a,b)*b (handle overflow)

bool sortinrev1(const pair<int,int>&a,const pair<int,int>&b)
{
    //return (a.first > b.first);
    if(a.first==b.first)return (a.second>b.second);
    else return (a.first > b.first);
}
bool sortinrev2(const pair<int,int>&a,const pair<int,int>&b)
{
    //return (a.first > b.first);
    if(a.first==b.first)return (a.second<b.second);
    else return (a.first > b.first);
}



int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int ans=(r/d)-(l/d);
    if(r%d==0 && l%d==0)ans++;
    cout<<ans<<endl;
}



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

using namespace std;

int main() {
  char c;
  cin >> c;
  
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    cout << "vowel";
  else
    cout << "consonant";
  cout << endl;
}

Measured memory_bytes: 256
# frozen_string_literal: true

s = gets.chomp.chars

loop.each do
  if s.empty?
    puts :YES
    exit
  elsif s.first(6).join == 'eraser'
    s.shift 6
  elsif s.first(5).join == 'erase'
    s.shift 5
  elsif s.first(11).join == 'dreameraser'
    s.shift 11
  elsif s.first(10).join == 'dreamerase'
    s.shift 10
  elsif s.first(7).join == 'dreamer'
    s.shift 7
  elsif s.first(5).join == 'dream'
    s.shift 5
  else
    puts :NO
    exit
  end
end

Measured memory_bytes: 13564
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

template<typename T>
struct Graph{
    vector<T> nodes;
    map<T,vector<pair<T,ll> > > nexts;
    Graph(ll n,T initial){
        nodes.resize(n,initial);
    }
    Graph(ll n){
        nodes.resize(n);
    }
    Graph(vector<T> &a):nodes(a){}
    Graph(){}
    void add_edge(T &s,T &e,ll c){
        this->nexts[s].push_back({e,c});
    }
    map<T,ll> dijkstra(T &s){
        map<T,ll> dist;
        for(T tmp:this->nodes){
            dist[tmp] = inf;
        }
        priority_queue<pair<ll,T>,vector<pair<ll,T> >,greater<pair<ll,T> > > q;
        q.push({0,s});
        dist[s] = 0;
        while(q.empty() == false){
            pair<ll,T> now = q.top();
            q.pop();
            if(now.first > dist[now.second]) continue;
            dist[now.second] = now.first;
            for(pair<T,ll> next:this->nexts[now.second]){
                if(now.first + next.second < dist[next.first]){
                    dist[next.first] = now.first+next.second;
                    q.push({dist[next.first],next.first});
                }
            }
        }
        return dist;
    }
};

struct Node{
    ll x;
    Node(ll a): x(a){}
    Node(): x(1){}
    bool operator<(const Node &b)const{
        return this->x < b.x;
    }
};

int main(void){
    ll n,m,s;
    cin>>n>>m>>s;
    s = min(s,2600LL);
    Graph<pl> g;
    rep(i,n){
        rep(j,2601){
            g.nodes.push_back(pl()={i+1,j});
        }
    }
    rep(i,m){
        ll u,v,a,b;
        cin>>u>>v>>a>>b;
        rep(j,2601){
            if(j>=a){
                g.add_edge(pl()={u,j},pl()={v,j-a},b);
                g.add_edge(pl()={v,j},pl()={u,j-a},b);
            }
        }
    }
    rep(i,n){
        ll c,d;
        cin>>c>>d;
        rep(j,2601){
            if(j+c <= 2600){
                g.add_edge(pl()={i+1,j},pl()={i+1,j+c},d);
            }
        }
    }
    map<pl,ll> dist = g.dijkstra(pl()={1,s});
    vl ans(n+1,inf);
    rep(i,n){
        rep(j,2601){
            ans[i+1] = min(ans[i+1],dist[{i+1,j}]);
        }
    }
    rep1(i,n){
        cout<<ans[i+1]<<endl;
    }
}

Measured memory_bytes: 51368
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = scanner.nextInt();
        int k = scanner.nextInt();
        int arr[] = new int[size];
        for (int i = 0; i < size; i++) {
            arr[i] = scanner.nextInt();
        }
        System.out.println(frog2(arr, k));

        scanner.close();

    }

    public static int frog2(int arr[], int k) {
        int sol[] = new int[arr.length];
        sol[0] = 0;
        for (int i = arr.length - 2; i >= 0; i--) {
            int cost = Integer.MAX_VALUE;
            for (int j = 1; j <= k; j++) {
                if (i + j < arr.length) {
                    cost = Math.min(Math.abs(arr[i + j] - arr[i]) + sol[i + j], cost);

                } else {
                    break;
                }
            }
            sol[i] = cost;
        }
        return sol[0];

    }

   

}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int n;
void dfs(string s,char maxc){
  if(s.size() == n){
    out(s);
    return;
  }
  for(char i='a';i<=maxc;i++){
    dfs(s+i,(i == maxc?maxc+1:maxc));
  }
}

signed main()
{   
  gearup;
  cin >> n;
  dfs("",'a');
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <cmath>
#include <math.h>
#include <ctime>
#include <cstring>
#include <climits>
#include <sstream>
#include <array>
#include <tuple>
#include <set>
#include <iterator>
#include <cstdio>
#include <string>
#include <stack>
#include <valarray>
#include <utility>
#include <iomanip>
#include <list>
#include <numeric>
#include <regex>
#include <map>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll          long long
#define PI          3.1415926535
#define pb          push_back
#define ins         insert
#define INF         LLONG_MAX
#define mk          make_pair
#define lb(v,x)     lower_bound(all(v),x)
#define ub(v,x)     upper_bound(all(v),x)
#define ff          first
#define ss          second
#define rev         reverse
#define uset        unordered_set
#define umap        unordered_map
#define endl        "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a)       (ll)a.size()
#define double      long double
#define minpq       priority_queue <ll,vector<ll>,greater<ll> > 
#define fill(x,y)   memset(x,y,sizeof(x))
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define MOD         1000000007 //1e9+7
#define bp(n)       __builtin_popcountll(n)
#define mxt(a)      *(max_element(a.begin(),a.end()))
#define mnt(a)      *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i, a, b) for(ll i = (a); i<= (b); ++i)
#define trav(a, x) 	 for(auto &a : x)
#define re(i,n)      for(ll i = 0; i < n; ++i) 
const ll N = 4e5 + 7;
typedef pair<ll,ll>   pii;
typedef vector<pii>   vpii;
typedef vector<ll>    vll;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
template<typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template<typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0){ if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll sqr(ll x) { return x * x;}
// always use 1ll*ans to avoid signed integer overflow; 
void prec(){

}
ll dp[101][N],wt[102];
ll val[102];
ll knapsack(int W,int i){
	if(i<0) return 0;
	if(dp[i][W]!=-1) return dp[i][W];
	if(wt[i]>W){
		dp[i][W]=knapsack(W,i-1);
		return dp[i][W];
	}
	else{
		dp[i][W]=max(val[i]+knapsack(W-wt[i],i-1),knapsack(W,i-1));
		return dp[i][W];
	}
}
void solve(){
	int n,W;cin>>n>>W;
	rep(i,0,n-1) cin>>wt[i]>>val[i];
	fill(dp,-1);
	cout<<knapsack(W,n-1)<<endl;
}

int main()
{
    ios;
    int tc=1;
    //cin>>tc;
    prec();
    while(tc--)
    	solve();
    return 0; 
}


Measured memory_bytes: 315904
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int A=s.nextInt();
		String op=s.next();
		int B=s.nextInt();
		
		if(op.charAt(0)=='+'){
			System.out.print(A+B);
		}else System.out.print(A-B);
		

	}

}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
#define MAX 100001
#define MOD 1000000007
#define ll long long
#define ld long double
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int main() {
	fast;
	int t = 1;
	// cin >> t;
	while(t--) {
		int n;
		cin >> n;
		vector<int> a(n), b(n);
		for(int i=0;i<n;i++) {
			cin >> a[i] >> b[i];
		}
		int flag = 0;
		for(int i=0;i<n-2;i++) {
			flag = 0;
			for(int j=i;j<i+3;j++) {
				if(a[j] != b[j]) {
					flag = 1;
					break;
				}
			}
			if(flag == 0) {
				cout << "Yes" << endl;
				flag = 2;
				break;
			}
		}
		if(flag != 2) cout << "No" << endl;
	}
}

Measured memory_bytes: 3640
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
bool prime[314514];
int rui[314514];

void init() {
    fill(prime, prime + 314514, true);
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i < 314514; i++) {
        if (prime[i]) {
            for (int j = i * 2; j < 314514; j += i) {
                prime[j] = false;
            }
        }
    }
    rep(i,0, 314514) {
        if (prime[i]) {
            rui[i]++;
        }
    }
    rep(i, 0, 314514 - 1) {
        rui[i + 1] += rui[i];
    }
//    rep(i,0,100){
//        if(prime[i]){
//            cout << i << " " << rui[i] << endl;
//        }
//    }
}

void solve(int n) {
    cout << rui[2 * n] - rui[n] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    init();
    while (true) {
        int n;
        cin >> n;
        if(n == 0) break;
        solve(n);
    }


    return 0;
}



Measured memory_bytes: 4644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 10000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main() 
{ 
    fastio
    ld n;
    cin>>n;
    cout<<fixed<<setprecision(15);
    cout<<(n/3)*(n/3)*(n/3)<<endl;
} 

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

int main(){
	int n;
	while(cin >> n,n){
		int grid[101][101] = {0};
		int w,h;
		cin >> w >> h;
		for(int i=0;i<n;i++){
			int x,y;
			cin >> x >> y;
			grid[x][y] = 1;
		}
		for(int i=0;i<=w;i++){
			for(int j=1;j<=h;j++){
				grid[i][j] += grid[i][j-1];
			}
		}
		for(int i=0;i<=h;i++){
			for(int j=1;j<=w;j++){
				grid[j][i] += grid[j-1][i];
			}
		}
		int s,t;
		cin >> s >> t;
		int ans = 0;
		for(int i=s;i<=w;i++){
			for(int j=t;j<=h;j++){
				int x = grid[i][j] - grid[i-s][j] - grid[i][j-t] + grid[i-s][j-t];
				ans = max(ans,x);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3044
#include <complex>
#include <vector>
using namespace std;

//  |p-o1|=r1, |p-o2|=r2 を満たす2個の点を返す
vector<complex<double>> circle_intersection(complex<double> o1, double r1, complex<double> o2, double r2)
{
    double d = abs(o1-o2);
    double cos = (r1*r1+d*d-r2*r2)/(2*r1*d);
    if (cos<-1.0 || 1.0<cos)
        return vector<complex<double>>();
    complex<double> p(r1*cos, r1*sqrt(1-cos*cos));
    vector<complex<double>> r{p, conj(p)};
    for (complex<double> &t: r)
        t = t*(o2-o1)/abs(o2-o1)+o1;
    return r;
}

#include <iostream>
#include <cmath>

int main()
{
    int N, K;
    cin>>N>>K;
    vector<complex<double>> p(N);
    vector<double> c(N);
    for (int i=0; i<N; i++)
    {
        double x, y;
        cin>>x>>y>>c[i];
        p[i] = complex<double>(x, y);
    }

    auto check = [&](complex<double> o, double t)
    {
        int k = 0;
        for (int i=0; i<N; i++)
            if (c[i]*abs(o-p[i])<=t)
                k++;
        return k>=K;
    };

    double l = 0.;
    double r = 1000000.;
    for (int i=0; i<100; i++)
    {
        double m = (l+r)/2.;
        bool ok = false;
        for (auto p1: p)
            if (check(p1, m))
                ok = true;
        for (int j=0; j<N; j++)
            for (int k=0; k<N; k++)
                for (complex<double> x: circle_intersection(p[j], m/c[j]-1e-8, p[k], m/c[k]-1e-8))
                    if (check(x, m))
                        ok = true;
        (ok ? r : l) = m;
    }
    printf("%.10f\n", l);
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int h = sc.nextInt();
		
      	int n = a/h;
        if(a%h!=0){
          n=n+1;
        }
		// 出力
		System.out.println(n);
	}
}

Measured memory_bytes: 22996
import sys
input = sys.stdin.readline
s = input()
s1 = s[0] + s[1]
s2 = s[2] + s[3]
if int(s1) > 12 or int(s1) == 0:
    if int(s2) > 12 or int(s2) == 0:
        print("NA")
    else:
        print("YYMM")
else:
    if int(s2) > 12 or int(s2) == 0:
        print("MMYY")
    else:
        print("AMBIGUOUS")

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  signed int a,b,c,x,y;
  scanf("%d%d%d",&a,&b,&c);
  x=a-b;
  y=b-c;
  if(x==y){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}


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

int main() {
  int count_N = 0 ;
  string input_N;
  cin >> input_N;
  if(input_N[0]=='1'){count_N++;}
  if(input_N[1]=='1'){count_N++;}
  if(input_N[2]=='1'){count_N++;}
  cout << count_N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int

using namespace std;



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    ll N;
    ll sum=0;
    cin>>N;
    vector<ll> arr(N);

    for(ll i=0;i<N;i++){
        cin>>arr[i];

    }
    
    vector<ll> ar(N+1,0);


    for(ll i=N;i>=1;i--){
        sum=0;
        for(ll j=i;j<=N;j+=(i)){
            sum+=ar[j];
        }
        if(sum%2!=arr[i-1]){
            ar[i]=1;

        }

    }

    vector<ll> r;
    for(ll i=1;i<=N;i++) if(ar[i]) r.push_back(i);

    cout<<r.size()<<endl;
    for(auto i:r) cout<<i<<endl;




    return 0;
}

Measured memory_bytes: 5108
from collections import Counter


def getinputdata():
    # 配列初期化
    array_result = []

    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            array_temp = []

            if (data != ""):

                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:

        return array_result


arr_data = getinputdata()

n = int(arr_data[0][0]) * 2

arr = [int(x) for x in arr_data[1]]
arr.sort(reverse=True)

mysum = 0

for v in range(1, n, 2):
    mysum += arr[v]

print(mysum)


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll ans=0;
    if(n%2==0){
        ans = n/2-1;
    }else{
        ans = n/2;
    }
    cout<<ans<<endl;
    return  0;
}


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

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();

            out.println(Math.abs(a - b) <= 1 ? "Brown" : "Alice");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21588
N = int(input())
a = [int(c) for c in input().split()]
m = 1
ans = 0
flag = True
for i in range(N):
  c = a[i]
  if c==m:
    m += 1
    flag = False
    continue
  ans += 1
if flag:
  print(-1)
else:
  print(ans)

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N,T;
    cin >> N >> T;
    int ans = 0;
    int now = 0;

    int t;
    rep(i,N) {
        cin >> t;
        if (now+T<t) {
            ans -= (t-(now+T));
        }
        now = t;
    }
    ans += T+t;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		String ans = "";

		for (int i = 0; i < 3; i++) {
			ans += sc.next().charAt(0);
		}

		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 22608
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &in, vector<T> &vec) {
    for (auto &e : vec) in >> e;
    return in;
}

inline void read() {}

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

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    int N;
    read(N);

    int s = 0;
    rep(i, N) {
        int a; read(a);
        s ^= a;
    }
    print(s ? "No" : "Yes");

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

typedef struct node{
	int number;
	node *parent;
}node;

node *root;

node *find(node *x){
	
	if(x->parent == root) return x;
	else{
		x->parent = find(x->parent);
		return x->parent;
	}
}

int main(void){
	int n,q;
	scanf("%d %d", &n, &q);
	std::vector<node> nodes(n);
	for(int i=0;i<n;i++){
		nodes[i].number = i;
		nodes[i].parent = root;
	}
	for(int i=0;i<q;i++){
		int op,x,y;
		node *x_parent, *y_parent;
		scanf("%d %d %d", &op, &x, &y);
		x_parent = find(&nodes[x]);
		y_parent = find(&nodes[y]);
		if (op==0){
			if (x_parent->number > y_parent->number) x_parent->parent = y_parent;
			else if (x_parent->number < y_parent->number) y_parent->parent = x_parent;
		}
		else{
			if (x_parent->number == y_parent->number) printf("1\n");
			else printf("0\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2692
#include<stdio.h>
#include<stdlib.h>
 
#define NMAX 1000000
#define QMAX 50000
 
int main(void){
  int i,j,n,S[NMAX],q,T[QMAX],C=0;
  int l,r,m,key;
   
  scanf("%d", &n);
  if(n>NMAX) exit(1);
  for(i=0;i<n;i++)scanf("%d", &S[i]);
 
  scanf("%d", &q);
  if(q>QMAX) exit(1);
  for(i=0;i<q;i++)scanf("%d", &T[i]);
 
  for(i=0;i<q;i++){
    l=0; r=n;
    while(l<r){
      m=(l+r)/2;
      if(S[m]==T[i]){
        C++;
        break;
      } else if(T[i]<S[m]){
        r=m;
      } else {
        l=m+1;
      }
    }
  }
     
  printf("%d\n",C);
  return 0;
}

Measured memory_bytes: 3180
#include<stdio.h>
 
int main(void)
{
   int a,b,c,d;
 
   scanf("%d%d%d",&a,&b,&c);
 
   d = b/a;
 
   if(d<c){
      printf("%d\n",d);
   }
    else printf("%d\n",c);

   return 0;
}

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

int main(){
  int N, L;
  cin >> N >> L;
  vector<int> v(N);
  int count = 0;
  int sum = 0;
  for(int i=0; i<N; i++){
    v.at(i)=L+i;
    //cout << "i=" << v.at(i) << endl;
    sum += v.at(i);
   // cout << "sum=" << sum << endl;
    if(v.at(i)==0){
      count++;
     // cout << "count=" << count << endl;
    }
  }
  int h_min = 300;
  int m_min;
  if(count!=1){
    for(int i=0; i<N; i++){
      m_min=min(abs(v.at(i)),h_min);
      h_min = m_min;
      if(i == N-1){
        if(sum>0){
          cout << sum - h_min << endl;
        }
        else if(sum<0){
          cout << sum + h_min << endl;
        }
      }
    }
  }
  else {
    cout << sum << endl;
  }
return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for i in range(n)]
m = int(input())
t = [input() for i in range(m)]
d = {}
for ss in s:
    if ss not in d.keys():
        d[ss] = 1
    else:
        d[ss] += 1
for tt in t:
    if tt not in d.keys():
        d[tt] = -1
    else:
        d[tt] -= 1
max = 0
for dd in d.values():
    if max < dd:
        max = dd
print(max)


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
INF = 10**9
MOD = 10**9 + 7

list =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
def main():
   k =int(input())
   print(list[k-1])
if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const int INF = INT_MAX / 2;

vector<vector<int>> board;

int solve(const int H, const int W, const int K, const vector<int> yokos) {
    int ans = 0;

    vector<int> whites(H, 0);
    for (int i = 0; i < W; i++) {
        vector<int> cur_whites(H, 0);
        for (int j = 0; j < H; j++) {
            if (board[j][i] == 1) {
                cur_whites[j]++;
            }
        }

        bool needs_line = false;
        for (int j = 0; j < (int) yokos.size() - 1; j++) {
            int white_count = 0;
            int cur_white_count = 0;
            for (int k = yokos[j]; k < yokos[j + 1]; k++) {
                white_count += whites[k];
                cur_white_count += cur_whites[k];
                whites[k] += cur_whites[k];
            }

            // impossible if whites on one colomun > K
            if (cur_white_count > K) {
                return INF;
            }

            if (white_count + cur_white_count > K) {
                needs_line = true;
            }
        }
        if (needs_line) {
            ans++;
            whites = cur_whites;
        }

        // printf("whites: ");
        // for (int j = 0; j < H; j++) {
        //     printf("%d ", whites[j]);
        // }
        // printf("\n");

    }

    // printf("yokos: ");
    // for (auto &x : yokos) {
    //     printf("%d ", x);
    // }
    // printf(", ans: %d\n", ans);

    return ans;
}

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

    board.resize(H, vector<int>(W, 0));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char x;
            cin >> x;
            board[i][j] = (int) (x - '0');
        }
    }

    int ans = INF;
    for (int bits = 0; bits < (1 << (H - 1)); bits++) {
        vector<int> yokos;
        yokos.push_back(0);
        for (int i = 0; i < H; i++) {
            if (bits & (1 << i)) {
                yokos.push_back(i + 1);
            }
        }
        yokos.push_back(H);

        chmin(ans, solve(H, W, K, yokos) + ((int) yokos.size() - 2));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256