#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <numeric>
#include <deque>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int n;
string s;
ll ans = 0;

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

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

  foreach_comb(n, 3, [](int *indexes) {
    if(indexes[1]- indexes[0] != indexes[2] - indexes[1]){
      if(s[indexes[0]] != s[indexes[1]] && s[indexes[1]] != s[indexes[2]] && s[indexes[0]] != s[indexes[2]]) ans++;
    }
  });

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


#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define xy          exit(0);
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y)
{
   return (x | y) & (~x | ~y);
}
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
ll NcR(int n, int r)
{
    ll p = 1, k = 1;
    if (n - r < r)
        r = n - r;

    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;
            ll m=__gcd(p, k);
            p /= m;
            k /= m;
            n--;
            r--;
        }
    }
    else
        p = 1;
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
ll gc(ll a,ll b,ll c)
{
	ll x=__gcd(a,b);
	return __gcd(x,c);
}
char cc(char a,char b)
{
	if(a!='R' && b!='R')
	return 'R';
	if(a!='G' && b!='G')
	return 'G';
	if(a!='B' && b!='B')
	return 'B';
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,m,d,x,h,l,n,p,q,k,ans;
    	cin>>n;
    	char s[n+1];
    	repi(i,1,n)
    	cin>>s[i];
    	ll r[n+1],g[n+1],b[n+1];
    	r[0]=0;g[0]=0;b[0]=0; ans=0;
    	repi(i,1,n)
    	{
    		r[i]=0;g[i]=0;b[i]=0;
    		if(s[i]=='R')
			r[i]=1;
    		else if(s[i]=='G')
			g[i]=1;
    		else
			b[i]=1;
		}
    	repi(i,1,n)
    	{
    		r[i]+=r[i-1];
    		g[i]+=g[i-1];
    		b[i]+=b[i-1];
		}
    	repi(i,1,n-2)
    	{
    		repi(j,i+1,n-1)
    		{
    			k=2*j-i;
    			if(s[i]!=s[j] && k<=n)
    			{
    				char c=cc(s[i],s[j]);
    				if(c=='R')
    				{
    					ans+=(r[k-1]-r[j]);
    					ans+=(r[n]-r[k]);
					}
					else if(c=='G')
					{
						ans+=(g[k-1]-g[j]);
    					ans+=(g[n]-g[k]);
					}
					else
					{
						ans+=(b[k-1]-b[j]);
    					ans+=(b[n]-b[k]);
					}
				}
				else if(s[i]!=s[j] && k>n)
    			{
    				char c=cc(s[i],s[j]);
    				if(c=='R')
    				{
    					ans+=(r[n]-r[j]);
					}
					else if(c=='G')
					{
    					ans+=(g[n]-g[j]);
					}
					else
					{
    					ans+=(b[n]-b[j]);
					}
				}
			}
		}
    	cout<<ans;
    }
	return 0;
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


 #include<iostream>
 using namespace std;

 int main() {
     int N, count;
     string S;
     cin >> N;
     cin >> S;
     count = 0;

     for (int i=0; i<N; i++) {
         for (int j=i; j<N; j++) {
             for (int k=j; k<N; k++) {
                if (!(j-i==k-j or S[i]==S[j] or S[i]==S[k] or S[j]==S[k])) {
                    count++;
                }
             }
         }
     }
    cout << count << endl;

     return 0;
 }


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

int main(){
	int l;
	char s[4010];
	long long sum=0;

	scanf("%d",&l);
	scanf("%s",s);

	for(int i=0;i<l-2;i++){
		for(int j=i+1;j<l-1;j++){
			for(int k=j+1;k<l;k++){
				if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]&&(j-i!=k-j)){
					sum++;
				}
			}
		}
	}
	printf("%lld\n",sum);

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)
#define mini(a,b) ((a<b)?a:b)
#define mega(a,b) ((a>b)?a:b)

int main() {
    int n; char s; int ans = 0;
    vector<int> r, g, b;
    cin >> n;
    fori(n) {
        cin >> s;
        if (s == 'R') {
            r.push_back(i);
        }
        else if (s == 'G') {
            g.push_back(i);
        }
        else {
            b.push_back(i);
        }
    }
    for (int i = 0; i < r.size(); ++i) {
        for (int j = 0; j < g.size(); ++j) {
            for (int k = 0; k < b.size(); ++k) {
                int ar[3]; ar[0] = r[i]; ar[1] = g[j]; ar[2] = b[k];
                sort(ar, ar + 3);
                if (ar[1]-ar[0]!=ar[2]-ar[1]) {
                    ++ans;
                }
            }
        }
    }
    cout << ans;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define mod 1000000007
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;

template <typename T>
void vecprint(vector<T> &vec) {
    cout<<'[';
    for(T x:vec){
        cout<<x<<',';
    }
    cout<<']'<<endl;
    return;
}

ll pomod(ll a,ll b){
    if(b==1) return a;
    if(b%2) return pomod(a*a%mod,b/2)*a%mod;
    else return pomod(a*a%mod,b/2)%mod;
}

int main() {
    int n;
    string s;
    cin>>n>>s;
    vector<vector<int>> rgb(3,vector<int>(n+1,0));
    for(int i=n-1;i>=0;i--){
        rgb[0][i]=rgb[0][i+1];rgb[1][i]=rgb[1][i+1];rgb[2][i]=rgb[2][i+1];
        if(s[i]=='R') rgb[0][i]++;
        if(s[i]=='G') rgb[1][i]++;
        if(s[i]=='B') rgb[2][i]++;
    }
    ll ans =0;
    map<char,int> mp;
    mp['R']=0;mp['G']=1;mp['B']=2;
    rep(i,n){
        rept(j,i+1,n-1){
            if(s[i]==s[j]) continue;
            int cl = 3-mp[s[i]]-mp[s[j]];
            ans+=rgb[cl][j+1];
            if(j*2-i<=n-1){
                if(mp[s[j*2-i]]==cl) ans--;
            }
        }
    }

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


#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=998244353 ;
const ll MAXN=1e6+5;
const ll inf=1e17;

int main()
{
    fastio;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    set < ll > r, g, b;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R') r.insert(i);
        else if(s[i] == 'G') g.insert(i);
        else if(s[i] == 'B') b.insert(i);
    }
    ll ans = 0;
    for(auto i : r){
        for(auto j : g){
            ll e = i, f = j;
            if(e > f) swap(e, f);
            ans += b.size();
            if(b.count(f + f - e)) ans--;
            if((e + f) % 2 == 0 && b.count((e + f) / 2)) ans--;
            if(b.count(e + e - f)) ans--;
        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535

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

    long long sum = 0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(s[i] != s[j] && s[j]!= s[k] && s[i]!=s[k] && (j-i)!=(k-j))
                    sum++;
            }
        }
    }
    cout << sum<<endl;
    return 0;

}


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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    int n;
    cin >> n;
    ll ans = 0;
    string s;
    cin >> s;
    map<char, ll> mp;
    for(auto ch: s) {
        mp[ch] ++;
    }
    mp[s[0]] --;
    for(int j = 1; j<n-1; j++) {
        mp[s[j]] --;
        for(int i = j-1; i>=0; i--) {
            if(s[j] != s[i]) {
                int r = 0, b = 0, g = 0;
                if(s[i] == 'R' || s[j] == 'R') r = 1;
                if(s[i] == 'G' || s[j] == 'G') g = 1;
                if(s[i] == 'B' || s[j] == 'B') b = 1;
                if(b == 0) {
                    ans += mp['B'];
                    int idx = (j-i);
                    if(j+idx < n && s[j + idx] == 'B') ans --;
                }
                else if(g == 0) {
                    ans += mp['G'];
                    int idx = (j-i);
                    if(j+idx < n && s[j + idx] == 'G') ans --;
                }
                else if(r == 0) {
                    ans += mp['R'];
                    int idx = (j-i);
                    if(j+idx < n && s[j + idx] == 'R') ans --;
                }
            }
        }
    }
    cout << ans;
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


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

