akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

#define MAX 100010
int V,E,s,t;
vector<int> G[MAX];
vector<ll> d;


class RMQ{
private:
  int limit,N;
  vector<ll> dat;
public:
  void init(int n_){
    N = n_;
    limit = 1;
    while(limit<n_)limit*=2;
    dat.clear();
    dat.resize(2*limit,LLONG_MAX);
  }
  
  ll _build(int cur,int L,int R,const vector<ll> &buf){
    if( !( 0 <= cur && cur < 2*limit ) ) return LLONG_MAX;
    if( L == R-1 ) {
      if( L >= N ) return LLONG_MAX;
      dat[cur] = buf[L];
    } else {
      ll vl = _build(cur*2+1,L,(L+R)/2,buf);
      ll vr = _build(cur*2+2,(L+R)/2,R,buf);
      dat[cur] = min(vl,vr);
    }
    return dat[cur];
  }

  void build(const vector<ll> &buf){ _build(0,0,limit,buf); };

  void update(int k,ll a){
    k += limit-1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = min(dat[k*2+1],dat[k*2+2]);
    }
  }
 
  ll _query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return LLONG_MAX;
    else if(a<=l && r<=b)return dat[k];
    ll vl = _query(a,b,k*2+1,l,(l+r)/2);
    ll vr = _query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }

  ll query(int a,int b){ return _query(a,b,0,0,limit); }
};



int main(){
  /*
  RMQ rmq2;
  rmq2.init(10);
  rmq2.build(vector<ll>(10,LLONG_MAX));
  while(1) {
    int t;
    int a,b;
    cout << "t = ";
    cin >> t;
    if( t == 0 ) {
      cin >> a >> b;
      cout << rmq2.query(a,b) << endl;
    } else {
      cin >> a >> b;
      rmq2.update(a,(ll)b);
    }
  }
  puts("--");
  */

  
  cin >> V >> E >> s >> t;
  --s, --t;
  d = vector<ll>(V,0);
  rep(i,V) cin >> d[i];
  rep(i,E) {
    int a,b;
    cin >> a >> b;
    --a, --b;
    if( a < s ) a = s;
    G[a].push_back(b);
  }
  if( t <= s ) {
    puts("0");
    return 0;
  }

  RMQ rmq;
  rmq.init(V+1);
  rmq.build(vector<ll>(V+1,LLONG_MAX));
  rmq.update(s,0LL);
  REP(i,s,V) {
    ll mini = rmq.query(i,V+1);
    rmq.update(i,mini);
    rep(j,(int)G[i].size()) {
      int nex = G[i][j];
      if( nex == i ) continue;
      ll v = rmq.query(nex,nex+1);
      if( v > mini + d[nex]) {
	//cout << mini << " + " << d[nex] << endl;
	rmq.update(nex,mini+d[nex]);
      }
    }
  }
  cout << rmq.query(t,t+1) << endl;
  return 0;
}

Measured memory_bytes: 11820
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <string>
using namespace std;

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;--i)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

//DEBUG
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	ll n; cin >> n;
	ll a[100002] = { 0 };
	int f = 0;
	ll sum = 0;
	REP(i, n) {
		cin >> a[i]; sum += a[i];
	}
	if (n == 1) {
		cout << "YES" << endl;
		return 0;
	}
	ll t = 0;
	if (sum % (((n + 1)*n) / 2) == 0) t = sum / (((n + 1)*n) / 2);
	else {
		cout << "NO" << endl;
		return 0;
	}

	int c = 0;

	REP(i, n) {
		if (i == n - 1) {
			if (a[0] - a[n - 1] == t) continue;
			else {
				ll s = t - (a[0] - a[n - 1]);
				if (s%n == 0&&s>t) continue;
				else {
					f = 1; break;
				}
			}
		}else{
			if (a[i + 1] - a[i] == t) continue;
			else {
				ll s = t - (a[i + 1] - a[i]);
				if (s%n == 0&&s>t) continue;
				else {
					f = 1; break;
				}
			}
		 }
	}


	if (f) cout << "NO" << endl;
	else cout << "YES" << endl;
}

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

ll segtree[1000001], n, h[300001], a[300001];

void update(ll node, ll start, ll end, ll ix, ll val) {
	if (start==end) {
		segtree[node] = val;
	}
	else {
		ll mid = (start+end)/2;
		if (ix<=mid) 
			update(2*node, start, mid, ix, val);
		else update(2*node+1, mid+1, end, ix, val);
		segtree[node] = max(segtree[2*node], segtree[2*node+1]);
	}
}

ll qmax(ll node, ll start, ll end, ll l, ll r) {
	ll mid = (start+end)/2;
	if(r<start || end<l) 
		return 0;
	else if(l<=start && end<=r)
		return segtree[node];
	else return max(qmax(2*node, start, mid, l, r), qmax(2*node+1, mid+1, end, l, r));
}

