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

using namespace std;

typedef pair<int, int> PII;
typedef long long int ll;



ostream& operator<<(ostream& out, const vector<int> &v) {
    for(auto it=v.begin();it != v.end();it++) {
        cout << *it << " ";
    }
    cout << endl;
    return out;
}

// union-find-tree
vector<int> uft;
vector<int> childs;
void init(int size) {
    for(int i=0; i<size;i++){uft.push_back(-1);childs.push_back(1);}
}
int root(int a) {
    if (uft[a] != -1) {
        //return root(uft[a]);
        int r = root(uft[a]);
        uft[a] = r;
        return r;
    }
    return a;
}
bool same(int a, int b) {
    return root(a) == root(b);
}
void merge(int p, int c) {
    childs[root(p)] += childs[root(c)];
    uft[root(c)] = root(p);
}
int child(int p){
    return childs[root(p)];
}



int main() {
    int n,m;
    vector<PII> v;
    cin >> n>> m;
    for (int i=0;i<m;i++) {
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a,b));
    }
    init(n);
    vector<ll> res; // list of joint cities after k bridge built(reverse)
    ll curjoint = 0;
    for(auto it = v.rbegin(); it != v.rend(); it++) {
        int a = (*it).first;
        int b = (*it).second;
        //cout << a << b << endl;
        //cout << uft;
        //cout << childs;
        if (! same(a-1,b-1)) {
            //cout << "nj " << curjoint << " " << child(a-1)  << " " <<  child(b-1) << endl;
            curjoint += (ll)child(a-1) * (ll)child(b-1);
            merge(a-1,b-1);
        }
        res.push_back(curjoint);
    }
    res.pop_back();
    for(auto it = res.rbegin();it != res.rend();it++) {
        cout << (curjoint - (*it)) << endl;
    }
    cout << curjoint << endl;
    return 0;
}

Measured memory_bytes: 4852
require 'scanf'
require 'matrix'

while str = STDIN.gets
    list = \
        str.scanf("%d,%d,%d,%d,%d," \
                  "%d,%d,%d,%d,%d," \
                  "%d,%d")
    total=0.0
    for i in 0..10-1
        total=total+list[i].to_f
    end
    vl,vr=list[10+0].to_f,list[10+1].to_f
    cross=total*vl/(vl+vr)

    accum=0.0
    for i in 0..10-1
        accum=accum+list[i].to_f
        if cross <= accum then
            print i+1,"\n"
            break
        end
    end
end

Measured memory_bytes: 7020
import heapq

n = int(input())
lst = list(map(int, input().split()))
heapq.heapify(lst)

while len(lst) > 1:
    a = heapq.heappop(lst)
    b = heapq.heappop(lst)
    heapq.heappush(lst, (a + b) / 2)
print(lst[0])

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