int main() {
    int n;
    string s;
    cin>>n>>s;
    int ans = 0;
    for(int i = 0;i<n-2;i++){
        for(int j = i+1;j<n-1;j++){
            for(int k = j+1;k<n;k++){
                if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]
                &&j-i!=k-j){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}
bool is_judge(const int& a, const int& b, const int& c) {
  int i = min(a, min(b, c));
  int k = max(a, max(b, c));
  int j = a+b+c - i - k;
  if (j-i==k-j)return false;
  return true;
}

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

  int N;
  cin >> N;
  std::vector<char> S(N);
  rep(i, N) cin >> S[i];
  vector<vector<int>> color_s(3);
  rep(i, N) {
    if (S[i] == 'R') color_s[0].push_back(i+1);
    else if (S[i] == 'G') color_s[1].push_back(i+1);
    else if (S[i] == 'B') color_s[2].push_back(i+1);
  }
  std::sort(color_s.begin(), color_s.end(), [](auto& l , auto& r){return l.size() < r.size();});

  ull answer {};
  for (const auto& e : color_s[0]) {
    for (const auto& f : color_s[1]) {
      for (const auto& g : color_s[2]) {
        if (is_judge(e, f, g) == true) ++answer;
      }
    }
  }
  cout << answer << '\n';
}


// May this submission get accepted
#include <bits/stdc++.h>

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using namespace std;

// AtCoder/Codeforces 用 デバッグ検知
#ifdef ONLINE_JUDGE
constexpr bool DEBUG_MODE = false;
#else
constexpr bool DEBUG_MODE = true;
#endif

// エイリアス (補完・コンパイルが重くなる)
// #include <boost/multiprecision/cpp_int.hpp>
// using mll = boost::multiprecision::cpp_int;

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define FOREACH(i,q) for (auto &i : q)
template<class T> bool chmax(T &a, const T b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T b) { if (a > b) {a = b; return true;} return false; }
constexpr int INF = numeric_limits<int>::max();
constexpr long long LINF = numeric_limits<long long>::max();
constexpr long double EPS = 1e-10L;
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define IIF(q,t,f) ((q) ? (t) : (f))
#define DUMP(q) DUMP_FUNC(q, #q, __FILE__, __LINE__)
template <typename T> void DUMP_PROC(T x) { if (is_integral<T>() || is_floating_point<T>()) cerr << "\e[32m" << x << "\e[m"; else cerr << x; }
template<> void DUMP_PROC<char>(char x) { cerr << "\e[36m\'" << x << "\'\e[m"; }
template<> void DUMP_PROC<string>(string x) { cerr << "\e[33m\"" << x << "\"\e[m"; }
template <typename T, typename U> void DUMP_PROC(pair<T, U> x) { cerr << "{"; DUMP_PROC(x.first); cerr << ", "; DUMP_PROC(x.second); cerr << "}"; }
template <typename ...T, typename U, U... Seq> void DUMP_PROC(tuple<T...> &x, integer_sequence<U, Seq...>) { (void)(int[]){(cerr << ((const char*[]){"", ", "})[!!Seq] << (DUMP_PROC(get<Seq>(x)), ""), 0)...}; }
template <typename ...T> void DUMP_PROC(tuple<T...> x) {cerr << "{"; DUMP_PROC(x, index_sequence_for<T...>()); cerr << "}";}
template <typename T> void DUMP_PROC(vector<T> x) { cerr << "["; for (auto &xi : x) { DUMP_PROC(xi); cerr << (&xi != &*x.rbegin()?", ":""); } cerr << "]"; }
template <typename T> void DUMP_FUNC(T x, const char* name, const char* fn, int ln) { cerr << "\e[32m[DEBUG]\e[m " << name << ": "; DUMP_PROC(x); cerr << " @ " << fn << "(" << ln << ")" << endl; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// 標準入出力
struct qin { // query input
    size_t sz;
    qin(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
qin in1; // input one
template <typename T> void say(const T x, const char* end = "\n") { cout << x << end; }
void say(const ld x, const char* end = "\n") { cout << setprecision(30) << x << end; }
template <typename T> void say(const vector<T> x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { cout << x[i] << (i+1 == i_len ? end : sep); } }
template <typename T> void say(const vector<vector<T>> x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { say(x[i], sep, end); } }

// モジュール
// [[LIBRARY]]

// 処理内容
int main() {

    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること

    ll n = in1;
    string s = in1;

    vector a(n, 0LL);
    REP(i, n) {
        switch (s[i]) {
            case 'R': a[i] = 0; break;
            case 'G': a[i] = 1; break;
            default : a[i] = 2;
        }
    }

    vector b(3, 0LL);
    REP(i, n) {
        b[a[i]]++;
    }

    ll ans = b[0] * b[1] * b[2];
    REP(i, n) {
        REP(d, n) {
            ll j = i + d;
            ll k = i + d * 2;
            if (k < n) {
                if (a[i] != a[j] && a[j] != a[k] && a[k] != a[i]) {
                    ans--;
                }
            }
        }
    }
    say(ans);

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  cout<<c<<" "<<b<<" "<<a;
}

Score : 100 points

Problem Statement

We have three boxes A, B, and C, each of which contains an integer.

Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.

We will now do the operations below in order. Find the content of each box afterward.

Swap the contents of the boxes A and B

Swap the contents of the boxes A and C

Constraints

1 \leq X,Y,Z \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z

Output

Print the integers contained in the boxes A, B, and C, in this order, with space in between.

Sample Input 1

1 2 3

Sample Output 1

3 1 2

After the contents of the boxes A and B are swapped, A, B, and C contain 2, 1, and 3, respectively.

Then, after the contents of A and C are swapped, A, B, and C contain 3, 1, and 2, respectively.

Sample Input 2

100 100 100

Sample Output 2

100 100 100

Sample Input 3

41 59 31

Sample Output 3

31 41 59


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const  int mod = 1000000007;
void add(ll& a, ll b)
{
    a+=b;
    while(a>=mod)
        a-=mod;
    while(a<0)
        a+=mod;

}

int main()
{
	int a,b,c; cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;

  	return 0;
}


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

int main() {
    int x, k;
    cin >> x >> k;

    cout << k % abs(x-k) << endl;
}


#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <algorithm>
using namespace std;

#define ll long long

int main(){

    ll int a, b, c;
    cin >> a >> b >> c;
    cout << a << a << b;

    return 0;
}


#include <iostream>

using namespace std;

int main(void) {
  int a, b, c;

  cin >> a >> b >> c;

  cout << c << " " << a << " " << b << endl;

  return 0;
}


#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}

#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e4 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	readc(a, b, c);
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c;
}


#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int a,b,c;
  cin  >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
}


#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  ll x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
  return 0;
}


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

int m,n;
int  a[102];

void solve(){
    cin >> n >> m;
    int s=0;
    for(int i=0;i<n;++i) {
        cin >> a[i];
        s+=a[i];
    }
    s/=(4*m);
    int cnt=0;
    for(int i=0;i<n;++i)
        cnt += (a[i]>=s);
    cout << (cnt >= m  ?  "Yes" : "No") << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--)
        solve();
    return  0;
}

Score : 200 points

Problem Statement

We have held a popularity poll for N items on sale. Item i received A_i votes.

From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.

If M popular items can be selected, print Yes; otherwise, print No.

Constraints

1 \leq M \leq N \leq 100

1 \leq A_i \leq 1000

A_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_N

Output

If M popular items can be selected, print Yes; otherwise, print No.

Sample Input 1

4 1
5 4 2 1

Sample Output 1

Yes

There were 12 votes in total. The most popular item received 5 votes, and we can select it.

Sample Input 2

3 2
380 19 1

Sample Output 2

No

There were 400 votes in total. The second and third most popular items received less than \dfrac{1}{4\times 2} of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.

Sample Input 3

12 3
4 56 78 901 2 345 67 890 123 45 6 789

Sample Output 3

Yes


