akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long
#define ld long double

using namespace std;

    /*   Every goose should go to prison!!!!!
         ██▀▀▄  ██     ██
    ▄███▀██░░░▌ ██     ██
    █████████████████████████████
        ▐██░░░▐ ██     ██
        ▌██░░░░▐██     ██
    █████████████████████████████
       ▐░██░▐▒▒▒██▒▒▒▀▀██
       ▐░██░▐▄▒▒██▒▒▒▒▒██▄
    █████████████████████████████
         ██▄▄▄▄▄██▄▄▄▄▄██▄▄▄▀▄
         ██    ▌██▌▌   ██
    █████████████████████████████
         ██  ▄▄▌██▌▌   ██ */

void solve() {
	ll n, d, m;
	cin >> n >> d >> m;
	vector<pair<ll, ll>> a(n);
	vector<ll> b(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
		b[i] = a[i].first;
	}

	sort(b.begin(), b.end());
	b.erase(unique(b.begin(), b.end()), b.end());
	for (auto& p : a) p.first = (ll)(lower_bound(b.begin(), b.end(), p.first) - b.begin());

	ll cnt = b.size();
	vector<ll> c(cnt);
	for (ll i = 0; i < n; i++) c[a[i].first] = max(c[a[i].first], a[i].second);

	ll now = 0;
	ll ans = 0;
	vector<ll> t(cnt + 1);
	for (ll i = 0; i < cnt; i++) {
		now += t[i];
		if (now < c[i]) {
			ll x = (c[i] - now) / m + ((c[i] - now) % m ? 1 : 0);
			ans += x;
			now += x * m;
			ll id = (ll)(upper_bound(b.begin(), b.end(), b[i] + d * 2) - b.begin());
			t[id] -= x * m;
		}
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector<bool> H(N);
  for (ll i = 0; i < K; i++) {
    ll d; cin >> d;
    for (ll j = 0; j < d; j++) {
      ll a; cin >> a; a--;
      H.at(a) = true;
    }
  }
  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    if (!H.at(i)) cnt++;
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3660
n = int(input())
alist = list(map(int, input().split()))
alist.sort(reverse=True)
p1 = []
p2 = []
for i in range(n):
    if i%2 == 0:
        p1.append(alist.pop(0))
    else:
        p2.append(alist.pop(0))

print(sum(p1)-sum(p2))

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

int main(){
        string message[3] = {"Sunny", "Cloudy", "Rainy"};
        string input;

        cin>>input;
        for(int i=0;i<3;i++){
                if(message[i] == input)cout<<message[(i+1)%3];
        }
}



Measured memory_bytes: 256
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include<cmath>
#include<string.h>
#include<vector>

int main(){
	long long n,a,b,m,sum=0,x;
	scanf("%lld %lld %lld",&n,&a,&b);
	m=a+b;
	x=n/m;
	n -= m*x;
	sum=x*a;
	if(n>=a) sum+=a;
	else sum+=n;
	printf("%lld\n",sum);
	return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    int N, L; cin >> N >> L;
    vector<string> s(N);
    rep(i, N) cin >> s[i];
    sort(all(s));
    rep(i, N) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    int N;
    cin>>N;
    dlog(N);
    cout<<3*N*N;
    return 0;
}

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

using namespace std;
#define ll long long
const int MAXN=1e5+1;
const int inf = MAXN;
vector<vector<int>> vert(MAXN, vector<int>(0));
vector<pair<int , int>> ans(0);
vector<int> arr;
vector<int> summ(MAXN, 0);
vector<int> cnt(MAXN, 0);

ll mod=998244353l;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        arr.push_back(a);
    }
    if(arr[0]!=0){
        cout<<0;
        return 0;
    }
    sort(arr.begin(), arr.end());
    cnt[0]=1;
    ll ans=1;
    for(int i=1;i<n;i++){
        if(arr[i]-1<0){
            cout<<0;
            return 0;
        }
        ans*=cnt[arr[i]-1];
        ans%=mod;
        cnt[arr[i]]++;
    }
    cout<<ans;


}

Measured memory_bytes: 4092
// Ballazt
//0a..brute force
//0b..greedy
//1..memorizatton of some sort	remember something cleverly
//2..sort
//3..binary search	keep check a particular solution
//4..dp				repeating strucutre,limited choices
//5..dfs/bfs		matrix with obstacles
//6..correlate to graph in some way		each state is a point
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"


int main()

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

	string s1,s2;
	cin>>s1;
	cin>>s2;

	int count=0;
	for(int i=0;i<s1.size();i++)
	{
		if(s1[i]==s2[i])
			count++;
	}

	if(count==s1.size()&&s2.size()==s1.size()+1)
		cout<<"Yes";
	else cout<<"No";



}





	

Measured memory_bytes: 3656
#!/usr/bin/ruby
def ite(a,n)
	b = Array.new(n+1)
	b[0] = 0
	1.step(n){|m|
		i = 0
		k = -1
		a.size.times{|i|
			#p a[i]
			if m >= a[i] && b[m-a[i]] >= 0 && (k < 0 || b[m-a[i]] + 1 < k)
				k = b[m-a[i]] + 1
			end
		}
		b[m] = k
	}
	b[n]
