akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define N 100003
#define M 103
#define db double
#define P putchar
#define G getchar
#define inf 998244353
using namespace std;
char ch;
int a[N],b[N],c[N],d[N],n,ans,f[N],g[N],s,x,y;
bool bz[N];
void read(int &n){
    n=0;
    ch=G();
    while((ch<'0' || ch>'9') && ch!='-')
		ch=G();
    ll w=1;
    if(ch=='-')
		w=-1,ch=G();
    while('0'<=ch && ch<='9')
		n=(n<<3)+(n<<1)+ch-'0',ch=G();
    n*=w;
}
void write(ll x){
	if(x>9)
		write(x/10);
	P(x%10+'0');
}
int get(int x){
    return f[x]=(x==f[x]?x:get(f[x]));
}
int main(){
    read(n);
	s=0;
    for(int i=1;i<=n;i++)
        read(a[i]),s^=a[i];
    a[n+1]=s;s=0;
    for(int i=1;i<=n;i++)
        read(b[i]),s^=b[i];
    b[++n]=s;
    for(int i=1;i<=n;i++)
        c[i]=a[i],d[i]=b[i],f[i]=i;
    sort(c+1,c+1+n),sort(d+1,d+1+n);
    for(int i=1;i<=n;i++)
        if(c[i]!=d[i]){
            puts("-1");
            return 0;
        }
    for(int i=1;i<=n;i++){
        if(a[i]!=b[i]||i==n){
            if(i!=n)
				ans++;
            x=lower_bound(c+1,c+1+n,a[i])-c,y=lower_bound(c+1,c+1+n,b[i])-c;
            bz[x]=bz[y]=1,f[get(x)]=get(y);
        }
    }
    if(ans==0){
        puts("0");
        return 0;
    }
    for(int i=1;i<=n;i++)
        if(bz[i]&&f[i]==i)
			ans++;
    write(ans-1);
    return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    llint x;
    cin >> x;

    for(llint p1=1;p1*p1<=x;p1++) {
        if(x%p1!=0) continue;
        llint p2 = x / p1;
        llint a;
        for(llint b=-2000;b<=2000;b++) {
            a = b + p1;
            if(a*a*a*a+a*a*a*b+a*a*b*b+a*b*b*b+b*b*b*b==p2) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

ll nCr_table[51][51];

void make_nCr_table(int max_num){
    for(int i = 0; i < 51; i++){
        for(int j = 0; j < 51; j++){
            nCr_table[i][j] = 1;
        }
    }

    for(int i = 1; i <= max_num; i++){
        ll v = 1;
        for(int j = 1; j <= i; j++){
            v *= (i-j+1);
            v /= j;
            nCr_table[i][j] = v;
        }
    }
}



int main() {
    int n, p;
    cin >> n >> p;
    int even = 0;
    int odd = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(a%2 == 0){even++;}
        else{odd++;}
    }
    make_nCr_table(n);
    for(int i = 0; i <= even; i++){
        for(int j = p; j <= odd; j+=2){
            ll ncr = nCr_table[even][i]*nCr_table[odd][j];
            ans += ncr;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	string s;
	cin >> s;

	string ans;
	if (s == "Sunny") ans = "Cloudy";
	else if (s == "Cloudy") ans = "Rainy";
	else ans = "Sunny";

	cout << ans << endl;

	return 0;
}


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

public class Main{
    public static void main(String [] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String temp[] = br.readLine().split(" ");
        
        long n = Long.parseLong(temp[0]);
        double y = Double.parseDouble(temp[1]);

        double temp2 = y*(double)(n);



        System.out.println((long)temp2);
       

    }
}

Measured memory_bytes: 32956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
	vector<ll> a(n); \
	rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
	vector<string> a(n); \
	rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
	vector<double> a(n); \
	rep(i, n) { cin >> a[i]; }
#define in(a) \
	ll a;     \
	cin >> a;
#define ins(a) \
	string a;  \
	cin >> a;
#define ind(a) \
	double a;  \
	cin >> a;
template <class T>
inline void out(T a)
{
	cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x) (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
using vell = vector<ll>;
using ves = vector<string>;
using ved = vector<double>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
#define yes out("Yes")
#define no out("No")

int main()
{
	in(an);
	in(bn);
	in(m);
	repin(a,an);
	repin(b,bn);
	ll ans = *min_element(all(a)) + *min_element(all(b));
	rep(i,m){
		in(x);
		in(y);
		in(c);
		ans = min(ans,a[x-1]+b[y-1]-c);
	}
	out(ans);
}

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

long long Gcd(long long m, long long n)
{
	long long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main(){
    int N;
    long long X;
    cin >> N >> X;

    vector<long long> p_dist;
    vector<long long> n_dist;

    for(int i=0;i<N;i++){
        long long d;
        cin >> d;
        if(d < X)
            n_dist.push_back(d);
        else
            p_dist.push_back(d);
    }

    n_dist.push_back(X);
    sort(p_dist.begin(),p_dist.end());
    sort(n_dist.begin(),n_dist.end(),std::greater<int>());

    //for(int i=0;i<p_dist.size();i++){
    //    cout << p_dist[i] << endl;
    //}
    //cout << endl;
    //for(int i=0;i<n_dist.size();i++){
    //    cout << n_dist[i] << endl;
    //}


    long long skip = -1;
    if(p_dist.size()>0){
        if(skip < 0)
            skip = p_dist[0] - X;
        for(int i=1;i<p_dist.size();i++){
            long long dist = p_dist[i] - p_dist[i-1];
            skip = Gcd(skip, dist);
            if(skip==1)
                break;
        }
    }

    if(n_dist.size()>1){
        if(skip < 0)
            skip = X - n_dist[0];
        for(int i=0;i<n_dist.size()-1;i++){
            long long dist = n_dist[i] - n_dist[i+1];
            skip = Gcd(skip, dist);
            if(skip==1)
                break;
        }
    }

    cout << skip << endl;

    return 0;
}

Measured memory_bytes: 1528
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0, cur = 0;
	rep(i,n){
		int h;
		cin >> h;
		if(h > cur) ans += h - cur;
		cur = h;
	}
	cout << ans << endl;
	return 0;
}

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

string week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int search(string day) {
    rep(i, 7) {
        if (day == week[i]) return i;
    }
    return 0;
}

int main() {
    string S;
    cin >> S;
    cout << 7 - search(S) << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int a, b;
    cin >> a >> b;
    if (a <= b) {
        forn(i, b) cout << a;
        cout << endl;
    } else {
        forn(i, a) cout << b;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,b[200009],num=0;
ll tmp=0,c[200009],d[200009],tmp1=0;
char a[200009];
ll pow1(ll a,int n,ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1)
            ans=ans*a%m;
        a=a*a%m;
        n>>=1;
    }
    return ans;
}
void solve(int x)
{
    //cout<<x<<endl;
    int num=1;
    while(x)
    {
        int tmp=x,num1=0;
        while(tmp)
        {
            num1+=tmp%2;
            tmp/=2;
        }
        x%=num1;
        num++;
    }
    printf("%d\n",num);
}
int main()
{
    scanf("%d%s",&n,a);
    for(int i=0; i<n; i++)
        b[n-i-1]=a[i]-'0';
    for(int i=0; i<n; i++)
        num+=b[i];
    for(int i=0; i<n; i++)
    {
        if(num-1>0)
            c[i]=pow1(2,i,num-1);
        d[i]=pow1(2,i,num+1);
        if(b[i])
            tmp+=c[i],tmp1+=d[i];
    }
    for(int i=n-1; i>=0; i--)
    {
        if(b[i])
        {
            if(num-1!=0)
                solve((tmp-c[i])%(num-1));
            else
                printf("0\n");
        }
        else
            solve((tmp1+d[i])%(num+1));
    }
    return 0;
}


Measured memory_bytes: 7852
#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N; cin>>N;
    long long ans =0;
    for(int i=1; i<=N; i++){
        if(i%3!=0 && i%5!=0){
            ans +=i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, k;
	cin >> n >> k;
	vll h(n);
	for (ll i = 0; i < n; i++) cin >> h[i];
	sort(all(h));
	ll ans = inf;
	for (ll i = 0; i < n - k + 1; i++) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	cout << ans << endl;
}


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

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int n,dp[2003][2003],a[6003],ans,tg,MX[2003],cur;
int A[100004],B[100004],C[100004],t;
void add(int x,int y,int z){A[t]=x,B[t]=y,C[t++]=z;}
int main(){
	cin>>n;
	for(int i=1;i<=3*n;i++)scanf("%d",&a[i]);
	memset(dp,-1,sizeof(dp));
	memset(MX,-1,sizeof(MX));
	dp[a[1]][a[2]]=dp[a[2]][a[1]]=MX[a[1]]=MX[a[2]]=cur=0;
	for(int i=3;i<3*n;i+=3){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){tg++;continue;}
		t=0;
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i+1]>a[i+2])swap(a[i+1],a[i+2]);
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i]==a[i+1]||a[i+1]==a[i+2])for(int j=1;j<=n;j++){
			if(a[i]==a[i+1]){
				if(dp[j][a[i]]>=0)add(j,a[i+2],dp[j][a[i]]+1);
			}else if(dp[j][a[i+1]]>=0)add(j,a[i],dp[j][a[i+1]]+1);
		}
		if(dp[a[i]][a[i]]>=0)add(a[i+1],a[i+2],dp[a[i]][a[i]]+1);
		if(dp[a[i+1]][a[i+1]]>=0)add(a[i],a[i+2],dp[a[i+1]][a[i+1]]+1);
		if(dp[a[i+2]][a[i+2]]>=0)add(a[i],a[i+1],dp[a[i+2]][a[i+2]]+1);
		add(a[i],a[i+1],cur),add(a[i+1],a[i+2],cur),add(a[i],a[i+2],cur);
		for(int k=1;k<=n;k++)if(MX[k]>=0)add(a[i],k,MX[k]),add(a[i+1],k,MX[k]),add(a[i+2],k,MX[k]);
		for(int j=0;j<t;j++)if(dp[A[j]][B[j]]<C[j])
			dp[A[j]][B[j]]=dp[B[j]][A[j]]=C[j],MX[A[j]]=max(MX[A[j]],C[j]),MX[B[j]]=max(MX[B[j]],C[j]),cur=max(cur,C[j]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)ans=max(ans,dp[i][j]);
		if(dp[i][i]>=0)if(i==a[3*n])ans=max(ans,dp[i][i]+1);
	}
	printf("%d",ans+tg);
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N, K;
	cin >> N >> K;

	int result = 0;
	for( int i = 0; i < N; ++i ) {
		int h;
		cin >> h;

		if( h >= K ) {
			result += 1;
		}
	}

	cout << result << endl;
	return 0;
}


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

int main() {
  int n;
  while(cin >> n, n) {
    bool isDowned, isLDown, isRDown;
    isDowned = isLDown = isRDown = true;
    int ans = 0;
    for(int i = 0; i < n; ++i) {
      string operation;
      cin >> operation;
      if(operation == "lu") isLDown = false;
      if(operation == "ld") isLDown = true;
      if(operation == "ru") isRDown = false;
      if(operation == "rd") isRDown = true;
      if((isDowned && !isLDown && !isRDown) || (!isDowned && isLDown && isRDown)) {
        ++ans;
        isDowned = !isDowned;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

//const ll mod = static_cast<int>(1e9 + 7);



int main() {
	int N, M;
	cin >> N >> M;

	vector<Pll> vec_p(N);
	for (int i = 0; i < N; ++i) {
		cin >> vec_p[i].first >> vec_p[i].second;
	}
	sort(vec_p.begin(), vec_p.end());

	auto compare = [](Pll& p1, Pll& p2) {
		if (p1.second < p2.second) {
			return true;
		}
		else if (p1.second == p2.second) {
			if (p1.first >= p2.first) {
				return true;
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
	};

	priority_queue<
		Pll,
		std::vector<Pll>,
		decltype(compare)
	> pq(compare);

	ll ans = 0;

	int idx = 0;
	for (int i = M - 1; i >= 0; --i) {
		int dt = M - i;
		for (; idx < vec_p.size() && vec_p[idx].first <= dt; ++idx) {
			pq.push(vec_p[idx]);
		}

		if (!pq.empty()) {
			Pll p = pq.top();
			pq.pop();
			ans += p.second;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MAXN = (1 << 20);
const int64_t inf = (int64_t)1e17 + 42;
const int maxn = 200100;

struct LiChao_min
{
	struct line
	{
		ll a, b;
		line() { a = 0; b = 0; }
		line(ll _a, ll _b) { a = _a; b = _b; }
		int64_t eval(ll x) { return a * 1ll * x + (int64_t)b; }
	};

	struct node
	{
		node *l, *r; line f;

		node() { f = line(); l = nullptr; r = nullptr; }
		node(int a, int b) { f = line(a, b); l = nullptr; r = nullptr; }
		node(line v) { f = v; l = nullptr; r = nullptr; }
	};

	typedef node* pnode;

	pnode root; int sz;
	void init(ll _sz) { sz = _sz + 1; root = nullptr; }

	void add_line(ll a, ll b) { line v = line(a, b); insert(v, -sz, sz, root); }
	int64_t query(ll x) { return query(x, -sz, sz, root); }

	void insert(line &v, int l, int r, pnode &nd)
	{
		if(!nd) { nd = new node(v); return; }

		int64_t trl = nd->f.eval(l), trr = nd->f.eval(r);
		int64_t vl = v.eval(l), vr = v.eval(r);

		if(trl <= vl && trr <= vr) return;
		if(trl > vl && trr > vr) { nd->f = v; return; }

		int mid = (l + r) >> 1;
		if(trl > vl) swap(nd->f, v);
		if(nd->f.eval(mid) < v.eval(mid)) insert(v, mid + 1, r, nd->r);
		else swap(nd->f, v), insert(v, l, mid, nd->l);
	}

	int64_t query(int x, int l, int r, pnode &nd)
	{
		if(!nd) return inf;
		if(l == r) return nd->f.eval(x);

		int mid = (l + r) >> 1;
		if(mid >= x) return min(nd->f.eval(x), query(x, l, mid, nd->l));
		return min(nd->f.eval(x), query(x, mid + 1, r, nd->r));
	}
};

ll n, c;
ll arr[maxn];
ll dp[maxn];

int main() {
    LiChao_min root;
    root.init(4*1e6);

    cin>>n>>c;
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
    }

    dp[1] = 0;
    root.add_line(-2*arr[1], dp[1] + arr[1]*arr[1]);

    for(int i=2;i<=n;i++) {
        dp[i] = c + arr[i] * arr[i] + root.query(arr[i]);
        root.add_line(-2*arr[i], dp[i] + arr[i]*arr[i]);
    }
    cout<<dp[n]<<"\n";
    return 0;
}


Measured memory_bytes: 12800
H, W, D = map(int, input().split())
a = [[0, 0] for i in range(H * W)]
for i in range(H):
	A = [int(j) for j in input().split()]
	for j in range(W):
		a[A[j] - 1][0] = i
		a[A[j] - 1][1] = j
Q = int(input())
b = [0] * H * W
i = D
while i < H * W:
	b[i] += abs(a[i - D][0] - a[i][0])
	b[i] += abs(a[i - D][1] - a[i][1])
	b[i] += b[i - D]
	i += 1
for i in range(Q):
	L, R = map(int, input().split())
	print(b[R - 1] - b[L - 1])

Measured memory_bytes: 65020
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
struct one
{
	int cost, val[15];
} w[15];
int a[15], t[15];
int n, m, k;
inline bool check(void)
{
	rep(i, 0, m) if (t[i] < k) return 0;
	return 1;
}
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>k;
	t[0] = 11;
	t[1] = 12;
	t[2] = 13;
	rep(i, 0, n)
	{
		cin>>w[i].cost;
		rep(j, 0, m) cin>>w[i].val[j];
	}
	int ans = 1000000000;
	for( a[0] = 0; a[0] < 2; a[0]++)
	for( a[1] = 0; a[1] < 2; a[1]++)
	for( a[2] = 0; a[2] < 2; a[2]++)
	for( a[3] = 0; a[3] < 2; a[3]++)
	for( a[4] = 0; a[4] < 2; a[4]++)
	for( a[5] = 0; a[5] < 2; a[5]++)
	for( a[6] = 0; a[6] < 2; a[6]++)
	for( a[7] = 0; a[7] < 2; a[7]++)
	for( a[8] = 0; a[8] < 2; a[8]++)
	for( a[9] = 0; a[9] < 2; a[9]++)
	for( a[10] = 0; a[10] < 2; a[10]++)
	for( a[11] = 0; a[11] < 2; a[11]++)
	{
		memset(t, 0, sizeof(t));
		int cos = 0;
		rep(i, 0, n)
			if (a[i])
			{
				cos += w[i].cost;
				rep(j, 0, m) t[j] += w[i].val[j];
			}
		if (check()) ans = min(ans, cos);
	}
	if (ans == 1000000000) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> to(n), cost(n);
  rep(i, n-1) {
    int a,b,w;
    cin >> a >> b >> w;
    a--;
    b--;
    to[a].push_back(b); cost[a].push_back(w);
    to[b].push_back(a); cost[b].push_back(w);
  }

  vector<int> ans(n, -1);
  queue<int> q;
  ans[0] = 0;
  q.push(0);

  while(!q.empty()) {
    int v = q.front();
    q.pop();
    rep(i, to[v].size()) {
      int u = to[v][i];
      int w = cost[v][i];
      if(ans[u] != -1) continue;
      ans[u] = ((ans[v] + w) % 2);
      q.push(u);
    }
  }

  rep(i, n) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 11904
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        final int n = sc.nextInt();

        final int[] ans = new int[n];
        for (int i = 2; i <= n; i++) {
            final int a = sc.nextInt();
            ans[a-1]++;
        }

        Arrays.stream(ans).forEach(System.out::println);
    }
}


Measured memory_bytes: 60576
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();


        }

        int cnt = 0;
        int b = 0;
        int r = 1;
        for (int i = 0 ; i < n ; i++) {


            if (b == a[i]) {
                r++;
            } else {
                b = a[i];
                cnt += r / 2;
                r = 1;
            }
            if (i == n - 1) {
                cnt += r /2 ;
            }
        }

        System.out.println(cnt);
    }

}

Measured memory_bytes: 23124
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    long answer = 0;
    int n = Integer.parseInt(br.readLine());
    long[][] div2div5cnt = new long[19][19];
    long[] pow10 = new long[10];
    pow10[0] = 1;
    for(int i = 1; i < 10; i++){
      pow10[i] = pow10[i - 1] * 10;
    }
    for(int i = 0; i < n; i++){
      int div5cnt = 0;
      int div2cnt = 0;
      String a = br.readLine();
      int idx = a.indexOf('.');
      long num = 0;
      if(idx > 0){
        num = Long.parseLong(a.replace(".", "")) * pow10[9 - (a.length() - idx - 1)];
      } else {
        num = Long.parseLong(a) * pow10[9];
      }
      while(num % 5 == 0){
        div5cnt++;
        num /= 5;
      }
      while(num % 2 == 0){
        div2cnt++;
        num /= 2;
      }
      div2div5cnt[Math.min(div2cnt, 18)][Math.min(div5cnt, 18)]++;
    }
    for(int div2a = 0; div2a <= 18; div2a++){
      for(int div5a = 0; div5a <= 18 ; div5a++){
        for(int div2b = 18 - div2a; div2b <= 18; div2b++){
          for(int div5b = 18 - div5a; div5b <= 18; div5b++){
            if(div2a == div2b && div5a == div5b) {
              answer += (div2div5cnt[div2a][div5a] * (div2div5cnt[div2b][div5b] - 1));
            } else {
              answer += (div2div5cnt[div2a][div5a] * div2div5cnt[div2b][div5b]);
            }
          }
        }
      }
    }
    System.out.println(answer / 2);
  }
}


Measured memory_bytes: 53236
s = [int(x) for x in input().split()]

str_a = str(s[0])
str_b = str(s[1])

# aをb回繰り返した文字列生成
for i in range(s[1]-1):
    str_a = str_a + str(s[0])

# bをa回繰り返した文字列生成
for i in range(s[0]-1):
    str_b = str_b + str(s[1])

# 生成した文字列のソート
str_list = [str_a,str_b]
str_list_sort = sorted(str_list)


print(str_list_sort[0])


Measured memory_bytes: 3064
#include <cstdio>
#define MOD 1000000007
using namespace std;

int n;
int lower_bound = 1, cnt = 0;

int main() {
	scanf("%d", &n);
	long long ret = 1;

	for (int i = 0; i < n; i++) {
		int pos;
		scanf("%d", &pos);
		ret = (ret * (cnt + 1)) % MOD;
		if (lower_bound <= pos) {
			lower_bound += 2;
			cnt++;
		}
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 128
function main()
    N = pread(Int)
    a = sort(readvec(Int, N))
    au = unique(a)
    ad = Dict((u, count(isequal(u), a)) for u in au)
    sumu = zeros(Int, length(au))
    sumu[1] = au[1]*ad[au[1]]
    for i in 2:length(au)
        sumu[i] = au[i]*ad[au[i]] + sumu[i-1]
    end
    aN = length(au)
    sumc = 0
    #for i in 1:aN-1
    i = 1
    while i <= aN-1
        v = sumu[i]
        nt = i
        while true
            nt = findlast(x -> x <= 2*v, view(au, nt:aN)) + nt - 1
            if aN == nt
                sumc += ad[au[i]]
                break
            elseif v == sumu[nt]
                i = nt+1
                break
            end
            v = sumu[nt]
        end
        if sumc != 0
            sumc += sum(map(x -> ad[au[x]], i+1:aN))
            break
        end
    end
    if sumc == 0
        sumc = ad[au[end]]
    end
    println(sumc)
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


Measured memory_bytes: 244840
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    vector<int> l(N);
    for(int i = 0; i < N; i++) cin >> l.at(i);
    sort(l.begin(), l.end(), greater<int>());
    
    int ans = 0;
    for(int i = 0; i < K; i++) ans += l.at(i);
    cout << ans << endl;
}


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

ll comb(int n, int k)
{
    ll ans = 1;
    for(int i=0; i<k; i++) ans *= (n-i);
    for(int i=1; i<=k; i++) ans /= i;
    return ans;
}

int my_pow(int num, int k)
{
    if(k<=0) return 0;
    int ans = 1;
    for(int i=0; i<k; i++) ans *= num;
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    int K;
    cin >> K;

    int N = S.length();
    ll ans = 0;
    for(int i=0; i<N; i++)
    {
        int num = S[i] - '0';
        if(num==0) continue;
        K--;
        // i: 1~num-1
        ans += (num-1) * my_pow(9, K) * comb(N-i-1, K);
        // i: 0
        ans += my_pow(9, K+1) * comb(N-i-1, K+1);
        if(K==0)
        {
            ans += num;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3648
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define PI 3.14159265358979323846264338327950288
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	int a, b;
	cin >> a >> b;
	int aa = (a + 1) / 0.08, bb = b / 0.1;

	for (int i = bb; i <= aa; i++) {
		if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC098 D = Xor Sum2
// 2020.06.19
// 「条件を満たす区間の部分区間も条件満たす」
// しゃくとり法、尺取法
// 組の個数
// 演算子の優先順位　^ よりも == の方が上 

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }

  int right = 0;
  ll res = 0;
  ll s = 0; // sは和
  for(int left = 0; left < N; left++){ // Nは要素数
    // rightの位置決め
    while(right < N && (s^A[right]) == (s+A[right])){
      s += A[right]; // 実際にrightを1進めたときの処理
      right++;
    }
  
    // whileループをbreakした後(rightは条件を満たす最大)に行う処理
    res += (right - left); // 要素の長さを足すことで組数を求めている
  
    // leftをインクリメントする準備
    if(right == left) right++;
    else s -= A[left];
  }

  cout << res <<endl;
}

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

using namespace std;

int main() {
    int n, k, cnt = 1;
    scanf("%d%d\n", &n, &k);
    vector<char> s(n);
    scanf("%s", &s.front());
    for (int i = 1; i < int(s.size()); ++i) if (s.at(i - 1) != s.at(i)) ++cnt;
    printf("%d\n", n - max(1, cnt - 2 * k));
    return 0;
}


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

int main(){
  int n, m ;
  int lmax, rmin ;
  int l, r ;
  int i ;

  cin >> n >> m ;

  cin >> l >> r ;
  lmax=l ;
  rmin=r ;

  for(i=1;i<m;i++){
    cin >> l >> r ;
    if(lmax<l)
      lmax=l ;
    if(r<rmin)
      rmin=r ;
  }

  if(lmax<=rmin)
    i=rmin-lmax+1 ;
  else
    i=0 ;

  cout << i ;
  return 0 ;
}


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

int main(){
  string s;
  vector <char> ans;
  cin >> s;
  
  int n = s.size();
  rep(i,n){
    if(s[i] == '0') ans.push_back('0');
    if(s[i] == '1') ans.push_back('1');
    if(s[i] == 'B' && ans.size() != 0) ans.pop_back();
  }
  
  for(char c : ans) cout << c;
  cout << endl;
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main() {

    int n, sum = 0;
    map<int, int> cnt;

    cin >> n;

    for(int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if(cnt.count(a) == 0) {
            cnt[a] = 1;
        } else {
            ++cnt[a];
        }
    }

    auto it = cnt.begin();
    while(it != cnt.end()) {
        sum += it->second % 2;
        ++it;
    }

    cout << sum << endl;

}

Measured memory_bytes: 4992
#include<stdio.h>
#include<stdlib.h>
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
int main(){
  long long n,a,b,c,d,e;
  scanf("%lld",&n);
  while(n--){
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    if(a<b)goto NO;
    if(d<b)goto NO;
    if(c>=b)goto YES;
    if(c>=a)goto YES;
    if(b-c<2)goto YES;
    e=(a-c)%gcd(d,b);
    if(e==0)e=gcd(d,b);
    //if(gcd(d,b)==1)goto NO;
    if(e<(b-c))goto NO;
  YES:;
    printf("Yes\n");
    continue;
  NO:;
    printf("No\n");
    continue;
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,add,sub,mul,div;
   vector<int>v;
   cin>>a>>b;
   add=a+b;

   v.push_back(add);
   sub=a-b;
   v.push_back(sub);
   mul=a*b;
   v.push_back(mul);
   sort(v.begin(),v.end());
   printf("%d",v[2]);
   cout<<endl;


return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <unordered_set>
#include <math.h>

using namespace std;

using ll = long long;
const ll mod = 1e9 + 7;

int main()
{
	ll k, a, b;
	cin >> k >> a >> b;
	for (ll i = a; i <= b; i++)
		if (i % k == 0)
		{
			cout << "OK";
			return 0;
		}
	cout << "NG";
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll n, m;
  cin >> n >> m;

  vector<ll> a(n), b(n), c(m), d(m);
  rep(i, 0, n) cin >> a[i] >> b[i];
  rep(i, 0, m) cin >> c[i] >> d[i];

  vector<ll> ans(n, 0);
  rep(i, 0, n){
    ll dmin = INF;
    ll check = -1;
    rep(j, 0, m){
      ll sum = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      //cout << sum << endl;
      if(dmin > sum){
        dmin = sum;
        check = j;
      }
    }
    ans[i] = check+1;
  }

  rep(i, 0, n) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::input;
use num::integer::gcd;

fn main() {
    input! {
        n: u64,
    }

    println!("{}", solve(n));
}

fn solve(n: u64) -> u64 {
    let mut res = 0;
    for a in 1..=n {
        for b in 1..=n {
            let ab = gcd(a, b);
            for c in 1..=n {
                res += gcd(ab, c);
            }
        }
    }
    res
}


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

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i=0;i<N;i++){
        A[i]=0;
    }
    for(int i=1;i<N;i++){

        int s;
        cin >> s;
        A[s-1] += 1;
    }
    for(int i=0;i<N;i++){
        cout << A[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4416
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;

const lli MAX = 100000000000;

lli min(lli a, lli b) {
	return a < b ? a : b;
}

void print(lli *ary, lli size) {
	lli i;
	for (i = 0; i < size; i++) printf("%lld ", ary[i]);
	printf("\n");
}

lli min_cost(lli *height, lli n, lli k, lli i, lli *dp) {
	if (i == n-1) return 0;

	if (dp[i] != -1) return dp[i];

	lli ans = MAX;
	lli j;
	for (j = 1; j <= k; j++) {
		if (i+j >= n) {
			dp[i] = min(ans, llabs(height[i] - height[i+j-1]) + min_cost(height, n, k, i+j-1, dp));
			return dp[i];
		} else {
			ans = min(ans, llabs(height[i] - height[i+j]) + min_cost(height, n, k, i+j, dp));
		}
	}
	dp[i] = ans;
	return dp[i];
}

int main() {
	lli n, k, i;
	scanf("%lld %lld", &n, &k);

	lli height[n], dp[n];
	memset(dp, -1, sizeof(lli)*n);
	for (i = 0; i < n; i++) scanf("%lld", &height[i]);

	printf("%lld\n", min_cost(height, n, k, 0, dp));
	// print(dp, n);
	return 0;
}

Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main(){
	int a,b[10],c=0,d=0,e,f=0;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>b[i];
		if(b[i]>c){
			c=b[i];
			e=i;
		}
	}
	for(int i=0;i<a;i++){
		f=f+b[i];
		if(i==e){
			f=f-b[i];
		}
	}
	if(c<f)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
use std::collections::{BinaryHeap, BTreeSet};
fn main() {
    proconio::input! {
        t: usize,
    }
    for _ in 0..t {
        proconio::input! {
            n: usize,
            klr: [(usize,i64,i64);n],
        }
        let mut ql=BinaryHeap::new();
        let mut qr=BinaryHeap::new();
        let mut s=0;
        for (k,l,r) in klr {
            if l>r {
                s+=l;
                ql.push((l-r,k));
            }
            else {
                s+=r;
                qr.push((r-l,k));
            }
        }
        let m=ql.len();
        let mut sl: BTreeSet<_>=(0..m).collect();
        while let Some((d,k))=ql.pop() {
            if let Some(&i)=sl.range(0..k).rev().next() {
                sl.remove(&i);
            }
            else {
                s-=d;
            }
        }
        let mut sr: BTreeSet<_>=(m..n).collect();
        while let Some((d,k))=qr.pop() {
            if let Some(&i)=sr.range(k..n).next() {
                sr.remove(&i);
            }
            else {
                s-=d;
            }
        }
        println!("{}",s);
    }
}

Measured memory_bytes: 13652
k = int(input())
s = input()

# nCr(n, r, m)
mod = 1000000007
n = len(s) + k

fac = [1,1] # 階乗 n!
inv = [0,1] # 逆元 1/n
finv = [1,1] # 逆元の階乗 (n^-1)! = (1/n)!

for i in range(2, n+1):
    fac.append( (fac[-1] * i ) % mod )
    inv.append( (-inv[mod%i] * (mod//i)) % mod )
    finv.append( (finv[-1] * inv[-1]) % mod )

def nCr(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

i25, i26 = [1], [1]
for _ in range(k+1):
    i25.append(i25[-1] * 25 % mod)
    i26.append(i26[-1] * 26 % mod)

n = len(s)
ans = 0
for i in range(k+1):
    ans += i25[i] * i26[k-i] * nCr(i+n-1, n-1, mod)
    ans %= mod
print(ans)


Measured memory_bytes: 226588
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

struct Point {
  int x, y;
  Point(int x, int y) : x(x), y(y) {;}
};

typedef pair<int, Point> State;

int W, H, C, INF = (1 << 22);
vector<Point> pos;
char field[20][20];
int  dist[11][11];
int dx[4] = {0, 1, 0, -1},
    dy[4] = {-1, 0, 1, 0};
int dp[1 << 11][11];

void bfs(int src)
{
  int d[20][20];
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      d[i][j] = INF;

  Point start = pos[src];

  queue<State> que;
  que.push(State(0, start));

  while (!que.empty()) {
    State s = que.front(); que.pop();
    Point p = s.second;
    if (d[p.y][p.x] != INF) continue;

    d[p.y][p.x] = s.first; 
    for (int k = 0; k < 4; k++) {
      int nx = p.x + dx[k], ny = p.y + dy[k];
      if (nx >= 0 && nx < W && ny >= 0 && ny < H && field[ny][nx] != 'x') {
        que.push(State(s.first + 1, Point(nx, ny)));
      }
    }
  }

  for (int dst = 0; dst < C; dst++) 
    if (dst != src) 
      dist[src][dst] = d[pos[dst].y][pos[dst].x];
}

int rec(int S, int v)
{
  // 訪問済み
  if (dp[S][v] >= 0) 
    return dp[S][v];

  // すべての頂点を訪れて戻ってきた
  if (S == (1 << C) - 1) {
    return dp[S][v] = 0;
  }

  int res = INF;
  for (int u = 0; u < C; u++) {
    if (!(S >> u & 1)) {
      // uが未訪問なので、uへ移動
      res = min(res, rec(S | 1 << u, u) + dist[v][u]);
    }
  }

  return dp[S][v] = res;
}

void solve()
{
  
  // 距離テーブルの初期化
  for (int i = 0; i < C; i++) 
    for (int j = 0; j < C; j++) 
      if (i == j) 
        dist[i][j] = 0;
      else 
        dist[i][j] = INF;

  // 全点間の距離を求める
  for (int src = 0; src < C; src++) 
    bfs(src);

  // TSP
  memset(dp, -1, sizeof(dp));
  int res = rec(0, 0);
  if (res >= INF) 
    cout << -1 << endl;
  else
    cout << res << endl;
}

int main()
{
  while (cin >> W >> H && (W && H)) {

    // スタート+汚れたタイルの数
    C = 1;
    pos.clear();
    pos.push_back(Point(-1, -1));
    // read
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> field[i][j];
        if (field[i][j] == '*') {
          pos.push_back(Point(j, i));
          C++;
        } else if (field[i][j] == 'o') {
          pos[0].x = j;
          pos[0].y = i;
        }
      }
    }

    solve();
  }
}

Measured memory_bytes: 1000
#include<iostream>
int main()
{
    int n;
    std:: cin >> n;

    if ((n%10==2)||(n%10==4)||(n%10==5)||(n%10==7)||(n%10==9)){
        std::cout << "hon" << std::endl;
    }
    
    else if ((n%10==0)||(n%10==1)||(n%10==6)||(n%10==8)){
        std::cout << "pon" << std::endl;
    }
    
    else{
        std::cout << "bon" << std::endl;
    }
    
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n, m;
    cin >> n >> m;
    if(n==m) cout << "Yes" << endl;
    else     cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
N =int(input())
A = list(map(int, input().split()))

#２整数の最大公約数を求める

def gcd2(x,y): 
    while y != 0:
        x , y = y , x % y 
    return x



#N 整数の最大公約数を求める
#A = [A[0],...,A[N]] とする

def gcd(A):
    ans = A[0]
    for i in range(1,N): #range(1,N)= 1,2,...,N-1
        ans = gcd2(ans, A[i])
    return ans
print(gcd(A))

Measured memory_bytes: 14228
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    char b;
    cin>>b;

    if('a'<=b&&b<='z'){
        cout<<'a'<<endl;
    }else{
        cout<<'A'<<endl;
    }
    
return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;


    UnionFind(ll N): par(N), siz(N, 1LL) {
        for (ll i = 0; i < N; ++i) par[i] = i;
    }

    void init(ll N) {
        par.resize(N);
        siz.assign(N, 1LL);
        for (ll i = 0; i < N; ++i) par[i] = i;
    }


    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }


    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    int index[100100];
    UnionFind tree(N+1);
    rep(i,0,N){
        int p; cin >> p;
        index[p] = i+1;
    }
    rep(i,0,M){
        int x,y; cin >> x >> y;
        tree.unite(x,y);
    }

    int ans = 0;
    rep(i,0,N){
        if(tree.same(i+1, index[i+1])) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	ll n;
	cin >> n;
	ll arr[n-1];
	for(ll i = 0; i < n-1; i++){
		ll x;
		cin >> x;
		arr[i]=x;
	}
	ll ans = arr[0];
	ans+=(min(arr[0],arr[1]));
	for(ll i = 1; i < n-2; i++){
		ans+=min(arr[i],arr[i+1]);
	}
	if(n>=3)
	ans+=arr[n-2];
	cout << ans << endl;
}






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

vector<pint> vp[10001];
ll d[10001];
ll INF=1000100010001000100;
int n;
int dijkstra(int st){
    priority_queue<pint,vector<pint>,greater<pint> > pq;
    rep(i,n) d[i]=INF;
    d[st]=0;
    pq.push(make_pair(0,st));
    while(!pq.empty()){
        pint pi=pq.top();pq.pop();
        int t=pi.second;
        if(d[t]<pi.first) continue;
        for(auto it:vp[t]){
            if(d[it.second]>d[t]+it.first){
                d[it.second]=d[t]+it.first;
                pq.push(make_pair(d[it.second],it.second));
            }
        }
    }
}
int main(){
    cin>>n;
    int u,k,v,c;
    rep(i,n){
        cin>>u>>k;
        rep(j,k){
            cin>>v>>c;
            vp[u].pb(c,v);
        }
    }
    dijkstra(0);
    rep(i,n){
        cout<<i<<" "<<d[i]<<endl;
    }
    return 0;
}


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

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int[] a = new int[n];
		str = br.readLine().split(" ");
		for(int i = 0; i < n; i++) a[i] = Integer.parseInt(str[i]);
		str = br.readLine().split(" ");
		int q = Integer.parseInt(str[0]);
		for(int i = 0; i < q; i++){
			str = br.readLine().split(" ");
			int b = Integer.parseInt(str[0]);
			int e = Integer.parseInt(str[1]);
			int t = Integer.parseInt(str[2]);
			for(int j = 0; j < (e - b); j++){
				int bf = a[b + j];
				a[b + j] = a[t + j];
				a[t + j] = bf;
			}
		}
		for(int i = 0; i < n; i++){
			System.out.print(a[i]);
			if(i != n - 1) System.out.print(" ");
		}
		System.out.print("\n");
	}
}



Measured memory_bytes: 26792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
using namespace std;

int main(){

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

	int count = 0;

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){//各点に移動

			if(a[i][j] == '.'){
				//
			}

			else{
				for(int k = -1; k <= 1; k++){
					for(int l = -1; l <= 1; l++){
						if(k==0 || l ==0){
							//cout << a[i+k][j+l] <<endl;
							if(a[i+k][j+l] == '#' ){
								count ++;
							}
						}
					}
				}
				//cout << count <<endl;
				if(count < 2){
					//cout << i << j << a[i][j] <<endl;
					cout << "No" <<endl;
					return 0;
				}
			}

			count = 0;

		}
	}
	cout <<"Yes"<<endl;
	return 0;



}

Measured memory_bytes: 256
let clock sec = 
let hour = sec/3600 in
let minute = (sec mod 3600) / 60 in
let second = sec mod 60 in
print_int hour;
print_string ":";
print_int minute;
print_string ":";
print_int second;
print_string "\n";;

let () = 
clock (int_of_string (read_line()));;


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int T, D, L;
  while ( cin >> T >> D >> L, T ) {
    int pre = -1e9;
    int ans = 0;    
    for ( int i = 0; i < T; i++ ) {
      if ( i-pre <= D ) ans++;
      int x;
      cin >> x;
      if ( L <= x ) pre = i;      
    }

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



Measured memory_bytes: 3112