int main() {
	cin >> n;
	memset(segtree, 0, sizeof(segtree));
	for (int i=1; i<=n; i++)
		cin >> h[i];
	for (int i=1; i<=n; i++) {
		cin >> a[i];
	}
	for (int i=1; i<=n; i++) {
		update(1, 1, n, h[i], qmax(1, 1, n, 1, h[i]-1)+a[i]);
 	}
	cout << segtree[1] << "\n";
}

Measured memory_bytes: 12288
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
l=0
r=10**5+1
for i in range(m):
    a,b=map(int,input().split())
    l=max(a,l)
    r=min(b,r)
res=r-l+1
if res>=0:
    print(res)
else:
    print(0)

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

using namespace std;

typedef long long ll;

int A[100010], B[100010], F[100010], tmp1[100010], tmp2[100010];

int dis(int op, int x, int y)
{
	if(op == 1) x = tmp1[x], y = tmp1[y]; else x = tmp2[x], y = tmp2[y];
	return min(abs(A[x] - A[y]), abs(B[x] - B[y]));
}

bool cmp1(int x, int y) {return A[x] < A[y];}
bool cmp2(int x, int y) {return B[x] < B[y];}

struct node {int op, x, y, ds; node(){} node(int a, int b, int c, int d) {op = a, x = b, y = c, ds = d;} bool operator < (const node& X) const {return ds > X.ds;}}; //!!! //!!!!!

int getf(int x) {return F[x] == x ? x : F[x] = getf(F[x]);}

