akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
int main() {
  INIT;
  
  int n,y;
  cin >> n >> y;
  
  y = y/1000;
  REP(i, y/10 + 1){
    REP(j, y/5 + 1){
      REP(k, y + 1){
        if(10*i + 5*j + k == y && i+j+k==n){
          printf("%d %d %d", i, j, k);
          exit(0);
        }
        else if(10*i + 5*j + k > y || i+j+k>n){
          break;
        }
      }
      if(10*i + 5*j > y || i+j>n){
        break;
      }
    }
    if(10*i > y || i>n){
      break;
    }
  }
  printf("-1 -1 -1");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	long long N, minx = (1LL << 60);
	cin >> N;

	for (long long i = 1; i * i <= N; i++) {
		if (N % i != 0) continue;
		long long r1 = i, r2 = (N / i);
		minx = min(minx, r1 + r2 - 2LL);
	}
	cout << minx << endl;
	return 0;
}

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

#define eps 1e-8
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)

typedef long long LL;
int ans=0;

void DFS(int x,int y,int z,int t){
    if(t==0) {ans=max(ans,x+y+z);return ;}
    DFS(2*x,y,z,t-1);
    DFS(x,2*y,z,t-1);
    DFS(x,y,2*z,t-1);
}

int main(){
    FAST_IO;
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    DFS(a,b,c,k);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
int A[100001];
int main()
{
    int N,even,odd;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&A[i]);
    even=0;
    odd=0;
    for(int i=0;i<N;i++)
        if(A[i]%2==0)
            even++;
        else odd++;
    even+=odd/2;
    odd%=2;
    if(odd==0)
        printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#define N 2000000
#define Ai 10000

int main(){
  int *A,*B,C[Ai+1];
  int n,i,j;

  scanf("%d",&n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);
  for(i=0;i<=Ai;i++)
    C[i]=0;
  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }


  
  for(i=1;i<=Ai;i++)
    C[i]=C[i]+C[i-1];


  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<n;i++){
    printf("%d ",B[i]);
  }
  printf("%d\n",B[n]);


  return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

ll n, k, c;
string s;

int main(void)
{
	cin >> n >> k >> c;
	cin >> s;
	vector<ll> f, l;
	ll prev = -INF;
	for (ll i = 0; i < n; i++) {
		if (s[i] != 'x') {
			ll d = i - prev;
			if (d > c) {
				f.push_back(i);
				prev = i;
				if (f.size() >= k) {
					break;
				}
			}
		}
	}
	prev = INF;
	for (ll i = n-1; i >= 0; i--) {
		if (s[i] != 'x') {
			ll d = prev - i;
			if (d > c) {
				l.push_back(i);
				prev = i;
				if (l.size() >= k) {
					break;
				}
			}
		}
	}
	vector<int> r;
	auto ff = f.begin();
	auto fl = l.rbegin();
	for (int i = 0; i < k; i++) {
		if (*ff == *fl) {
			r.push_back(*ff+1);
		}
		ff++;
		fl++;
	}
	for (auto p : r) {
		cout << p << endl;
	}
	return 0;
}


Measured memory_bytes: 6644
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;