/*
ID: learnin7
TASK: test
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

int main(){

    ios_base::sync_with_stdio(0);

    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n,m;
    cin>>n>>m;
    int x[n];
    int tot=0;
    forn(i,n){
        cin>>x[i];
        tot += x[i];
    }
    sort(x,x+n);
    bool flag = true;
    for(int i=n-1;i>=n-m;i--){
        if(4*m*x[i]<tot){
            flag = false;
            break;
        }
    }
    if(flag)    cout<<"Yes\n";
    else        cout<<"No\n";
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n);
  for (int i = 0; i < n; i++) cin >> A[i];

  sort(A.begin(), A.end(), greater<int>());
  int sum = 0;
  for (int i = 0; i < n; i++) sum += A[i];
  for(int i = 0; i < m; i++) {
    if (A[i] < sum / (4 * m)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

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

    int tmp;

    for(int i=N; i>0; i--){
        for(int j=1; j<i; j++){
            if(A[j] > A[j-1]){
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
            }
        }
    }

    int tol = 0;

    double W = (V/(4*M));

    for(int i=0; i<M; i++){
        if(A[i] >= W){
            tol = tol + 0;
        }else{
            tol = tol + 1;
        }
    }

    if(tol == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
	int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int topVote = 0, allVote = 0;
  int input;
  rep(i, n){
    cin >> input;
	a.push_back(input);
    allVote+=input;
  }
  sort(a.begin(), a.end(), greater<int>());
  rep(i, m){
	if(a[i] <= allVote / (4 * m)){
      cout << "No" << endl;
//      cout << a[i] << " " << allVote / (4 * m) << endl;
	  return 0;
    }
  }
  cout << "Yes" << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int ar[n];
    long long total_votes=0;
    for(int i=0;i<n;i++){
        cin>>ar[i];
        total_votes=total_votes + ar[i];
    }
    int cnbeselected=0;
    int tobecompared = ((1.000/(4.000*m))*total_votes);
    for(int i=0;i<n;i++){
        if(ar[i]> tobecompared){
            cnbeselected++;
        }
    }
    if(cnbeselected>=m) cout<<"Yes";
    else cout<<"No";

}


#include<iostream>
#include<vector>

using namespace std;

int main() {
	int n, m;//n個，ｍ選ぶ
	cin >> n >> m;
	vector<int>sina(n);
	int i;
	for (i = 0; i < n; i++)cin >> sina[i];
	int x = 0;
	for (i = 0; i < n; i++)x += sina[i];
	auto z = ((long double)(x / (long double)(4 * m)));
	int y = 0;
	for (i = 0; i < n; i++) {
		if (z <= sina[i]) {
			y++;
		}
	}
	if (y >= m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,x) for(int i=0;i<x; i++)
typedef long long  ll;
using namespace std;
int main(){
	int N,M;
  cin>>N>>M;
  int A[N];
	int all=0;
  rep(i,N){
  	cin>>A[i];
    all+=A[i];
  }

  int sinsa=all/(4*M),counter=0;
  rep(i,N){
  	if(A[i]>=sinsa){
    	counter++;
    }
  }
  if(counter>=M){
  	cout<<"Yes";
  }else{
  	cout<<"No";
  }
}


#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rall(x) x.rbegin(),x.rend()
#define mu(x) x.resize(unique(all(x))-x.begin());
#define srt(x) sort(all(x));
#define sum(x) accumulate(all(x),0ll);
#define rev(x) reverse(all(x));
#define each(x,a) for(auto& x:a)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cerr<<#x<<" "<<x<<"\n";
#define debug_v(x) { cout<<#x<<"\n";  each(y,x) cout<<y<<" "; cout<<'\n';}
#define debug_vp(x) { cout<<#x<<"\n";  each(y,x) cout<<y.ff<<" "<<y.ss<<'\n'; cout<<'\n';}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vb;

int main(){
	fastio;
	int n,m;
	cin>>n>>m;
	vi a(n);
	rep(i,n)cin>>a[i];
	int tot=sum(a);
	int x=tot/(4*m)+(tot%(4*m)!=0);
	srt(a);
	rev(a);
	if(a[m-1]>=x){
		cout<<"Yes";
	} else {
		cout<<"No";
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <climits>

using namespace std;

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

    vector<int> a(n);

    int s = 0;

    for (int i = 0; i < n; ++i) {
        cin >> a.at(i);
        s += a.at(i);
    }

    int cnt = 0;

    for (int j = 0; j < n; ++j) {
        if (a.at(j) >= 1.0 * s / (4 * m)) {
            cnt++;
        }
    }

    if (cnt >= m)
        cout << "Yes";
    else
        cout << "No";
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> av;
  ll sum = 0;
  rep(i,n) {
    int a;
    cin >> a;
    av.push_back(a);
    sum += a;
  }
  int cnt = 0;
  double d = (double) sum / (double) (4*m);
  rep(i,n) {
    if ((double)av[i] >= d) cnt++;
  }
  if(cnt >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


#include<iostream>
#include<vector>

using namespace std;

int main()
{
  int n,m;
  int count = 0;
  long long int all = 0;
  cin >> n >> m;

  vector<int> a(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
    all += a[i];
  }

  for(int i = 0; i < n ; i++)
  {
    if(a[i] >= (all / (4 * m)))
    {
      count++;
    }
  }

  if(count >= m)
  {
    cout << "Yes";
  }
  else if(count < m)
  {
    cout << "No";
  }
}


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

int main(void)
{
    using namespace std;
    int N, M;
    cin >> N >> M;

    int total = 0;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        total += A[i];
    }
    double sikii = (double)total / (4 * M);

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] >= sikii) {
            cnt++;
        }
    }

    if (cnt >= M) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}


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

typedef long long int ll;
#define f(a, b) for(auto i = a;i < b;i++)

bool sortbysec(const pair<ll, ll> &a, const pair<ll,ll> &b)
{
    return (a.second < b.second);
}
void solve()
{
	return ;
}

int main()
{
	double  sum = 0;
	ll n , m;
	cin >> n >> m;

	vector < double > vect;

	f(0, n)
	{
		double a;
		cin >> a;
		sum += a;
		vect.push_back(a);
	}

	ll cnt = 0;
	double x = (sum/4.0)/m;
	f(0, n)
	{
		if(vect[i] >= x)
			cnt++;
	}

	if(cnt >= m)
		cout << "Yes\n";
	else
		cout << "No\n";
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sumAll;
  for(int i=0; i<n; i++){
    cin >> a[i];
    sumAll = sumAll + a[i];
  }
  sort(a.begin(), a.end(), greater<int>());

  int count;

  for(int i=0; i<n; i++){
    if(a[i] > sumAll/(4*m)){
      count++;
    }
  }

  if(count >= m) {
    cout <<"Yes"<< endl;
  }else{
    cout <<"No"<< endl;
  }
}


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

int main() {
  int N, M, pop, total;
  cin >> N >> M;
  total = 0;

  vector<int> A(N);
  for(int i = 0;i < N;i++){
  cin >> A.at(i);
  total = total + A.at(i);
  }

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

  for(int i = 0;i < M;i++){
  pop = pop + A.at(N - 1 - i);
  }

  if(pop >= total / 4 * M){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }

}


/**
 * Author RDP
 *
**/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bitset>
#define endl '\n'
#define bp(x) __builtin_popcount(x)
#define zf(x) __builtin_clz(x)
#define zl(x) __builtin_ctz(x)
#define par(x) __bultin_parity(x)
#define FAST_IO ios::sync_with_stdio(0); std::cin.tie(0);
typedef long long ll;
using namespace std;

void test_case()
{
    FAST_IO
    int n, m;
    cin >> n >> m;
    vector <int> num(n);
    ll votes = 0;
    for(int &x : num)
    {    cin >> x;
        votes += x;
    }
    int cnt = 0;
    float thres = 0.25 *  ( float(votes) / m );
    for(int x : num)
    {
        if( float(x) >=  thres)
            cnt ++;
    }
    if(cnt >= m)
        cout <<"Yes"<<endl;
    else
        cout <<"No" <<endl;
    return ;
}
int main()
{
    FAST_IO
    test_case();
    return 0;
}


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

int main()
{
	int n,m,sum=0,digit,t=0;
	cin>>n>>m;

	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];

	for(int i=1;i<=n;i++)
	   {
	     sum+=a[i];
	   }

	   digit=sum/(4*m);

	for(int i=1;i<=n;i++)
	{
		if(a[i]>=digit)
		t++;
	}

	if(t>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;

}


#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(void){
  int n;
  double m,vote=0;
  cin>>n>>m;
  vi a(n);
  rep(i,0,n){
    cin>>a[i];
    vote+=a[i];
  }
  sort(all(a));

  if(a[n-m]<(double)vote/4/m){
    cout << "No";
  }else{
    cout << "Yes";
  }

  return 0;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  int i,N,M,sum,all;
  bool can;
  int A[100];
  can=false;
  //  string S,A;

  cin>>N>>M;
  for(i=0;i<N;i++){
    cin>>A[i];
  }
  all=0;
  sum=0;
  for(i=0;i<N;i++){
    all+=A[i];
  }
  for(i=0;i<N;i++){
    if(A[i]>=(all/(4.0*M)))sum+=1;
  }
  if(sum>=M){
  cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
   return 0;
}


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

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl

const int MAX = 2e6 + 5, MOD = 1e9 + 7  , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