end

n=gets.to_i
puts ite(gets.split.map(&:to_i),n)

Measured memory_bytes: 6504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int num = in.nextInt();
		int count = 1;

		for (count = 1; count <= num; count++) {

			// 3??§?????????????????°?????¨???
			if (count % 3 == 0) {

				System.out.print(" " + count);

				// ???????????????3?????°?????¨???
			} else if (count % 10 == 3) {

				System.out.print(" " + count);

				// else if(count / 10 == 3)
			} else {

				int x = count;
				int display = 0;

				while (x > 10) {
					x /= 10;

					if (x % 10 == 3) {
						display = count;
					}
				}
				if(display != 0) {
					System.out.print(" " + display);
				}
			}
		}
		System.out.println("");
	}

}

Measured memory_bytes: 28784
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////



int main() {

	string s;
	cin >> s;

	ll a[MAX] = {};
	ll ab[MAX] = {};
	ll abc[MAX] = {};

	ll q = 1;

	repn(i, s.size()) {
		if (s[i - 1] == 'A') {
			a[i] = a[i - 1] + q;
			ab[i] = ab[i - 1];
			abc[i] = abc[i - 1];
		}

		if (s[i - 1] == 'B') {
			a[i] = a[i - 1];
			ab[i] = ab[i - 1] + a[i - 1];
			abc[i] = abc[i - 1];
		}

		if (s[i - 1] == 'C') {
			a[i] = a[i - 1];
			ab[i] = ab[i - 1];
			abc[i] = abc[i - 1] + ab[i - 1];
		}

		if (s[i - 1] == '?') {
			a[i] = 3*a[i - 1] + q;
			ab[i] = 3*ab[i - 1] + a[i - 1];
			abc[i] = 3*abc[i - 1] + ab[i - 1];
			q=q*3%MOD;
		}
		a[i] %= MOD;
		ab[i] %= MOD;
		abc[i] %= MOD;
		
	}

	cout << abc[s.size()];

	
	system("PAUSE");
}

Measured memory_bytes: 24184
N, M = [int(x) for x in input().split()]
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]


def f(r, c):
    if r+M > N or c+M > N:
        return False
    for i in range(M):
        if A[r+i][c:c+M] != B[i]:
            return False
    return True


def main():
    for i in range(N):
        for j in range(N):
            if f(i,j):
                print("Yes")
                return 
    print("No")

main()

Measured memory_bytes: 3064
n = int(input())
k = [0] * (n + 1)
for i in range(min(n + 1, 6)): k[i] = i
for i in range(6, n + 1):
    m = k[i - 1] + 1
    for j in range(1, 8):
        l = pow(6, j)
        if l > i: break
        m = min(m, k[i - l] + 1)
    for j in range(1, 8):
        l = pow(9, j)
        if l > i: break
        m = min(m, k[i - l] + 1)
    k[i] = m
print(k[n])


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

bool ans;
int H, W;
vector<bool> used;
vector<int> mrr;
vector<string> S;

bool same(int l, int r) {
  for (int k = 0; k < H; ++k) {
    if (S[k][l] != S[mrr[k]][r]) return false;
  }
  return true;
}

void solve() {
  int isOdd = W % 2;
  used = vector<bool>(W, false);
  for (int i = 0; i < W; ++i) {
    for (int j = i + 1; j < W; ++j) {
      if (used[i] || used[j]) continue;
      if (same(i, j)) used[i] = used[j] = true;
    }
  }
  for (int i = 0; i < W; ++i) {
    if (used[i]) continue;
    if (!isOdd || !same(i, i)) return;
    used[i] = true;
    isOdd = 0;
  }
  ans = true;
}

void dfs(int n, int isOdd) {
  if (ans) return;
  if (n > H - 1) {
    solve();
    return;
  }
  if (mrr[n] != -1) {
    dfs(n + 1, isOdd);
    return;
  }
  if (isOdd) {
    mrr[n] = n;
    dfs(n + 1, 0);
  }
  for (int i = n + 1; i < H; ++i) {
    if (mrr[i] == -1) {
      mrr[n] = i;
      mrr[i] = n;
      dfs(n + 1, isOdd);
      mrr[i] = -1;
    }
  }
  mrr[n] = -1;
}


