akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
  
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    string s;
    cin >> n >> s;
    int ans[300005] = {};
    for(int i = n - 1;i > 0;i --){
      if(s[i] == 'E'){
	ans[i] ++;
      }
      ans[i - 1] += ans[i];
    }
    int minv = INF, sum = 0;
    rep(i,n){
      minv = min(minv , ans[i + 1] + sum);
      if(s[i] == 'W'){
	sum ++;
      }
    }
    cout << minv << '\n';
    return 0;
}


Measured memory_bytes: 1812
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		sc.close();
		long ans = 0;
		long l = 0;
		long r = 0;
		for(long i=1; i <= Math.sqrt(n); i++){
			if(n%i == 0) {
				l = i;
				r = n/i;
				if (l-1!=0 && n/(l-1) == n%(l-1)) ans += l-1;
				if (l!=r && r-1!=0 && n/(r-1) == n%(r-1)) ans += r-1;
			}
		}
		System.out.println(ans);
	}

}



Measured memory_bytes: 23764
import fractions

A, B = map(int, input().split())

GCD = fractions.gcd(A, B)

def pf(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(set(pf(GCD))) + 1)

Measured memory_bytes: 5048
/*input
5 5 9 3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=1005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

char g[maxn][maxn];

void tryyyyy(int n,int m,int a,int b){
	REP(i,n) REP(j,m) g[i][j]='.';
	if(n<3||m<3||a<2||b<2) return;
	g[0][0]='^';
	g[1][0]='v';
	g[2][0]='<';
	g[2][1]='>';
	g[2][2]='v';
	g[1][2]='^';
	g[0][2]='>';
	g[0][1]='<';
	a-=2;b-=2;
	for(int i=3;i<n;i+=2){
		g[i][0]='^';
		g[i+1][0]='v';
		b--;
	}
	for(int i=3;i<m;i+=2){
		g[0][i]='<';
		g[0][i+1]='>';
		a--;
	}
	for(int i=1;i<n;i+=2) for(int j=1;j<m;j+=2) if(i!=1||j!=1){
		if(a){
			if(a==1){
				g[i][j]='<';
				g[i][j+1]='>';
				a--;
			}
			else{
				g[i][j]=g[i+1][j]='<';
				g[i][j+1]=g[i+1][j+1]='>';
				a-=2;
			}
		}
		else{
			if(b==0);
			else if(b==1){
				g[i][j]='^';
				g[i+1][j]='v';
				b--;
			}
			else{
				g[i][j]=g[i][j+1]='^';
				g[i+1][j]=g[i+1][j+1]='v';
				b-=2;
			}
		}
	}
	if(a||b){
		return;
	}
	cout<<"YES\n";
	REP(i,n) REP(j,m){
		cout<<g[i][j];
		if(j==m-1) cout<<'\n';
	}
	exit(0);
}



int N,M;

int main(){
	IOS;
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	if(n%2&&m%2) tryyyyy(n,m,a,b);
	N=n,M=m;
	REP(i,n) REP(j,m) g[i][j]='.';
	if(n%2){
		for(int i=0;i+1<m;i+=2){
			if(!a) break;
			g[n-1][i]='<';
			g[n-1][i+1]='>';
			a--;
		}
		n--;
	}
	if(m%2){
		for(int i=0;i+1<n;i+=2){
			if(!b) break;
			g[i][m-1]='^';
			g[i+1][m-1]='v';
			b--;
		}
		m--;
	}
	for(int i=0;i<n;i+=2) for(int j=0;j<m;j+=2){
		if(a){
			if(a==1){
				g[i][j]='<';
				g[i][j+1]='>';
				a--;
			}
			else{
				g[i][j]=g[i+1][j]='<';
				g[i][j+1]=g[i+1][j+1]='>';
				a-=2;
			}
		}
		else{
			if(b==0);
			else if(b==1){
				g[i][j]='^';
				g[i+1][j]='v';
				b--;
			}
			else{
				g[i][j]=g[i][j+1]='^';
				g[i+1][j]=g[i+1][j+1]='v';
				b-=2;
			}
		}
	}
	if(a||b){
		cout<<"NO\n";
		return 0;
	}
	cout<<"YES\n";
	REP(i,N) REP(j,M){
		cout<<g[i][j];
		if(j==M-1) cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 2176
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var input = fs.readFileSync('/dev/stdin', 'utf8').split('\n');
var n = input[0];
console.log("" + 2 * 3.14 * parseInt(n, 10));


Measured memory_bytes: 29776
n, k = map(int, input().split())
R, S, P = map(int, input().split())
t = input()

num = 0
ans = 0
li = [True]*n

for i in range(n):
    if t[i]=="r":
        num = P
    elif t[i]=="s":
        num = R
    else:
        num = S
    if i>=k and t[i]==t[i-k] and li[i-k]:
        li[i] = False
        num = 0
    ans += num

print(ans)

Measured memory_bytes: 4084
#include<iostream>
#include<cmath>
using namespace std;
struct infor
{
 int x;
 int y;
 int h;
};

infor in[101], in1[101], in2[101];
int main()
{
 int N;
 int i,j=0,k=0;
 int Xc, Yc;
 cin >> N;
 for (i = 0; i < N; i++)
 {
     cin >> in[i].x >> in[i].y >> in[i].h;
     if(in[i].h>0)
         in1[j++] = in[i];
     else
         in2[k++] = in[i];
 }
    
 int m;//m遍历数
    for(Xc = 0; Xc < 101; Xc++ )
    {
        for (Yc = 0; Yc < 101; Yc++ )
        {
            int H ;
            H = in1[0].h + abs(Xc - in1[0].x) + abs(Yc - in1[0].y);
            int flag1, flag2;
            flag1 = flag2 = 1;
            for (m = 1; m < j; m ++)
            {
                if (H == in1[m].h + abs(Xc - in1[m].x) + abs(Yc - in1[m].y));
                else
                {
                    flag1 = 0;
                    break;
                }
            }
            
            if(flag1)
            {
                for ( m = 0; m < k; m++ )
                    if( H - abs( in2[m].x - Xc ) - abs( in2[m].y - Yc ) > 0)
                    {
                        flag2 = 0;
                        break;
                    }
                if (flag2)
                {
                    cout << Xc << ' ' << Yc << ' ' << H;
                    return 0;
                }
            }
            else continue;
        }
    }
 }

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

typedef long long LL;
const int MAXN = 1e5+10;
const LL mod = 1e9+7;
map<int,int> mp;
int n,num;

LL mpow(LL a, LL b)
{
    LL ret = 1;
    while(b)
    {
        if(b&1) ret = ret*a%mod;
        a = a*a%mod;
        b >>= 1;
    }
    return ret;
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> num;
        mp[num]++;
    }
    int sz = mp.size();
    if(n&1)
    {
        if(sz != n/2+1 || mp[0] != 1)
        {
            puts("0");
            return 0;
        }
        cout << mpow(2,sz-1) << endl;
    }
    else
    {
        if(sz != n/2 || mp[0] != 0)
        {
            puts("0");
            return 0;
        }
        cout << mpow(2,sz) << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define REP(i, a, b) for(long long i=a; i<=b; ++i)
#define REPN(i, a, b) for(long long i=a; i<=b; --i)
#define rep(i, a, b) for(long long i=a; i<b; ++i)
#define rep0(i,b) for(long long i=0; i<b; ++i)
#define REP0(i,b) for(long long i=0; i<=b; ++i)
#include<cmath>
#include <iomanip>
using namespace std;


typedef long long ll;

int MODE = 1e9+7;
ll prefix[403];
ll dp[403][403];
ll arr[403];
int n;


ll helper(int left, int right)
{
    if(left < 0 || right > n-1 || left > right || left == right)
    {

        return 0;
    }
    if(dp[left][right] != -1)
    {
        return dp[left][right];
    }

    ll minimum = 1e18+5;

    for(int i=left; i<right; ++i)
    {
        minimum = min(minimum, helper(left, i) + helper(i+1, right));

    }

    return dp[left][right] = minimum + prefix[right] - prefix[left-1];

}




int main()
{


    cin>>n;

    memset(dp, -1, sizeof(dp));

    rep0(i, n)
    {
        cin>>arr[i];
    }

    prefix[0] = 0;
    rep0(i, n+1)
    {
        prefix[i] = prefix[i-1] + arr[i];
    }


    cout<<helper(0 , n-1)<<endl;



    /*for(int i=0; i<n; ++i)
    {
        dp[i][i] = 0;
    }

    for(int i=n-2; i>=0; --i)
    {

        for(int j=i+1; j<n; ++j)
        {
            dp[i][j] = 1e18+5;
            ll s =  prefix[j] - prefix[i-1];
            for(int k = i; k<j; ++k)
            {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + s);
            }
        }
    }*/





    return 0;

}