int arr[MAX];
int main(){

    fastio;
    int n,m;
    cin>>n>>m;
    int sum = 0;
    for(int i=0; i<n; i++) cin>>arr[i], sum += arr[i];
    sort(arr,arr+n, greater<int>());
    bool ok = true;
    sum /= 4;
    sum /= m;
    for(int i=0; i<m; i++){
        if(arr[i] < sum) {ok = false; break;}
    }
    if(ok) cout<<"Yes\n";
    else cout<<"No\n";
}


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

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

    int n, m;
    cin >> n >> m;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];

    int sum = accumulate(a, a + n, 0);
    int min = (int) ceil((float)sum / (float)(4*m));

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (min <= a[i]) cnt++;
    }

    cout << (cnt >= m ? "Yes" : "No") << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main()
{
    IOS;
    in n,m,tot=0;
    cin >> n >> m;
    vector<in> p(n);
    rep(i,0,n){
        cin >> p[i];
        tot+=p[i];
    }
    in k = tot/(4*m),count=0;
    if(tot % (4*m) != 0) k++;
    rep(i,0,n){
        if(p[i]>=k) count++;
    }
    (count>=m) ? cout << "Yes\n" : cout << "No\n";
}


// code.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
int n,m,A;
A=0;
cin>>n>>m;
int a[n];
for(int i=0; i<n; i++){
	cin>>a[i];
}
int sum =0;
for(int i=0; i<n; i++){
	sum = sum+a[i];
}
int p = 4*m;
int val = sum/p;
for(int i=0; i<n; i++){
	if(a[i]>=val){
		A++;
	}
}
if(A>=m){
	cout<<"Yes";
}
else{
	cout<<"No";
}

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define of(i,p,n) for(ll i=n-1;i>=p;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define mem(x,p) memset(x,p,sizeof(x))
#define trav(it,a) for(auto it=a.begin();it!=a.end();++it)
#define kk "\n"
const ll mod=1e9+7;
int main()
{
  IOS
  ll n,m;
  cin>>n>>m;
  ll arr[n],s=0;
  fo(i,n)
  {
    cin>>arr[i];
    s=s+arr[i];
  }
  sort(arr,arr+n);
  ll p=s/(4*m);ll c=0;
  fo(i,n)
  {
    if(arr[i]>=p)
      c++;
  }
  if(c>=m)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;

int n, m, a[1002], sum;

int main(){
    scan(n, m);
    for(int i = 0; i < n; i++){
        scan(a[i]);
        sum += a[i];
    }
    sum = ceil(1.0*sum/(4.0*m));
    int cnt = 0;
    for(int i = 0; i < n ;i++){
        if(a[i] >= sum)
            cnt++;
    }

    if(cnt >= m)
        puts("Yes");
    else
        puts("No");

    return 0;
}


#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e4+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    ll red[a],green[b];
    vll ans;
    loop(a,i,0)
        cin>>red[i];
    loop(b,i,0)
        cin>>green[i];
    sort(all(red,a),greater<ll>());
    sort(all(green,b),greater<ll>());
    loop(x,i,0)
        ans.pb(red[i]);
    loop(y,i,0)
        ans.pb(green[i]);
    loop(c,i,0){
        ll z;cin>>z;
        ans.pb(z);
    }
    ll res=0;
    sort(allv(ans),greater<ll>());
    loop(x+y,i,0)
        res+=ans[i];
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}

Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74


#include <bits/stdc++.h>

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))
#define MOD 1000000007

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<ll> llList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  llList p, q, r;
  ll a;
  for(int i=0;i<A;i++){
    cin >> a;
    p.push_back(a);
  }
  for(int i=0;i<A;i++){
    cin >> a;
    q.push_back(a);
  }
  for(int i=0;i<A;i++){
    cin >> a;
    r.push_back(a);
  }

  p.sort();
  q.sort();
  r.sort();
  for(int i=0;i<A-X;i++){
    p.pop_front();
  }
  for(int i=0;i<B-Y;i++){
    q.pop_front();
  }
  p.merge(move(q));
  p.merge(move(r));
  p.reverse();
  ll sum = 0;
  for(int i=0;i<X+Y;i++){
    sum += p.front();
    p.pop_front();
    //cout << p.front() << endl;
  }

  cout << sum << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
	int X, Y, A, B, C;
	vector<int> p, q, r;
	cin >> X >> Y >> A >> B >> C;
	p.reserve(A);
	q.reserve(B);
	r.reserve(C);
	int tmp;
	rep (i, A) {
		cin >> tmp;
		p.push_back(tmp);
	}
	rep(i, B) {
		cin >> tmp;
		q.push_back(tmp);
	}
	rep(i, C) {
		cin >> tmp;
		r.push_back(tmp);
	}
	sort(p.begin(), p.end(), greater<int>());
	sort(q.begin(), q.end(), greater<int>());
	sort(r.begin(), r.end(), greater<int>());

	int a = X-1;
	int b = Y-1;
	int c = 0;

	char target;
	while (1) {
		if (a < 0 || b < 0 || c >= C) break;
		if (p[a] < q[b]) {
			tmp = p[a];
			target = 'a';
		} else {
			tmp = q[b];
			target = 'b';
		}
		if (tmp < r[c]) {
			if (target == 'a') a--;
			else b--;
			c++;
		} else {
			break;
		}
	}
	ll ans = 0;
	rep(i, a+1){
		ans += p[i];
	}
	rep(i, b+1){
		ans += q[i];
	}
	rep(i, c){
		ans += r[i];
	}
	cout << ans << "\n";
	return 0;
}


#include <bits/stdc++.h>

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define SIZE(arr) ((int)arr.size())
#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;

using namespace std;

using ll = long long;

const int MOD = 1e9 + 7;
const ll INF_LLONG = 1e18 + 9;
const int INF_INT = 1e9 + 9;

int dist[2001][2001];

int main()
{
	//	#ifndef ONLINE_JUDGE
	//		(void)freopen("input.txt", "r", stdin);
	//		(void)freopen("output.txt", "w", stdout);
	//	#endif
	FAST_IO;
	ll x, y, A, B, C;
	cin >> x >> y >> A >> B >> C;
	vector<ll> a(A);
	vector<ll> b(B);
	vector<ll> c(C);
	for (int i = 0; i < A; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < B; ++i) {
		cin >> b[i];
	}
	for (int i = 0; i < C; ++i) {
		cin >> c[i];
	}
	sort(a.begin(), a.end(), greater<ll>());
	sort(b.begin(), b.end(), greater<ll>());
	ll ans = 0;
	for (int i = 0; i < x; ++i) {
		c.push_back(a[i]);
	}
	for (int i = 0; i < y; ++i) {
		c.push_back(b[i]);
	}
	sort(c.begin(), c.end(), greater<ll>());
	for (int i = 0; i < x + y; ++i)
		ans += c[i];
	cout << ans;
	return 0;
}


#include<iostream>
#include<queue>
using namespace std;

#define int long long

signed main(){
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;

	priority_queue<pair<int,int> > h;

	while(a--){
		int w;
		cin>>w;
		h.push(make_pair(w,1));
	}

	while(b--){
		int w;
		cin>>w;
		h.push(make_pair(w,2));
	}

	while(c--){
		int w;
		cin>>w;
		h.push(make_pair(w,3));
	}

	int z=x+y;
	int ans=0;

	while(z){
		pair<int,int> f=h.top();
		h.pop();
		if(f.second==3){
			ans+=f.first;
			--z;
		}
		else if(f.second==1 && x){
			ans+=f.first;
			--x;
			--z;
		}
		else if(f.second==2 && y){
			ans+=f.first;
			--y;
			--z;
		}
	}

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


//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
//#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
//----------------------------------------------------
int x, y, a, b, c;
vector<int> r, g, d;
set<int> s;
ll ans = 0;
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> x >> y >> a >> b >> c;
    r.resize(a), g.resize(b), d.resize(c);
    forn(i, a) cin >> r[i];
    forn(i, b) cin >> g[i];
    forn(i, c) cin >> d[i];
}

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    sort(all(r), greater<int>());
    sort(all(g), greater<int>());
    sort(all(d), greater<int>());

    forn(i, x) ans += r[i], s.insert(r[i]);
    forn(i, y) ans += g[i], s.insert(g[i]);

    int k = 0;
    while (k < d.size() && d[k] > *s.begin()){
        ans = ans - *s.begin() + d[k];
        s.erase(s.begin());
        s.insert(d[k]);
        k++;
    }

    cout << ans << endl;

}