int main() {
  cin >> H >> W;
  S = vector<string>(H);
  for (int i = 0; i < H; ++i) cin >> S[i];
  mrr = vector<int>(H, -1);
  dfs(0, H % 2);
  cout << ( (ans) ? "YES" : "NO" ) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define REP(i, k, n) for (signed long long int i = (signed long long int)(k); i < (signed long long int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define loop(n) rep(looping, n);
#define rREP(i, k, n) for (signed long long int i = (signed long long int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) std::sort(all(x))
#define REV(x) std::reverse(all(x))
#define UNIQUE(x) x.erase(std::unique(all(x)), x.end());
#define MAX(x) *std::max_element(all(x))
#define MIN(x) *std::min_element(all(x))
#define LOWitr(x, n) std::lower_bound(all(x), n)
#define UPRitr(x, n) std::upper_bound(all(x), n)
#define cii(x) int x; std::cin >> x
#define cill(x) signed long long int x; std::cin >> x
#define cis(x) std::string x; std::cin >> x
#define co(x) std::cout << x << "\n"
#define pb push_back
#define mp std::make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) if(DEBUG) std::cout<<#x<<" : "<<(x)<<"\n"
using std::cin;
using std::cout;
using std::string;
using std::min;
using std::max;
using std::abs;
using std::next_permutation;
template<class T>using V = std::vector<T>;
template<class T>using VV = std::vector<std::vector<T>>;
template<class T>using Q = std::queue<T>;
template<class T>using PQ = std::priority_queue<T>;
template<class T,class U>using P = std::pair<T, U>;
template<class T,class U>using M = std::map<T, U>;
template<class T,class U>using UM = std::unordered_map<T, U>;
using LL = signed long long int;
using VL = V<LL>;
using VVL = V<VL>;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f; //1061109567
const LL LLINF = 0x3f3f3f3f3f3f3f3fLL; //4557430888798830399
const double PI = M_PI;
template<class T,class U>inline LL min(T a, U b){return std::min((LL)a, (LL)b);}
template<class T,class U>inline LL max(T a, U b){return std::max((LL)a, (LL)b);}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T>inline void vcin(T &v){for(auto&& i : v) std::cin >> i;}
template<class T>inline void dumpv(const T& v, std::ostream& os = std::cout){
    if(DEBUG){
        os<<"{";std::for_each(all(v),[&os](typename T::value_type p){os<<p<<',';});os<<"}\n";
    }
}

void Main(){
    cill(x);
    cill(n);
    LL min = LLINF;
    if (n==0){
        co(x);
        return;
    }
    VL v(200, 1);
    rep(i, n){
        LL a;
        cin >> a;
        v[a]=0;
    }
    LL ans=100;
    rREP(i, -1, 102){
        if(v[i]==0) continue;
        if (min==abs(x-i)){
            ans=i;
        }
        if (chmin(min, abs(x-i))){
            ans=i;
        }
    }
    co(ans);
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3660
import heapq
def dijkstra_heap(s):
    d = [float("inf")] * n
    used = [True] * n
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))
    return d

n,w,s,t = map(int,input().split())

edge = [[] for i in range(n)]
for i in range(w):
    x,y = map(int,input().split())
    edge[x-1].append((1,y-1))
    edge[y-1].append((1,x-1))
a,b = [0]*n,[0]*n
x = dijkstra_heap(s-1)
y = dijkstra_heap(t-1)
distance = x[t-1] - 1
for t in x:
    if t < n:
        a[t] += 1
for t in y:
    if t < n:
        b[t] += 1
ans = 0
for i in range(distance + 1):
    if distance - i > 0:
        ans += a[i] * b[distance - i - 1]
print(ans)


Measured memory_bytes: 66908
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int N;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int x; cin >> x;
		if (x % 2 == 0 && (x % 3 && x % 5))
		{
			cout << "DENIED"; return 0;
		}
	}
	cout << "APPROVED";
}

Measured memory_bytes: 256
def down(d, last, c):
    result = 0
    for i in range(26):
        result += c[i] * (d - last[i])
    return result


def main():
    D = int(input())
    C = [int(c) for c in input().split()]

    S = [0] * D

    for d in range(D):
        S[d] = [int(s) for s in input().split()]

    last = [0] * 26

    score = 0
    scores = [0] * D
    for d in range(D):
        t = int(input()) - 1

        score += S[d][t]
        last[t] = d + 1

        score -= down(d + 1, last, C)
        scores[d] = score

    for score in scores:
        print(score)


if __name__ == "__main__":
    main()


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

string S;

string binary_num(int a, string b)
{
    if (b.length() == S.length() - 1) return b;
    char mod = a % 2 + '0';
    b = mod + b;
    return binary_num(a / 2, b);
}

