akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int h, w;
	int ans = 0;
	cin >> h >> w;
	queue<pair<int, int>> q;
	bool none = true;
	
	vector<string> a(h);
	rep(i, h) {
		cin >> a[i];
		rep(j, w) {
			if (a[i][j] == '#') {
				q.emplace(i, j);
			}
		}
	}
	q.emplace(INF, INF);
	Pi at;
	if (q.size() == h * w + 1) {
		cout << 0 << endl;
		return 0;
	}
	while (true) {
		at = q.front();
		q.pop();
		if (at.F == INF and at.S == INF) {
		//	clog << "+" << endl;
	
		if (none == true) {
			none = false;
			ans++;
			q.emplace(INF, INF);
			} else {
				cout << ans << endl;
				return 0;
			}
			continue;
		}
		for (int ni = max(at.F - 1, 0); ni < min(at.F + 2, h ); ni++) {
			for(int nj = max(at.S - 1, 0); nj <min(at.S + 2, w); nj++) {
				if ((ni == at.F) xor (nj == at.S)) {
					if (a[ni][nj] == '.') {
					//	clog << "add: " << ni << " " << nj << endl;
						q.emplace(ni, nj);
						none = true;
						a[ni][nj] = '#';
					}
				}
			}
		}
	}
	// cout<<ans<<endl;
}

Measured memory_bytes: 13520
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,i,min=1000000,max=-1000000;
    long long sum=0;
    cin >> n;
    vector<int> a(n);
    for(i=0;i<n;i++){
        cin >> a[i];
    if(a[i]<min){
        min=a[i];
    }
    if(a[i]>max){
        max=a[i];
    }
    sum=sum+a[i];
    }
    cout << min;
    cout << " ";
    cout << max;
    cout << " ";
    cout << sum;
    cout << endl;
}



Measured memory_bytes: 3112
MOD = 10**9 + 7
n, k = map(int, input().split())
a = list(map(int, input().split()))
am = []
ap = []
for ai in a:
    if ai > 0:
        ap.append(ai)
    elif ai < 0:
        am.append(-ai)
am.sort(reverse=True)
ap.sort(reverse=True)

nm = len(am)
np = len(ap)
nz = n - np - nm
# print(am)
# print(ap)

if np + nm < k:
    ans = 0
elif np == 0:
    if k % 2 == 1:
        if nz > 0:
            ans = 0
        else:
            am.sort()
            ans = -1 + MOD
            for i in range(k):
                ans *= am[i]
                ans %= MOD
    else:
        ans = 1
        for i in range(k):
            ans *= am[i]
            ans %= MOD
elif np < k:
    if (k - np) % 2 == 1:
        idx1 = np - 1
        idx2 = k - np + 1
        if k - np + 1 > nm:
            if nz > 0:
                ans = 0
            else:
                if nm % 2 == 1:
                    ans = -1 + MOD
                else:
                    ans = 1
                for i in range(np):
                    ans *= ap[i]
                    ans %= MOD
                for i in range(nm):
                    ans *= am[i]
                    ans %= MOD
        else:
            while idx1 >= 2 and idx2 + 1 < nm and \
                ap[idx1 - 1] * ap[idx1 - 2] < am[idx2] * am[idx2 + 1]:
                idx1 -= 2
                idx2 += 2
            ans = 1
            for i in range(idx1):
                ans *= ap[i]
                ans %= MOD
            for i in range(idx2):
                ans *= am[i]
                ans %= MOD
    else:
        idx1 = np
        idx2 = k - np
        while idx1 >= 2 and idx2 + 1 < nm and \
            ap[idx1 - 1] * ap[idx1 - 2] < am[idx2] * am[idx2 + 1]:
            idx1 -= 2
            idx2 += 2
        ans = 1
        for i in range(idx1):
            ans *= ap[i]
            ans %= MOD
        for i in range(idx2):
            ans *= am[i]
            ans %= MOD
else:
    idx1 = k
    idx2 = 0
    while idx1 >= 2 and idx2 + 1 < nm and \
        ap[idx1 - 1] * ap[idx1 - 2] < am[idx2] * am[idx2 + 1]:
        idx1 -= 2
        idx2 += 2
    ans = 1
    for i in range(idx1):
        ans *= ap[i]
        ans %= MOD
    for i in range(idx2):
        ans *= am[i]
        ans %= MOD

print(ans)


Measured memory_bytes: 33440
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

void swap(vector<long long> &heap, int i, int j){
    long long tmp = heap[i];
    heap[i]=heap[j];
    heap[j]=tmp;
}