#include <iostream>//数据输入输出流
#include <cstring>//字符串操作函数
#include <cstdio>//C的输入输出
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>//C中的数学函数
#include <string>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>//bitset可按位定义串
//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define LOCAL
#define zeros(a,n) memset(a,0,(n)*sizeof(a[0]))
const int modn = 1e9+7;
int mod(int x) { return x<0?x+modn:x<modn?x:x-modn; }
const int N = 200005;
int p[N],q[N],e[N];
int n,x,y,a,b,c,idx;
int d[N], r[N];
bool cmp(const int& a, const int& b){
    return a>b;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>x>>y>>a>>b>>c;
    for(int i=0;i<a;++i)cin>>p[i];
    for(int i=0;i<b;++i)cin>>q[i];
    for(int i=0;i<c;++i)cin>>e[i];
    sort(p,p+a,cmp);
    sort(q,q+b,cmp);
    sort(e,e+c);
    idx = 0;
    priority_queue<int>que1,que2,que3;
    for(int i=0;i<min(x,a); ++i) que1.push(-p[i]);
    for(int j=0;j<min(y,b);++j) que2.push(-q[j]);
    for(int i=0;i<c;++i) que3.push(e[i]);
    while(que1.size()<x && que3.size()){
        que1.push(-que3.top());
        que3.pop();
    }
    while(que2.size()<y && que3.size()){
        que2.push(-que3.top());
        que3.pop();
    }
    while(que3.size()){
        int x = -que1.top();
        int y= -que2.top();
        int z = que3.top(); que3.pop();
        if(x > y){
            if(z > y) {
                que2.pop();
                que2.push(-z);
            }
        }else{
            if(z > x) {
                que1.pop();
                que1.push(-z);
            }
        }
    }
    LL ans = 0;
    while(que1.size()){
        ans += -que1.top();
        que1.pop();
    }
    while(que2.size()){
        ans += -que2.top();
        que2.pop();
    }
    /*
    for(int i=0;i<min(x,a);++i) d[idx++]=p[i];
    for(int i=0;i<min(b,y);++i) d[idx++]=q[i];
    sort(d,d+idx);
    priority_queue<int>que;
    for(int i=0, j=0; i<=min(c-1,idx-1), j<c;++i,++j){
        que.push(d[i]);
        que.push(e[j]);
    }
    LL ans=0;
    for(int i=c;i<=idx-1;++i) ans+=d[i];
    int t = (x + y) - (idx - c);
    while(t--){
        ans += que.top();
        que.pop();
    }
    */
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define pb push_back
#define mp make_pair
const int mod=1e9+7;

void solve()
{
  int x,y,a,b,c;
  ll ans=0;
  cin>>x>>y>>a>>b>>c;
  int A[a],B[b],C[c];
  for(int i=0;i<a;i++)
  cin>>A[i];
  for(int i=0;i<b;i++)
  cin>>B[i];
  for(int i=0;i<c;i++)
  cin>>C[i];
  sort(A,A+a);
  sort(B,B+b);
  sort(C,C+c);
  int ai=a-1,bi=b-1,ci=c-1;
  int p=min(x,y),q=max(x,y);
  while(x!=0 && y!=0 && ci!=-1)
  {
    //cout<<"p";
    if(A[ai]>=C[ci] && B[bi]>=C[ci])
    {
      //cout<<"f";
      if(A[ai]>=B[bi])
      {
        ans+=A[ai];
        ai--; x--;
      }
      else
      {
        ans+=B[bi];
        bi--; y--;
      }
    }
    else if(A[ai]>=C[ci] && B[bi]<C[ci])
    {
      //cout<<"g";
      ans+=A[ai];
      ai--;
      x--;
    }
    else if(A[ai]<C[ci] && B[bi]>=C[ci])
    {
    //  cout<<"h";
      ans+=B[bi];
      bi--; y--;
    }
    else if(A[ai]<C[ci] && B[bi]<C[ci])
    {
  //    cout<<"j";
      if(A[ai]<=B[bi])
      {
        ans+=C[ci];
        ci--;
        x--;
      }
      else
      {
        ans+=C[ci];
        ci--;
        y--;
      }
    }
    p--;
  }

//cout<<endl;
  if(x==0 && y==0)
  {
  //  cout<<"e";
    cout<<ans<<endl;
    return;
  }
//cout<<endl;
  if(ci==-1)
  {
    while(x!=0)
    {
      ans+=A[ai];
      ai--;
      x--;
    }
    while(y!=0)
    {
      ans+=B[bi];
      bi--;
      y--;
    }
    cout<<ans<<endl;
    return;
  }

  if(x==0)
  {
    while(y!=0 && ci>-1)
    {
  //    cout<<"x";
      if(B[bi]>=C[ci])
      {
        ans+=B[bi];
        bi--;
        y--;
      }
      else
      {
        ans+=C[ci];
        ci--;
        y--;
      }
    }
    if(ci==-1)
    {
      while(x!=0)
      {
        ans+=A[ai];
        ai--;
        x--;
      }
      while(y!=0)
      {
        ans+=B[bi];
        bi--;
        y--;
      }
      cout<<ans<<endl;
      return;
    }
  }
  else if(y==0)
  {
    while(x!=0 && ci>-1)
    {
      if(A[ai]>=C[ci])
      {
        ans+=A[ai];
        ai--;
        x--;
      }
      else
      {
        ans+=C[ci];
        ci--;
        x--;
      }
    }
    if(ci==-1)
    {
      while(x!=0)
      {
        ans+=A[ai];
        ai--;
        x--;
      }
      while(y!=0)
      {
        ans+=B[bi];
        bi--;
        y--;
      }
      cout<<ans<<endl;
      return;
    }
  }
  cout<<ans<<endl;
}

int main()
{
  fastio
  solve();
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
//#define int ll
#define pb push_back
using pii = pair<int,int>;
const int N = 100005;
const int Inf = 1e9+7;

int p[N], q[N];

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
	int x, y, a, b, c, sm=0;
	cin >> x >> y >> a >> b >> c;
	vector<int> r(c);
	for (int i = 0; i < a; ++i)
	{
		cin >> p[i];
	}
	for (int i = 0; i < b; ++i)
	{
		cin >> q[i];
	}
	for (int i = 0; i < c; ++i)
	{
		cin >> r[i];
	}
	sort(p, p + a);
	sort(q, q + b);
	vector<int> v, s;
	for (int i = a - x; i < a; ++i)
	{
		sm += p[i];
		v.push_back(p[i]);
	}
	for (int i = b - y; i < b; ++i)
	{
		sm += q[i];
		v.push_back(q[i]);
	}
	sort(v.begin(), v.end());
	sort(r.begin(), r.end());
	reverse(r.begin(), r.end());
	int ptr = 0, cnt = 0;
	while (ptr < c)
	{
		while (ptr < c && r[ptr] <= v[cnt])
		{
			++ptr;
		}
		if (ptr != c)
		{
			sm -= v[cnt];
			sm += r[ptr];
		}
		++ptr;
		++cnt;
	}
	cout << sm;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr);
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--)

int32_t main(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;

    priority_queue<int>q1;
    priority_queue<int>q2;
    priority_queue<int>q3;

    for(int i = 0;  i <a; i++){
        int x;cin>>x;q1.push(x);
    }
    for(int i = 0;  i <b; i++){
        int x;cin>>x;q2.push(x);
    }

    for(int i = 0;  i <c; i++){
        int x;cin>>x;q3.push(x);
    }

    int ex=0;
    int ey=0;
    int ext=0;
    int res=0;
    while(ex+ey+ext < x+y){

        int vx = -1e12;
        int vy = -1e12;
        int vex = -1e12;
        if(q1.size() && ex<x)
         vx = q1.top();

         if(q2.size() && ey<y)
         vy = q2.top();

         if(q3.size())
         vex = q3.top();

        if(vx > vy && vx > vex ){
            res+=vx;
            ex++;
            q1.pop();
        }
        else if(vy>vx && vy>vex){

            res+=vy;
            ey++;
            q2.pop();
        }
        else {
            res+=vex;
            ext++;
            q3.pop();
        }

    }
    // cout<<ex<<" "<<ey<<" "<<ext<<endl;
    cout<<res<<endl;

}


#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=3e5+5;
int n,m,p,q,nm,cnt,ans,come[N],num,choose[N],c;

struct apple{
	int x,k;
	inline bool operator < (const apple &nt) const {
		return x>nt.x;
	}
}a[N];