int main()
{
    cin >> S;

    long long ans = 0;
    for (int i = 0; i < pow(2, S.length() - 1); i++)
    {
        string pls = binary_num(i, ""); // 「どこに『＋』が入るか」

        long long expo[10] = {};
        expo[S.length() - 1] = 1;
        for (int j = S.length() - 2; j >= 0; j--)
        {
            if (pls[j] == '0') expo[j] = expo[j + 1] * 10;
            else expo[j] = 1;
        }

        for (int k = 0; k < S.length(); k++)
        {
            ans += (S[k] - '0') * expo[k];
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

vector<i64> a;
int main() {
  read_n(a, 3);
  sort(begin(a), end(a));
  cout << a[0] + a[1] << '\n';
  return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline


# 処理内容
def main():
    A, B, C = map(int, input().split())
    K = int(input())

    for _ in range(K):
        if A >= B:
            B *= 2
        elif B >= C:
            C *= 2
    
    if A < B and B < C:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 61892
#include <cstdio>
#include <iostream>
int main(){
	int y,m,d,x;
	while(std::cin>>y>>m>>d){
		x=y*10000+m*100+d;
		if(x<18680908)printf("pre-meiji\n");
		else if(x<19120730)printf("meiji %d %d %d\n",y-1867,m,d);
		else if(x<19261225)printf("taisho %d %d %d\n",y-1911,m,d);
		else if(x<19890108)printf("showa %d %d %d\n",y-1925,m,d);
		else printf("heisei %d %d %d\n",y-1988,m,d);
	}
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using LL = long long;
using namespace std;
class UnionFind{
private:
    vector<int> vec;
public:
    void init(int N){
        vec.resize(N,-1);
    }
    int root(int a){
        if(vec[a] < 0)return a;
        else return vec[a] = root(vec[a]);
    }
    bool connect(int a,int b){
        a = root(a);
        b = root(b);
        if(a == b)return false;
        if(vec[a] > vec[b])swap(a,b);
        vec[a] += vec[b];
        vec[b] = a;
        return true;
    }
    bool check(int a ,int b){
       return root(a) == root(b);
    }
};
vector<bool> sieve(int s){
    vector<bool> IsPrime;
    IsPrime.resize(s,true);

    IsPrime[0]=false;
    IsPrime[1]=false;
    for(int i = 0;i <=s;i++)
        if(IsPrime[i])
            for(int j =i+1;j <= s;j++)
                if(j%i==0)
                    IsPrime[j]=false;

    return IsPrime;
}
int main(){
    int N;cin >> N;
    vector<pair<int,int>> vec;
    UnionFind Uni;
    Uni.init(N);
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(make_pair(b,a));
    }
    vector<bool> pR = sieve(10010);
    vector<int> prime;
    for(int a = 0;a < pR.size();a++){
        if(pR[a])prime.push_back(a);
    }

    for(int a = 0;a < prime.size();a++){
        //cout<<prime.at(a)<<endl;
        int s = -1;
        for(int b = 0;b < N;b++){
            if(!(vec.at(b).first%prime.at(a))){
                if(s != -1){
                   // cout<<s<<" "<<b<<" "<<vec.at(b).first<<" "<<prime.at(a)<<endl;
                    Uni.connect(s,b);
                }else{
                    s = b;
                }
            }
        }
    }
    vector<pair<int,int>> ins = vec;
    sort(ins.begin(),ins.end());
    for(int a = 0;a < N;a++){
        if(!Uni.check(ins.at(a).second,a)){
            cout<<0<<endl;
            return 0;
        }
    }
    cout<<1<<endl;
}
//2t+2


Measured memory_bytes: 5056
import sys
from heapq import heappush, heappop
input = sys.stdin.readline
X, Y, Z = map(int, input().split())
N = X + Y + Z
A, B, C = [], [], []
for i in range(N):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)

gs = [(A[i] - B[i], i) for i in range(N)]
gs = sorted(gs)

silver = [0] * (Z + 1)

sb = []
for i in range(Y):
    j = gs[i][1]
    heappush(sb, (B[j] - C[j], j))
    silver[0] += B[j]

for i in range(Z):
    j = gs[i + Y][1]
    heappush(sb, (B[j] - C[j], j))
    silver[i + 1] += silver[i] + B[j]
    k = heappop(sb)
    silver[i + 1] -= k[0]

gs = sorted(gs, reverse=True)
gold = [0] * (Z + 1)
gb = []
for i in range(X):
    j = gs[i][1]
    heappush(gb, (A[j] - C[j], j))
    gold[0] += A[j]

for i in range(Z):
    j = gs[i + X][1]
    heappush(gb, (A[j] - C[j], j))
    gold[i + 1] += gold[i] + A[j]
    k = heappop(gb)
    gold[i + 1] -= k[0]

ans = 0
for i in range(Z + 1):
    ans = max(ans, silver[i] + gold[Z - i])

print(ans)





Measured memory_bytes: 82524
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<stack>
#include<utility>
#include<algorithm>
using namespace std;
typedef pair<int,int> p1;
int main(){
char c;	
int i=0;
stack<int> s1;
stack<p1> s2;
while(scanf("%c",&c)!=EOF){
	if (c=='\\'){s1.push(i);}
	else if(c=='/'&&s1.size()>0){
		int j=s1.top();s1.pop();
		int a=i-j;
		p1 p=make_pair(j,a);
		while(!s2.empty()&&p.first<s2.top().first){
			a+=s2.top().second;s2.pop();
			p=make_pair(j,a);
		}
		s2.push(p);
	}
	i++;
}
stack<int> p;int sum=0;int count=0;
while(!s2.empty()){
	int i=s2.top().second;s2.pop();
	sum+=i;
	count++;
	p.push(i); 
}
printf("%d\n",sum);
printf("%d",count);
while(!p.empty()){
	int i=p.top();p.pop();
	printf(" %d",i);
}
cout<<endl;
}




Measured memory_bytes: 3300
#include <stdio.h>
#include <math.h>

int main(void){

  int x;
  scanf("%d", &x);
  int list[x+1];
  for (int i = 0; i < x+1; i++) {
    list[i] = 0;
  }
  list[1] = 1;
  int number;
  for (int b = 2; b <= sqrt(x); b++) {
    for (int p = 2; ; p++) {
      number = pow(b,p);
      if (number > x) {
        break;
      }
      list[number] = 1;
    }
  }
  for (int i = x; i > 0; i--) {
    if (list[i] == 1) {
      printf("%d\n", i);
      break;
    }
  }

  return 0;
}

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int N, M;
  cin >> N >> M;

  VI A(N);
  VP CB(M);

  REP(i, N) cin >> A.at(i);
  REP(i, M) cin >> CB.at(i).snd >> CB.at(i).fst;

  SORT(A);
  SORT(CB);
  REV(CB);

  //REP(i, M) cout << CB.at(i).fst << " " << CB.at(i).snd << endl;

  int now=0;

  REP(i, M){
    int cnt=0;
    REP(j, CB.at(i).snd){
      if(N<=now+j) break;
      if(CB.at(i).fst>A.at(now+j)){
          A.at(now+j)=CB.at(i).fst;
          cnt++;
      }else{
        break;
      }
    }
    now+=cnt;
  }

  int ans=0;

  REP(i, N) ans+=A.at(i);

  //REP(i, N) cout << A.at(i) << endl;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    
    LL N,P;
    cin >> N >> P;
    if(N == 1){
        cout << P << endl;
        return 0;
    }

    //n乗根→1/n乗
    LL s = pow(P,(double)1/N);
    LL ans = 1;
    for(LL i=2; i<=s+1; i++){
        for(LL j=0; j<N; j++){
            if(P % i == 0){
                P /= i;

                if(j == N-1){
                    ans *= i;
                    i--;
                }
            }
            else{
                break;
            }
        }
        if(P == 1) break;
    }
    cout << ans << endl;

    
    return 0;
}

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

Measured memory_bytes: 512
N = int(input())
a = list(map(int, input().split()))

b = [0] * N
for i in range(N-1, -1, -1):
    cnt = 0
    for j in range(i, N, i+1):
        cnt += b[j]
    b[i] = (cnt + a[i]) % 2
    
print(sum(b))
print(*[i+1 for i in range(N) if b[i]==1])

Measured memory_bytes: 13116
import scala.io.StdIn

import java.util.Arrays.binarySearch

object Main extends App {
  val n = StdIn.readInt
  val a, b, c = StdIn.readLine.split(" ").map(_.toLong).sorted
  
  val ans = {
      var posA = 0
      var posC = 0
      def findA(tar:Long):Int = {
        while(posA < n && a(posA) < tar) posA += 1
        posA
      }
      def findC(tar:Long):Int = {
        while(posC < n && c(posC) <= tar) posC += 1
        posC
      }

      b./:(0L)((acc,e) => {
        val ac = findA(e)
        val cc = n - findC(e)

        acc +  ac.toLong * cc.toLong
      })
    }

  println(ans)
}

Measured memory_bytes: 79868
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,ans=0; string A,B,C;
  cin >> N >> A >> B >> C;
  for(int i=0; i<N; i++) {
    if(A[i]!=B[i] && A[i]!=C[i] && B[i]!=C[i]) ans+=2;
    else if(A[i]!=B[i] && A[i]!=C[i]) ans++;
    else if(A[i]!=B[i] && B[i]!=C[i]) ans++;
    else if(B[i]!=C[i] && A[i]!=C[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
int A[20],n;
int check(int ,int);
int main(void){
  int q,m,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(check(0,m)==1)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
int check(int i,int m){
  if(m==0)return 1;
  if(i>n-1)return 0;//over factor(要素)
  if(check(i+1,m)==1 || check(i+1,m-A[i])==1)return 1;
  else return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
ll n, k;
int main() {
    cin >> n >> k;
    ll ans, keep;
    keep = k;
    for (int i = 0; i < 30; i++) {
        if (n < keep) {
            ans = i;
            break;
        } else {
            keep *= k;
        }
    }
    cout << ans + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl          '\n'
#if     DEBUG
#define trace(var)  {cerr << "Line " << __LINE__ << ": " << #var << "=" << var << nl;}
#else
#define trace(var)	{}
#endif
#define fori(n)			for(int i = 0; i < n; ++i) 
#define forj(n)			for(int j = 0; j < n; ++j)
#define fork(n)			for(int k = 0; k < n; ++k)
#define forl(n)			for(int l = 0; l < n; ++l)

typedef long long ll;typedef pair<int,int> pii;typedef vector<bool> vbool;typedef vector<int> vint;typedef vector<ll> vll;typedef long double ld;typedef vector<vector<int>> vvi;

const ll N = 100010;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

int mem[N][3]; int n;

int solve(vvi &happy, int cur, int va) {
	if (mem[cur][va] != 0) return mem[cur][va];
	if (cur == n) return 0;
	int res = happy[cur][va];
	res += max(solve(happy, cur+1, (va+1)%3), solve(happy, cur+1, (va+2)%3));
	return mem[cur][va] = res;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	vvi happy(n, vint(3));
	fori(n) {
		cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
	}
	cout << max(solve(happy, 0, 0), max(solve(happy, 0, 1), solve(happy, 0, 2))) << nl;
	
	#if DEBUG
	cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
	#endif
	return 0;
}


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


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> A(m);
    rep(i, m){
        cin >> A.at(i);
    }
    reverse(A.begin(), A.end());
    for (auto ai: A){
        n -= ai;
    }
    if (n < 0) cout << -1 << endl;
    else cout << n << endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  ll head = 0;
  while(s[head] != 'A') head++;

  ll bot = s.size() - 1;
  while(s[bot] != 'Z') bot--;

  cout << bot - head + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 640
n = int(input())
height = list(map(int,input().split()))
ans = 0
for i in range(1,len(height)):
  if height[i] >= height[i-1]:
    continue
  if height[i] < height[i-1]:
    ans += height[i-1] - height[i]
    height[i] = height[i-1]
print(ans)

Measured memory_bytes: 32124
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

class UFTree {
    vector<int> parent;
    vector<int> height;

public:
    UFTree(int size)
    {
        for (int i = 0; i < size; i++) {
            parent.push_back(i);
            height.push_back(0);
        }
    }
    int root(int node)
    {
        if (parent[node] == node) {
            return node;
        }
        return parent[node] = root(parent[node]);
    }
    void merge(int n0, int n1)
    {
        int r0 = root(n0), r1 = root(n1);
        if (r0 == r1) {
            return;
        }
        if (height[r0] < height[r1])
            swap(r0, r1);
        if (height[r0] == height[r1])
            height[r0]++;
        parent[r1] = r0;
    }
};

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

    using P = tuple<int, int>;
    vector<int> a(n), b(n);
    vector<P> p(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    rep(i, n)
    {
        cin >> b[i];
    }

    rep(i, n)
    {
        p[i] = P(b[i], a[i]);
    }
    sort(p.begin(), p.end());

    vector<P> q(n);
    rep(i, n)
    {
        int c;
        tie(ignore, c) = p[i];
        q[i] = P(c, i);
    }

    sort(q.begin(), q.end());

    rep(i, n)
    {
        int c, d;
        tie(c, ignore) = q[i];
        tie(d, ignore) = p[i];
        if (d < c) {
            cout << "No" << endl;
            return 0;
        }
    }

    UFTree uft(n);
    rep(i, n)
    {
        int j;
        tie(ignore, j) = q[i];
        uft.merge(i, j);
    }

    int cnt = 0;
    vector<bool> isCounted(n, false);
    rep(i, n)
    {
        if (!isCounted[uft.root(i)]) {
            cnt++;
            isCounted[uft.root(i)] = true;
        }
    }

    if (cnt > 1) {
        cout << "Yes" << endl;
    } else {
        rep(i, n - 1)
        {
            int a, b;
            tie(b, ignore) = p[i];
            tie(a, ignore) = q[i + 1];
            if (b >= a) {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    }

    return 0;
}

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

#define endl '\n'

using namespace std;

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

	string s;
	getline(cin, s);
	for(int i = 0 ; s[ i ] ; i++)
		if(s[ i ] >= 65 && s[ i ] <= 90)
			s[ i ] += 32;
		else if(s[ i ] >= 97 && s[ i ] <= 122)
			s[ i ] -= 32;
	cout << s << endl;
	return 0;
}


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

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

  bool ok =true;
  for(int i=0;i<2;i++){
   for(int j=i+1;j<3;j++){
    if(S[i]==S[j]){
      ok=false;
    }
   }
  }
  if(ok){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	string s, t;
	cin >> n >> s >> t;
	
	int a = 0, b = 0;
	for(int i = 0; i < 2 * n; ++i) {
		if( i % 2 == 0 ) {
			cout << s[a];
			a++;
		} else {
			cout << t[b];
			b++;
		}
	}
	
	cout << endl;
	
	return 0;
}


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T,class U>
ostream& operator<<(ostream& os,const map<T, U> & mp){
	os << "{";
	int i = 0;
	for(auto it : mp){
		if(i) os<<", ";
		os << it;
		i++;
	}
	os << "}";	
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = 105;
char s[N];
int main(){
	vector<int> v;
	int k;
	scanf("%s", s + 1);
	scanf("%d", &k);
	int n = strlen(s + 1);
	int curr = 0, i = 1;
	while(i <= n){
		char c = s[i];
		int j = i;
		while(j <= n && s[j] == s[i]) j++;
		v.push_back(j - i);
		i = j;
	}
	ll ans = 0;
	for(int i = 1; i + 1< sz(v); i++) ans += (v[i] / 2) * (ll) k;
	if(sz(v) == 1){
		ans += (n * (ll) k) / 2;
		printf("%lld\n", ans);
		return 0;
	}
	if(s[1] != s[n]){
		ans += ((v[0]) / 2)	 * (ll) k;
		ans += ((v.back()) / 2)	 * (ll) k;
	} else{
		ans += ((v[0] + v.back()) / 2) * (ll) (k - 1);
		ans += v[0] / 2;
		ans += v.back() / 2;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
signed main(){
    int n;
    cin>>n;
    int kai=0;
    int ans=0;
    for(int i=1;i<=n;i++){
        kai+=i;
        ans++;
        if(kai>n){
            if(kai-n<=i){
                cout<<ans<<endl;
                return 0;
            }
        }
        else if(kai==n){
            cout<<ans<<endl;
            return 0;
        }
        else{
            continue;
        }
    }
}

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

ll gcd(ll m, ll n){
    ll tmp;
    while(m%n){
        tmp = n;
        n = m % n;
        m = tmp;
    }
    return n;
}

pair<map<ll, ll>, set<ll>> prime_factor(ll n){
    map<ll, ll> res;
    set<ll> primes;
    for(ll i = 2; i*i <= n; ++i) {
        if(n%i==0) primes.insert(i);

        while(n%i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) {
        res[n] = 1;
        primes.insert(n);
    }
    return make_pair(res, primes);
}

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

    int n;
    cin >> n;

    vector<ll> a(n);
    ll g;
    bool ispair = true;
    map<ll, ll> primes;
    rep(i, n){
        cin >> a[i];
        if(i == 0){
            g = a[i];
        }
        else{
            g = gcd(g, a[i]);
        }
        if(a[i] == 1) continue;
        if(ispair){
            set<ll> pri = prime_factor(a[i]).second;
            for(ll elem: pri){
                if(primes[elem] > 0){
                    ispair = false;
                    break;
                }
                ++primes[elem];
            }
        }
    }

    if(ispair) puts("pairwise coprime");
    else if(g == 1) puts("setwise coprime");
    else puts("not coprime");

    return 0;
}

Measured memory_bytes: 11124
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

int N, M, L;

struct Edge {
	int to, cost, enemy;
	Edge(int _t, int _c, int _e) : to(_t), cost(_c), enemy(_e) {}
};
bool operator > (const Edge& e1, const Edge& e2) {
	if (e1.enemy < e2.enemy) return true;
	else if (e1.to > e2.to) return true;
	return e1.cost < e2.cost;
}
bool operator == (const Edge& e1, const Edge& e2) {
	if (e1.enemy == e2.enemy && e1.to==e2.to && e1.cost == e2.cost) return true;
	return false;
}
bool operator != (const Edge& e1, const Edge& e2) { return !(e1 == e2); }
bool operator < (const Edge& e1, const Edge& e2) { return !(e1 > e2) && (e1 != e2); }
bool operator >= (const Edge& e1, const Edge& e2) { return (e1 > e2) || (e1 == e2); }
bool operator <= (const Edge& e1, const Edge& e2) { return (e1 < e2) || (e1 == e2); }

const int INF = 1e9;
int d[110][110];

int main() {
	while (1) {
		cin >> N >> M >> L; if (N==0 && M==0 && L==0) break;
		vector< vector<Edge> > G(N+1, vector<Edge>());
		
		for (int i=0; i<M; i++) {
			int a, b, d, e; cin >> a >> b >> d >> e;
			G[a].push_back(Edge(b, d, e));
			G[b].push_back(Edge(a, d, e));
		}
		
		for (int i=0; i<=N; i++) fill(d[i], d[i] + L + 1, INF);
		
		d[1][0] = 0;
		
		priority_queue<Edge, vector<Edge>, greater<Edge> > q;
		q.push( Edge(1, 0, 0) );
		
		while (!q.empty()) {
			Edge e = q.top(); q.pop();
			
			for (int i=0; i<(int)G[e.to].size(); i++) {
				Edge ne = G[e.to][i];
				
				if (e.cost + ne.cost <= L) {
					if (d[ne.to][e.cost + ne.cost] > e.enemy) {
						d[ne.to][e.cost + ne.cost] = e.enemy;
						q.push(Edge(ne.to, e.cost + ne.cost, e.enemy));
					}
				}
				
				if (d[ne.to][e.cost] > e.enemy + ne.enemy) {
					d[ne.to][e.cost] = e.enemy + ne.enemy;
					q.push(Edge(ne.to, e.cost, e.enemy + ne.enemy));
				}
			}
		}
		
		int ans = INF;
		for (int i=0; i<=L; i++) ans = min(ans, d[N][i]);
		cout << ans << endl;
	}
	
	return 0;
}

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



int main() {
	string a,t; cin >> a>>t;

	
	int count = 0;
	for (int i = 0; i < 3; i++) {
		if (a.at(i) == t.at(i)) {
			count++;
		}
		
	}
	
cout << count << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	int x = s.nextInt();
	int y = s.nextInt();

	while(x != 0 || y != 0){
	    if(x <= y) System.out.println(x+" "+y);
	    else System.out.println(y+" "+x);

	    x = s.nextInt();
	    y = s.nextInt();
	}
    }
}



Measured memory_bytes: 35052
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  vi d(n);
  scan(d);
  sort(all(d));
  print(d[n/2] - d[n/2 - 1]);

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
//vvi(n, vector<int>(m, -1))
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a) (a).begin(), (a).end()

int main(){
	int a[5], i;
  rep(i, 5) cin >> a[i];
  int sum = 0;
  int b[5];
  rep(i, 5){
    b[i] = a[i] % 10;
  }
  int m = 10;
  rep(i, 5){
    if(a[i]%10 == 0){
      sum += a[i];
      continue;
    }
    m = min(m,b[i]);
    int d = 10 - a[i] % 10;
    sum += a[i] + d;
  }
  if(m != 10) sum = sum - 10 + m;

  cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;

signed main(){
    int a,b;
    cin>>a>>b;
    cout<<(b-1+a-1-1)/(a-1)<<endl;
    return 0;
}



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

using namespace std;
using ll = long long;


int main(){
  int X, A;
  cin >> X >> A;
  
  
  if(X<A){
    cout << 0 << endl;
  }else{
    cout << 10 << endl;
  }
 
  return 0;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int n, q, s, t, x, u, a[1 << 18], b[1 << 18];
bool f;

void add(int k, int l, int r) {
	if (!(t < l || r < s)) {
		if (s <= l&&r <= t) {
			a[k] += x;
			b[k] += x;
		}
		else {
			add(k * 2, l, (l + r) / 2);
			add(k * 2 + 1, (l + r) / 2 + 1, r);
			a[k * 2] += b[k];
			a[k * 2 + 1] += b[k];
			b[k * 2] += b[k];
			b[k * 2 + 1] += b[k];
			b[k] = 0;
			a[k] = min(a[k * 2], a[k * 2 + 1]);
		}
	}
}

int find(int k, int l, int r) {
	if (t < l || r < s)return intmax;
	else if (s <= l&&r <= t)
		return a[k];
	else {
		a[k * 2] += b[k];
		a[k * 2 + 1] += b[k];
		b[k * 2] += b[k];
		b[k * 2 + 1] += b[k];
		b[k] = 0;
		a[k] = min(a[k * 2], a[k * 2 + 1]);
		return min(find(k * 2, l, (l + r) / 2), find(k * 2 + 1, (l + r) / 2 + 1, r));
	}
}

int main(){
	cin >> n >> q;
	for (u = 1; u < n; u *= 2);
	--u;
	for (int i = 0; i != q; ++i) {
		cin >> f >> s >> t;
		if (f)
			cout << find(1, 0, u) << endl;
		else {
			cin >> x;
			add(1, 0, u);
		}
	}
	return 0;
}



Measured memory_bytes: 4688
def hoge(n, k)
  c = 1
  while n < k
    n *= 2
    c *= 1/2r
  end
  return c
end


n, k = gets.split.map(&:to_i)

a = Array.new(n) {|i|
  hoge(i + 1, k)
}

p a.reduce(0.0, &:+).to_f / n.to_f


Measured memory_bytes: 2684
import sys
 
def dijkstra(nodes, start, matrix):
  defnode = [False] * (nodes)
  cost = [sys.maxint] * (nodes)
  cost[start] = 0
  node = start
  counter = 0
  while True:
    counter += 1
    if counter == nodes or node == sys.maxint:
      return cost
    defnode[node] = True
    for i in xrange(nodes):
      if defnode[i]:
        continue
      if matrix[node][i] == sys.maxint:
        continue
      cost[i] = min(cost[i], cost[node]+matrix[node][i])
    minnode = sys.maxint
    mincost = sys.maxint
    for i in xrange(nodes):
      if defnode[i]:
        continue
      if cost[i] < mincost:
        minnode = i
        mincost = cost[i]
    node = minnode

def get_state(a, c, k):
  return (a-1) * (c+1) + k
 
while True:
  c,n,m,s,d = map(int, raw_input().split())
  if c == 0:
    break
  matrix = [[sys.maxint] * n*(c+1) for i in xrange(n*(c+1))]
  for i in xrange(m):
    a,b,f = map(int, raw_input().split())
    # no use ticket
    for i in xrange(c+1):
      matrix[get_state(a, c, i)][get_state(b, c, i)] = f
      matrix[get_state(b, c, i)][get_state(a, c, i)] = f
    # use ticket
    for i in xrange(c):
      matrix[get_state(a, c, i)][get_state(b, c, i+1)] = f/2
      matrix[get_state(b, c, i)][get_state(a, c, i+1)] = f/2
  costs = dijkstra(n*(c+1), get_state(s, c, 0), matrix)
  mincost = sys.maxint
  for i in xrange(c+1):
    mincost = min(mincost, costs[get_state(d, c, i)])
  print mincost

Measured memory_bytes: 20728