int main() {
	int N, K, i;
	int ans =0;
	int x = 1;

	cin >> N >> K;

	while (x<=N) {
		x *= K;
		++ans;
		//cout << "x="<<x << endl;

	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    long long n, m;
  	cin >> n >> m;
  	if (n == 1 && m == 1)
  		cout << 1;
  	else if (n == 1) 
  	  	cout << m - 2;
  	else if (m == 1)
  	  	cout << n - 2;
  	else {
  	  	cout << n * m - (2 * n + 2 * (m - 2));
  	}
}

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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 1e5+5;

void solve(){
    LL a, b, c, d;
    cin >> a >> b >> c >> d;
    LL mx = LLONG_MIN;
    mx = max(mx, a*c);
    mx = max(mx, b*d);
    mx = max(mx, a*d);
    mx = max(mx, b*c);
    cout << mx << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
typedef long long ll;
typedef struct {
	ll to, from;
} Edge;

ll tree[100005];
ll ans[100005];
Edge edge[100005];

ll sum(ll a);
void init(void);
void unite(ll a, ll  b);
ll root(ll a);

int main()
{
	init();

	ll n, m;
	ll now;

	scanf("%lld %lld", &n, &m);

	for (ll i = 0; i < m; i++) {
		scanf("%lld %lld", &edge[i].to, &edge[i].from);
	}

	now = sum(n - 1);
	for (ll i = m - 1; i >= 0; i--) {
		ans[i] = now;

		ll a = edge[i].to;
		ll b = edge[i].from;

		a = root(a);
		b = root(b);

		if (a != b) {
			now = now + sum(-tree[a]);
			now = now + sum(-tree[b]);

			unite(a, b);
			a = root(a);
			now = now - sum(-tree[a]);
		}
	}

	for (ll i = 0; i < m; i++) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}

void init(void)
{
	for (ll i = 0; i < 100005; i++) {
		tree[i] = -1;
	}
}

void unite(ll a, ll  b)
{
	a = root(a);
	b = root(b);

	if (a != b) {
		tree[a] = tree[a] + tree[b];
		tree[b] = a;
	}

	return;
}

ll root(ll a)
{
	if (tree[a] < 0) {
		return a;
	} 

	return tree[a] = root(tree[a]);
}

ll sum(ll a)
{
	return (a * (a + 1) / 2);
}


Measured memory_bytes: 4352
import sys


h, w = map(int, input().split())
while h != 0:
    a = "#"
    b = "."
    for _ in range(h):
        for i in range(w):
            if i % 2 == 0:
                sys.stdout.write(a)
            else:
                sys.stdout.write(b)
        a, b = b, a
        print()
    print()
    h, w = map(int, input().split())



Measured memory_bytes: 6308
#include<stdio.h>
#define N 100
int main(){
  int i,j;
  int a[N][N]={0};
  int n,x,y,z;

  scanf("%d",&n);//頂点数

  for(i=0; i<n; i++){
      scanf("%d %d",&x,&y); //x：1からn番目 y：各頂点に何個隣接するのがあるか
      for(j=0; j<y; j++){ //j<yまで、なぜなら隣接する個数分だけスキャンするから
	scanf("%d",&z); //z:隣接する頂点の分だけスキャンされる
	a[x-1][z-1]=1; //配列だから-1しないといけない n番目に入れたいならn-1とかくように
    }
  }

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      if(j==n-1){
	printf("%d",a[i][j]);
      }
      else{
      printf("%d ",a[i][j]);
      }
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2104
import numpy as np

n,k = map(int,input().split())
a = np.array(list(map(int,input().split())))
f = np.array(list(map(int,input().split())))

a.sort();f.sort();f = f[::-1]

def test(x):
    return np.maximum(0,a-x//f).sum() <= k

def nibutan(low,hi):
    while True:
        ave = (low+hi)//2
        #ここの条件式を問題文に合わせる
        if test(ave):
            hi = ave
        else:
            low = ave
        if hi - low == 1:
            break
    li = [low,hi]
    return li

li = nibutan(-1,10**12)

print(li[1])

Measured memory_bytes: 37184
#include <iostream>
#include <queue>
using namespace std;
priority_queue<long long>h;

long long n,m,i,s,x;
int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {cin>>x;
    h.push(x);}
    for(i=1;i<=m;i++)
    {
        x=h.top();
        x/=2;
        h.pop();
        h.push(x);
    }
    for(i=1;i<=n;i++)
    {
        s+=h.top();
        h.pop();
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 1400
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string S; cin >> S;
    if (S[0] == S[1] && S[1] == S[2]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
	ll N;cin>>N;
	vector<ll>A(N);
	ll yon=0;
	ll even=0;
	for(int i=0;i<N;i++){
		cin>>A[i];
		if(A[i]%4==0)yon++;
		if(A[i]%2==1)even++;
	}
	
	if(N%2==0 && even>yon)cout<<"No"<<endl;
	else if(N%2==1 && even>yon+1)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	
	
	
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	map<string,int>m;
	m["Rock"]=1;
	m["Fire"]=2;
	m["Scissors"]=3;
	m["Snake"]=4;
	m["Human"]=5;
	m["Tree"]=6;
	m["Wolf"]=7;
	m["Sponge"]=8;
	m["Paper"]=9;
	m["Air"]=10;
	m["Water"]=11;
	m["Dragon"]=12;
	m["Devil"]=13;
	m["Lightning"]=14;
	m["Gun"]=15;
	int n;
	while(cin>>n,n){
		vector<string>in(n);
		rep(i,n)cin>>in[i];
		in.erase(unique(all(in)),in.end());
		if(in.size()==1){
			cout<<"Draw"<<endl;
			continue;
		}
		bool h=false;
		rep(i,in.size()){
			bool hh=true;
			rep(j,in.size()){
				int t=m[in[i]],s=m[in[j]];
				if(t==s)continue;
				if(t>s&&t-s<8||t<s&&15-s+t<8)hh=false;
			}
			if(hh){
				h=true;
				cout<<in[i]<<endl;
				break;
			}
		}
		if(!h)cout<<"Draw"<<endl;
	}
}

Measured memory_bytes: 1272
a=input()
b=input()
c=input()
turn="a"
winner=""
while True:
    if turn=="a":
        if len(a)==0:
            winner="A"
            break
        turn=a[0]
        a=a[1:len(a)]
    if turn=="b":
        if len(b)==0:
            winner="B"
            break
        turn=b[0]
        b=b[1:len(b)]
    if turn=="c":
        if len(c)==0:
            winner="C"
            break
        turn=c[0]
        c=c[1:len(c)]
    if winner!="":
        break
print(winner)

Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long a = 0;
		for (int i = 1; i < N; i++) {
			a += i;
		}
		System.out.println(a);
	}
}

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

int main(){
    int e,y;
    cin>>e>>y;
    if(!e){
    if(y<1912)cout<<'M'<<y-1867<<endl;
    else if(y<1926)cout<<'T'<<y-1911<<endl;
    else if(y<1989)cout<<'S'<<y-1925<<endl;
    else cout<<'H'<<y-1988<<endl;
    }
    
    if(e ==1)cout<<y+1867<<endl;
    if(e==2)cout<<y +1911<<endl;
    if(e==3)cout<<y+1925<<endl;
    if(e==4)cout<<y+1988<<endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S.size() //配列名.Length()
using namespace std;
typedef unsigned long long ll;

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

  int cnt1 = 0, cnt2 = 0;

  for(int i = 0; i < S.size(); i++){
    if(i % 2 == 0 && S[i] != '1') cnt1++;
    else if(i % 2 == 1 && S[i] != '0') cnt1++;
  }
  for(int j = 0; j < S.size(); j++){
    if(j % 2 == 0 && S[j] != '0') cnt2++;
    else if(j % 2 == 1 && S[j] != '1') cnt2++;
  }
  
  cout << min(cnt1, cnt2) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;

long long anss,anst;
string s;
int main()
{
    cin>>s;
    for (int i=0; i<s.size(); i++){
        if(s[i]=='S') anss++;
        else {
            anst++;
            if(anss) anss--,anst--;
        }
    }
    cout<<anss+anst<<endl;
    return 0;
}



Measured memory_bytes: 3764
S = input()
T = input()

minimum = len(T)
for i in range(len(S)):
    count = len(T)
    for j in range(len(T)):
        if i+j >= len(S):
            count = len(T)
            break
        if S[i+j] == T[j]:
            count -= 1
    minimum = min(minimum, count)

print(minimum)

Measured memory_bytes: 9116
using System;
using System.Linq;
class Test{
	static void Main(){
		
		int N, L;
		var d = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
		N = d[0]; L = d[1];
		String[] S = new String[N];
		for(int i=0;i<N;i++) S[i] = Console.ReadLine();
		Array.Sort(S);
		Console.WriteLine(String.Join("",S));
		
	}

}

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

int main() {
  
  int a,b;
  cin >> a >> b;
  
  if(a*b % 2 == 0) cout << "No" << endl;
  else cout << "Yes" << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <limits>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
#define ll long long
#define rep(i_, start, end) for(ll i_=(ll)start; i_<(ll)end; i_++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");
 
int main()
{
  string s, t;
  cin >> s >> t;
  print(t+s);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	int k,s;
	scanf("%d%d",&k,&s);
	long long res = 0;
	for(int x=0; x<=min(k,s); x++)
	{
		int a1=max(0,s-x-k);
		int a2=min(k,s-x);
		if(a1>k) continue;
		res+=a2-a1+1;
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(void)
{
  //Nを入力
  int n;
  scanf("%d",&n);
  //市名と点数を入力
  int i,j,k,p[n],pn[n];
  char s[n][20];
  for(i=0;i<n;i++){
    scanf("%s",&s[i]);
    scanf("%d",&p[i]);
    pn[i] = i+1;
  }
  //点数順に並び替え
  int tmp;
  char stmp[20];
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      if(p[i]<p[j]){
        tmp  = p[i];
        p[i] = p[j];
        p[j] = tmp;
        tmp   = pn[i];
        pn[i] = pn[j];
        pn[j] = tmp;
        strcpy(stmp,s[i]);
        strcpy(s[i],s[j]);
        strcpy(s[j],stmp);
      }
  //辞書順に並び替え
  for(i=0;i<n-1;i++){
    for(j=n-1;j>=i+1;j--)
      if(strcmp(s[j],s[j-1])<0){
        tmp  = p[j];
        p[j] = p[j-1];
        p[j-1] = tmp;
        tmp   = pn[j];
        pn[j] = pn[j-1];
        pn[j-1] = tmp;
        strcpy(stmp,s[j]);
        strcpy(s[j],s[j-1]);
        strcpy(s[j-1],stmp);
      }
//    printf("[%d] %s %d\n",pn[i], s[i], p[i]);
  }
  for (i=0; i<n; i++) {
    printf("%d\n",pn[i]);
//  printf("[%d] %s %d\n", pn[i], s[i], p[i]);
  }
  return 0;
}


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

int select(int* a, int n) {
    int copy;
    int count = 0;
    int min;
    
    for(int i = 0; i < n; ++i) {
        min = i;
        for(int j = i; j < n; ++j) {
            if(a[j] < a[min]) {
                min = j;
            }
        }
        if(i != min) {
            copy = a[i];
            a[i] = a[min];
            a[min] = copy;
            count++;
        }
    }
    return count;
}
int main(void) {
    int n;
    int a[100];
    int count = 0;

    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    
    count = select(a, n);
    
    cout << a[0];
    for(int i = 1; i < n; ++i) {
        cout << ' ' << a[i];
    }
    cout << endl;
    cout << count << endl;
    
    return 0;
}



Measured memory_bytes: 3104
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<vector<ll>> connect(N);
    for (ll i = 0; i < N - 1; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        connect[a].push_back(b);
        connect[b].push_back(a);
    }
    vector<ll> c(N);
    for (ll i = 0; i < N; i++) {
        cin >> c[i];
    }
    sort(c.begin(), c.end(), greater<>());

    struct Node {
        ll node, num;
        bool operator<(const Node& rhs) const {
            return num < rhs.num;
        }
    };

    priority_queue<Node> pq;
    for (ll i = 0; i < N; i++) {
        pq.push({ i, (ll)connect[i].size() });
    }

    vector<bool> used(N, false);

    ll score = 0;
    vector<ll> ans(N);

    stack<ll> st;
    for (ll i = 0; i < N; i++) {
        if (st.empty()) {
            while (true) {
                auto t = pq.top();
                pq.pop();

                if (used[t.node]) {
                    continue;
                }
                used[t.node] = true;

                ans[t.node] = c[i];

                for (auto next : connect[t.node]) {
                    st.push(next);
                }

                break;
            }
        } else {
            while (true) {
                auto t = st.top();
                st.pop();

                if (used[t]) {
                    continue;
                }
                used[t] = true;
                for (auto next : connect[t]) {
                    st.push(next);
                }

                ans[t] = c[i];
                score += c[i];
                break;
            }
        }
    }

    cout << score << endl;
    for (ll i = 0; i < N; i++) {
        cout << ans[i] << " \n"[i == N - 1];
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (c >=a && c<=b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
const static int MOD = (1e+9)+7;

int main(){
    string s; cin >> s;
    if(s=="ABC") cout << "ARC";
    else cout << "ABC";
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long int ll;
int main(void){
ll n,a,b;
cin>>n>>a>>b;
vector<ll> x(n);
for(ll i=0;i<n;i++){
	cin>>x[i];
}
int now=x[0];
ll ans=0;
for(ll i=0;i<n-1;i++){
ans+=min(b,(x[i+1]-x[i])*a);
}
cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int h = 8;
int w = 8;
int field[10][10];
int tempField[10][10];
int dx[8] = { 1, 1, 1, 0, -1, -1, -1, 0 };
int dy[8] = { -1, 0, 1, 1, 1, 0, -1, -1 };

void PrintField(int field[10][10]) {
  REP(y, h) {
    REP(x, w) {
      int c = field[y][x];
      if (c == -1) { putchar('.'); }
      if (c == 0) { putchar('o'); }
      if (c == 1) { putchar('x'); }
    }
    puts("");
  }
}

int Put(int sx, int sy, int player) {
  int ret = 0;
  if (field[sy][sx] != -1) { return 0; }
  memcpy(tempField, field, sizeof(field));
  tempField[sy][sx] = player;
  REP(dir, 8) {
    int lcnt = 0;
    int nx = sx;
    int ny = sy;
    while (true) {
      nx += dx[dir];
      ny += dy[dir];
      if (nx < 0 || nx >= w || ny < 0 || ny >= h || tempField[ny][nx] == -1) {
        lcnt = 0;
        break;
      }
      if (tempField[ny][nx] == player) { break; }
      lcnt++;
    }
    if (lcnt == 0) { continue; }
    nx = sx;
    ny = sy;
    while (true) {
      nx += dx[dir];
      ny += dy[dir];
      if (tempField[ny][nx] == player) { break; }
      tempField[ny][nx] ^= 1;
    }
    ret += lcnt;
  }
  return ret;
}

void calc(int player, int pass) {
  if (pass == 2) { return; }
  //PrintField(field);
  //puts("");
  int cnt = 0;
  int ansy = -1;
  int ansx = -1;
  int sy = player == 0 ? 0 : h - 1;
  int sx = player == 0 ? 0 : w - 1;
  int dir = player == 0 ? 1: -1;
  for (int y = sy; 0 <= y && y < h; y += dir) {
    for (int x = sx; 0 <= x && x < w; x += dir) {
      int lcnt = Put(x, y, player);
      if (lcnt > cnt) {
        cnt = lcnt;
        ansx = x;
        ansy = y;
      }
    }
  }
  if (cnt == 0) {
    calc(player ^ 1, pass + 1);
  } else {
    Put(ansx, ansy, player);
    memcpy(field, tempField, sizeof(field));
    calc(player ^ 1, 0);
  }
}

int main() {
  while (true) {
    MEMSET(field, -1);
    REP(y, h) {
      REP(x, w) {
        char c;
        int v = scanf(" %c ", &c);
        if (v != 1) { return 0; }
        if (c == 'o') { field[y][x] = 0; }
        if (c == 'x') { field[y][x] = 1; }
      }
    }
    calc(0, 0);
    PrintField(field);
  }
}

Measured memory_bytes: 0
x = input()
x = input()
x = x.split(" ")
x = [int(z) for z in x]
cmax = -1000000
cmin = 1000000
csum = 0
for z in x:
    if cmax < z:
        cmax = z
    if cmin > z:
        cmin = z
    csum += z
print("%d %d %d" % (cmin, cmax, csum))

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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> A, std::vector<long long> B){
  vector<pair<ll, ll>> v;
  ll t = 0;
  ll a = 0;
  for(ll i=0; i<N; i++) {
    v.push_back(make_pair(A[i]+B[i], i));
  }
  sort(v.rbegin(), v.rend());
  for(ll i=0; i<N; i++) {
    if(i%2==0)
      t+=A[v[i].second];
    else
      a+=B[v[i].second];
  }
  std::cout << t-a << std::endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


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

int main() {
	// your code goes here
	int n, s, j[1000], minj, maxj;
	
	while(cin >> n, n){
		s = 0;
		minj = maxj = 0;
		for(int i = 0; i < n; i++){
			cin >> j[i];
			s += j[i];
			if(i != 0) minj = min(minj, j[i]); else minj=j[0];
			if(i != 0) maxj = max(maxj, j[i]); else maxj=j[0];
		}
		s = (s - maxj - minj)/(n-2);
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>

const int N = 50;

const char* t = "AKIHABARA";
const int m = 9;

char s[N + 1];
bool dp[N + 1][m + 1];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("A.in", "r", stdin);
#endif
    while (scanf("%s", s) == 1) {
        int n = strlen(s);
        memset(dp, 0, sizeof(dp));
        dp[n][m] = true;
        for (int i = n; i >= 0; -- i) {
            for (int j = m; j >= 0; -- j) {
                if (i < n && j < m && s[i] == t[j]) {
                    dp[i][j] |= dp[i + 1][j + 1];
                }
                if (j < m && t[j] == 'A') {
                    dp[i][j] |= dp[i][j + 1];
                }
            }
        }
        puts(dp[0][0] ? "YES" : "NO");
    }
}


Measured memory_bytes: 128
n, m = gets.split.map(&:to_i)
ary = (n + 1).times.map { Array.new(n + 1) }
m.times do
  x, y = gets.split.map(&:to_i)
  ary[x][y] = ary[y][x] = true
end

puts [*2..n].permutation.count { |per|
  ([1] + per).each_cons(2).all? { |s| ary.dig(*s) }
}


Measured memory_bytes: 14168
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.TreeSet;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CKthSubstring solver = new CKthSubstring();
        solver.solve(1, in, out);
        out.close();
    }

    static class CKthSubstring {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int k = in.nextInt();
            TreeSet<String> ts = new TreeSet<>();
            for (int i = 0; i < s.length(); i++) {
                for (int j = i + 1; j < s.length()+1; j++) {
                    if (j - i <= k) {
                        ts.add(s.substring(i, j));
                    }
                }
            }

            for (String t : ts) {
                k -= 1;
                if (k == 0) {
                    out.println(t);
                }
            }
        }
    }
  
}



Measured memory_bytes: 30856
import fractions

N = int(input())
A = list(map(int, input().split()))

L, R = [0], [0]
for i in range(N):
    L.append(fractions.gcd(L[i], A[i]))
    R.append(fractions.gcd(R[i], A[-i-1]))
L.append(0)
R.append(0)
R = R[::-1]

M = []
for i in range(N):
    M.append(fractions.gcd(L[i], R[i+2]))
print(max(M))

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

using namespace std;

int main(){
  int a,b;
  int cnt = -1;
  while(cin >> a >> b){
    if(a==0 && b==0){
      break;
    }

    if(cnt >= 0){
      cout << endl;
    }
    cnt = 0;

    for(int i = (a-1)/4+1;i < b/4+1;i++){
      if(i%25==0 && i%100!=0){
	continue;
      }
      else{
	cout << i*4 << endl;
	cnt++;
      }
    }
    if(!cnt){
      cout << "NA" << endl;
    }
    //    cout << a << " " << b << endl;
  }
}

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

int main(){
  int A, B, C, D, train, bus;
  cin >> A >> B >> C >> D;
  if (A < B) train = A;
    else train = B;
  if (C < D) bus = C;
  	else bus = D;
  cout << train + bus << endl;
}


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

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

        int[] faceToEast = new int[n];
        int[] faceToWest = new int[n];
        Arrays.fill(faceToEast, 0);
        Arrays.fill(faceToWest, 0);
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'E') {
                faceToEast[i]++;
            } else {
                faceToWest[i]++;
            }
        }

        for (int i = 1; i < n; i++) {
            faceToEast[i] += faceToEast[i - 1];
        }

        for (int i = n - 2; i >= 0; i--) {
            faceToWest[i] += faceToWest[i + 1];
        }

        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int incorrectDirection = n - 1;
            if (i - 1 >=0) {
                incorrectDirection -= faceToEast[i - 1];
            }
            if (i + 1 < n - 1) {
                incorrectDirection -= faceToWest[i + 1];
            }

            ans = Math.min(ans, incorrectDirection);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 44492
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e3;
char c;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> c;
  if(c <= 'Z'){
    cout << 'A' << endl;
  }else{
    cout << 'a' << endl;
  }
}

Measured memory_bytes: 3652
//https://youtu.be/LfN_fj57Dhs?t=11
#include<bits/stdc++.h>
//#define endl "\n"
using namespace std;
#define Me3za() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
int h,w;
long long mem[1001][1001];
char arr[1001][1001];
long long solve(int i=0,int j=0){
if(i==h-1&&j==w-1)return 1;
if(arr[i][j]=='#')return 0;
if(i<0||j<0||i==h||j==w)return 0;
if(~mem[i][j])return mem[i][j];
long long ch1=0,ch2=0;
ch1=solve(i+1,j)%1000000007;
ch2=solve(i,j+1)%1000000007;
return mem[i][j]=(ch1+ch2)%1000000007;
}
int main(){
Me3za();
memset(mem,-1,sizeof mem);
cin>>h>>w;
for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)cin>>arr[i][j];
}
cout<<solve();
}


Measured memory_bytes: 9216
n=input()
nn=int(n)
cnt=nn-int('9'+(len(n)-2)*'0')
if len(n)==1:
    ans=nn
elif len(n)==2:
    ans=9
elif len(n)==3:
    ans=cnt
elif len(n)==4:
    ans=909
elif len(n)==5:
    ans=cnt-90
else:
    ans=90909
print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<assert.h>
#include<string.h>
#include<math.h>

#define MAX 1001
#define MAX_C 100001
#define max(a,b) ((a>b)?a:b)

int C, N, c[MAX], v[MAX], i, j, dp[MAX_C];

int main() {
  scanf("%d %d",&N,&C);
  assert( N < MAX );
  assert( C < MAX_C );
  for(i=0;i<N;i++) scanf("%d %d",v+i,c+i);
  
  memset(dp,-1,sizeof dp);
  dp[0] = 0;
  for(i=0;i<N;++i) {
    for(j=C;j>=0;--j) if( dp[j] != -1 ) {
      if( j + c[i] <= C ) {
	dp[j+c[i]] = max(dp[j+c[i]],dp[j]+v[i]);
      }
    }
  }

  int maxi = 0;
  for(i=0;i<=C;i++) maxi = max(maxi,dp[i]);
  printf("%d\n",maxi);
  
  return 0;
}

Measured memory_bytes: 1432
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
void Dice(char *p, int d[]);
 
int main() {
    int d[6], i;
    char dir[101],*p;
    for (i = 0; i < 6; i++)  scanf("%d", &d[i]);
    scanf("%s", dir);
    p = dir;
    Dice(p, d);
    printf("%d\n",d[0]);
    return 0;
}
 
void Dice(char *p, int d[]){
    int tmp;
    while (*p) {
        if (*p == 'S') { tmp = d[0]; d[0] = d[4]; d[4] = d[5]; d[5] = d[1]; d[1] = tmp; }
        if (*p == 'W') { tmp = d[0]; d[0] = d[2]; d[2] = d[5]; d[5] = d[3]; d[3] = tmp; }
        if (*p == 'E') { tmp = d[0]; d[0] = d[3]; d[3] = d[5]; d[5] = d[2]; d[2] = tmp; }
        if (*p == 'N') { tmp = d[0]; d[0] = d[1]; d[1] = d[5]; d[5] = d[4]; d[4] = tmp; }
        *(p++);
    }
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=t[i])
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

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

int main(){
  
  string S,T;
  cin >> S >> T ;
  for(int i = 0; i < S.size(); i++){
    if (S.at(i) != T.at(i) ){
      cout << "No" << endl;
        break;
    }
    if ( i == S.size()-1 ) {
      cout << "Yes" << endl;
    }
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

struct Node {
  int id, left = -1, right = -1, parent = -1;
  Node(int id = -1): id(id) {}
};

void preorder(map<int, Node> &tree, Node &nd, queue<int> &q) {
  int left = nd.left, right = nd.right;
  
  q.push(nd.id);
  if (left != -1) preorder(tree, tree[left], q);
  if (right != -1) preorder(tree, tree[right], q);
}

void inorder(map<int, Node> &tree, Node &nd, queue<int> &q) {
  int left = nd.left, right = nd.right;

  if (left != -1) inorder(tree, tree[left], q);
  q.push(nd.id);
  if (right != -1) inorder(tree, tree[right], q);
}

void postorder(map<int, Node> &tree, Node &nd, queue<int> &q) {
  int left = nd.left, right = nd.right;
  
  if (left != -1) postorder(tree, tree[left], q);
  if (right != -1) postorder(tree, tree[right], q);
  q.push(nd.id);
}

void print_queue(queue<int> &q) {
  while (!q.empty()) {
    printf(" %d", q.front());
    q.pop();
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  
  map<int, Node> tree;
  rep(i, n) {
    int id, left, right;
    cin >> id >> left >> right;
    
    if (!tree.count(id)) tree[id] = Node(id);
    auto &nd = tree[id];
    nd.left = left;
    nd.right = right;

    if (left != -1) {
      if (!tree.count(left)) tree[left] = Node(left);
      tree[left].parent = id;
    }

    if (right != -1) {
      if (!tree.count(right)) tree[right] = Node(right);
      tree[right].parent = id;
    }
  }

  int parent = tree[0].parent, root_id = 0;
  while (parent != -1) {
    root_id = parent;
    parent = tree[parent].parent;
  }

  auto &root = tree[root_id];

  cout << "Preorder" << endl;
  queue<int> q;
  preorder(tree, root, q);
  print_queue(q);

  cout << "Inorder" << endl;
  q = queue<int>();
  inorder(tree, root, q);
  print_queue(q);

  cout << "Postorder" << endl;
  q = queue<int>();
  postorder(tree, root, q);
  print_queue(q);
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

	int n;

	cin >> n;

	int l[n];
	int sum = 0;

	int i, len = n - 1;

	rep(i, n) cin >> l[i];

	sort(l, l + n);

	rep(i, len) sum += l[i];

	if (l[n - 1] < sum) Out("Yes");
	else Out("No");
	
	return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){
    int H,W; cin >> H >> W;
    char s[H][W]; REP(i,H)REP(j,W) cin >> s[i][j];

    char ans[H][W];
    REP(i,H)REP(j,W){
        if(s[i][j] == '#') ans[i][j] = '#';
        else{
            int n = 0;
            if(i-1>=0 && j-1>=0 && s[i-1][j-1]=='#') n++;
            if(i-1>=0 && s[i-1][j]=='#') n++;
            if(i-1>=0 && j+1<W && s[i-1][j+1]=='#') n++;
            if(j-1>=0 && s[i][j-1]=='#') n++;
            if(j+1<W && s[i][j+1]=='#') n++;
            if(i+1<H && j-1>=0 && s[i+1][j-1]=='#') n++;
            if(i+1<H && s[i+1][j]=='#') n++;
            if(i+1<H && j+1<W && s[i+1][j+1]=='#') n++;
            ans[i][j] = '0'+n;
        }
    }

    REP(i,H){
        REP(j,W) cout << ans[i][j];
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_two_switches(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int cnt[110] = { 0 };
	for (int i = a; i < b; i++) cnt[i]++;
	for (int i = c; i < d; i++) cnt[i]++;
	int overlap = 0;
	for (int i = 0; i <= 100; i++) {
		if (cnt[i] == 2) overlap++;
	}
	cout << overlap << endl;
}

int main()
{
	b_two_switches();
    return 0;
}

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

int main(void){
  int N,i,j,buff,h;
  long a[100005],A,B,center,min;
  char str[1000010],*p;
  
  fgets(str,sizeof(str),stdin);
  N=atoi(str);
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  a[0]=atol(p);
  
  for(i=1;i<N;i++){
    p=strtok(NULL," \n");
    a[i]=atol(p);
  }
  
  for(h=1;h<N/9;h=3*h+1);
  
  for(;h>0;h=h/3){
    for(i=h;i<N;i++){
      j=i;
      
      while(j>=h && a[j-h]<a[j]){
        buff=a[j-h],a[j-h]=a[j],a[j]=buff;
        j-=h;
      }
    }
  }
  
  A=a[0];
  
  center=a[0]/2;
  
  min=a[0];
  
  for(i=1;i<N;i++){
    if(labs(a[i]-center)<min){
      min=labs(a[i]-center);
      B=a[i];
    }
  }
  
  printf("%ld %ld\n",A,B);
  
 return 0; 
}

Measured memory_bytes: 1920
//Author- VMAX


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*
/*
ll prf(ll n)
{
    ll c=0,i;
    while(n%2==0)
    {
        n=n/2;
        c++;
    }
    for(i=3;i*i<=n;i++)
    {
        while(n%i==0)
    }
    
    
    
}
*/

int main()
{
     fast
     
     ll n;
     cin>>n;
     ll a[n],i;
     ll g=0;
     f(i,n)
     {
         cin>>a[i];
         g=g^a[i];
     }
   
       f(i,n)
       { ll p=g^a[i];
           o1(p)
       }
     
   
    re
}

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

ll a[100001];
ll b[100001];

int fun(ll l,ll r,ll v){
    while(l<r){
	ll m=(l+r)/2;
	if((b[m]<=v)&&(b[m+1]>v))
	 return(m);
	else if(b[m+1]<=v)
	l=m+1;
	else
	r=m-1;
    }
    return(l);
}

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

//return 0;
    ll len=1;
    b[len]=a[0];
    for(ll i=1;i<n;i++){
        if(a[i]>=b[len])
            b[++len]=a[i];
        else if(a[i]<b[1]){
            b[1]=a[i];
        }
        else{
            b[fun(1,len-1,a[i])+1]=a[i];
        }
    }
    cout<<len;
}

Measured memory_bytes: 1792