priority_queue <node> hsh;

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d%d", &A[i], &B[i]), F[i] = i, tmp1[i] = tmp2[i] = i;
	sort(tmp1 + 1, tmp1 + n + 1, cmp1), sort(tmp2 + 1, tmp2 + n + 1, cmp2);
	for(int i = 1; i < n; i++) hsh.push(node(1, i, i + 1, dis(1, i, i + 1))), hsh.push(node(2, i, i + 1, dis(2, i, i + 1)));
	long long ans = 0;
	for(int T = 1; T < n;) {
		node tmp = hsh.top();
		hsh.pop();
		int a = tmp.op == 1 ? tmp1[tmp.x] : tmp2[tmp.x], b = tmp.op == 1 ? tmp1[tmp.y] : tmp2[tmp.y];
		if(getf(a) != getf(b)) ans += dis(tmp.op, tmp.x, tmp.y), T++, F[getf(a)] = getf(b);
		if(tmp.y != n) hsh.push(node(tmp.op, tmp.x, tmp.y + 1, dis(tmp.op, tmp.x, tmp.y + 1)));
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

int main(){
    int n,total,answer=pow(10,13);
    cin >> n;
    vector<int> x(n);

    for(auto &e:x) cin >> e;

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

    for(int i=x[0];i<=x[n-1];i++){
        total = 0;
        for(int h=0;h<n;h++){
            total += pow(x[h]-i,2);
           // cout << pow(x[h]-i,2) << "\t";
        }
      //  cout << answer << "\t" <<total <<endl;
        if(answer<=total){
           // cout << answer << "\t" <<total <<endl;
            break;
        }
        answer = total;
    }
    cout << answer <<endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int A, B, C, i;
	scanf("%d%d%d", &A, &B, &C);
	for(i = 2; i <= A && i <= B; i++) if((!(A%i)) && (!(B%i)) && C%i){
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 128
N = int(input())
N_list = list(map(int,[i for i in str(N)]))
N_list=N_list[::-1]


if len(N_list)%2==0:
  ans=0
  for i in range(len(N_list)):
    if i %2==0:
      ans+=9*(10**i)
else:
  ans=0
  for i in range(len(N_list)-1):
    if i % 2 ==0:
      ans+=9*(10**i)
  ans+=N - (10**(len(N_list)-1)) + 1

print(ans)

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

#define int unsigned long long

int gcd(int x, int y)
{
    int z = 1;
    
    z = x % y;
    while(z != 0)
    {
        x = y;
        y = z;
        z = x % y;
    }
    return y;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a;
    cin >> a;
    int ans = 1;
    int in;
    
    for(int i = 0;i < a; ++i)
    {
        cin >> in;
        auto x = gcd(in, ans);
        ans *= (in / x);
    }
    
    cout << ans << endl;
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    nth_element(a, a + n / 2, a + n);
    long long result = 0;
    for (int i = 0; i < n; i++) {
        result += abs(a[i] - a[n / 2]);
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 1024
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,k,r,p,s,ans=0;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  for(int i=0; i<n; i++) {
    if(i-k>=0&&t[i]==t[i-k]) {
      t[i]='z';
      continue;
    }
    if(t[i]=='r') {
      ans+=p;
    }
    if(t[i]=='s') {
      ans+=r;
    }
    if(t[i]=='p') {
      ans+=s;
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    char prev = '1';
    vector<int> a;
    int ctr = 0;
    rep (i, s.size()) {
        switch (s[i]) {
            case '0':
                if (prev == '1') {
                    a.push_back(ctr);
                    ctr = 0;
                }
                prev = '0';
                ctr++;
                break;
            case '1':
                if (prev == '0') {
                    a.push_back(ctr);
                    ctr = 0;
                }
                ctr++;
                prev = '1';
                break;
        }
    }
    a.push_back(ctr);
    if (s[s.size() - 1] == '0') {
        a.push_back(0);
    }
    vector<int> b(a.size()+1);
    b[0] = 0;
    rep (i, a.size()) {
        b[i+1] = b[i] + a[i];
    }
    if (k * 2 + 1 >= b.size()) {
        cout << n << endl;
        exit(0);
    }
    int ans = 0;
    rep (i, 2 * k + 1, b.size()) {
        int p = b[i] - b[i - (2 * k + 1)];
        chmax(ans, p);
        i++;
    }
    cout << ans << endl;
}

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

int main(){
    int_fast64_t N(0);
    cin >> N;
    vector<int> divisors(25);
    vector<int> prime({2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97});
    for(int i = 1; i <= N; ++i){
        int j = i;
        for(int k = 0; k < 25; ++k){
            while(j % prime[k] == 0){
                ++divisors[k];
                j /= prime[k];
            }
        }
    }
    int_fast64_t ans(0);
    for(int i = 0; i < 25; ++i){
        if(divisors[i] >= 74)++ans;
        for(int j = 0; j < 25; ++j){
            if(i != j && divisors[i] >= 2 && divisors[j] >= 24)++ans;
            if(i != j && divisors[i] >= 4 && divisors[j] >= 14)++ans;
            for(int k = j + 1; k < 25; ++k){
                if(i != j && j != k && i != k && divisors[i] >= 2 && divisors[j] >= 4 && divisors[k] >= 4)++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<tuple<string,int,int> > v(n,make_tuple(" ",0,0));
    for(int i = 0;i<n; i++)
    {
    cin>>get<0>(v[i])>>get<1>(v[i]);
    get<1>(v[i])=-1*(get<1>(v[i]));
    get<2>(v[i])=i+1;
    }
    sort(v.begin(),v.end());
    for(int i = 0;i<n; i++)
    {
     cout<<get<2>(v[i])<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, x, y;
	cin >> n >> x >> y;
	x--; y--;
	vector<vector<int>> g(n, vector<int>(n,inf));
	vector<int> ans(n, 0);

	for (int i = 0; i <= n - 2; ++i) {
		for (int j = i + 1; j <= n - 1; ++j) {
			g[i][j] = j - i;
		}
	}
	for (int i = 0; i <= n - 2; ++i) {
		for (int j = i + 1; j <= n - 1; ++j) {
			g[i][j] = min(g[i][j], abs(x - i) + abs(y - j) + 1);
			g[i][j]--;
			ans[g[i][j]]++;
		}
	}
	rep(i, n - 1) dunk(ans[i]);
	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  vector<vector<int>> books(10);

  for (int i = 0; i < N; i++)
  {
    int C, G;
    cin >> C >> G;
    G--;
    books[G].push_back(C);
  }

  for (int i = 0; i < 10; i++)
  {
    sort(books[i].begin(), books[i].end(), greater<int>());
  }

  vector<vector<int>> dp(11, vector<int>(K + 1));

  for (int i = 0; i < 10; i++)
  {
    for (int j = 0; j <= K; j++)
    {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    }

    // ジャンルiから何冊売るか
    for (int j = 0; j <= books[i].size(); j++)
    {
      int add = (j - 1) * j;
      int tot = add;
      for (int k = 0; k < j; k++)
        tot += books[i][k];
      for (int l = j; l <= K; l++)
      {
        dp[i + 1][l] = max(dp[i + 1][l], dp[i][l - j] + tot);
      }
    }
  }

  cout << dp[10][K] << endl;
  return 0;
}

// dp[i + 1][j]:=ジャンルiの本までにj冊売ったときの買取価格の最大値
// ジャンルiを売り終わった後の売った本の冊数をlとしてありうるパターンを全て試すのが大事



Measured memory_bytes: 3212
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	int n;
	cin>>n;
	int count = 0;
	for(int i = 1 ; i <= n ; i++){
		for (int j = 1; j <= n ; j++){
			for (int k = 1; k <= n ; k++){
				if(i <= n && j <= n && k <= n){
					count++;
				}
			}
		}
	}
	cout<<count<<endl;
}

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

int main() {
    ll x;
    cin >> x;
    ll ans = x / 11;
    ans *= 2;
    if (0 < x % 11 && x % 11 < 7) {
        ans++;
    } else if (7 <= x % 11) {
        ans += 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())

amount = 0
for v in range(1, n+1):
    tmp = v
    s = 0
    while True:
        t = int(tmp % 10)
        tmp /= 10
        s += t
        if tmp == 0:
            break

    if a <= s and s <= b:
        amount += v

print(amount)


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

int main()
{
    int n,m;
    cin >> n >> m;
    if( m < n )
    {
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    getline(cin,a);
    if(a.size()==2 && a[0]==a[1]){
        cout<<"1 2"<<endl;
        return 0;
    }
    long long i,flag=0;
    for(i=0;i<a.size()-2;i++)
    {
        if(a[i]==a[i+1] || a[i]==a[i+2] || a[i+1]==a[i+2]){
            cout<<i+1<<" "<<i+3<<endl;
            flag=1;
            break;
        }

    }
    if(!flag)
        cout<<"-1 -1"<<endl;
}


Measured memory_bytes: 512
n,m = map(int, input().split())
ns = set(i+1 for i in range(n))
l_min = 0
r_max = n
for i in range(m):
    l, r = map(int, input().split())
    l_min = max(l_min, l)
    r_max = min(r_max, r)
print(max(r_max - l_min+1, 0))


Measured memory_bytes: 11884
#include <iostream>
#include <string>
using namespace std;
int a,b;
int main(){
  string o,e;
  cin >> o >> e;
  int i=0;
     while(1){
       if(a==o.size()&&b==e.size()) break;
        if(i%2==0){
           cout << o[a];a++;
        }
        else{
           cout << e[b];b++;
        }
        i++;
     }
     cout << endl;
  }


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

// =======================
// ------ graph ------ //
using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge1(Graph &g, int a, int b, Weight w = 1) {
    g[a].emplace_back(a, b, w);
}

// ------ disjoint set ------ //
struct UnionFind {
    vector<int> data;
    int __size;
    UnionFind(int size) : data(size, -1), __size(size) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) != (y = root(y))) {
            if (data[y] < data[x]) swap(x, y);  // par -> child とは限らない
            data[x] += data[y]; data[y] = x; __size--;
        }
        return x != y;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return __size; }
    vector<int> subset_roots() {
        vector<int> roots;
        for (int i = 0; i < data.size(); i++) if (data[i] < 0) roots.push_back(i);
        return roots;
    }
};

// ------ minimumSpanningForest ------ //
pair<Weight, Edges> kruskal(priority_queue<Edge> &PQ, int n) {
    UnionFind uf(n);
    Weight total = 0;
    Edges F;
    while (F.size() < n-1 && !PQ.empty()) {
        Edge e = PQ.top(); PQ.pop();
        if (uf.unionSet(e.src, e.dst)) {
            F.push_back(e);
            total += e.weight;
        }
    }
    return pair<Weight, Edges>(total, F);
}
// =======================

int main() {
    int n, m;
    while (cin >> n >> m, n) {
        priority_queue<Edge> PQ;
        for (int i = 0; i < m; i++) {
            int a, b, cost; cin >> a >> b >> cost;
            PQ.push(Edge{a, b, cost});
        }
        pair<Weight, Edges> res = kruskal(PQ, n);
        cout << res.first << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
h, w = gets.chomp.split(" ").map(&:to_i)
rows = []
h.times do
  rows.push(gets.chomp.chars)
end
judge = false
rows.each_with_index do |ary, aryIndex|
  ary.each_with_index do |elm, elmIndex|
    if elm == "#"
      judge = false
      searchAry = [[aryIndex - 1, elmIndex], [aryIndex, elmIndex - 1], [aryIndex, elmIndex + 1], [aryIndex + 1, elmIndex]]
      searchAry.each do |search|
        if search[0] >= 0 && search[0] <= h - 1 && search[1] >= 0 && search [1] <= w - 1
          if rows[search[0]][search[1]] == "#"
            judge = true
          end
        end
      end
      if judge == false
        puts "No"
        exit
      end
    end
  end
end
puts "Yes"

Measured memory_bytes: 2172
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

x=int(input())
a,b=divmod(x,100)
if a*5>=b:
    print(1)
else:
    print(0)

Measured memory_bytes: 5068
use std::str::FromStr;
use std::io::Read;
use std::ops::Sub;
use std::convert::From;

pub trait AsZeroOrigin {
    fn as_zero_origin(self) -> Self;
}

pub trait AsZeroOriginWithMatrix {
    fn as_zero_origin(self) -> Self;
}

impl<T> AsZeroOrigin for Vec<T>
where
    T: Sub<T, Output = T> + From<u8>,
{
    fn as_zero_origin(self) -> Self {
        self.into_iter().map(|i| i - T::from(1)).collect()
    }
}

impl<T> AsZeroOriginWithMatrix for Vec<Vec<T>>
where
    T: Sub<T, Output = T> + From<u8>,
{
    fn as_zero_origin(self) -> Self {
        self.into_iter()
            .map(|v| v.into_iter().map(|i| i - T::from(1)).collect())
            .collect()
    }
}

pub trait Convert<T>
where
    T: FromStr,
{
    fn read_one(&mut self) -> T;
    fn to_vec(&mut self, n: usize) -> Vec<T>;
    fn to_matrix(&mut self, n: usize, m: usize) -> Vec<Vec<T>>;

    fn to_tuples<U>(&mut self, n: usize) -> Vec<(T, U)>
    where
        U: FromStr;
}

impl<'a, T> Convert<T> for ::std::str::SplitWhitespace<'a>
where
    T: FromStr,
{
    fn read_one(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }

    fn to_vec(&mut self, n: usize) -> Vec<T> {
        (0..n)
            .map(|_| self.next().unwrap().parse().ok().unwrap())
            .collect::<Vec<_>>()
    }

    fn to_matrix(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.to_vec(m)).collect::<Vec<_>>()
    }

    fn to_tuples<U>(&mut self, n: usize) -> Vec<(T, U)>
    where
        U: FromStr,
    {
        (0..n)
            .map(|_| {
                let a = self.next().unwrap().parse().ok().unwrap();
                let b = self.next().unwrap().parse().ok().unwrap();
                (a, b)
            })
            .collect::<Vec<_>>()
    }
}

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let v: Vec<u64> = iter.to_vec(5);
    let k: u64 = iter.read_one();

    let mut ds = Vec::new(); 
    for i in 0..4 {
        for j in (i + 1)..5 {
            ds.push(v[j] - v[i]);
        }
    }

    println!("{}", if ds.into_iter().all(|d| d <= k) { "Yay!" } else { ":(" });
}


Measured memory_bytes: 4352
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

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; }

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int main()
{
	int k[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int n;
	cin >> n;
	cout << k[n - 1];
}


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

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

    if (b == 'A') cout << 'T' << endl;
    else if (b == 'T') cout << 'A' << endl;
    else if (b == 'C') cout << 'G' << endl;
    else if (b == 'G') cout << 'C' << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main(){
  bool a = true;
  int n, s;//n舞のおさつ、合計s円
  cin >> n >> s;
  int x, y, z;
  rep(i, n+1){
    if(10000*i>s){
      break;
    }
    else if(10000*i<=s){
      rep(j, n+1-i){
        if(5000*j+10000*i>s){
          break;
        }
        if(5000*j+10000*i<=s){
          rep(l, n+1-i-j){
            if(1000*l+5000*j+10000*i==s && l+i+j==n){
              x = i,y = j,z = l;
              a = false;
            }
            else{
              continue;
            }
          }
        }
      }
    }
  }
  if(a){
    cout << "-1 -1 -1" << endl;
  }
  else{
    cout << x << " " << y << " " << z << endl;
  }
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        k: u64,
        x:[u64;n]
    }

    let mut ret = 0;
    for i in 0..n {
        ret += std::cmp::min(x[i], k - x[i])*2;
    }
    println!("{}", ret);
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e9;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll n, res = 0;
  cin >> n;
  vector<ll> a(n), l(n + 1), r(n + 1);

  rep(i, n) cin >> a[i];
  for (int i = 0; i < n; ++i) l[i + 1] = gcd(a[i], l[i]);
  for (int i = n - 1; i >= 0; --i) r[i] = gcd(a[i], r[i + 1]);
  res = -INF;
  for (int i = 0; i < n; ++i) res = max(res, gcd(l[i], r[i + 1]));
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2560
n, k = map(int, input().split())
s = [0] * n
for i in range(k):
  d = int(input())
  a = map(int, input().split())
  for ad in a:
    s[ad-1] += 1

print(sum(map(lambda x: 1 if x == 0 else 0, s)))

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 1e5+1;
int n, k, a[N];
long fact[N], ifact[N], res;

long POW(long x, long n){
  if (n == 0) return 1;
  long y = POW(x, n / 2);
  y = y * y % MOD;
  if (n % 2) return x * y % MOD;
  else return y;
}

int main()
{
  fastio;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n); fact[0] = 1;
  for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
  ifact[n] = POW(fact[n], MOD - 2); ifact[0] = 1;
  for (int i = n - 1; i > 0; i--) ifact[i] = ifact[i + 1] * (i + 1) % MOD;
  auto C = [&](int k, int n){
    return fact[n] * (ifact[k] * ifact[n - k] % MOD) % MOD;
  };
  for (int i = 1; i <= n - k + 1; i++){
    res -= 1ll * a[i] * C(k - 1, n - i);
    res %= MOD;  
  }
  reverse(a + 1, a + 1 + n);
  for (int i = 1; i <= n - k + 1; i++){
    res += 1ll * a[i] * C(k - 1, n - i);
    res %= MOD;
  }
  res += MOD; res %= MOD;
  cout << res;
  return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long i,sum=1,n;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		while(sum<=n)
		{
			sum=2*sum;
			if(sum>n)
			{
				cout<<sum/2<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
int main()
{
  int n;
  scanf("%d", &n);
  int d[n], i, j;
  long sum = 0;
  for (i = 0; i < n; i++)
    scanf("%d", &d[i]);
  for (i = 0; i < n - 1; i++)
  {
    for (j = i + 1; j < n; j++)
    {
      sum += d[i] * d[j];
    }
  }
  printf("%ld", sum);
}

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

int main() {
  int n;
  cin >> n;
  vector<bool> v(n);
  rep(i, n){
    if(i == 0 || i == 1 || i == 2 || i == 4 || i == 5) v[i] = 0;
    else if(i % 4 == 3) v[i] = 1;
    else if(i % 7 == 6) v[i] = 1;
    else if(v[i-4] || v[i-7]) v[i] = 1;
    else v[i] = 0;
  }
  if(v[n-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
let s = read_line ()
let rec f s n i =
  if i >= n/2 then true else if s.[i] <> s.[n-i-1] then false
  else f s n (i+1)
let n = String.length s
let ans = if f s n 0 && f s ((n-1) / 2) 0 then "Yes" else "No"
let () = print_endline ans

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

int main(){
  int N;
  cin>>N;
  vector<string> s(N);
  map<string,int> blue;
  map<string,int> red;
  for(int i=0;i<N;i++){
    cin>>s[i];
    blue[s[i]]=0;
    red[s[i]]=0;
  }
  for(int i=0;i<N;i++){
    blue[s[i]]++;
  }
  int M;
  cin>>M;
  vector<string> t(M);
  for(int i=0;i<M;i++){
    cin>>t[i];
    red[t[i]]=0;
  }
  for(int i=0;i<M;i++){
    red[t[i]]++;
  }
  
  string ans="";
  int max_v=0;
  // Keyの値が小さい順にループ
  for (pair<string, int> p : blue) {
    //string key = p.first;
    //int value = p.second;
    //cout<<key<<":"<<value<<endl;
    //cout<<red[p.first]<<endl;
    if(p.second-red[p.first]>0){
      if(p.second-red[p.first]>max_v){
        ans=p.first;
        max_v=p.second-red[p.first];
      }
    }
  }
  cout << max_v <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n; string s;

string check(string x, char rast){
    reps(i, 1, n - 1){
        if(s[i] == 'o'){
            if(x[i] == 'S'){
                if(x[i - 1] == 'S') x += 'S';
                else x += 'W';
            }else{
                if(x[i - 1] == 'S') x += 'W';
                else x += 'S';
            }
        }else{
            if(x[i] == 'S'){
                if(x[i - 1] == 'S') x += 'W';
                else x += 'S';
            }else{
                if(x[i - 1] == 'S') x += 'S';
                else x += 'W';
            }
        }
    }
    // cout << "r " << rast << endl;
    // cout << x << endl;
    if(s[n - 1] == 'o'){
        if(x[n - 1] == 'S'){
            if(x[n - 2] == x[0] && x.back() == rast) return x;
            else return "-1";
        }else{
            if(x[n - 2] != x[0] && x.back() == rast) return x;
            else return "-1";
        }
    }else{
        if(x[n - 1] == 'S'){
            if(x[n - 2] != x[0] && x.back() == rast) return x;
            else return "-1";
        }else{
            if(x[n - 2] == x[0] && x.back() == rast) return x;
            else return "-1";
        }
    }
}

int main(void){
	cin >> n >> s;
    string t1, t2, t3, t4;
    char r1, r2, r3, r4;
    if(s[0] == 'o'){
        t1 = "SS", r1 = 'S';
        t2 = "SW", r2 = 'W';
        t3 = "WW", r3 = 'S';
        t4 = "WS", r4 = 'W';
    }else{
        t1 = "SS", r1 = 'W';
        t2 = "SW", r2 = 'S';
        t3 = "WS", r3 = 'S';
        t4 = "WW", r4 = 'W';
    }
    vector<string> ans;
    ans.pb(check(t1, r1));
    ans.pb(check(t2, r2));
    ans.pb(check(t3, r3));
    ans.pb(check(t4, r4));
    for(auto u : ans){
        if(u != "-1"){
            cout << u << endl;
            return 0;
        }
    }
    printf("-1\n");
	return 0;
}

Measured memory_bytes: 816
#include <stdio.h>

int main(){
	long a,b;
    long n;

  	scanf("%ld %ld",&a,&b);
  
    n = (a + b) / 2;
  
    if((a + b)%2 == 0){
    	printf("%ld",n);	    
    }else{
    	printf("IMPOSSIBLE");
    }
  
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

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

  ll n;
  cin >> n;

  vector<ll> a(n);

  ll sum_v = 0;

  rep(i, n) {
    cin >> a[i];
    sum_v += abs(a[i]);
  }

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

  ll p_idx = -1;

  rep(i, n) {
    if (a[i] >= 0) {
      p_idx = i;
      break;
    }
  }

  ll cur = a[0];

  // if all plus
  if ( p_idx == 0 ) {
    cout << sum_v - 2*a[0] << endl;
    for ( int i = 1; i < n-1; i++) {
      cout << cur << " " << a[i] << endl;
      cur -= a[i];
    }
    cout << a[n-1] << " " << cur << endl;
    return 0;
  }

  // if all minus
  if ( p_idx == -1 ) {
    cur = a[n-1];
    cout << sum_v + 2*a[n-1] << endl;
    for ( int i = 0; i < n-1; i++) {
      cout << cur << " " << a[i] << endl;
      cur -= a[i];
    }
    return 0;
  }
  
  cout << sum_v << endl;

  for (int i = p_idx; i < n-1; i++) {
    cout << cur << " " << a[i] << endl;
    cur -= a[i];
  } 

  for (int i = 0; i < p_idx; i++) {
    if ( i == 0 ) {
      cout << a[n-1] << " " << cur << endl;
      cur = a[n-1] - cur;
    } else {
      cout << cur << " " << a[i] << endl;
      cur -= a[i];
    }
  }

  return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<string>
#include<list>
#include <stdio.h>
#include<set>

using namespace std;
set<string> lst;

int main()
{
	int dataset; scanf("%d", &dataset);
	for (int i = 0; i < dataset; i++)
	{
		string order;
		cin >> order;
		if (order[0] == 'i') {
			string a; cin >> a;
			lst.insert(a);
		}
		else {
			string finder;
			cin >> finder;
			if (lst.find(finder) == lst.end()) {
				cout << "no" << endl;
			}
			else {
				cout<<"yes"<<endl;
			}

		}
	}
	return 0;
}

Measured memory_bytes: 32112
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-15 19:53:54

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	int one = 0, zero = 0;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == '1')	one++;
		if(s[i] == '0')	zero++;
	}
	cout << 2*min(one, zero) << endl;
	return 0;
}

Measured memory_bytes: 512
def sol():
    import sys
    input=sys.stdin.readline
    n=int(input())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    ans=0
    for i in range(n):
        if b[i]>a[i]:
            ans+=a[i]
            b[i]-=a[i]
            ans+=min(b[i],a[i+1])
            a[i+1]=max(0,a[i+1]-b[i])
        else:
            ans+=b[i]
    print(ans)

if __name__=="__main__":
    sol()


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

int main(){
  int N;
  cin >> N;
  vector<int> width(N);
  for(int i = 0; i < N; ++i){
    cin >> width.at(i);
  }
  sort(width.begin(), width.end());
  int sum = 0;
  int pre = 0;
  for(int i = 0; i < N; ++i){
    sum += (pre < width.at(i));
    pre = width.at(i);
  }
  cout << sum << endl;
}

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

using namespace std;

int N;
long long arr[200005];

int main(){
    cin >> N;
    for (int i = 1; i <= N; i ++)
        cin >> arr[i];
    sort(arr + 1, arr + 1 + N);
    for (int i = 2; i <= N; i ++){
        if (arr[i] == arr[i - 1]){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}


Measured memory_bytes: 1792
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    K = int(readline())
    K -= 1

    idx = 0
    for i, c in enumerate(S):
        if c != '1':
            idx = i
            break
    if idx > K:
        print(1)
    else:
        print(S[idx])

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    // 整数の入力
    int N;
    cin >> N;
    int count = 0;
    for (int i = 1; i <= N; i++){
    	int digit = log10(i);
    	if (digit % 2 == 0){
    		count += 1;
    	}
    }
    // 出力
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class C
{
	public static void Main()
	{
		long H = GetLong();
		long W = GetLong();

		Console.WriteLine(
			Math.Min(
				divFirstHorizontal(H,W),
				divFirstHorizontal(W,H)));
	}

	private static long divFirstHorizontal(long H, long W)
	{
		long ans = long.MaxValue;
		for(long h = 1; h < H; h++)
		{
			long S = h * W;
			long SMax = 0, SMin = 0;
			if(halfHorizontal(H - h, W, ref SMax, ref SMin))
			{
				SMax = Math.Max(S, SMax);
				SMin = Math.Min(S, SMin);
				ans = Math.Min(ans, SMax - SMin);
			}				
			if(halfVertical(H - h, W, ref SMax, ref SMin))
			{
				SMax = Math.Max(S, SMax);
				SMin = Math.Min(S, SMin);
				ans = Math.Min(ans, SMax - SMin);
			}
		}
		return ans;
	}

	private static bool halfHorizontal(long H, long W, ref long SMax, ref long SMin)
	{
		if(H < 2)
			return false;

		SMax = ((H + 1)/2) * W;
		SMin = (H/2) * W;
		return true;	
	}

	private static bool halfVertical(long H, long W, ref long SMax, ref long SMin)
	{
		if(W < 2)
			return false;

		SMax = H * ((W + 1)/2);
		SMin = H * (W/2);
		return true;	
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13140
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readInt
  val a = StdIn.readLine.split(" ").map(_.toLong)
  val sum = a.sum
  val initial = (math.abs(a.head-(sum-a.head)),a.head)

  val ans = a.tail.init./:(initial)((acc,i) => {
      val x = acc._2 + i
      val y = sum - x
      val xy = math.min(math.abs(x-y), acc._1)
      (xy, x)
    })._1

  println(ans)
}

Measured memory_bytes: 58764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  string S;
  cin >> S;
  if(S.size() % 2 == 1) cout << "No" << endl;
  else {
    rep(i, S.size()) {
      if((i % 2 == 0 && S[i] != 'h') ||
         (i % 2 == 1 && S[i] != 'i')) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  return 0;
}


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

int main(){
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = 0;
  if(A+B>=2*C){
    ans += 2*C*min(X,Y);
  }else{
    ans += (A+B)*min(X,Y);
  }
  if(X>Y){
    if(A>=2*C){
      ans += 2*C*(X-Y);
    }else{
      ans += A*(X-Y);
    }
  }else{
    if(B>=2*C){
      ans += 2*C*(Y-X);
    }else{
      ans += B*(Y-X);
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



class UnionFind{
    public:
    vector<ll> par;
    UnionFind(ll size) : par(size,-1){}
    bool unite(ll x,ll y){
        x = root(x),y = root(y);
        if(x == y)return false;
        if(par[y] < par[x])swap(x,y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool find(ll x,ll y){
        return root(x) == root(y);
    }
    ll root(ll x){
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }
    ll size(ll x){
        return -par[root(x)];
    }
};

int main(){
  
  int n,m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i,m){
    int a,b;cin >> a >> b;
    a--;b--;
    uf.unite(a,b);
  }
  int cnt  = 0;
  rep(i,n)if(uf.root(i) == i)cnt++;
  cout << cnt-1 << "\n";



  return 0;
}

Measured memory_bytes: 4084
#include<stdio.h>
 
#define MAXLEN 20000
 
int area, areas[(MAXLEN/2)+1],cnt;
 
int getArea( char *areastr, int start, int maxh )
{
    int i;
    int ravine,squre;
    int down;
 
	down=0;
    areas[cnt]=squre=ravine=0;
    for( i=start; '\0'!=*(areastr+i); i++ ) {
        if( '\\'== *(areastr+i) ) {
            ravine++;
            down++;
            down+=((maxh-ravine)*2);
        } else if( 0 < ravine && '/' == *(areastr+i) ) {
            ravine--;
            if( 0 == ravine ) {
                squre=(i-start+1)*maxh;
                areas[cnt]+=squre;
                areas[cnt]-=(down);
                break;
            }           
        } else {
            areas[cnt]-=(maxh-ravine);
        }
    }
    return areas[cnt];
}
 
 
int checkRavine( char *checkstr, int start )
{
    int i,j;
    int ravine,maxh;
 
    ravine=maxh=0;
    for( i=start, j=0; '\0'!=*(checkstr+i) &&  j<MAXLEN; i++, j++ ) {
        if( '\\'== *(checkstr+i) ) {
                     
            ravine++;
        } else if( 0 < ravine && '/' == *(checkstr+i) ) {
             
            if( maxh < ravine ) { maxh=ravine; }     
            ravine--;
            if( 0 == ravine ) {
                area+=getArea( checkstr, start, maxh );
                cnt++;
                return j;
            }           
        }
    }
 
    return 0;
}
 
void getAreas( char *inputs )
{
    int i,next;
     
    next=cnt=0;
    for( i=0; '\0'!=inputs[i]; i++ ) {
        next=checkRavine( inputs, i );
        i+=next;
    }
 
    return;
}
 
int main( void ) 
{
    char inputs[MAXLEN+1];
    int i;
 
    scanf( "%s", inputs );
    area=cnt=0;
    getAreas( inputs );
     
    printf( "%d\n", area );
    if( cnt ) {
        printf( "%d ", cnt );
        for( i=0; i<cnt; i++ ) {
            printf( "%d", areas[i] );
            if( i < cnt-1 ) {
                printf( " " );  
            } else {
                printf( "\n" ); 
            }
        }
    } else {
        printf( "0\n" );
    }
     
    return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int m;
  while(cin>>m,m){
    int sx[m],sy[m];
    for(int i=0;i<m;i++) cin>>sx[i]>>sy[i];
    int n;
    cin>>n;
    int cx[n],cy[n];
    for(int i=0;i<n;i++) cin>>cx[i]>>cy[i];
    typedef pair<int,int> P;
    set<P> sp;
    for(int i=0;i<n;i++) sp.insert(P(cx[i],cy[i]));
    for(int i=0;i<n;i++){
      int dx=cx[i]-sx[0],dy=cy[i]-sy[0];
      bool flg=0;
      for(int j=0;j<m;j++){
	if(sp.count(P(sx[j]+dx,sy[j]+dy))) continue;
	flg=1;
	break;
      }
      if(flg) continue;
      cout<<dx<<" "<<dy<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3172
from sys import exit
class UnionFind():
    #負の値は根で集合の個数
    #正の値は次の要素を返す
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]

    #集合の代表を求める
    def find(self,x):
        if self.table[x] < 0:return x
        root = self.find(self.table[x])
        self.table[x] = root
        return root

    #併合
    def union(self,x,y):
        s1 = self.find(x)#代表のIndexを取得する
        s2 = self.find(y)
        if s1 != s2:#代表のIndexが違う場合
            if self.table[s1] < self.table[s2]:#要素数の多い方へMergeする
                self.table[s2] += self.table[s1]#子の和を増やす(-)
                self.table[s1] = s2#Mergeされる側の代表をする側のインデックスに
            else:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
        return
    def size(self,x):
        return -self.table[self.find(x)]

N,M = [int(n) for n in input().split()]
p = [int(n) for n in input().split()]

UF = UnionFind(N)
for _ in range(M):
    x,y = [int(n)-1 for n in input().split()]
    UF.union(x,y)
ans = 0
for i in range(N):
    if UF.find(i) == UF.find(p[i]-1):
        ans+=1
print(ans)


Measured memory_bytes: 14452