signed main(){
	read(p);read(q);read(n);read(m);read(nm);
	for(int i=1,x;i<=n;i++) a[++cnt]=(apple){read(x),1};
	for(int i=1,x;i<=m;i++) a[++cnt]=(apple){read(x),2};
	for(int i=1,x;i<=nm;i++) a[++cnt]=(apple){read(x),0};
	sort(a+1,a+1+cnt);
	for(int i=1;(p||q)&&i<=cnt;i++){
		if(a[i].k==1){
			if(p) p--,choose[++c]=a[i].x,ans+=a[i].x;
		}
		if(a[i].k==2){
			if(q) q--,choose[++c]=a[i].x,ans+=a[i].x;
		}
		if(a[i].k==0){
			come[++num]=a[i].x;
		}
	}
	sort(choose+1,choose+1+c);
	sort(come+1,come+1+num,greater<int>());
	for(int i=1;i<=num;i++) if(come[i]>choose[i]) ans+=come[i]-choose[i];
	write(ans);
}


#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
    long double a, b, c;

    cin >> a >> b >> c;

    long double delta = c - a - b;

    long double sqrt_ab = (long double)2*sqrt(a*b);
    //long double sqrt_a = (long double)sqrt(a);
    //long double sqrt_b = (long double)sqrt(b);

    if(delta < 0){
        printf("No\n");
    }
    else{
        if(delta > sqrt_ab){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }

    return 0;
}

Score : 300 points

Problem Statement

Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?

Constraints

1 \leq a, b, c \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a \ b \ c

Output

If \sqrt{a} + \sqrt{b} < \sqrt{c}, print Yes; otherwise, print No.

Sample Input 1

2 3 9

Sample Output 1

No

\sqrt{2} + \sqrt{3} < \sqrt{9} does not hold.

Sample Input 2

2 3 10

Sample Output 2

Yes

\sqrt{2} + \sqrt{3} < \sqrt{10} holds.


#include<bits/stdc++.h>
using namespace std;
long double sq(long double x){
	long double fx,pre;
	long double c=x;
	fx=x*x-c;
	do{
		pre=x;
		x-=fx/2/x;
		fx=x*x-c;
	}while(abs(x-pre)>1e-13);
	return x;
}
int main()
{
	long double a,b,c;
	cin>>a>>b>>c;
	puts(sq(a)+sq(b)-sq(c)<-1e-13?"Yes":"No");
}


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

int main(){
    int a, b, c;
    scanf("%d%d%d" ,&a, &b, &c);
    if(a+b+2*sqrt(a*b) < c) printf("Yes\n");
    else printf("No\n");
}