void minHeapify(vector<long long> &heap, int n){
    int l,r,smallest,last;
    l=2*n+1;
    r=2*n+2;
    smallest=n;
    last=heap.size();

    if (l<last && heap[l] < heap[smallest])smallest=l;
    if (r<last && heap[r] < heap[smallest])smallest=r;
    if(smallest!=n){
        swap(heap,n,smallest);
        minHeapify(heap,smallest);
    }
}

long long minHeapPop(vector<long long> &heap){
    long long min_=heap[0];
    heap[0]=heap[heap.size()-1];
    heap.pop_back();
    minHeapify(heap,0);

    return min_;
}

void minHeapPush(vector<long long> &heap, long long num){
    heap.push_back(num);
    int i = heap.size()-1;
    int parent = (i-1)/2;
    while (i>0 && heap[parent] > heap[i]){
        swap(heap,i,parent);
        i=parent;
        parent=(i-1)/2;
    }
}

void buildMinHeap(vector<long long> &heap){
    int size=heap.size();
    for(int i=(size-1)/2; i>=0; i--){
        minHeapify(heap,i);
    }
}

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> V(N,0);
    for(int i=0; i<N; i++){
        cin >> V[i];
    }

    int ans=0;
    for(int x = 0; x <= min(K,N); x++){
        for(int i=0; i<=x; i++){
            vector<long long> heap(0);
            int tmp=0;
            int cnt = K-x;
            for(int j=0; j<i; j++){
                minHeapPush(heap, V[j]);
                tmp+=V[j];
            }
            for(int j=N-1; j>N-1-(x-i); j--){
                minHeapPush(heap, V[j]);
                tmp+=V[j];
            }
            int p=1;
            if ((int) heap.size()>0){
                p=minHeapPop(heap);
            }
            
            while(p<0 && (int) heap.size() > 0 && cnt>0){
                tmp-=p;
                p=minHeapPop(heap);
                cnt--;
            }
            ans=max(ans,tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M, X, Y = input().split()

N = int(N)
M = int(M)
X = int(X)
Y = int(Y)

x = list(map(int,input().split()))
y = list(map(int,input().split()))

x_max = max(x)
y_min = min(y)

if( Y - X > 0 and y_min - x_max > 0 and Y - x_max > 0 and y_min - X > 0):
    print("No War")
    
else:
    print ("War")

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

long long n, s;
int main() {
    scanf("%lld%lld", &n, &s);
    long long p = abs(n-s), q = sqrt(p), ans = 1e18;
    if(n == s) return !printf("%lld", n+1);
    for(long long k = 1; k <= q; k++) {
        if(p%k==0) {
            long long sum = 0, r = n;
            while(r) sum += r%(k+1), r/=(k+1);
            if(sum == s) ans = min(ans, k+1);
            r = n, sum = 0; long long t = p/k+1;
            while(r) sum += r%t, r/=t;
            if(sum == s) ans = min(ans, t);
        }
    }
    printf("%lld", (ans == 1e18 ? -1 : ans));
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++) 
#define rrep(i,n) for(int i = 1; i <= (int)(n); i++) 
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod = 1000000007;
//const ll INF = mod * mod;
//const double pi = 3.14159265358979;

int main() {
    string s;
    cin >> s;
    string ans = s == "ABC" ? "ARC" : "ABC";
    cout << ans << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int rt, K, n, cnt, typ;
vector<int> linker[2005];

void dfs(int x, int fa, int ndep)
{
	if (ndep > ((K - typ) >> 1)) ++ cnt;
	for (int cur : linker[x])
		if (cur != fa) dfs(cur, x, ndep + 1);
}

int main()
{
	scanf("%d %d", &n, &K);
	for (int i = 1; i < n; i ++)
	{
		int u, v; scanf("%d %d", &u, &v);
		linker[u].push_back(v), linker[v].push_back(u);
	}
	int ans = n; typ = 0;
	for (rt = 1; rt <= n; rt ++)
	{
		cnt = 0, dfs(rt, 0, 0);
		ans = min(ans, cnt);
	}
	typ = 1;
	for (rt = 1; rt <= n; rt ++)
	{
		for (auto rt2 : linker[rt])
		{
			cnt = 0;
			dfs(rt, rt2, 0), dfs(rt2, rt, 0);
			ans = min(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let s: Vec<char> = input::<String>().chars().collect();
    let t: Vec<char> = input::<String>().chars().collect();

    let mut u = vec![-1; 26];
    let mut v = vec![-1; 26];
    let mut ok = true;
    for i in 0..s.len() {
        let j = (s[i] as u8 - b'a') as usize;
        let k = (t[i] as u8 - b'a') as usize;
        if u[j] < 0 {
            u[j] = k as i32;
        } else if u[j] != k as i32 {
            ok = false;
        }
        if v[k] < 0 {
            v[k] = j as i32;
        } else if v[k] != j as i32 {
            ok = false;
        }
    }
    println!("{}", if ok { "Yes" } else { "No" });
}


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

int main(){
  int n, k;
  cin >> n >> k;
  
  int d[k] = {};
  int a[k][n] = {};
  for(int i = 0; i < k; i++){
    cin >> d[i];
    for(int j = 0; j < d[i]; j++){
      cin >> a[i][j];
    }
  }
  
  int m = 0;
  
  for(int l = 1; l < n+1; l++){
    for(int i = 0; i < k; i++){
      for(int j = 0; j < d[i]; j++){
        if(a[i][j] == l){
          m++;
          l++;
        }
      }
    }
  }
  cout << n-m << endl;
}

Measured memory_bytes: 3648
#include <stdio.h>

int main(){
 int x=0;
 scanf("%d",&x);
 int h,m,s=0;
 h = x/3600;
 m = (x - 3600*h) / 60;
 s = x - 3600*h - m*60;
 printf("%d:%d:%d\n",h,m,s);
 return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define ll long long
const int N =2e5 + 5 ;
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
swap(a,b);
swap(a,c);
cout<<a<<" "<<b<<" "<<c<<endl;
return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif /* __DEBUG__ */

int main(int argc, char **argv)
{
  unsigned N;
  std::cin >> N;
  
  std::vector<long> a(N), b(N);
  N_TIMES(n, N) std::cin >> a[n];
  N_TIMES(n, N) std::cin >> b[n];
  
  unsigned x = 0;
  for (unsigned k = 0; k < 29; ++k) {
    long T = 1 << k;
    
    std::vector<long> c(a), d(b);
    N_TIMES(n, N) {
      c[n] %= T << 1;
      d[n] %= T << 1;
    }
    std::sort(d.begin(), d.end());
    
    unsigned S = 0;
    N_TIMES(n, N) {
      auto itr1 = std::lower_bound(d.begin(), d.end(), 1 * T - c[n]);
      auto itr2 = std::lower_bound(d.begin(), d.end(), 2 * T - c[n]);
      S += std::distance(itr1, itr2);
      
      auto itr3 = std::lower_bound(d.begin(), d.end(), 3 * T - c[n]);
      auto itr4 = std::lower_bound(d.begin(), d.end(), 4 * T - c[n]);
      S += std::distance(itr3, itr4);
    }
    
    x += (S & 1) * T;
  }
  std::cout << x << std::endl;
  
  return 0;
}

Measured memory_bytes: 6548
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################


a = int(input())
print(a + a*a + a*a*a)








Measured memory_bytes: 9300
#include<stdio.h>
#include<math.h>
#define MAX 10000000

int main() {
	int i, j, n, s, ary[10000], y;
	double x;

	scanf("%d", &n);
	s = n;
	for (i = 0; i < n; i++) {
		scanf("%d", &ary[i]);
	}
	for (i = 0; i < n; i++) {
		for (j = 2; j <= sqrt(ary[i]); j++) {
			if (ary[i] % j == 0) {
				s= s - 1;
				break;
			}
		}
	}
	printf("%d\n", s);

}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

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

int main(void)
{
    int r, g;
    cin >> r >> g;
    cout << (2 * g) - r << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    H, W = (int(i) for i in input().split())
    A = [input() for i in range(H)]
    dxy = ((-1, 1), (0, 1), (1, 1), (1, 0),
           (1, -1), (0, -1), (-1, -1), (-1, 0))
    c = [["0"]*W for h in range(H)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                c[h][w] = "#"
            else:
                cur = 0
                for dx, dy in dxy:
                    if not(0 <= h + dy < H and 0 <= w + dx < W):
                        continue
                    if A[h + dy][w + dx] == "#":
                        cur += 1
                c[h][w] = str(cur)
    for h in range(H):
        print("".join(c[h]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
use num_integer::gcd;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        s: Chars,
        t: Chars,
    }
    let gcd = gcd(n, m);
    let l = n * m / gcd;

    let n_p = n / gcd;
    let m_p = m / gcd;
    let mut flag = true;

    for i in 0..gcd {
        if s[i * n_p] != t[i * m_p] {
            flag = false;
            break;
        }
    }
    if flag {
        println!("{}", l);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 2832
#include <iostream>
#include <string>
#include <algorithm>

#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	std::string word;
	std::string tmp;
	int count = 0;
	
#if INPUT_FROM_FILE
	ifs >> word;
#else
	std::cin >> word;
#endif

#if INPUT_FROM_FILE
	while(ifs >> tmp){
#else
	while(std::cin >> tmp){
#endif
		std::transform(tmp.cbegin(), tmp.cend(), tmp.begin(), tolower);	
		if(word == tmp){
			count++;
		}
	}

	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 3136
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        long N = sc.nextLong();
        long[] AE = new long[5];
        
        long min = (long)1e16; 
        for(int i = 0; i < 5; i++){
            AE[i] = sc.nextLong();
            min = Math.min(min, AE[i]);
        }

        System.out.println( 4L + (long)Math.ceil((double)N / min) );
    }
}


Measured memory_bytes: 23764
require 'pp'

n = gets.to_i
a_n = gets.split.map(&:to_i)

money = 1000
kabu = 0
# 次のほうが高ければ次に売れば損はしない
# 次のほうが安ければ次で買えば損はしない
n.times do |i|
    #pp "===="
    #pp i
    #pp money
    #pp kabu

    if i == n - 1
        # 最後は全部売る
        money += kabu * a_n[i]
        kabu = 0
        break
    end

    if a_n[i+1] > a_n[i]
        # 買い
        buy = money / a_n[i]
        kabu += buy
        money -= buy * a_n[i]
    else
        # 売れるだけ売る
        money += kabu * a_n[i]
        kabu = 0
    end
end

puts money


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


void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    input();
    map<string,ll>m;
 	cases{
 		string str;
 		cin>>str;
 		m[str]++;
 	}
 	cout<<"AC x "<<m["AC"]<<endl;
 	cout<<"WA x "<<m["WA"]<<endl;
 	cout<<"TLE x "<<m["TLE"]<<endl;
 	cout<<"RE x "<<m["RE"]<<endl;
}




Measured memory_bytes: 3684
using System;

public class Hello
{
	public static void Main()
	{
		var n = int.Parse(Console.ReadLine().Trim());
		Console.WriteLine(getAns(n));
	}
	static int getAns(int n)
	{
		var count = 0;
		for (int i = 1; i <= n; i++)
			if (i.ToString().Length % 2 == 1) count++;
		return count;
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int main(int argc, const char * argv[]) {
    // input from txt

    /////////
    //write//
    /////////
    
    int v, e;
    cin >> v >> e;
    vector<int> glaph[MAX];
    int degree[MAX];
    bool col[MAX];
    
    rep(i, e){
        int s, t;
        cin >> s >> t;
        glaph[s].push_back(t);
    }
    
    fill(degree, degree+v, 0);
    fill(col, col+v, false);
    
    rep(i, v){
        rep(j, glaph[i].size()){
            degree[glaph[i][j]]++;
        }
    }
    
    queue<int> res;
    rep(i, v){
        if(degree[i] == 0 && !col[i]){
            queue<int> q;
            q.push(i);
            col[i] = true;
            while(!q.empty()){
                int u = q.front(); q.pop();
                res.push(u);
                rep(j, glaph[u].size()){
                    int u2 = glaph[u][j];
                    degree[u2] --;
                    if(degree[u2] == 0 && !col[u2]){
                        col[u2] = true;
                        q.push(u2);
                    }
                }
            }
        }
    }
    
    while(!res.empty()){
        int foo = res.front(); res.pop();
        cout << foo;
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 5964
H, W, K = map(int,input().split())
C = []
for _ in range(H):
    C.append(input())
ans = 0
for h in range(2**H):
    temp = C.copy()
    hi = format(int(h), "b").zfill(H)
    for i in range(H):
        if hi[i] == '1':
            temp[i] = 'r'*W
    for w in range(2**W):
        tempw = temp.copy()
        wi = format(int(w), "b").zfill(W)
        for j in range(W):
            if wi[j] == '1':
                for i in range(H):
                    tempw[i] = tempw[i][:j] + 'r' + tempw[i][j+1:]
        num = 0
        for i in range(H):
            for j in range(W):
                if tempw[i][j] == '#':
                    num += 1
        if num == K:
            ans += 1
print(ans)


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


using namespace std;



int main(){
    int n ;scanf("%d" , &n) ;
    int h[n + 10] ;


    for(int i = 0 ; i < n ; i++)
        cin>> h[i] ;

    int jump[n + 10] = {0 , abs(h[1] - h[0]) } ;



    for(int i = 2 ; i < n ; i++){

        jump[i] = min(jump[i - 1] + abs(h[i] - h[i - 1]) , jump[i - 2] + abs(h[i] - h[i - 2])  ) ;

    }



    printf("%d\n" , jump[n - 1]) ;
}





Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	string S;
	cin >> S;
	bool ans[26];
	for (int i = 0; i < 26; i++) {
		ans[i] = false;
	}
	for (int j = 0; j < S.size(); ++j) {
		ans[S[j] - 'a'] = true;
	}
	for (int i = 0; i < 26; ++i) {
		if (!ans[i]) {
			cout << (char)(i + 'a');
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

string s;

int main() {
  cin >> s;

  if (s.size() % 2 == 1) {
    if (s[0] == s[s.size() - 1]) {
      cout << "Second" << endl;
    } else {
      cout << "First" << endl;
    }
  } else {
    if (s[0] == s[s.size() - 1]) {
      cout << "First" << endl;
    } else {
      cout << "Second" << endl;
    }
  }

  return 0;
}


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

int main(){
  int N;cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  int cnt = 0,i=0;
  for(int j=0;j<N;j++){
    if(j==N-1){
      cnt += (j-i+1)%2;
      cout << cnt << endl;
      return 0;
    }
    if(A[j]!=A[j+1]){
      cnt += (j-i+1)%2;
      i = j + 1;
    }
  }
}

Measured memory_bytes: 3796
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  vector<string> S(N);
  vector<int> p(N);
  FOR(i, N) { cin >> S[i] >> p[i]; }
  vector<int> index(N);
  FOR(i, N) index[i] = i;
  sort(ALL(index), [&](const int& l, const int& r) {
    if (S[l] != S[r]) {
      return S[l] < S[r];
    } else {
      return p[l] > p[r];
    }
  });
  FOR(i, N) { print(index[i] + 1); }
  return 0;
}

Measured memory_bytes: 256
n, a, b, c = list(map(int, input().split()))
ls = [int(input()) for _ in range(n)]

min_ans = 10 ** 10
for i in range(4 ** n):
	mm = [[], [], [],[]]
	tmp = i
	for i2 in range(n):
		g = tmp // (4 ** (n - i2 - 1))
		tmp = tmp % (4 ** (n - i2 - 1))
		mm[g%4].append(ls[i2])
	
	if len(mm[0]) * len(mm[1]) * len(mm[2]) == 0:
		continue

	#print(mm)
	ans = abs(sum(mm[0]) - a) + abs(sum(mm[1]) - b) + abs(sum(mm[2]) - c) + (len(mm[0]) - 1) * 10 + (len(mm[1]) - 1) * 10 + (len(mm[2]) - 1) * 10
	min_ans = min(ans, min_ans)

print(min_ans)

Measured memory_bytes: 3064
const main = (val) => {
  const aray = val.split(" ");
  console.log(calc(parseInt(aray[0]), parseInt(aray[1])));
}
const calc = (a, b) => {
  if (is_even(a)|| is_even(b)) {
    return "Even";
  } else {
    return "Odd";
  }
}
const is_even = (num) => {
  if ((num % 2) === 0) {
    return true;
  } else {
    return false;
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>=(0);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)

int main(){
    int X,Y;
    cin >> X >>Y;
    cout << X + (Y/2) << endl;

}


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

int main()
{
	int A, B;
	cin >> A >> B;
	puts(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0 ? "Possible" : "Impossible");
	return 0;
}


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, nn;
    cin >> n;
    nn = n;
    vector<int> v;

    for (int i = 0; i <= n; i++)
    {
        v.push_back(i);
    }

    int sum = 0;
    int i;
    for (i = 1; sum + i <= n; i++)
    {
        sum += i;
        nn -= i;
    }
    // cout << sum << "," << nn << "," << i << endl;
    if (nn == 0)
    {
        for (int j = 1; j < i; j++)
        {
            cout << j << endl;
        }
    }
    else
    {
        for (int j = 1; j < i; j++)
        {
            if (j == i - nn)
            {
                cout << j + nn << endl;
            }
            else
            {
                cout << j << endl;
            }
        }
    }
}

Measured memory_bytes: 133212
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    int a[3] = {};
    cin >> n;
    rep(i, 3) cin >> a[i];
    vec l(n);
    rep(i, n) cin >> l[i];

    int res = INF;

    vec pow_table;
    int cur = 1;
    rep(i, 10) {
        pow_table.push_back(cur);
        cur *= 4;
    }

    rep(flag, pow_table[n]) {
        int tres = 0;
        int kad[3] = {};
        int cnt[3] = {};

        rep(i, n) {
            int bits = (flag % pow_table[i+1]) / pow_table[i];
            if (bits == 0) continue;

            kad[bits-1] += l[i];
            cnt[bits-1]++;
        }

        bool emp = false;
        rep(i, 3) if (cnt[i] == 0) emp = true;
        if (emp) continue;

        rep(i, 3) tres += (cnt[i] - 1) * 10;

        rep(i, 3) tres += abs(kad[i] - a[i]);

        res = min(res, tres);
    }

    cout << res << endl;
    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/04  Problem: ABC 100 A / Link: http://abc100.contest.atcoder.jp/tasks/abc100_a  ----- */


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

	LL A, B; cin >> A >> B;
	LL ans = abs(A-B);
	
	
	cout << (ans<=1?"Yay!":":(") << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
#define MAXN 300000
#define INF 100000000000000000
LL n;
LL ans;
LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
  return x*F;
}
int main()
{
  n=read();
  ans=INF;
  for(LL a=1;a*a<=n;a++)
  if(n%a==0){
    LL b=n/a;
    ans=min(ans,(a-1)+(b-1));
  }
  printf("%lld",ans);
}


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

public class Main {

	int[][] g;
	
	
	int ans = 0;
	void submit() {
		int n = nextInt();
		g = new int[n][];
		int[] a = new int[2 * n - 2];
		int[] deg = new int[n];
		for (int i = 0; i < 2 * n - 2; i++) {
			a[i] = nextInt();
			deg[a[i]]++;
		}

		for (int i = 0; i < n; i++) {
			g[i] = new int[deg[i]];
		}
		
		for (int i = 0; i < 2 * n - 2; i += 2) {
			int v = a[i];
			int u = a[i + 1];
			g[v][--deg[v]] = u;
			g[u][--deg[u]] = v;
		}
		
		int root = 0;
		while (root < n && g[root].length < 3) {
			root++;
		}
		
		if (root == n) {
			out.println(1);
			return;
		}
		
//		System.err.println(root);
		
		dfs(root, -1);
		out.println(ans);
	}
	
	boolean dfs(int v, int p) {
		int k = 0;
		boolean ret = false;
		for (int u : g[v]) {
			if (u == p) {
				continue;
			}
			if (!dfs(u, v)) {
				k++;
			} else {
				ret = true;
			}
		}
//		System.err.println(v + " " + k);
		
		if (k >= 2) {
			ans += k - 1;
			return true;
		}
		return ret;
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

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

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

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

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

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


Measured memory_bytes: 50700
import sys

a, b, c = map(int, sys.stdin.readline().split())

c_prime = []
for i in range(1, c+1):
    if(c % i == 0):
        c_prime.append(i)

ans = 0
for i in range(a, b+1):
    if(i in c_prime):
        ans += 1

print(ans)

Measured memory_bytes: 7660
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> h(n+1,0);
  for(int i=1;i<=n;i++){
    cin>>h[i];
  }
  h[0] = 0;
  vector<long long int> mincost(n+1);
  mincost[2] = abs(h[2]-h[1]);
  for(int i=3;i<=n;i++){
    mincost[i] = min(mincost[i-1] + (long long int)abs(h[i]-h[i-1]) ,mincost[i-2] + (long long int)abs(h[i]-h[i-2]));
  }
  cout<<mincost[n];
  return 0;
}

Measured memory_bytes: 4576
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
      int[] x=new int[5];
      for(int i=0;i<5;i++){
      	x[i]=sc.nextInt();
        if(x[i]==0){
        	System.out.println((i+1));
          return;
        }
      }
	}
}

Measured memory_bytes: 27036
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<string>
#include<map>
#define INF 0x3f3f3f3f
#define ll long long
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
using namespace std;
int main()
{
   int x,a,b;
   cin >> x>>a >>b;
   //while(cin >> x >> a >> b){
   if(a>=b) cout <<"delicious" <<endl;
   else if(a+x>=b) cout << "safe" <<endl;
   else if(a+x<b) cout << "dangerous" <<endl;
    //}
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstdlib>

using namespace std;

struct node{
    int key;
    node *right,*left,*parent;
};

node *root,*NIL;

void insert(int k)
{
    node *y=NIL;
    node *x=root;
    node *z;

    z=(node*)malloc(sizeof(node));
    z->key=k;
    z->left=NULL;
    z->right=NULL;

    while(x!=NULL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }

    z->parent=y;

    if(y==NIL){
        root=z;
    }else{
        if(z->key<y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}

void inorder(node *u)
{
    if(u==NULL){
        return ;
    }
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(node *u)
{
    if(u==NULL){
        return ;
    }
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

node *find(node *u,int k)
{
    while(u!=NIL&&k!=u->key){
        if(k<u->key){
            u=u->left;
        }else{
            u=u->right;
        }
    }
    return u;
}

node *treeminimum(node *x)
{
    while(x->left!=NIL){
        x=x->left;
    }
    return x;
}

node *treesuccessor(node *x)
{
    return treeminimum(x->right);
}

void treedelete(node *z)
{
    node *y;
    node *x;
    if(z->left==NIL||z->right==NIL){
        y=z;
    }else{
        y=treesuccessor(z);
    }
    if(y->left!=NIL){
        x=y->left;
    }else{
        x=y->right;
    }
    if(x!=NIL){
        x->parent=y->parent;
    }
    if(y->parent==NIL){
        root=x;
    }else{
        if(y==y->parent->left){
            y->parent->left=x;
        }else{
            y->parent->right=x;
        }
    }
    if(y!=z){
        z->key=y->key;
    }
    free(y);
}

int main()
{
    int n,k;
    string com;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>com;
        if(com=="insert"){
            scanf("%d",&k);
            insert(k);
        }else if(com=="print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }else if(com=="find"){
            scanf("%d",&k);
            node *t=find(root,k);
            if(t!=NULL){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }else{
            scanf("%d",&k);
            treedelete(find(root,k));
        }
    }
    return 0;
}
/*
18
insert 8
insert 2
insert 3
insert 7
insert 22
insert 1
find 1
find 2
find 3
find 4
find 5
find 6
find 7
find 8
print
delete 3
delete 7
print
*/



Measured memory_bytes: 22008
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    fact();
    int ans = 0;
    int cnt = 0;
    rep(i, min(H - A, W - B)) {
        ans = (ans + Mul(C(A + W - B - 1, W - B - i - 1), C(H - A + B - 1, B + i))) % mod;
        //cout << (A + W - B - 1) << " " << W - B - i - 1 << " " << H - A + B - 1 << " " << B + i << endl;
    }
    cout << ans << endl;

    return 0;
}
// ..
// .o C(2, 1) * C(1, 1)
// x.

// ... 
// ..o C(3, 1) * C(2, 0) 
// .o. C(3, 2) * C(2, 1)
// x..

// ....o.. C(4, 0) * C(5, 2)
// ...o... C(4, 1) * C(5, 3)
// xxx....
// xxx....

// .....o....
// ....o.....
// ...o......
// xxx.......
// xxx.......
// xxx.......
// xxx.......

Measured memory_bytes: 16640
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 17;
ll i,j,k,s,n;
ll a[N][N],w[1 << N],dp[1 << N];
ll solve(ll mask)
{
    if(dp[mask] != -1) return dp[mask];
    
    if(mask == 0)
        return dp[mask] = 0;
    
    ll res = -MAX;
    for(ll i = mask;i > 0;i = (i - 1) & mask)
        res = max(res, w[i] + solve(i ^ mask));
    
    return dp[mask] = res;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>n;
    rep(i,0,n) rep(j,0,n) cin>>a[i][j];
    for(i = 0;i < 1 << n;i += 1){
        s = 0;
        rep(j,0,n) if(i & (1 << j)){
            rep(k,j + 1,n) if(i & (1 << k))
                s += a[j][k];
        }
        w[i] = s;
    }
    cout<<solve((1 << n) - 1);
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    string s; cin>>s;
    string div[4]={"dream","dreamer","erase","eraser"};
    reverse(s.begin(),s.end());
    rep(i,4) reverse(div[i].begin(),div[i].end());
    bool ok=true;
    for(int i=0;i<s.size();){
        bool ok2=false;
        rep(j,4){
            string d=div[j];
            if(s.substr(i,d.size())==d){
                ok2=true;
                i+=d.size();
            }
        }
        if(!ok2){
            ok=false;
            break;
        }
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3720
import java.util.ArrayList;
import java.util.Scanner;

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

        int n = stdIn.nextInt();
        int q = stdIn.nextInt();

        int[] uf = new int[n];

        init_uf(uf);

        int p, a, b;
        for(int i=0; i<q; i++){
            p = stdIn.nextInt();
            a = stdIn.nextInt();
            b = stdIn.nextInt();

            if(p == 0){
                if(search_root(a, uf) != search_root(b, uf)){
                    union_group(a, b, uf);
                }
            }else{
                if(search_root(a, uf) == search_root(b, uf)){
                    System.out.println("1");
                }else{
                    System.out.println("0");
                }
            }
        }
    }

    static void init_uf(int[] uf){
        for(int i=0; i<uf.length; i++){
            uf[i] = i;
        }
    }

    static int search_root(int f, int[] uf){
        ArrayList<Integer> list = new ArrayList<Integer>();
        int idx = f;
        while(idx != uf[idx]){
            list.add(idx);
            idx = uf[idx];
        }
        // ツリー圧縮
        while(!list.isEmpty()){
            int item = list.remove(0);
            uf[item] = idx;
        }
        return idx;
    }

    static void union_group(int f1, int f2, int[] uf){
        int root1 = search_root(f1, uf);
        int root2 = search_root(f2, uf);
        uf[root2] = root1;
    }
}


Measured memory_bytes: 99900
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define speed ios::sync_with_stdio(false)
#define pb push_back
#define mp make_pair
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define all(x) (x).begin(), (x).end()
#define uint usigned int
typedef vector <ll> vi;
ll mod=1918;
//vi v1[200005],v2;
//bool visit[200005]={false};

/*void bfs(ll n){
    queue<ll> q;
    q.push(n);
    visit[n]=true;
    while(!q.empty()){
        ll t=q.front();
        q.pop();
        v2.pb(t);
        for(ll i=0;i<v1[t].size();i++){
            if(visit[v1[t][i]]==false){
                q.push(v1[t][i]);
                visit[v1[t][i]]=true;
            }
        }
    }
}*/
/*void dfs(ll n){
    for(ll i=0;i<v1[n].size();i++)
    {
        ll y=v1[n][i];
        if(visit[y]==0)
        {
            v2.pb(y);
            visit[y]=1;
            dfs(y);
        }
    }
}*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    ll a,b,c,d,e,k,x=0,p,y=0,ans=0,m=0;
    cin>>a>>b>>c>>d>>e>>k;
    if(b-a>k){
        cout<<":(";
        return 0;
    }
    if(c-a>k){
        cout<<":(";
        return 0;
    }
    if(d-a>k){
        cout<<":(";
        return 0;
    }
    if(e-a>k){
        cout<<":(";
        return 0;
    }
    if(c-b>k){
        cout<<":(";
        return 0;
    }
    if(d-b>k){
        cout<<":(";
        return 0;
    }
    if(e-b>k){
        cout<<":(";
        return 0;
    }
    if(d-c>k){
        cout<<":(";
        return 0;
    }
    if(e-c>k){
        cout<<":(";
        return 0;
    }
    if(e-d>k){
        cout<<":(";
        return 0;
    }
    cout<<"Yay!";
    
    
    return 0; 
}

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

using namespace std;

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

template <typename T> inline void print(T val) { cout << val << '\n'; }

template <typename Iterator> inline void print(Iterator begin, Iterator end) {
  for (auto it = begin; it != end; it = next(it)) {
    cout << *it << ' ';
  }
  cout << '\n';
}

void solve() {
  string a, b;
  cin >> a >> b;

  int n = a.size();

  assert(a.size() == b.size());

  int ans = 0;

  for (auto i = 0; i < n; ++i) {
    if (a[i] != b[i]) {
      ++ans;
    }
  }

  print(ans);
}

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

#ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  solve();

  return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int n;
	cin >> n;
	cout << (n % 2 == 0 ? n : n * 2) << endl;
	return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
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; }

const long long INF = 1LL << 60;


int main()
{
  int N,K;
  cin >> N >> K;
  long long h[100010];
  long long dp[100010];

  for(int i=0;i<N;i++)
    cin >> h[i];

  for(int i=0;i<100010;i++)
    dp[i] = INF;
  dp[0] = 0;

  for(int i=0;i<N;i++){
    for(int j=0;j<K;j++){
      if(i-1-j>=0){
        chmin(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]));
      }
    }
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;cin>>n;
	ll cu=1,s=0;
	while(n>=1){
		n /= 2;
		if(n==0)break;
		s += cu*2;
		// cout<<cu*2<<" ";
		cu = cu*2;
	}
	cout<<s+1;
}

Measured memory_bytes: 256
import bisect
K, T = [int(_) for _ in input().split()]
A = sorted([int(_) for _ in input().split()])
while len(A) > 1:
    A[-1] -= 1
    if A[-1] == 0:
        A = A[:-1]
    else:
        i_bisect_left = bisect.bisect_left(A[:-1], A[-1])
        if i_bisect_left == len(A) - 1:
            A = A[:-2] + [A[-1], A[-2]]
        else:
            v = A[-1]
            A = A[:-1]
            A.insert(i_bisect_left, v)
print(A[0] - 1)


Measured memory_bytes: 3064