Measured memory_bytes: 4752
N,K = map(int,input().split())
S = list(input())
happy = 0
L = 0
R = 0
for i in range(N-1):
  if S[i] == S[i+1]:
    happy += 1
  elif S[i] == 'L' and S[i+1] == 'R':
    L += 1
  else:
    R += 1
if min(R,L) >= K:
  happy += K*2
else:
  happy += min(R,L) + K
if happy <= len(S) - 1:
  print(happy)
else:
  print(len(S) - 1)


Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,H,W;
  cin>>N>>H>>W;
  int count=0;
  for(int i=0;i<N;i++){
    int A=0;
    int B=0;
    cin>>A>>B;
    if(A>=H && B>=W){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int fib(int);

int A[50];

int main(){
  int n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i]=-1;
  }
  printf("%d\n",fib(n));
  return 0;
}


int fib(int n){
  int i;
  A[0]=1;
  A[1]=1;
  for(i=2;i<=n;i++){
  A[i]=A[i-1]+A[i-2];
  }
  return A[n];
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>

int main() {
  size_t N;
  std::cin >> N;

  std::vector<long> A(N);
  for (size_t i=0; i<N; i++) {
    std::cin >> A[i];
  }

  size_t ans = 0;
  size_t l = 0;
  long s = 0;
  long x = 0;

  for (size_t r=0; r<N; r++) {
    s += A[r];
    x ^= A[r];
    if (s != x)
      while (s != x) {
        s -= A[l];
        x ^= A[l];
        l++;
      }
    ans+=r-l+1;
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から

int main(){
    int x,y;cin >> x >> y;
    if ((x+y)%3!=0) {
        cout << 0 << endl;
        return 0;
    }

    int n = (2*y - x) / 3;
    int m = y - 2*n;
    COMinit();
    ll ans = COM(n+m, n);
    cout << ans << endl;
}

Measured memory_bytes: 119808
N=int(input())
nf=int(str(N)[0])
nl=len(str(N))
if nl==1:
  print(N)
  exit()

ans=0
for i in range(1,N+1):
  a=i
  f=int(str(a)[0])
  l=int(str(a)[-1])
  if l!=0:
    if l<nf: 
      for j in range(2,nl+1):
        ans+=10**(j-2)
      if f==l:
        ans+=1
    elif l>nf:
      if nl-3>=0:
        for j in range(3,nl+1):
          ans+=10**(j-3)
        if f==l:
          ans+=1
      else:
        if f==l:
          ans+=1
    else:
      if int(str(N)[-1])>=f:
        if nl>=3:
          ans+=int("".join(str(N)[1:-1]))+1
          for j in range(3,nl+1):
            ans+=10**(j-3)
          if f==l:
            ans+=1
        else:
          ans+=1
          if f==l:
            ans+=1
      else:
        if nl>=3:
          ans+=int("".join(str(N)[1:-1]))
          for j in range(3,nl+1):
            ans+=10**(j-3)
          if f==l:
            ans+=1
print(ans)

Measured memory_bytes: 3192
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define srep(i) for (int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
    using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int n, w;
int weight[105] = {}, value[105] = {};

int dp[105][10005] = {};

int main()
{
    int a,b,c,x;
    ull ans=0;
    cin >> a >> b >> c >> x;
    rep(i,0,a+1){
        rep(j,0,b+1){
            rep(k,0,c+1){
                if(x==500*i+100*j+50*k){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n=int(input())
S=[''.join(sorted(input())) for i in range(n)]


memo={}
ans=0
for i in range(n):
  if S[i] not in memo:
    memo[S[i]]=1
  else:
    memo[S[i]]+=1
    ans+=memo[S[i]]-1
print(ans)

Measured memory_bytes: 19400
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

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

const long long MOD = 1000000007;

int main(){
  int n, k;
  cin>>n>>k;
  vector<int> d(n);
  rep(i,n) cin>>d[i];
  int x = min(n,k);
  int ans = 0;
  for(int i=0; i<=x; i++) {
    for(int j=0; j<=x-i; j++) {
      vector<int> v;
      int tmp = 0;
      for(int a = 0; a<i; a++) {
	v.push_back(d[a]);
	tmp+=d[a];
      }
      for(int b=0; b<j; b++) {
	v.push_back(d[n-1-b]);
	tmp+=d[n-1-b];
      }
      sort(v.begin(), v.end());
      for(int l = 0; l < k-(i+j); l++) {
	if(l >= v.size()) break;
	if(v[l] >= 0) break;
	tmp -= v[l];
      }
      ans = max(ans, tmp);
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

void no() {
	cout << "NO\n";
	exit(0);
}

int n, a, b;
int now = 1;

int ans[1 << 17];

int fs(int x) {
	for (int i = 0; i < n; ++i)
		if ((x >> i) & 1)
			return i;
	return 0;
}

void run(int x, int y) {
	int c = __builtin_popcount(x);
	if (c == 1) {
		if (y == 0) {
			ans[now] = ans[now - 1] ^ x;
			++now;
		}
		else {
			int b = fs(y);
			run(1 << b, y ^ (1 << b));
			ans[now] = ans[now - 1] ^ x;
			++now;
			run(1 << b, y ^ (1 << b));
		}
	}
	else {
		int a = fs(x);
		int b = fs(x ^ (1 << a));
		run(x ^ (1 << a) ^ (1 << b), y ^ (1 << b));
		ans[now] = ans[now - 1] ^ (1 << a);
		++now;
		run(1 << b, y ^ x ^ (1 << a) ^ (1 << b));
	}
}


int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> a >> b;
	int x = a ^ b;
	int y = (1 << n) - 1;
	ans[0] = a;
	y ^= x;
	if (__builtin_popcount(x) % 2 == 0)
		no();
	run(x, y);
	cout << "YES\n";
	for (int i = 0; i < now; ++i)
		cout << ans[i] << " ";
	cout << "\n";
	return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  string hi = "hi";
  bool can = true;
    for (int i = 0; i < s.size();) {
        bool can2 = false; 
        if (s.substr(i, hi.size()) == hi) { // d で divide できるか
          can2 = true;
          i += hi.size(); // divide できたら i を進める
        }
      	if (!can2) { // divide できなかったら
            can = false;
            break;
        }
    }
  
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=200000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}

class Edge{
public:
	long long from;
	long long to;
	long long w;
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long N;
	cin>>N;
	vector<long long>L;
	for(int i=0;i<2*N;i++){
		long long l;
		cin>>l;
		L.push_back(l);
	}
	sort(L.begin(),L.end(),greater<long long>());
	long long ans=0;
	for(int i=1;i<2*N;i+=2){
		ans+=L[i];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int a[n + 1];
  
  for(int i = 1; i <= n; i++)
  {
    cin>>a[i];
  }
  int f[110000] = {};
  int ans = 0;
  f[1] = 1;
  int next = a[1];
  if(next == 2) {
    cout<<1<<endl;
    return 0;
  }
  while(f[next] != 1) {
    ans++;
    if(a[next] == 2) {
      cout<<ans + 1<<endl;
      return 0;
    }
    f[next] = 1;
    next = a[next];
  }
  cout << -1 << endl;
  

  return 0;
}


Measured memory_bytes: 1024
N = int(input())
a_input = map(int, input().split())
a = list(a_input)
alice = 0
bob = 0
for i in range(len(a)):
    max_i = 0
    max_a = 0
    for j in range(N):
        if a[j] > max_a:
            max_a = a[j]
            max_i = j
    if i%2 == 0:
        alice = alice + max_a
    else:
        bob = bob + max_a
    a[max_i] = 0
print(alice-bob)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;


int A, B, C;

signed main()
{
	cin >> A >> B >> C;

	int cnt = 0;

	REP(i, C)
	{
		if (B < A) break;
		B -= A;
		cnt++;
	}

	cout << cnt << endl;
}









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

using namespace std;

int getLongestPathBFS (const vector <vector <int>> &graph) {
    int n = graph.size();
    vector <int> maxlength(n);
    vector <int> indegree(n);

    for (int node = 1; node < n; ++node) {
        for (int neighbor : graph[node]) {
            ++indegree[neighbor];
        }
    }
    queue <int> q;
    for (int i = 1; i < n; ++i) {
        if (indegree[i] == 0) {
            q.emplace(i);
        }
    }

    while (!q.empty()) {
        int curr = q.front(); q.pop();
        for (int neighbor : graph[curr]) {
            if (--indegree[neighbor] == 0) {
                q.emplace(neighbor);
                maxlength[neighbor] = 1 + maxlength[curr];
            }
        }
    }
    return *max_element(maxlength.begin(), maxlength.end());
}


int  main () {
    int n, m;
    cin >> n >> m;
    vector <vector <int>> graph(n + 1, vector <int>());

    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        graph[u].emplace_back(v);
    }
    cout << getLongestPathBFS(graph) << "\n";
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 1; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int k;
    cin >> k;
    ll ans = 0;
    k++;
    rep(i, k) rep(j, k) rep(l, k)
    {
        int gcd = __gcd(l, __gcd(i, j));
        ans += gcd;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3676
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<unordered_map>
#define maxn 400005
#define RG register
using namespace std;
unordered_map<int,int> mp;
int n,ans,ans1,a[maxn];
int cmp(int a,int b){return a>b;}
int main()
{
	//freopen("test.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),mp[a[i]]++;
	sort(a+1,a+n+1,cmp);
	for(RG int i=1;i<=n;i++)
	{
		if(mp[a[i]]==0) continue;
		for(RG int j=30,k=(1<<j);j>=0;j--,k>>=1)
		{
			int tg=k-a[i];
			if(tg>a[i]||tg<0) continue;
			else if(tg==a[i]) {if(mp[a[i]]>=2) {ans1++,mp[a[i]]-=2;break;}}
			else if(mp[tg]>0) {ans1++,mp[a[i]]--,mp[tg]--;break;}
		}
	}
	printf("%d",ans1);
	return 0;
}

Measured memory_bytes: 17524
const memo = {}

const main = stdin => {
  const input = stdin.trim().split('\n')
  const [N, K] = input[0].split(' ').map(x => parseInt(x))

  const ms = []
  for (let i = 0; i < N; i++) {
    ms.push(parseInt(input[i + 1]))
  }

  let sum = K
  ms.map(m => sum -= m)

  console.log(N + Math.floor(sum / Math.min(...ms)))
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29540
#include<bits/stdc++.h>
using namespace std;
static const int MAX=200000;

int main()
{
    int n,a[MAX];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int mina=a[0],maxv=-2000000000;
    for(int i=1;i<n;i++){
        maxv=max(maxv,a[i]-mina);
        mina=min(mina,a[i]);
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3868
void main() {
	int[] arr;
	foreach(_; 0..3) {
		auto ip = readAs!(int[]), a = ip[0], b = ip[1];
		arr ~= a; arr ~= b;
	}
	arr.sort();
	auto a = arr.group();
	auto b = a.map!(i => i[1]);
	if(b.count(2) == 2 && b.count(1) == 2) {
		writeln("YES");
	} else writeln("NO");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

lint A, B, C;

int main()
{
    cin >> A >> B >> C;
    lint ans = min(C, A + B) + B;
    if (C > A + B)
        ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
A = list(map(int,input().split()))
qs = [tuple(map(int,input().split())) for i in range(Q)]

class SegTree:
    def __init__(self,arr,func,unit):
        self.func = func
        self.unit = unit
        n = 1
        while n < len(arr):
            n *= 2
        self.n = n
        nodes = [unit]*(2*n-1)
        nodes[n-1:n-1+len(arr)] = arr
        for i in range(n-2,-1,-1):
            nodes[i] = func(nodes[2*i+1],nodes[2*i+2])
        self.nodes = nodes

    def update(self,i,val):
        i += self.n-1
        self.nodes[i] = val
        while i >= 0:
            i = (i - 1) // 2
            self.nodes[i] = self.func(self.nodes[2*i+1], self.nodes[2*i+2])

    def query(self,l,r):
        l += self.n
        r += self.n
        s = self.unit
        while l < r:
            if r & 1:
                r -= 1
                s = self.func(self.nodes[r-1], s)
            if l & 1:
                s = self.func(s, self.nodes[l-1])
                l += 1
            l >>= 1
            r >>= 1
        return s

INF = float('inf')
segt = SegTree(A, lambda x,y:max(x,y), -INF)

ans = []
for a,b,c in qs:
    if a==1:
        segt.update(b-1,c)
    elif a==2:
        ans.append(segt.query(b-1,c))
    else:
        l = b-1
        r = N
        if segt.query(l,r) < c:
            ans.append(N+1)
        else:
            while r-l > 1:
                m = (l+r)//2
                if segt.query(l,m) >= c:
                    r = m
                else:
                    l = m
            ans.append(r)
print(*ans, sep='\n')

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

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; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;


struct UnionFind{
  /*データメンバ*/
  vector<int> par; //par[i]:iの親の番号。
  /*コンストラクタ。独自の初期化処理などを行いたいときにコンストラクタを使う。引数の数を変えることで複数のコンストラクタを定義可能。*/
  UnionFind(int N) : par(N) {/*:の後ろに記述されたデータメンバの初期化を行う。*/
    rep(i,N)par[i]=i;
  }

  int root(int x){
    if(par[x]==x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){//unite trees
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){
    int N,M; cin>>N>>M;
    UnionFind tree(N+1);
    rep(i,M){
        int a,b; cin>>a>>b;
        tree.unite(a,b);
    }
    vector<int> boss(N+1);
    rep1(i,N)boss[i] = tree.root(i);
    map<int,int> G;
    rep1(i,N)G[boss[i]]++;
    int res = 0;
    for(auto i:G)res = max(res,i.second);
    cout<<res<<endl;
}


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

int main(){
    long long n, a[100005], b[100005];
    cin >> n;
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    long long ans = 0;
    rep(i,n){
        ans += min(a[i],b[i]);
        b[i] -= a[i];
        if(b[i] > 0){
            ans += min(a[i+1], b[i]);
            a[i+1] -= min(a[i+1], b[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
Integer N
Character(100)S
INTEGER R,B
Read*,N,S
R=0
B=0
do i=1,N
  if(S(i:i)=="R")R=R+1
  if(S(i:i)=="B")B=B+1
end do
if(R>B)then
  print"(A)","Yes"
else
  print"(A)","No"
endif
end

Measured memory_bytes: 768
fn main() {
    loop {
        let (n, k) = read_tuple();
        if n == 0 && k == 0 {
            break;
        }
        let data = (0..n).map(|_| read::<i64>()).collect::<Vec<i64>>();

        let acc_sum = accumulate_each(data.iter(), add_i64, 0);

        let mut ans = 0;
        for i in 0..(n - k + 1) {
            let local_sum = acc_sum[i + k] - acc_sum[i];
            if ans < local_sum {
                ans = local_sum;
            }
        }

        println!("{:?}", ans);
    }
}

fn add_i64(a: i64, b:i64) -> i64 {
    a + b
}

fn accumulate_each<T: std::clone::Clone>(iterable: std::slice::Iter<T>, func: fn(T, T) -> T, init: T) -> Vec<T> {
    let mut res = Vec::new();
    let mut acc = init.clone();
    res.push(acc.clone());
    for element in iterable {
        acc = func(acc, element.clone());
        res.push(acc.clone());
    }
    res
}


fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}


fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 7080
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var a = ReadArrayInt();
            var cnt = a.Distinct().Count();
            var even = a.Distinct().Where(i => i % 2 == 0).ToArray();
            var odd = a.Distinct().Where(i => i % 2 != 0).ToArray();
            var ans = true;
            if (cnt == 1)
            {
                if (!(a[0] == 0)) ans = false;
            }
            else if (cnt == 2)
            {
                if (even.Count() == 1)
                {
                    if (even[0] != 0) ans = false;
                    else
                    {
                        var evenCnt = a.Count(i => i == even[0]);
                        var oddCnt = a.Count(i => i == odd[0]);
                        if (evenCnt * 2 != oddCnt) ans = false;
                    }
                }
                else if (even.Count() == 2)
                {
                    var even1Cnt = a.Count(i => i == even[0]);
                    var even2Cnt = a.Count(i => i == even[1]);
                    if (even1Cnt < even2Cnt)
                    {
                        if (even[0] != 0) ans = false;
                        else if (even1Cnt * 2 != even2Cnt) ans = false;
                    }
                    else
                    {
                        if (even[1] != 0) ans = false;
                        else if (even2Cnt * 2 != even1Cnt) ans = false;
                    }
                }
                else ans = false;
            }
            else if (cnt == 3)
            {
                if (!(even.Count() == 1 && odd.Count() == 2)) ans = false;
                else
                {
                    var evenCnt = a.Count(i => i == even[0]);
                    var odd1Cnt = a.Count(i => i == odd[0]);
                    var odd2Cnt = a.Count(i => i == odd[1]);
                    if (!(evenCnt == odd1Cnt && odd1Cnt == odd2Cnt)) ans = false;
                    else if ((odd[0] ^ odd[1]) != even[0]) ans = false;
                    else if ((even[0] ^ odd[1]) != odd[0]) ans = false;
                    else if ((even[0] ^ odd[0]) != odd[1]) ans = false;
                }
            }
            else ans = false;

            Console.WriteLine(ans ? "Yes" : "No");
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}


Measured memory_bytes: 27872
#include <bits/stdc++.h>
#include<stdint.h>
using namespace std;
#define vi vector<int> 
#define pb push_back
#define w(t)   int t;cin>>t;while(t--) 
#define show(ar) for(int i=0;i<ar.size();i++) cout<<ar[i]<<" "; cout<<endl;
#define mod 1e9+7
#define ff first
#define ss second 
#define fio ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define all(x) (x.begin(),x.end())
#define inf 1e9+7


vi inp(int n)
{
	vi v; int x;
	for(int i=0;i<n;i++) {
		cin>>x; v.pb(x);
	}
	return v; 
}


int main()
{
	long long int n,k; cin>>n>>k;
	vi ar=inp(n);
	//show(ar);
	int ind=0;
	if(k<=n)
	{
		while(k--)
		{
			ind=ar[ind]-1;
		}
		cout<<ind+1<<endl;
		return 0;
	}
	map<int,int> mp;
	mp[0]=1;
	int count=1; ind=ar[0]-1;
	while(mp[ind]==0)
	{
	//	cout<<" ind "<<ind+1<<endl;
		mp[ind]=1;
		ind=ar[ind]-1;
		count++;
	}
	vector<int> v;
	v.pb(ind );
	mp.clear();
	mp[ind]++;
	ind=ar[ind]-1;
	while(mp[ind]==0)
	{
		//cout<<" ind "<<ind+1<<endl;
		mp[ind]=1;
		v.pb(ind );
		ind=ar[ind]-1;
		count++;
	}
	//show(v);
	mp.clear();
	for(int i=0;i<v.size();i++)
		mp[v[i]]++;
	ind=0;
	while(mp[ind]==0)
	{
		k--;
		ind=ar[ind]-1;
	}
	int imin=0;
	//cout<<" ind "<<ind<<endl;
	for(int i=0;i<v.size();i++)
	{
		if(v[i]==ind){
			imin=i; break;
		}
	}
	
	long long int res=v.size();
	k+=imin;
	k%=res;
	cout<<v[k]+1<<endl;
}

Measured memory_bytes: 11340
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	int A, B;
	cin >> A >> B;

	cout << max(max(A + B, A - B), A * B) << endl;
	
	return 0;
}



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

int main(){
    string s;
  cin >> s;
  
  if(s.at((int)s.size()-1)=='s')
    cout << s+"es" << endl;
  else
    cout << s+'s' << endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int scc(const VV<>& g, V<>& comp) {
  int n = g.size();
  VV<> rg(n);
  for (int v = 0; v < n; v++) for (int w : g[v]) {
    rg[w].push_back(v);
  }
  V<> vs;
  V<bool> vis(n);
  comp.resize(n);
  auto dfs = [&](const auto& dfs, int v) -> void {
    vis[v] = true;
    for (int w : g[v]) if (!vis[w]) {
      dfs(dfs, w);
    }
    vs.push_back(v);
  };
  auto rdfs = [&](const auto& rdfs, int v, int k) -> void {
    vis[v] = true;
    comp[v] = k;
    for (int w : rg[v]) if (!vis[w]) {
      rdfs(rdfs, w, k);
    }
  };
  for (int v = 0; v < n; v++) if (!vis[v]) {
    dfs(dfs, v);
  }
  vis.assign(n, false);
  int k = 0;
  reverse(begin(vs), end(vs));
  for (int v : vs) if (!vis[v]) {
    rdfs(rdfs, v, k++);
  }
  return k;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  VV<> g(n);
  while (m--) {
    int a, b; cin >> a >> b, --a, --b;
    g[a].push_back(b);
  }
  V<> comp;
  int k = scc(g, comp);
  for (int v = 0; v < n; ++v) {
    V<> res;
    for (int w = 0; w < n; ++w) if (comp[v] == comp[w]) {
      res.push_back(w);
    }
    for (int i = 0; i < (int)res.size(); ++i) {
      cout << res[i] + 1 << " \n"[i == (int)res.size() - 1];
    }
  }
}


Measured memory_bytes: 4148
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        ReadLine();
        var L = new List<string>(ReadLine().Split(' ')).Select(ele => Int32.Parse(ele)).ToList();
        var max = L.Max();
        L.Remove(max);
        if (L.Sum() > max)
            WriteLine("Yes");
        else
            WriteLine("No");

        Console.ReadLine();
    }
}


Measured memory_bytes: 13396
import sys
x, n = (int(i) for i in input().split())
try:
    ps = [int(i) for i in input().split()]
    ps.sort()
    # print(x, n)
    # print(ps)
    result = 0
    d = 0
    while x-d > 0:
        if x-d not in ps:
            print(x-d)
            sys.exit()
        elif x+d not in ps:
            print(x+d)
            sys.exit()
        d += 1
    print(0)
except EOFError:
    print(x)

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

using namespace std;

int main()
{                 
	int n, px = 0, py = 0, pt = 0, carry_out = 1;

	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		int x, y, t;

		cin >> t >> x >> y;

		int a = t - pt;
		int b = abs(x - px) + abs(y - py);

		if (!(a >= b && (a - b) % 2 == 0))
			carry_out = 0;
			
		px = x;
		py = y;
		pt = t;
	}
		
	if (carry_out)
		puts("Yes");
	else
		puts("No");

	return 0;
}

Measured memory_bytes: 256
using System;

class ITP1_1_C{
  static void Main(string[] args){
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    Console.WriteLine("{0} {1}", a*b, a*2 + b*2);
  }
}

Measured memory_bytes: 8968
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int V = sc.nextInt();
        int E = sc.nextInt();
        int [][]dist = new int [V][V];
        int [][]path = new int [V][V];


        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++){
                dist[i][j] = -1;
                path[i][j] = j;
            }
        }

        int a[] = new int[E];
        int b[] = new int[E];
        int c[] = new int[E];

        for(int i=0;i<E;i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            a[i]=x-1;
            b[i]=y-1;
            dist[x-1][y-1] = sc.nextInt();
            dist[y-1][x-1] = dist[x-1][y-1];
            c[i] = dist[x-1][y-1];
        }

        for(int i = 0;i< V;i++)
        {
            for(int j = 0;j< V;j++)
            {
                for(int k = 0;k< V;k++)
                {
                    int tmp = dist[j][i]+dist[i][k];
                    if(dist[j][i]>=0&&dist[i][k]>=0) {
                        if (tmp < dist[j][k]||dist[j][k]==-1) {
                            dist[j][k] = tmp;
                            path[j][k] = path[j][i];
                        }
                    }

                }
            }
        }

        int ans = 0;

        for(int i=0;i<E;i++){
            if(dist[a[i]][b[i]]<c[i]){
                ans++;
            }
        }

//        StringBuilder sb = new StringBuilder();
//        for(int i=0;i<V;i++)
//        {
//            for(int j=0;j<V;j++)
//            {
////               sb.append("("+i+","+j+"):");
////                sb.append(i);
//                int tmp = i;
//                while (tmp!=j){
//
//                    tmp = path[tmp][j];
////                    sb.append(tmp);
//
//                }
////                System.out.println(sb.toString());
////                sb = new StringBuilder();
//            }
//        }

        System.out.println(ans);
        sc.close();
    }



}

Measured memory_bytes: 14588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define sorted(a_1) sort(a_1.begin(),a_1.end())
#define rsorted(a_1) sort(a_1.rbegin(),a_1.rend())
#define t1(a_1) cout<<a_1<<endl;
#define t2(a_1) for(auto it_test : a_1) cout<<it_test<<" ";

const int MAX = 1000001;
vector<long long >isprime(MAX , true); 
vector<long long >prime; 
vector<long long >SPF(MAX); 
void Seive(int N) 
{ 
    isprime[0] = isprime[1] = false ; 
   
    for (long long int i=2; i<N ; i++) 
    { 
        if (isprime[i]) 
        { 
            prime.push_back(i);  
            SPF[i] = i; 
        } 
  
        for (long long int j=0; j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) 
        { 
            isprime[i*prime[j]]=false; 
   
            SPF[i*prime[j]] = prime[j] ; 
        } 
    } 
} 

ll expo(ll a, ll b, ll m) 
{ 
    if (b == 0) 
        return 1; 
    ll p = expo(a, b / 2, m) % m; 
    p = (p * p) % m; 
  
    return (b % 2 == 0) ? p : (a * p) % m; 
} 
#define N_MAX 101
#define W_MAX 1000000001
#define V_SUM_MAX 100001

bool v[V_SUM_MAX][N_MAX];
vector<vector<ll>>dp(V_SUM_MAX,vector<ll>(N_MAX));
ll solveDp(int r, int i, vector<ll>&w, vector<ll>&val, int n) 
{ 
    // Base cases 
    if (r <= 0) 
        return 0; 
    if (i == n) 
        return W_MAX; 
    if (v[r][i])
        return dp[r][i]; 
 	// t1("test");
    v[r][i] = 1; 
   
    dp[r][i]=min(solveDp(r, i + 1, w, val, n), w[i] + solveDp(r - val[i], i + 1, w, val, n)); 
    return dp[r][i]; 
} 
// int knapsack(vector<ll>val, std::vector<ll> weight, int value, int n){
// 	for(int i=0;i<=value;i++){
// 		for(int j=0;j<(int)n;j++){
// 			// if(v[i][j]) continue;
// 			if(i==0 || j==n){ dp[i][j] = W_MAX;}
// 			else if(val[j+1]<=i)
// 			dp[i][j+1] = min(weight[j] + dp[i+val[j]][j],dp[i][j+1]);
// 			else
// 			dp[i][j] = dp[i][j- 1];
// 			v[i][j]=1;
// 			// t1(dp[i][j]);
// 		}
// 	}
// 	return dp[value][n];
// }
void solve(){
	int n,we;
	cin>>n>>we;
	vector<ll>val(n),weight(n);
	for(int i=0;i<n;i++) cin>>weight[i]>>val[i];
	int sum1 = accumulate(val.begin(),val.end(),0);
	memset(v,false,sizeof(v));
	// for(int i=0;i<V_SUM_MAX;i++){
	// 	for(int j=0;j<W_MAX;j++){
	// 		dp[i][j] = INT_MAX;
	// 	}
	// }
	// knapsack(val,weight,sum1,n);
	for(int i=sum1;i>=0;i--){
		if(solveDp(i,0,weight,val,n)<=we){
			cout<<i<<endl;
			break;
		}
		// t1("end");
		// t1(dp[17][n]);
		// if(knapsack(val,weight,i,n)<=we){
			
		// 	cout<<i<<endl;
		// 	break;
		// }
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--){
		solve();
	}

return 0;
}

Measured memory_bytes: 110644
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <math.h>
using namespace std;

void solve(int n){
    long int ans = 0;
    for(int i=0; i<=n; i++){
        if(i%3==0) continue;
        else if(i%5==0) continue;
        else ans += i;
    }
    cout << ans << endl;
}

int main(){
    int n;
    cin >> n;
    solve(n);
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<vector<int>>vec(2, vector<int>(N));
	rep(i, 0, 2)rep(j, 0, N)cin >> vec[i][j];
	int ans = 0;
	rep(i, 0, N) {
		int res = 0;
		int k = 0;
		rep(j, 0, N) {
			if (i == j) {
				res += vec[k][j];
				++k;
				res += vec[k][j];
			}
			else {
				res += vec[k][j];
			}
		}
		chmax(ans, res);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256