#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>
#include <cfloat>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

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

  ll a, b, c;
  cin >> a >> b >> c;
  ll right = (c - (a + b)) * (c - (a + b));
  ll left = 4 * a * b;
  if (right - left > 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    int ans = 1;
    if(c-a-b <= 0) ans = 0;
    else{
        if((c-a-b)*(c-a-b) <= 4*a*b) ans = 0;
    }
    if(ans == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<tgmath.h>
using namespace std;

long double EPS = 1E-14;

// r の(誤差付きの)符号に従って, -1, 0, 1 を返す.
int sgn(long double r){ return (r > EPS) - (r < -EPS); }
// a, b の(誤差付きの)大小比較の結果に従って, -1, 0, 1 を返す.
int sgn(long double a, long double b){ return sgn(a - b); }

int main(){
    long double a,b,c;
    cin >> a >> b >> c;
    if(sgn(sqrtl(c),sqrtl(a)+sqrtl(b)) == 1){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-11; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrt((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}

int main(void) {
	Rapid_pleaseAC_fast;
    double a,b,c,ad=1.0, bd=1.0, cd=1.0,x,y,z;
	cin >> a>>b>>c;
	ad += a - 1.0;
	bd += b - 1.0;
	cd += c - 1.0;
	x = mysqrtl(ad);
	y = mysqrtl(bd);
	z = mysqrtl(cd);
	if (x+y<z)cout << "Yes" << endl;
	else cout << "No" << endl;
	please AC;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)
#define Inf 2147483647
#define llInf 9223372036854775807
#define all(x) x.begin(),x.end()
#define pb push_back

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//セグ木・0-indexed・非再帰・(大きさ・単位元)で初期化
template<typename T>
struct SegTree {
	//比較関数の型
	using F = function<T(T, T)>;
	//二分木を配列で表したもの
	vector<T>seg;
	//木の半分の大きさ
	int siz;
	//単位元
	const T unit;
	//比較する関数
	const F f;

	//大きさn、unit(単位元)でsegtreeを初期化する
	SegTree(int n, const T unit, const F f) : unit(unit), f(f) {
		siz = 1;
		while (siz < n)siz <<= 1;
		seg.assign(siz * 2 - 1, unit);
		siz--;
	}

	//k番目にtを入力
	void set(int k, const T& t) {
		seg[k + siz] = t;
	}

	//fによって木を構築する
	void build() {
		for (int i = siz - 1; 0 <= i; i--) {
			seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2]);
		}
	}

	T operator[](const int i) {
		return seg[i + siz];
	}

	//k番目をxに更新する
	void update(int k, T x) {
		k += siz;
		seg[k] = x;
		while (0 < k) {
			k = (k - 1) >> 1;
			seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
		}
	}

	//[a,b)について、fした結果を返す
	//半開区域のためa以上b未満の位置を指す
	T query(int a, int b) {
		T l = unit, r = unit;
		for (a += siz, b += siz; a < b; a >>= 1, b >>= 1) {
			if (!(a & 1))l = f(seg[a++], l);
			if (!(b & 1))r = f(seg[--b], r);
		}
		return f(l, r);
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

template<typename T>
bool check(T a, T b) {
	return a < b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	//a,b,cの係数
	int x = 1, y = 1, z = 1;
	for (int i = 2; i * i <= a; i++) {
		if ((int)a % (i * i) == 0) {
			x *= i;
			a /= i * i;
			i--;
		}
	}
	for (int i = 2; i * i <= b; i++) {
		if ((int)b % (i * i) == 0) {
			y *= i;
			b /= i * i;
			i--;
		}
	}
	for (int i = 2; i * i <= c; i++) {
		if ((int)c % (i * i) == 0) {
			z *= i;
			c /= i * i;
			i--;
		}
	}
	if (a == b && b == c) {
		Yes(x + y < z);
	}
	else {
		double A = x * sqrt((double)a), B = y * sqrt((double)b), C = z * sqrt((double)c);
		Yes(A + B < C && A < C - B && B < C - A);
	}
	return 0;
}


#include "algorithm"
#include "cmath"
#include "iomanip"
#include "iostream"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define all(vec) vec.begin(), vec.end()
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  double a, b, c;
  cin >> a >> b >> c;
  if (sqrt(a) + sqrt(b) < sqrt(c)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


#include<iostream>
#include<math.h>

using namespace std;
int main ()
{
    long long a,b,c;
    double p,q,r,s=0;
    cin>>a>>b>>c;

        p=sqrt(a);
        q=sqrt(b);
        r=sqrt(c);
        s=p+q;
   if(s<=r)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


#include<cstdio>
#include<cmath>
#define ll long long
int main()
{
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	c-=(a+b);
	ll sq=sqrt(4*a*b);
	if(c>sq)
		printf("Yes");
	else
	if(c<sq)
		printf("No");
	else
	{
		if(sq*sq!=4*a*b)
			printf("No");
		else
			printf("Yes");
	}
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    unsigned long long  a, b, c, diff;
    long double ab;
    cin >> a >> b >> c;

    if (c < a + b) {
        cout << "No" << endl;
        return 0;
    }

    diff = c - a - b;
    // ab = sqrt(a) * sqrt(b);
    // // cout << ab << endl;
    // if (diff > 2 * ab) {
    //     cout << "Yes" << endl;
    // } else {
    //     cout << "No" << endl;
    // }

    if (((diff / 2) * (diff / 2)) > (a * b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

int main(void) {
    FAST_IO;

    ll a, b, c;
    cin >> a >> b >> c;
    if ((a + b- c) *(a + b - c) < 4*a*b) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}


#include <bits/stdc++.h>
#define rep( i, n ) for (long long i = 0; i < ( long long )(n); i++)

using namespace std;
typedef long long ll;
typedef pair< int , int > P;

int main(){
  ll a,b,c;
  long double aa,bb,cc;
  cin>>a>>b>>c;
  aa= (long double) sqrt((long double)a);
  bb= (long double) sqrt((long double)b);
  cc= (long double) sqrt((long double)c);
  if(aa+bb<cc) cout<<"Yes";
  else "No";
}


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

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

    double aa=sqrt(a);
    double bb=sqrt(b);
    double cc=sqrt(c);

    double sahen;
    double uhen;

    sahen = aa + bb - cc;
    uhen = 0;

    if(sahen < uhen){cout << "Yes" << endl; return 0;}
    cout << "No" << endl;

}


/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <math.h>
using namespace std;

typedef long double ld;
const ld eps = 1.0e-18; // 許容される誤差

ld mysqrtl(ld x)
{
  ld a = sqrt((double)x); // 近似値
  do {
    a = (a + x/a) / 2.0L;
  } while (fabsl(x - a*a) > eps);
  return a;
}

int main(){
	ld a, b, c;
	long double A, C;
	cin >> a >> b >> c;

	A = mysqrtl(a+b);
	C = mysqrtl(c);

	if (A < C){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main() {
    long long a, b, c;
    cin >> a >> b >> c;
    long long left = 4 * a * b;
    long long right = (a + b - c) * (a + b - c);
    if(left < right) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	uint64_t a,b,c;
	cin>>a>>b>>c;
	double ab;
	ab=pow(a*b,0.5);
	if(a+ab*2+b<c)cout<<"Yes\n"s;
	else cout<<"No\n"s;
}


#include <bits/stdc++.h>
#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>;

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

  if ((sqrt(a) + sqrt(b)) < sqrt(c)) {
      cout << "Yes" << endl;
  }
  else {
      cout << "No" << endl;
  }

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

double n, m, p;

int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> p;
	if (sqrt(n) + sqrt(m) < sqrt(p)) {
		cout << "Yes";
		return 0;
	}
	cout << "NO";
}


#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

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

    double sq = sqrt(a);
    double sb = sqrt(b);
    double sc = sqrt(c);

    if (sc - sq - sb > 1e-12) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long double a, b, c;
  cin >> a  >> b >> c;
  if (a + b + 2 * (long double)sqrt(a*b) < c) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)
typedef long long ll;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }
int main(){
	// in;
	// out;
	ll a,b,c;
	cin>>a>>b>>c;
	double aa,bb,cc;
	aa=sqrt(a);
	bb=sqrt(b);
	cc=sqrt(c);
	if(aa+bb<cc) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (4 * a * b < (c - a - b) * (c - a - b))
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
using ll = long long;
const int INF = 1001001001;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> S(M);
    vector<int> C(M);
    rep(i, M) {
        int s, c;
        cin >> s >> c;
        --s;
        S[i] = s;
        C[i] = c;

    }
    vector<int> num(N, 0);

    rep(i, M) {
        num[S[i]] = C[i];
    }
    int ans = 0;
    reverse(num.begin(), num.end());
    print(num);
    rep(k, N) {
        ans += num[k] * pow(10, k);
    }

    int k = (int)log10(ans);
    if(k+1<N) {
        print(-1);
        return 0;
    }

    print(ans);

    return 0;
}

Score : 300 points

Problem Statement

If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)

The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)

Constraints

All values in input are integers.

1 \leq N \leq 3

0 \leq M \leq 5

1 \leq s_i \leq N

0 \leq c_i \leq 9

Input

Input is given from Standard Input in the following format:

N M
s_1 c_1
\vdots
s_M c_M

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702

702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them.

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m,si,ci,ans;ans=0;
    scanf("%d%d",&n,&m);
    int num[n+1];
    for(int i=1;i<=n;i++)num[i]=9;
    bool check[n+1]={false};
    for(int i=0;i<m;i++){
        scanf("%d%d",&si,&ci);
        check[si]=true;
        num[si]=min(num[si],ci);
    }
    if(num[1]==0&&n>=2){
        ans=-1;
        printf("%d\n", ans);
        return 0;
    }
    for(int i=1;i<=n;i++){
        if(!check[i]) {
            num[i]=0;
            if (i==1) {
                ans=-1;
                break;
            }
        }
        ans+=num[i]*pow(10,n-i);
    }
    printf("%d\n",ans);
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

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

int main(){
    int n,m;
    cin >> n >> m;
    int pos,num;
    string str;

    rep(i,n) str += '0';
    string number = "0123456789";
    rep(i,m){
        cin >> pos >> num;
        pos--;
        if(str[pos] == '0' || str[pos] == number[num]){
            str[pos] = number[num];
        }else{
            cout << -1 << endl;
            return 0;
        }
    }

    if(str[0] == '0'){
        cout << -1 << endl;
    }else{
        cout << str << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  int s[M];
  string a[N],p[N],c[M];
  for(int i=0;i<M;i++){
    cin>>s[i]>>c[i];
  }
  for(int i=0;i<N;i++){
    a[i]="0";
    p[i]="No";
  }

  bool judge=true;

  for(int i=0;i<M;i++){
    if(p[s[i]-1]=="No"||a[s[i]-1]==c[i]){
      a[s[i]-1]=c[i];
      p[s[i]-1]="Yes";
    }
    else{
      judge=false;
    }
  }
  string ans;
  for(int i=0;i<N;i++){
    ans+=a[i];
  }

  if(a[N-1]=="0"&&N!=1){
    judge=false;
  }

  if(judge){
    cout<<ans<<endl;
  }
  else{
    cout<<-1<<endl;
  }
}


#include <bits/stdc++.h>
#define REPZ(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12
#define MOD 1000000007    //合同式の法

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// intの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 setprecision()
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
using namespace std;
int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n,m; cin >> n >> m;
  // 右から数字が何か入れる
  int d[]={-1,-1,-1};
  REP(i,m){
    int digit, value; cin >> digit >> value;
    if((d[n-digit]!=-1 and d[n-digit]!=value) or (n!=1 and digit==1 and value==0)){
      cout << -1 << endl;
      return 0;
    }
    d[n-digit]=value;
  }
  if(d[n-1]==-1 or d[n-1] ==0) d[n-1]=1;
  int res=0;
  int temp=1;
  REP(i,n){
    if(d[i]!=-1)res+=d[i]*temp;
    temp*=10;
  }
  cout << res << endl;
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep_bit(n) for (int bit = 0; bit < (1<<n); ++bit)
#define ll long long
using namespace std;

int main(){

    int N,M;
    cin >> N >> M;
    vector<int> s(M);
    vector<int> c(M);

    vector<int> num(N,0);
    vector<bool> exist(N,false);
    bool ok = false;
    rep(i,M){
        int a,b;
        cin >> a >> b;
        if(exist.at(a-1) && num.at(a-1) != b){
            ok = true;
            break;
        }
        else{
            num.at(a-1) = b;
            exist.at(a-1) = true;
        }

    }
    int ans = 0;
    rep(i,N){
        ans+=pow(10,N-1-i)*num.at(i);
    }
    if(exist.at(0) == false) ans += pow(10,N-1);
    bool mendou =false;
    if(N>=2&&num.at(0) == 0&&exist.at(0)) mendou = true;
    if(ok || mendou) cout << -1 << endl;
    else cout << ans << endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

long long n,m;
cin>>n>>m;
long long arr[n];
for(long long i=0;i<=n;i++)
{
    arr[i]=-1;
}
bool hbe=true;
for(long long i=0;i<m;i++)
{
    long long k,l;
    cin>>k>>l;

    if((arr[k-1]!=-1 && arr[k-1]!=l) || k>n )
    {
        hbe=false;
    }
    else
    {
        arr[k-1]=l;
    }
    if(k==1 && l==0)
    {
        hbe=false;
    }
}
if(!hbe)
{
    cout<<-1<<endl;
    return 0;
}
bool z=false;
long long ans[n];
for(long long i=0;i<n;i++)
{
    if(arr[i]==-1 && !z)
        arr[i]=1;
    if(arr[i]==-1 && z)
        ans[i]=0;

    if(arr[i]>0){
        z=true;

    }
}

for(long long i=0;i<n;i++)
{
cout<<arr[i];

}
cout<<endl;

}


#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;

int n,m,c[5];

bool check(int x)
{
    vector<int>digit;
    while(x)
    {
        digit.push_back(x%10);
        x/=10;
    }
    reverse(digit.begin(),digit.end());
    for(int i=0;i<digit.size();i++) if(c[i+1]!=-1&&digit[i]!=c[i+1]) return false;
    return true;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(c,-1,sizeof c);
    cin>>n>>m;
    while(m--)
    {
        int pos,val;
        cin>>pos>>val;
        if(c[pos]!=-1&&c[pos]!=val) return cout<<-1,0;
        c[pos]=val;
    }
    if(n==1)
    {
        if(c[1]==-1||c[1]==0) return cout<<0,0;
    }
    int lim=1;
    for(int i=1;i<=n;i++) lim*=10;
    for(int i=lim/10;i<lim;i++) if(check(i)) return cout<<i,0;
    cout<<-1;
}


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

int main(){int p=0;
int N;
cin >> N;
int M;
cin >> M;
vector<int> s(M+1,0);
vector<int> c(M+1,0);
for(int i=0;i<M;i++){
    cin>>s.at(i)>>c.at(i)
;}
vector<int> ans(N+1,0);
if(N>1){ans.at(0)=1;}
vector<bool> vec(N+1,0);
for(int i=0;i<M;i++){
    int j=s.at(i)-1;
  if(vec.at(j)==1&&ans.at(j)!=c.at(i)){cout<<-1<<endl;p++;
  break;}
  else {ans.at(j)=c.at(i);vec.at(j)=1;}
;}

if(p==0){if(ans.at(0)==0&&N>1){cout<<-1<<endl;}
 else{ for(int i=0;i<N;i++){cout<<ans.at(i)
;}cout<<endl;}}
}


#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;

int main() {
int n,m;
cin >> n >> m;
int s;
char c;
char ans[n]={'x'};
int x;
bool flg = true;
REP(i,m) {
  cin >> s >> c;
  s--;
  if(ans[s]=='x') {
    ans[s]=c;
  } else {
    flg = false;
  }
}
if(ans[0]==0) flg=false;
if(flg==true) {
  REP(i,n) {
    if(ans[i]=='x') {
      if(i==0) {
        cout << "1";
      } else {
        cout << "0";
      }
    } else {
      cout << ans[i];
    }
  }
  cout << endl;
} else {
  cout << "-1" << endl;
}
return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; }

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

  int n,m;
	cin >> n >> m;

	vector<int> num(n,-1);
	rep(i, m) {
	  int s, c;
		cin >> s >> c;
		if (num[n-s] == -1 || num[n-s] == c) num[n-s] = c;
		else {
			cout << -1 << endl;
			return 0;
		}
	}

	rep(i, 1000) {
		if(!(pow(10,n-1) <= i && i < pow(10,n)) && !(i == 0 && n == 1)) continue;
		bool e = true;
		string s = to_string(i);reverse(all(s));
		rep(d,n) {
		  e = e && (num[d] == (int) (s[d] - '0') || num[d] == -1);
		}
		if (e) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<char> a(n);

  rep(i,m) {
    int s;
    char c;
    cin >> s >> c;
    if(n != 1 && s == 1 && c == '0') {
      cout << -1 <<endl;
      return 0;
    }
    if(a[s - 1] == '\0') {
      a[s - 1] = c;
    } else if(a[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  rep(i,n) {
    if(a[i] == '\0') a[i] = '0';
  }

  rep(i,n) cout << a[i];
  cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
int k,a[40];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		if(a[x]!=y&&a[x]||n>2&&x==1&&y==0)
		{
			cout<<-1;
			return 0;
		}
		a[x]=y;
	}
    if(a[1]==0&&n>2)
     cout<<1;
	for(int i=1;i<=n;i++)
	 cout<<a[i];

}


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

int main() {
    int n, m; cin >> n >> m;
    vector<int> target(n, -1);

    for (int i = 0; i < m; i++) {
        int s, c; cin >> s >> c;

        s--;
        if (target[s] != -1 && target[s] != c) {
            cout << -1 << endl;
            return 0;
        } else if (s == 0 && c == 0) {
            cout << -1 << endl;
            return 0;
        }
        target[s] = c;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (target[i] == -1) {
            if (i == 0) {
                ans += pow(10, n-1);
            }
        } else {
            ans += target[i] * pow(10, n-i-1);
        }
    }

    cout << ans << endl;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int n, m;
bool ok = true;

int main() {
	cin >> n >> m;
	vector<pair<int, int>>p(m);
	rep(i, m) {
		cin >> p[i].first >> p[i].second;
	}
	rep(x, 1000) {
		int keta = 1;
		int nx = x / 10;
		vector<int>d(1, x % 10);
		while (nx) {
			keta++;
			d.push_back(nx % 10);
			nx /= 10;
		}
		reverse(d.begin(), d.end());
		if (keta == n) {
			ok = true;
			rep(i, m) {
				if (d[p[i].first - 1] != p[i].second) {
					ok = false;
				}
			}
			if (ok) {
				cout << x << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}


#include <cstdio>
using namespace std;

int main(int argc, char** argv)
{
	int n, m;
	scanf("%d%d", &n, &m);
	char res[5], temp_output = '\0';
	for(int i=0; i<n; i++) res[i] = '0';
	int lastc[5] = {-1, -1, -1, -1, -1};
	for(int i=0; i<m; i++)
	{
		int s, c;
		scanf("%d%d", &s, &c);
		if(lastc[--s] != -1)
		{
			if(lastc[s] == c) continue;
			puts("-1");
			return 0;
		}
		if(s == 0)
		{
			if(n == 1) temp_output = c + '0';
			else if(c == 0) {puts("-1"); return 0;}
		}
		lastc[s] = c;
		res[s] = c + '0';
	}
	if(temp_output) {putchar(temp_output); putchar('\n'); return 0;}
	if(n == 1) {puts("0"); return 0;}
	if(res[0] == '0') res[0] = '1';
	puts(res);
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    string number;
    for (int i = 0; i < N; i++)
        if (i == 0)
            number.push_back('1');
        else
            number.push_back('0');
    vector<int> clear(N, -1);
    for (int i = 0; i < M; i++) {
        int digit, num;
        cin >> digit >> num;
        if (clear[digit-1] != num && clear[digit-1] != -1) {
            cout << -1 << endl;
            return 0;
        } else {
            clear[digit-1] = num;
        }
        number[digit-1] = static_cast<char>(num+48);
    }
    if (number.size() > 1 && number[0] == '0')
        cout << -1 << endl;
    else
        cout << number << endl;
};


#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outs(vector<T> V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
inline void solve(void){
  int N,M;in(N,M);
  vector<int>A(N+1,-1);
  rep(i,M){
    int s,c;in(s,c);
    if(A[s]==-1||A[s]==c)A[s]=c;
    else{
      out(-1);
      return;
    }
  }
  if(N>1&&A[1]==0){
    out(-1);
    return;
  }
  up(i,1,N){
    if(i==1&&A[i]==-1)A[i]=1;
    if(i!=1&&A[i]==-1)A[i]=0;
  }
  up(i,1,N)cout<<A[i];
  cout<<endl;
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;
int ten(int n){
    if(n == 0){
        return 1;
    }
    return ten(n-1)*10;
}
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    for(int i = 0; i < m; i++){
        cin >> s[i] >> c[i];
    }
    for(int i = 0; i < m; i++){
        if(n != 1 && s[i] == 1 && c[i] == 0){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = i+1; j < m; j++){
            if(s[i] == s[j]){
                if(c[i] != c[j]){
                    cout << -1 << endl;
                    return 0;
                }else{
                    c[j] = 0;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < m; i++){
        ans += c[i] * ten(n-s[i]);
    }

    if(ans >= ten(n)){
        cout << ans << endl;
    }else{
        if(ans != 0){
            ans = ten(n) + ans;
            cout << ans << endl;
        }else{
            cout << ans << endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,m,ans[9];
vector<pair<int,int> >sc;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;i++) {
		int s,c;
		cin>>s>>c;
		if(s==1&&c==0&&n>1) {
			cout<<-1<<endl;
			return 0;
		}
		bool put=1;
		for(int j=0;j<sc.size();j++)
			if(s==sc[j].first)
				if(c==sc[j].second) put=0;
				else {
					cout<<-1<<endl;
					return 0;
				}
		if(put) sc.push_back(make_pair(s,c));
	}
	if(n==1) {
		if(m==0) cout<<0<<endl;
		else cout<<sc[0].second<<endl;
		return 0;
	}
	if(m==0) {
		cout<<1;
		while(n>1) cout<<0,n--;
		return 0;
	}
	memset(ans,-1,sizeof(ans));
	m=sc.size();
	sort(sc.begin(),sc.end());
	for(int i=1;i<sc[0].first;i++) ans[i]=(i==1?1:0);
	for(int i=0;i<m-1;i++)
		if(ans[sc[i].first]==-1) {
			ans[sc[i].first]=sc[i].second;
			for(int j=sc[i].first+1;j<sc[i+1].first;j++) ans[j]=0;
		}
	ans[sc[m-1].first]=sc[m-1].second;
	int pos=sc[m-1].first;
	while(pos<n) ans[++pos]=0;
	for(int i=1;i<=n;i++) cout<<ans[i];
	return 0;
}