int main()
{
    cin.sync_with_stdio(0);

    int n; cin>>n;
    vector<int> a(n);
    map<long, int> m;
    for(int i=0; i<n; ++i) {
        cin>>a[i];
        m[a[i]]++;
    }
    vector<int> c(n);
    for(int i=0; i<n; ++i) {
        for(long j=1; j<1L<<31; j*=2) {
            if (m.count(j-a[i])==0) continue;
            c[i]+=m[j-a[i]];
            if (a[i]==j-a[i]) c[i]--;
        }
    }

    vector<pair<int, int>> b;
    for(int i=0; i<n; ++i) b.emplace_back(c[i], i);
    sort(begin(b), end(b));
    map<int, int> v;
    for(auto& e: b) v[a[e.second]]=e.first;

    int res=0;
    for(auto& e: b) {
        int i=e.second;
        if (m[a[i]]==0) continue;
        m[a[i]]--;
        
        int k=-1, x=INT_MAX;
        for(long j=1; j<1L<<31; j*=2) {
            if (m.count(j-a[i])==0) continue;
            if (m[j-a[i]]) {
                if (k<0 || x>v[j-a[i]]) k=j-a[i], x=v[k];
            }
        }
        if (k>=0) {
            m[k]--;
            ++res;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 25328
def i_input(): return int(input())
def s_input(): return input()

def main():
    k = i_input()
    s = s_input()

    len_s = len(s)

    if len_s <= k:
        print(s)
        exit()

    for i in range(k):
        print(s[i],end='')

    print('...')    

if __name__ == '__main__':
    main()


Measured memory_bytes: 62016
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    set<ll> st;
    V<ll> mp(n+2,0),a;
    //for(ll i=1;i*i<=n;i++)a.push_back()
    for(ll i=1;i*i<=n;i++){
        for(ll j=1;j*j<=n;j++){
            for(ll k=1;k*k<=n;k++){
                
                if(n>=i*i+j*j+k*k+i*j+j*k+k*i){
                    ll m=i*i+j*j+k*k+i*j+j*k+k*i;
                    mp[m]++;
                }
            }
        }
    }
    for(ll i=1;i<=n;i++)cout<<mp[i]<<'\n';
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3688
a = int(input()) # 500
b = int(input()) # 100
c = int(input()) # 50
x = int(input())

X = []
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            X.append(500 * i + 100 * j + 50 * k)
print(X.count(x))

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int MOD = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        string s,t;
        cin>>s>>t;
        int ok = 1;
        for(int i=0;ok && i<s.length();i++)if(s[i]!=t[i])ok=0;
        cout<<(ok?"Yes":"No")<<endl;
    }
    return 0;
}


Measured memory_bytes: 3652
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    F = [[] for _ in range(n)]
    for w in range(n):
        l = list(map(int, input().split()))
        for i in range(5):
            F[w].append(l[i * 2: i * 2 + 2])
    P = [list(map(int, input().split())) for _ in range(n)]

    ans = -10**10
    for case in range(1, 1 << 10):
        profit = 0
        for i in range(n):
            c = 0
            for t in range(10):
                if F[i][t // 2][t % 2] and case & (1 << t): c += 1
            profit += P[i][c]
        ans = max(ans, profit)
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 74056
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
#define int long long int
int dp[310][310] = {0};
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin >> n; 
    int rem;cin >> rem;
    vi in(n);
    FOR(i, n)cin >> in[i];
    if(n == rem){
        cout << 0 << endl;
        return 0;
    }
    int prev = 0;
    FOR(i, n){
        if(in[i] > prev){
            dp[i][0] = in[i] - prev + dp[max(i-1, 0LL)][0];
        }else{
            dp[i][0] = dp[max(i-1, 0LL)][0];
        } 
 //       cout << dp[i][0] << " "; 
        prev = in[i];
    }
  //  cout << endl;
    for(int k = 1; k <= rem; k++){
        for(int i = 0; i < n; i++){
            //computing dp[i][k];
            if(i + 1 <= k){
               dp[i][k] = in[i]; 
               continue;
            }
            int & ans= dp[i][k];
            ans = 1e18;
            int h = in[i];
            for(int las = 0; las <= k; las++){
                int prev = i - las - 1;
                if(prev < 0){
                    ans = min(ans, h);
                    break;
                }
                int pH = in[prev];
                ans = min(ans, max(h- pH, 0LL) + dp[prev][k - las]);
            }
//            cout<< dp[i][k] << " ";
        }
//    cout <<endl;
    }
    int ans = 1e18;
    for(int i =0; i <= rem;i++){
        ans = min(ans, dp[n-1-i][rem-i]);
    }
    cout << ans;
}




Measured memory_bytes: 1024
#include <stdio.h>

int main(){

	int a, b;
	char op;
	while(1){
		scanf("%d %c %d",&a, &op, &b);
		if(op == '?')
			break;
		if(op == '+'){
			printf("%d\n", a + b);
		}
		else if(op == '-'){
			printf("%d\n", a - b);
		}
		else if(op == '*'){
		  printf("%d\n", a * b);
		}
		  else if(op == '/'){
		  	printf("%d\n", a / b);
		  }
	}
return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>

using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){

    ll r, D, x2000;

    cin >> r >> D >> x2000;

    vector<ll> x(11);
    x[0] = x2000;

    for(int i = 1; i <= 10; i++){
        x[i] = r * x[i-1] - D;
        cout << x[i] << endl;
    }

    
}

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

using namespace std;
typedef long long ll;

int chmax(pair<int, vector<int> >& t0, pair<int, vector<int> > t1){
	if(t0.first<t1.first) {
		t0=t1; return 0;
	}else if(t0.first>t1.first) {
		return 0;
	}else{
		for(int i=0; i<(int)t0.second.size(); i++){
			if(t0.second[i]<t1.second[i]) {t0=t1; return 0;}
			if(t0.second[i]>t1.second[i]) return 0;
		}
	}
	return 0;
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(10,0);
	for(int i=0; i<m; i++){
		int l;
		cin >> l;
		if(l==1 && a[2]<l) a[2]=1;
		if(l==2 && a[5]<l) a[5]=2;
		if(l==3 && a[5]<l) a[5]=3;
		if(l==4 && a[4]<l) a[4]=4;
		if(l==5 && a[5]<l) a[5]=5;
		if(l==6 && a[6]<l) a[6]=6;
		if(l==7 && a[3]<l) a[3]=7;
		if(l==8 && a[7]<l) a[7]=8;
		if(l==9 && a[6]<l) a[6]=9;
	}
	vector<pair<int, int> > ap;

	for(int i=0; i<10; i++){
		if(a[i]!=0) ap.push_back(make_pair(i, a[i]));
	}

	sort(ap.begin(), ap.end(), [](auto lhs, auto rhs){
		return lhs.second > rhs.second;
	});

	//for(int i=0; i<(int)ap.size(); i++) cout << ap[i].first << " " << ap[i].second << endl;

	vector<pair<int, vector<int> > > r(n+1, make_pair(0, vector<int>((int)ap.size(),0)));
	pair<int, vector<int> > t0=make_pair(0, vector<int>((int)ap.size(),0));
	pair<int, vector<int> > t1=make_pair(0, vector<int>((int)ap.size(),0));

	for(int i=0; i<(int)ap.size(); i++){
		if(ap[i].first<n+1){
			r[ap[i].first].first=1;
			r[ap[i].first].second[i]=1;
		}
	}

	//for(int i=0; i<n; i++) cout << r[i].first;
	//cout << endl;

	for(int i=1; i<n+1; i++){
		t0=r[i];
		for(int l=0; l<(int)ap.size(); l++){
			int j;
			j=i-ap[l].first;
			if(j<0) continue;
			t1=r[j];
			if(t1.first==0) continue;
			t1.first++;
			t1.second[l]++;
			chmax(t0, t1);
		}
		r[i]=t0;
	}

	//for(int i=0; i<n; i++) cout << r[i].first;
	//cout << endl;

	vector<int> rmax(10,0);

	for(int l=0; l<(int)ap.size(); l++){
		rmax[ap[l].second]=t0.second[l];
	}

	for(int i=9; 0<=i; i--){
		for(int j=0; j<rmax[i]; j++) cout << i;
	}
	cout << endl;
	return 0;

}



Measured memory_bytes: 896
#include <iostream>

using namespace std;

class Solver {
    public:
        int n, m, p;
        int x[100];
        int solve() {
            int gold = 0;
            for (int i = 0; i < n; ++i) {
                gold += x[i] * 100;
            }
            if (x[m - 1] == 0) {
                return 0;
            }
            return gold / 100 * (100 - p) / x[m - 1];
        }
};

int main() {
    Solver s;
    while (true) {
        cin >> s.n >> s.m >> s.p;
        if (s.n == 0) {
            return 0;
        }
        for (int i = 0; i < s.n; ++i) {
            cin >> s.x[i];
        }
        cout << s.solve() << endl;
    }
}

Measured memory_bytes: 1160
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 262144
#define REP(i,n) for(long long i = 0;i < n;++i)    
long long gogo[400000];
long long cnt[26];
long long now_cnt[26];
long long seg_tree[seg_size * 2];
queue<long long> findings[26];
long long seg_find(long long now, long long n_l, long long n_r, long long w_l, long long w_r) {
	if (w_l <= n_l && n_r <= w_r) return seg_tree[now];
	if (w_r <= n_l || n_r <= w_l) return 0;
	return seg_find(now * 2, n_l, (n_l + n_r) / 2, w_l, w_r) + seg_find(now*2 +1,(n_l+n_r)/2,n_r,w_l,w_r);
}
long long seg_set(long long now) {
	seg_tree[now] = seg_tree[now * 2] + seg_tree[now * 2 + 1];
	if (now != 1) seg_set(now / 2);
	return 0;
}
int main() {
#define int long long
	string s;
	cin >> s;
	REP(i, s.length()) {
		cnt[s[i] - 'a']++;
	}
	int hoge = 0;
	REP(i, 26) {
		hoge += (cnt[i]) % 2;
	}
	if (hoge >= 2) {
		cout << -1 << endl;
		return 0;
	}
	string a, b;
	long long ans = 0;
	long long tmp = 0;
	REP(i, s.length()) {
		int hoge = s[i] - 'a';
		now_cnt[hoge]++;
		if (cnt[hoge] % 2 == 1 && (cnt[hoge] + 1) / 2 == now_cnt[hoge]) {
			ans += b.length();
			tmp++;
		}
		else {
			if (cnt[hoge] / 2 >= now_cnt[hoge]) {
				a.push_back(s[i]);
				ans += tmp;
			}
			else {
				b.push_back(s[i]);
				tmp++;
			}
		}
	}
	reverse(b.begin(), b.end());
	REP(i, b.length()) {
		seg_tree[(seg_size + i)]++;
		seg_set((seg_size + i) / 2);
		findings[b[i] - 'a'].push(i);
	}
	REP(i, a.length()) {
		int hoge = a[i] - 'a';
		long long now = findings[hoge].front();
		findings[hoge].pop();
		ans += seg_find(1, 0, seg_size, 0, now);
		seg_tree[(seg_size + now)]--;
		seg_set((seg_size + now) / 2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5628
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>

using namespace std;

int solve(const vector<int> &v) {
    int res = numeric_limits<int>::min();
    for (int i = 0; i < v.size(); i++) {
        for (int j = i + 1; j < v.size(); j++) {
            res = max(res, v[j] - v[i]);
        }
    }
    return res;
}

int solve2(const vector<int> &v) {
    int maxv = numeric_limits<int>::min();
    int minv = v.front();

    for (int i = 1; i < v.size(); i++) {
        maxv = max(maxv, v[i] - minv);
        minv = min(minv, v[i]);
    }

    return maxv;
}

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;

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

    //cout << solve(v) << endl;
    cout << solve2(v) << endl;

    return 0;
}

Measured memory_bytes: 3936
#include<iostream>  
#include<cstdio>  
#include<cstring>  
using namespace std;  
int n,m,ans;  
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};  
char ch;  
  
char map[111][111];  
  
void dfs(int x,int y)  
{  
    if(x<1||x>n||y<1||y>m) return ;  
    if(map[x][y]!=ch) return ;  
    map[x][y]='.';  
    for(int i=0;i<4;i++) {  
        dfs(x+dx[i],y+dy[i]);  
    }  
      
}  
  
  
int main()  
{  
    int i,j;  
    while(cin>>n>>m) {  
        if(n==0 && m==0 ) break;  
        for(i=1;i<=n;i++) {  
            for(j=1;j<=m;j++) cin>>map[i][j];  
        }  
        ans=0;  
        for(i=1;i<=n;i++) {  
            for(j=1;j<=m;j++){  
                if(map[i][j]=='.') continue;  
                ch=map[i][j];  
                dfs(i,j);  
                ans++;  
            }  
        }  
        cout<<ans<<endl;  
    }  
    return 0;  
}  


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

int main() {
  int N, H;
  cin >> N >> H;
  vector<pair<int, int>> BA(N);
  int max_a = 0, a, b;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    BA[i] = make_pair(b, a);
    max_a = max(max_a, a);
  }
  sort(BA.begin(), BA.end(), greater<>());
  int ans = 0;
  for (int i = 0; i < N; i++) {
    b = BA[i].first, a = BA[i].second;
    if (b < max_a) break;
    H -= b; ans++;
    if (H <= 0) {
      cout << ans << endl;
      return 0;
    }
  }
  ans += 1 + (H-1) / max_a;
  cout << ans << endl;
}

Measured memory_bytes: 1024
w = input()

cnt_dict = {}
for c in w:
    if c not in cnt_dict.keys():
        cnt_dict[c] = 0
    cnt_dict[c] += 1

ans = "Yes"
for c in cnt_dict.keys():
    if cnt_dict[c] % 2 == 1:
        ans = "No"
        break
print(ans)


Measured memory_bytes: 9096
#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<ll, ll> 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;
	bool second = true;
	rep(i,n){
		int a;
		cin >> a;
		if(a%2 != 0) second = false;
	}
	if(second) cout << "second" << endl;
	else cout << "first" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
li = list(map(int, input().split()))
max_num = float('inf')
li.sort()
for i in range(1, 101):
    temp_sum = 0
    for j in li:
        temp_sum = temp_sum + ((j - i) ** 2)

    if temp_sum < max_num:
        max_num = temp_sum

print(max_num)

Measured memory_bytes: 38512
import sys

N, K = map(int, sys.stdin.readline().strip().split())
V = list(map(int, sys.stdin.readline().strip().split()))

ans=0
act = min(N, K)
for i in range(act + 1): # 左
    for j in range(N - act + i, N+1): # 右
        count = V[0:i] + V[j:N]
        count.sort()
        ans = max(ans, sum(count))
        for x in range(1, K - len(count) + 1): # 正負関係なく小さいものを捨てる 
            # print(sum(count[x:]))
            ans = max(ans, sum(count[x:]))
print(ans)

Measured memory_bytes: 43496
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val h = readLine()!!.split(" ").map(String::toInt)

    println(op142b(k, h))
}


fun op142b(limit: Int, member: List<Int>) = member.filter { it >= limit }.count()


Measured memory_bytes: 46316
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, L, R, H, W;

vector<vector<long long int>>edge;
int place[10] = {};
long long int ans = LLONG_MAX;

void Search(vector<int>v, int num, long long int sum, int last) {
	if (num == K) {
		ans = min(ans, sum);
		return;
	}
	for (int i = 0; i < K; i++) {
		if (v[i]) {
			continue;
		}
		v[i] = 1;
		Search(v, num + 1, sum + edge[last][place[i]], place[i]);
		v[i] = 0;
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> M >> K;
	edge.resize(N + 1, vector<long long int>(N + 1, INT_MAX));
	for (int i = 1; i <= N; i++) {
		edge[i][i] = 0;
	}
	for (int i = 0; i < K; i++) {
		cin >> place[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> H;
		edge[L][R] = H;
		edge[R][L] = H;
	}
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
			}
		}
	}
	vector<int>box(K,0);
	for (int i = 0; i < K; i++) {
		box[i] = 1;
		Search(box, 1, 0, place[i]);
		box[i] = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define LEN 100005
#define MAX 100000

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void initialize(){
  head = tail = 0;
}

int isEmpty(){
  if(head == tail) return 0;
  else return 1;
}

int isFull(){
  if(head == (tail + 1) % MAX) return 0;
  else return 1;
}

void enqueue(P x){
  if(isFull() == 0) printf("??¨?????????????????????????????????\n");
  else {
    Q[tail] = x;
    if(tail + 1 == MAX)  tail = 0;
    else   tail++;
  }
}

P dequeue(){
  P x;
  if(isEmpty() == 0) printf("??¨???????????¢?????????????????????\n");
  else {
    x = Q[head];
    if(head + 1 == MAX) head = 0;
    else   head++;
  }
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;

  initialize();
  scanf("%d %d", &n, &q);

  for (i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while(head != tail){
    u = dequeue();
    if(q > u.t) c = u.t;
    else c = q;
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n", u.name, elaps);
    }
  }    
  return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(v) (v).begin(),(v).end()

using namespace std;

typedef pair<int,int>P;
typedef complex<double> C;

//??????
double cross(const C& a, const C& b) {
    return imag(conj(a)*b);
}

//????§???¢?????¢???
double area(const vector<C> &ps) {
    double A = 0;
    rep(i,ps.size()){
        A += cross(ps[i],ps[(i+1) % ps.size()]);
    }
    return A / 2.0;
}

int main()
{
    vector<C> vec;
    int n;
	scanf("%d",&n);
	rep(i,n){
		int x,y;
        cin >> x >> y;
        vec.push_back(C(x,y));
	}
    printf("%.1f\n",area(vec));
	return 0;
}

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

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

    string ans = "";

    int num = s.size();
    rep(i, s.size()) {
        if ('B' == s.at(i) && ans.size() > 0) {
            ans.pop_back();
        } else if ('0' == s.at(i) || '1' == s.at(i)) {
            ans.push_back(s.at(i));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

// ll C[2005][2005];
ll dp[100005][13];


int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A==B && A != C)cout << "Yes" << endl;
    else if(A==C && B != C)cout << "Yes" << endl;
    else if(C==B && A != C)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0) cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////
int N, M; 
vector<int>V[200100];
bool visited[200100];
void dfs(int k) {
	if (visited[k])return;
	visited[k] = true;
	for (int a : V[k]) {
		dfs(a);
	}
}

int main() {
	cin >> N >> M;
	REP(i, 200100)visited[i] = false;
	REP(i, N) {
		int k; cin >> k;
		REP(j, k) {
			int l; cin >> l;
			l--;
			V[i].push_back(N + l);
			V[N + l].push_back(i);
		}
	}
	dfs(0);
	REP(i, N) {
		if (!visited[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


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

int main(){
  string w;
  int i,j,cnt;
  cin>>w;
  for(i=0;i<=w.size()-1;i++){
    cnt=0;
    for(j=0;j<=w.size()-1;j++){
      if(w.at(i)==w.at(j))cnt++;
    }
    if(cnt%2!=0){
      cout<<"No";
      break;
    }
    if(i==w.size()-2)cout<<"Yes";
  }
}

Measured memory_bytes: 256
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, a, b = gi()
if a > b:
	a, b = b, a
if (abs(a - b) % 2):
	x = a
	b -= a
	x += (b - 1) // 2
	b += a
	y = n - b + 1
	a += y
	y += (n - a) // 2
	print(min(x, y))
else:
	print(abs(a - b) // 2)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define rn return
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;





int main()
{
    int N,M; cin >> N >> M;
    int x[M],y[M];
    bool ball[N]; rep(i,N) ball[i] = 0;ball[0] = true;
    int n[N]; rep(i,N) n[i] = 1;
    
    rep(i,M) cin >> x[i] >> y[i];
    rep(i,M){
        x[i]--; y[i]--;
        n[x[i]]--;n[y[i]]++;
        ball[y[i]] |= ball[x[i]];
        ball[x[i]] = ball[x[i]]*n[x[i]];
    }
    int ans = 0;
    rep(i,N) if (ball[i]) ans++;
    cout << ans;
    rn 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 1e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n,k;
int a[200010];
int mi[200010], ma[200010];
int increase[200010];

void input() {
    cin >> n >> k;
    REP(i,n) cin >> a[i];
}

void solve() {

    int ans = n - k + 1;

    // 不連続部分を引く
    REP(i,n - 1) {
        if (a[i + 1] > a[i]) increase[i]++;
    }

    int blocks = 0;
    int cnt = 0;
    REP(i,n) {
        if (increase[i]) {
            cnt++;
        } else {
            if (cnt >= k - 1) {
                blocks++;
            }
            cnt = 0;
        }
    }
    ans -= max(0,blocks - 1);
    // cout <<ans << endl;

    // 連続部分を引く
    set<int> st;
    REP(i,k) st.insert(a[i]);
    REP(i,n-k) {
        int mi = *st.begin();
        st.erase(a[i]);
        st.insert(a[i+k]);
        auto it = st.end();
        it--;
        int ma = *it;
        // for (auto p:st) {
        //     cout << p << " ";
        // }
        // cout << endl;
        // cout << mi << " " << ma << endl;
        ans -= (mi == a[i] && ma == a[i+k]);
    }

    cout << ans << endl;
}

int main(int argc, char *argv[]){
    input();
    solve();
    return 0;
}


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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N, M;
int X[110000], diff[110000];
signed main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) { cin >> X[i]; }
    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }
    sort(X, X + M);
    for (int i = 0; i < M - 1; i++) { diff[i] = X[i + 1] - X[i]; }
    sort(diff, diff + M - 1);
    reverse(diff, diff + M - 1);
    int ans = X[M - 1] - X[0];
    for (int i = 0; i < N - 1; i++) { ans -= diff[i]; }
    cout << ans << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 998244353LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pi;

#define maxn 200005

int main()
{
    i64  x, y ;

    scanf("%lld %lld",&x,&y) ;

    if( x==y || x==y+1 || x==y-1 ) printf("Brown\n") ;
    else printf("Alice\n") ;

    return 0 ;
}


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

#define iosx ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(20)
#define hell 1000000007LL
#define INF 100000000000000000LL
#define hmap unordered_map
#define hset unordered_set
#define PQ priority_queue
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define lld long double
#define ll int
#define all(C) begin(C),end(C)
#define rep(i,a,b) for(ll i = (a); i < (b); ++(i))
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define pii pair<ll,ll>
#define len(C) (ll)(C).size()
#define lexcmp lexicographical_compare
#define whats(C,n) 	rep(i,0,n) cout<<(C)[i]<<" \n"[i+1==n]

class UnionFind {                                             
private:
  vi p, rank, setSize;                      
  ll numSets;
public:
  UnionFind(ll n) {
    setSize.assign(n, 1); numSets = n; rank.assign(n, 0);
    p.assign(n, 0); for (ll i = 0; i < n; i++) p[i] = i; }
  ll findSet(ll i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(ll i, ll j) { return findSet(i) == findSet(j); }
  void unionSet(ll i, ll j) { 
    if (isSameSet(i, j))
        return; // discard union
        
    numSets--; 
    ll x = findSet(i), y = findSet(j);
    // rank is used to keep the tree short
    if (rank[x] > rank[y]){
      p[y] = x; setSize[x] += setSize[y];
    } else {
      p[x] = y; setSize[y] += setSize[x];
      if (rank[x] == rank[y])
        rank[y]++;
    } 
  }
  ll numDisjointSets() { return numSets; }
  ll sizeOfSet(ll i) { return setSize[findSet(i)]; }
};

void solve(int tm){
	ll n,m;
	cin>>n>>m;

	UnionFind uf(n+1);

	ll x,y,z;
	rep(i,0,m){
		cin>>x>>y>>z;
		uf.unionSet(x,y);
	}

	cout<<uf.numDisjointSets()-1;
}

// g++.exe -static -DONLINE_JUDGE -lm -s -x c++ -Wl,--stack=268435456 -O2 -std=c++14 sol.cpp & a.exe & del a.exe
// vim cli: !g++ -static -lm -s -x c++ -O2 -std=c++14 sol.cpp -o out; ./out; 
int main(){ 
	iosx; 
	int t=1;
    // cin >> t;

	for(int i=1; i<=t; ++i)
        solve(i);

	return 0;
}

Measured memory_bytes: 1408
n, m = map(int, input().split())
h = list(input().split())
l = [1] * n

for i in range(0, int(m)):
    a, b = map(int, input().split())
    a_int = int(h[int(a)-1])
    b_int = int(h[int(b)-1])

    if (a_int < b_int):
        l[a - 1] = 0
    
    if (a_int > b_int):
        l[b - 1] = 0
    
    if (l[a-1] == 1):
        if (a_int == b_int):
            l[a - 1] = 0
            l[b - 1] = 0
    elif (l[b-1] == 1):
        if (a_int == b_int):
            l[a - 1] = 0
            l[b - 1] = 0 
       
cnt = 0
for k in range(0, len(l)):
    if(l[k]==1):
        cnt+=1

print(cnt)

Measured memory_bytes: 82156
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
  int a;
  string b;
  cin>>a>>b;
  int x=0;
  int y=0;
  int z=0;
  rep(i,a){
    if(b.at(i)=='R'){
      x++;
    }
    if(b.at(i)=='G'){
      y++;
    }
    if(b.at(i)=='B'){
      z++;
    }
  }
  if (a<3){
    cout<<0;
  }
  else{int sum=x*y*z;
    rep1(j,a/2){
      rep(k,a){
        if(k+j*2>a-1){
         break;
        }
       else if(b.at(k)!=b.at(k+j)&&b.at(k)!=b.at(k+j*2)&&b.at(k+j)!=b.at(k+j*2)){
          sum--;
      }
    }
  }
   cout<<sum;
      }
}


Measured memory_bytes: 3636
char m[30][30];
W,H,w,h,i,j;

int s(int y,int x)
{
	if(m[y][x]!='.')
		return 0;
	m[y][x]=0;
	return s(y+1,x)+s(y-1,x)+s(y,x+1)+s(y,x-1)+1;
	
}
int main()
{
	for(;scanf("%d%d\n",&W,&H),W;)
	{ 
		memset(m,0,sizeof(m));
		for(i=1;i<=H;i++)
			for(j=1;j<W+2;j++)
			{
				m[i][j]=getchar();
				if(m[i][j]=='@')
					h=i,w=j,m[i][j]='.';
			}
		printf("%d\n",s(h,w));
	}
	return 0;
}

Measured memory_bytes: 624
#include<stdio.h>
int main(void)
{
	int A=0, B=0, C=0;
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
	if (A <= C && C<= B ) {
		printf("Yes\n");
	}
	else if (B <= C && C <= A) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
INF = float("inf")
import math


class SegmentTree(object):
    # セグメント木

    def __init__(self, N):
        # 単位元
        self.idelem = 0
        # 比較関数
        self.func = max

        self.N0 = 1
        while self.N0 < N:
            self.N0 *= 2
        self.tree = [self.idelem]*(2*self.N0)

    def update(self, k, x):
        k += self.N0-1
        self.tree[k] = x
        while k > 1:
            k = (k-1)//2
            self.tree[k] = self.func(self.tree[2*k+1], self.tree[2*k+2])

    def query(self, l, r):
        l += self.N0-1
        r += self.N0-1
        s = self.idelem
        while l < r:
            if r % 2 == 0:
                r -= 1
                s = self.func(s, self.tree[r])

            if l % 2 == 0:
                s = self.func(s, self.tree[l])
                l += 1
            l //= 2
            r //= 2
        return s

    def __str__(self):
        return str(self.tree[self.N0-1:-1])


def solve(N: int, h: "List[int]", a: "List[int]"):

    seg = SegmentTree(N+1)

    for i in range(N):
        temp = a[i] + seg.query(0, h[i])
        seg.update(h[i], temp)
    print(seg.query(0, N+1))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, h, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 113364
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int x,y,z,n;
ll a[100001],b[100001],c[100001];
vector<P> vec;
ll resl[100001];
ll resr[100001];

int main(void){
	scanf("%d%d%d",&x,&y,&z);
	n=x+y+z;
	for(int i=0;i<n;i++){
		scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
		vec.push_back(P(a[i]-b[i],i));
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	ll sum=0;
	priority_queue<P> qa,qb;
	for(int i=0;i<x;i++){
		qa.push(P(c[vec[i].second]-a[vec[i].second],vec[i].second));
		sum+=a[vec[i].second];
	}
	resl[x]=sum;
	for(int i=x;i<x+z;i++){
		sum+=a[vec[i].second];
		qa.push(P(c[vec[i].second]-a[vec[i].second],vec[i].second));
		P p=qa.top();
		qa.pop();
		sum+=p.first;
		resl[i+1]=sum;
	}
	sum=0;
	for(int i=x+z;i<n;i++){
		qb.push(P(c[vec[i].second]-b[vec[i].second],vec[i].second));
		sum+=b[vec[i].second];
	}
	resr[x+z]=sum;
	for(int i=x+z-1;i>=x;i--){
		sum+=b[vec[i].second];
		qb.push(P(c[vec[i].second]-b[vec[i].second],vec[i].second));
		P p=qb.top();
		qb.pop();
		sum+=p.first;
		resr[i]=sum;
	}
	ll res=0;
	for(int i=x;i<=x+z;i++){
		res=max(res,resl[i]+resr[i]);
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 7536
#include <algorithm>
#include <iostream>
#include <vector>

int main()
{
    std::string s;
    std::cin >> s;
    std::reverse(s.begin(), s.end());

    std::vector<long long> reminders(13, 0);
    reminders[0] = 1;

    const int mod = 1000000007;
    int pos = 1;
    for (auto c : s) {

        std::vector<long long> new_reminders(13, 0);
        if (c == '?') {
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 13; j++) {
                    new_reminders[(i * pos + j) % 13] += reminders[j];
                    new_reminders[(i * pos + j) % 13] %= mod;
                }
            }
        } else {
            int i = c - '0';
            for (int j = 0; j < 13; j++) {
                new_reminders[(i * pos + j) % 13] += reminders[j];
                new_reminders[(i * pos + j) % 13] %= mod;
            }
        }

        pos *= 10;
        pos %= 13;

        reminders = new_reminders;
    }

    std::cout << reminders[5] << std::endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,ar[101],i,sum;
	float c;
	while(~scanf("%d", &a)){
		sum=0;
		for(i=0; i<a; i++){
			scanf("%d", ar+i);
			sum+=ar[i];
		}
		c=(float)sum/a;
		if(c>((ceil(c)+floor(c))/2))
			b=ceil(c);
		else
			b=floor(c);
		sum=0;
		for(i=0; i<a; i++){
			sum+=pow(ar[i]-b, 2);
		}

		printf("%d\n", sum);
		
	}

	return 0;
}

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

ll pown(ll n, ll c){
	ll ans = 1;
	ll base = n;
	while(c){
		if(c & 1){
			ans = (ans * base) % mod;
		}
		base = (base * base) % mod;
		c = c >> 1;
	}
	return ans;
}

int num[100000 + 5];
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
		cin >> num[i];
    }
    sort(num, num + n);
    bool ok = true;
    for(int i = n - 1; i >= 0; i = i - 2){
		if(num[i] != num[i - 1]){
			ok = false;
		}
		if(num[i] != (i / 2) * 2 + !(n % 2)){
			ok = false;
		}
    }
    if(ok) cout << pown(2, n / 2) << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 640
use std::io;
use std::collections::VecDeque;

fn main() {
    let mut input = Input::new();
    let h: usize = input.next();
    let w: usize = input.next();
    let k: usize = input.next();
    let mut s = (0, 0, 0);
    let mut a: Vec<Vec<bool>> = (0..h)
        .map(|i| {
            input
                .next::<String>()
                .chars()
                .enumerate()
                .map(|(j, c)| {
                         if c == 'S' {
                             s = (i, j, 0);
                         }
                         c != '#'
                     })
                .collect()
        })
        .collect();
    let mut min = h + w;
    let mut queue = VecDeque::<(usize, usize, usize)>::new();
    queue.push_back(s);
    while !queue.is_empty() {
        let (y, x, d) = queue.pop_front().unwrap();
        if d == k + 1 {
            break;
        }
        min = *[min, x, y, w - x - 1, h - y - 1].iter().min().unwrap();
        let mut action = |y: usize, x: usize| if a[y][x] {
            a[y][x] = false;
            queue.push_back((y, x, d + 1));
        };
        if y > 0 {
            action(y - 1, x);
        }
        if y + 1 < h {
            action(y + 1, x);
        }
        if x > 0 {
            action(y, x - 1);
        }
        if x + 1 < w {
            action(y, x + 1);
        }
    }
    println!("{}", 1 + (min + k - 1) / k);
}

struct Input {
    queue: VecDeque<String>,
}

impl Input {
    fn new() -> Input {
        Input { queue: VecDeque::new() }
    }

    fn next<T>(&mut self) -> T
        where T: std::str::FromStr,
              T::Err: std::fmt::Debug
    {
        if self.queue.is_empty() {
            let mut line = String::new();
            let _ = io::stdin().read_line(&mut line);
            for x in line.split_whitespace() {
                self.queue.push_back(String::from(x));
            }
        }
        return self.queue.pop_front().unwrap().parse::<T>().unwrap();
    }
}



Measured memory_bytes: 4476
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int c = scanner.nextInt();

        final boolean[][] table = new boolean[c][100001];
        for (int i = 0; i < n; i++) {
            final int s = scanner.nextInt();
            final int t = scanner.nextInt();
            final int channel = scanner.nextInt() - 1;
            for (int j = s - 1; j < t; j++) {
                table[channel][j] = true;
            }
        }

        int max = 0;
        for (int i = 0; i < 100001; i++) {
            int tmp = 0;
            for (int j = 0; j < c; j++) {
                tmp += table[j][i] ? 1 : 0;
            }
            max = Math.max(max, tmp);
        }

        System.out.println(max);
    }
}


Measured memory_bytes: 100524
<?php

while (true) {
	$n = trim(fgets(STDIN));
	if ($n == 0) {
		break;
	}
	$result = array();
	for ($i = 0; $i < $n; $i++) {
		list($c, $m1, $s1, $m2, $s2, $m3, $s3, $m4, $s4) = explode(' ', trim(fgets(STDIN)));
		$result[] = array(
			'team' => $c,
			'time' => ($m1 + $m2 + $m3 + $m4) * 60 + ($s1 + $s2 + $s3 + $s4)
		);
	}

	usort($result, function($a, $b) {
		return $a['time'] - $b['time'];
	});

	echo $result[0]['team'] . "\n";
	echo $result[1]['team'] . "\n";
	echo $result[count($result) - 2]['team'] . "\n";
}

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

int main()
{
	int n = 0, k = 0, b = 0, c = 0;

	cin >> n >> k;

	vector<int> a(n);

	for (int i = 0; i < n; i++) {
		cin >> b;
		a[b - 1]++;
	}

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

	int j = 0, u = n;
	
	while (u > k) {
		c += a[j];
		j++;
		u--;
	}

	cout << c << endl;

	return 0;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  ll D, G;
  cin >> D >> G;
  ll p[D+1], c[D+1];
  for (int i = 0; i < D; i++) cin >> p[i] >> c[i];

  int ans = INF;
  for (int i = 0; i < 1 << D; i++) {
    ll sum = 0;
    int mini = 0;
    int maxi_i = 0;
    for (int j = 0; j < D; j++) {
      if ((i >> j) & 1) {
        sum += (100 * (j + 1)) * p[j] + c[j];
        mini += p[j];
      } else {
        maxi_i = j;
      }
    }
    for (int j = 0; j < p[maxi_i]; j++) {
      if (sum >= G) {
        ans = min(ans, mini);
        break;
      }
      sum += 100 * (maxi_i + 1);
      mini++;
    }
    if (sum + c[maxi_i] >= G) {
      ans = min(ans, mini);
    }
  }

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


Measured memory_bytes: 256
// ABC 161 D LUNLUN number.


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()

{
  ll i,x,k,temp,count=0;
  cin>>k;
  queue<ll>v;
  for(i=1;i<=9;i++)v.push(i);

    while(count!=k)
      {
        count++;
        x=v.front();
        v.pop();
        temp=x*10+x%10;
        if(x%10!=0)v.push(temp-1);
        v.push(temp);
        if(x%10!=9)v.push(temp+1);
      }
      cout<<x<<"\n";

      return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int x1,x2,y1,y2,x3,y3,x4,y4;
    cin>>x1>>y1>>x2>>y2;
    x3=(x2+(y1-y2));
    y3=(y2+(x2-x1));
    x4=(x1+(y1-y2));
    y4=(y1+(x2-x1));
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;

mat t;
vll v;
lli c;
string s;
lli x;

void insert(lli x,lli i){
    if(x < v[i]){
        if(t[i][0] >= 0) insert(x,t[i][0]);
        else t[i][0] = c;
    }else{
        if(t[i][1] >= 0) insert(x,t[i][1]);
        else t[i][1] = c;
    }
}
bool find(lli x,lli i){
    if(x == v[i]) return true;
    if(x < v[i]){
        if(t[i][0] >= 0) return find(x,t[i][0]);
        else return false;
    }else{
        if(t[i][1] >= 0) return find(x,t[i][1]);
        else return false;
    }
}

void inorder(lli i){
    if(t[i][0] >= 0) inorder(t[i][0]);
    cout << " " << v[i];
    if(t[i][1] >= 0) inorder(t[i][1]);
}

void preorder(lli i){
    cout << " " << v[i];
    if(t[i][0] >= 0) preorder(t[i][0]);
    if(t[i][1] >= 0) preorder(t[i][1]);
}

int main(){
    cin >> n;
    t = mat(n,vll(2,-1));
    v = vll(n);
    for(lli i = 0;i < n;i++){
        cin >> s;
        if(s == "insert"){
            cin >> x;
            v[c] = x;
            if(i) insert(x,0);
            c++;
        }else if(s == "print"){
            inorder(0);cout << endl;
            preorder(0);cout << endl;
        }else if(s == "find"){
            cin >> x;
            cout << (find(x,0) ? "yes" : "no") << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 34052