akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, A, B;
    string S;
    cin >> N >> A >> B >> S;
    
    int a = 0;
    int b = 0;
    rep(i, N) {
        if (S[i] == 'a') {
            if (a + b < A + B) {
                cout << "Yes" << endl;
                ++a;
            } else {
                cout << "No" << endl;
            }
        }
        if (S[i] == 'b') {
            if (a + b < A + B && b < B) {
                cout << "Yes" << endl;
                ++b;
            } else {
                cout << "No" << endl;
            }
        }
        if (S[i] == 'c') cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000000000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

LL bnum,bit[26][500010]={0};
void badd(LL c,LL i,LL n){
  for(;i<=bnum;i+=i&-i)bit[c][i]+=n;
}
LL bsum(LL c,LL i){
  LL ans=0;
  for(;i;i-=i&-i)ans+=bit[c][i];
  return ans;
}

int main(){
  LL Q,j,k,n,i,l,r,a[26],ans;
  scanf("%lld",&bnum);
  char S[bnum+1],c;
  scanf("%s %lld",S,&Q);
  rep(j,bnum)badd(S[j]-'a',j+1,1);
  rep(j,Q){
    scanf("%lld",&n);
    if(n==1){
      scanf("%lld %c",&i,&c);
      badd(S[i-1]-'a',i,-1);
      S[i-1]=c;
      badd(c-'a',i,1);
    }else{
      scanf("%lld %lld",&l,&r);
      ans=0;
      rep(k,26)a[k]=0;
      rep(k,26)a[k]+=bsum(k,r)-bsum(k,l-1);
      rep(k,26)if(a[k]>0)ans++;
      printf("%lld\n",ans);
    }
  }

  //printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 103168
import java.util.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

    static int ni() {
        return Integer.parseInt(sn());
    }

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static long maxn = 200005;

    static void solve() {
        int n = ni();
        int m = ni();
        int dp[] = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int l = ni() - 1;
            int r = ni() - 1;
            dp[l]++;
            dp[r + 1] -= 1;
        }
        int ans = 0;
        if (dp[0] == m)
            ans += 1;
        for (int i = 1; i < n + 1; i++) {
            dp[i] += dp[i - 1];
            if (dp[i] == m)
                ans++;
        }
        out.println(ans);
    }
}

Measured memory_bytes: 38920
fun main(args: Array<String>) {
    val (n, k) = (1..2).map { readLine()!!.toInt() }
    val (x, y) = (1..2).map { readLine()!!.toInt() }
    val price = if (n <= k) {
        x * n
    } else {
        x * k + y * (n - k)
    }
    println(price)
}

Measured memory_bytes: 33688
import numpy as np
[H,W,K] = list(map(int,input().split()))
C = []
for i in range(H):
    C.append(list(input()))

ta = np.zeros((H,W))
out = np.zeros((H,W))

for i in range(H):
    for j in range(W):
        if C[i][j]=='#':
            ta[i,j]=1

cnt = 1
nasi = 0
ok = 0
for i in range(H):
    num = []
    for j in range(W):
        if ta[i,j]==1:
            num.append(j)
    if len(num)==0:
        nasi += 1
        continue
    elif len(num)==1:
        out[(i-nasi):(i+1),:]=cnt
        nasi = 0
        cnt += 1
    else:
        left = 0
        ok = 0
        for n in num:
            out[(i-nasi):(i+1),left:(n+1)]=cnt
            cnt += 1
            left = n+1
            if n==W-1:
                ok = 1
        if ok!=1:
            out[(i-nasi):(i+1),num[-1]:W]=cnt-1
        nasi = 0

if nasi != 0:
    out[(H-nasi):H,:]=out[(H-nasi-1),:]

for A in range(H):
    st = ""
    for B in range(0,W-1):
        st += "{} ".format(int(out[A,B]))
    st += "{} ".format(int(out[A,W-1]))
    print(st)

Measured memory_bytes: 15056
#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;
}
*/

struct st {
	ll w, s, v;
};

int n;
st a[1200];

ll dp[20100];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i].w >> a[i].s >> a[i].v;
	}
	sort(a, a + n, [] (st a, st b) -> bool {
			return a.s + a.w < b.s + b.w;
			});
	for (int i = 0; i < n; ++i) {
		for (int j = a[i].s; j >= 0; --j)
			dp[j + a[i].w] = max(dp[j + a[i].w], dp[j] + a[i].v);
	}
	ll ans = 0;
	for (int i = 0; i < 20100; ++i)
		ans = max(ans, dp[i]);
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 512
import qualified Data.ByteString.Char8 as BC
import qualified Data.IntMap as M
import Data.Array.IO
import Data.Maybe (fromJust)
import Data.List
import Control.Monad

main = do
  [h,w,n] <- map read . words <$> getLine :: IO [Int]
  painted <- getInt2DListBC
  let sub = map (\x -> (head x, length x)) . group . sort . map length . group . sort . concat $ map (solve h w) painted
  memo <- newArray (1, 9) 0 :: IO (IOUArray Int Int)
  foldM count memo sub
  ans <- getElems memo
  let zero = (h-2)*(w-2) - (sum ans)
  print zero
  putStr $ unlines . map show $ ans

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getInt2DListBC :: IO [[Int]]
getInt2DListBC = map (map bsToInt . BC.words) . BC.lines <$> BC.getContents

solve :: Int -> Int -> [Int] -> [(Int, Int)]
solve h w [x, y] = [(i, j) | i <- [x-1..x+1], j <- [y-1..y+1], 2 <= i, i <= h-1, 2 <= j, j <= w-1]

count :: IOUArray Int Int -> (Int, Int) -> IO (IOUArray Int Int)
count memo (i, c) = do
  writeArray memo i c
  return memo


Measured memory_bytes: 159100
/********************************************
 *Author*        :ZZZZone
 *Created Time*  : 日 10/ 8 19:55:57 2017
 * Ended  Time*  : 日 10/ 8 20:02:24 2017
*********************************************/

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

char s[100];

int main()
{
	while(~scanf("%s", s)){
		int len = strlen(s);
		for(int i = 0; i < len - 8; i++) printf("%c", s[i]);
		printf("\n");
	}
    
    return 0;
}


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

int main(){

	ll n,m;
	cin>>n>>m;

	ll a[m+5];

	ll sum=0;
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}

	if(sum>n){
		cout<<"-1\n";
		return 0;
	}
	else{
		cout<<n-sum<<endl;
	}

	

	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	string s;
	cin >> s;
	
	int n = s.size();
	
	if( s[0] != 'A' ) {
		cout << "WA" << endl;
		return 0;
	}
	
	int cnt = 0;
	int cnt2 = 0;
	for(int i = 0; i < n; ++i) {
		if( i >= 2 && i <= n - 2 && s[i] == 'C') cnt++;
		if( s[i] - 'A' >= 26 ) cnt2++;
	}
	
	if( cnt == 1 && cnt + cnt2 + 1 == n ) cout << "AC" << endl;
	else cout << "WA" << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int K=sc.nextInt();
	long ans=0;
	for(long i=1;i<=K;i++) {
		for(long j=1;j<=K;j++) {
			for(long k=1;k<=K;k++) {
				ans+=gcd(gcd(i,j),k);
			}
		}
	}
	System.out.println(ans);
}

private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


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

typedef long long ll;

ll culc(string s, ll sum, ll x) {
	ll head = s[0] - '0';
	string next = s.substr(1);
	if (s.size() == 1) {
		return sum + x * 10LL + head;
	} else {
		return culc(next, sum + x * 10LL + head, 0) + culc(next, sum, x * 10LL + head);
	}
}

int main() {
	string s;
	cin >> s;
	cout << culc(s, 0, 0) << endl;

	return 0;
}


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

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

int main() {
  int cityNum;
  int roadNum;
  int from;
  int to;
  cin >> cityNum >> roadNum;
  vector<int> city(cityNum);

  for(int i = 0; i < roadNum; i++){
    cin >> from >> to;
    city.at(from-1) += 1;
    city.at(to-1) += 1;
  }
  for(int i = 0; i < cityNum; i++){
    cout << city.at(i) << endl;
  }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        h: i64,
        w: i64,
        ab: [(i64, i64); n],
    }

    println!(
        "{:?}",
        ab.iter().filter(|&(a, b)| (a / h) * (b / w) != 0).count()
    );
}


Measured memory_bytes: 2172
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define INF 1<<30

typedef long long ll;

struct edge{
  ll to;
  ll cost;
};

typedef pair<ll,ll> P;

const ll MAX_V = 100000, MAX_E = 500000;

ll V, E, r;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d+V, INF);
  d[s] = 0;
  que.push(P(0,s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    ll v = p.second;
    if (d[v] < p.first) continue;

    for (ll i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to]>d[v]+e.cost) {
        d[e.to] = d[v]+e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
}

int main(int argc, char const *argv[]) {
  cin >> V >> E >> r;
  for (ll i = 0; i < E; i++) {
    ll s, t, dist;
    cin >> s >> t >> dist;
    edge e = {t, dist};
    G[s].push_back(e);
  }
  dijkstra(r);
  for (ll i = 0; i < V; i++)
  {
    if (d[i]==INF) cout << "INF" << endl;
    else cout << d[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 19520
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

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

	string t = "keyence";
	bool ok = true;
	if (t == s) {
		cout << "YES" << endl;
		return 0;
	} else {
		for (int i = 0; i < s.size(); ++i) {
			for (int j = 0; j < s.size(); ++j) {
				string sub = "";
				if (i > 0) {
					sub += s.substr(0, i);
				}
				if (j < s.size() - 1) {
					sub += s.substr(j + 1, s.size() - j - 1);
				}

				if (sub == t) {
					cout << "YES" << endl;
					return 0;
				}
			}
		}
	}

	cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, int arr[]){for(int i = 0; i < n; i++){cout << arr[i] << " ";} cout << endl << endl;}

int main()
{
    Hello
    int n;
    cin >> n;
    ll arr[n + 5], sum[n + 5];
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr, arr + n);
    reverse(arr, arr + n);
    sum[0] = 0;
    sum[1] = arr[0];
    int arrIdx = 1, arrSum = 2;
    while(arrSum < n){
        sum[arrSum] = arr[arrIdx];
        sum[++arrSum] = arr[arrIdx++];
        arrSum++;
    }
    ll ans = 0;
    for(int i = 0; i < n; i++)
        ans += sum[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 6740
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>
#include <stack>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;
using Graph = Vvec<int>;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N+1), B(N+1), C(N+1);
    for(auto& x: A) cin >> x;
    if(N==0){
        if(A[0] == 1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }

    if(A[0]!=0){
        cout << -1 << endl; return 0;
    }

    C[0] = 1;
    const ll infty = 1e18;
    for(int i=0; i<N; i++){
        C[i+1] = min(2*C[i] - A[i+1], infty);
        if(i!=N-1 && C[i+1] <= 0){
            cout << -1 << endl;
            return 0;
        }
    }
    if(C[N] < 0){
        cout << -1 << endl; return 0;
    }

    B[N] = A[N];
    for(int i=N; i>0; i--){
        if((B[i]+1)/2 > C[i-1]){
            cout << -1 << endl; return 0;
        }
        B[i-1] = min(B[i], C[i-1]) + A[i-1];
        if(B[i-1] <= 0){
            cout << -1 << endl; return 0;
        }
    }

    ll ans = 0;
    for(int i=0; i<=N; i++) ans += B[i];
    cout << ans << endl;
}

Measured memory_bytes: 5584
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;


int main(){
    int N, M;
    cin >> N >> M;
    vector<int> H(100010);
    for(int i = 1; i <= N; i++) cin >> H.at(i);
    vector<set<int>> T(100010, set<int>());

    rep(i,M){
        int a, b;
        cin >> a >> b;
        T.at(a).insert(b);
        T.at(b).insert(a);
    }

    int ans = 0;
    for(int i = 1; i <= N; i++){
        bool flag = true;
        for(auto v : T.at(i)){
            if(H.at(i) <= H.at(v)){
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }

    cout << ans << endl;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;
constexpr int MAX_W = 100000;
constexpr int MAX_D = 9;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

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

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

  int n;
  cin >> n;
  vector<int64> vs(n + 1);
  vector<int64> ws(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> vs[i] >> ws[i];
  }
  int q_count;
  cin >> q_count;
  vector<int> q_nodes(q_count);
  vector<int64> q_weights(q_count);
  for (int i = 0; i < q_count; i++) {
    cin >> q_nodes[i] >> q_weights[i];
  }

  auto dp = Make2DVector<int64>(1 << MAX_D, MAX_W + 1, 0LL);
  for (int w = ws[1]; w <= MAX_W; w++) {
    dp[1][w] = vs[1];
  }
  for (int v = 2; v <= min(n, (1 << MAX_D) - 1); v++) {
    int p = v / 2;
    for (int w = 0; w <= MAX_W; w++) {
      UpdateMax(dp[v][w], dp[p][w]);
      if (w >= ws[v]) {
        UpdateMax(dp[v][w], dp[p][w - ws[v]] + vs[v]);
      }
    }
  }

  for (int q_index = 0; q_index < q_count; q_index++) {
    int64 ans = [&]() -> int64 {
      int node = q_nodes[q_index];
      if (q_nodes[q_index] < (1 << MAX_D)) {
        return dp[node][q_weights[q_index]];
      }

      vector<int64> extra_vs;
      vector<int64> extra_ws;
      while (node >= (1 << MAX_D)) {
        extra_vs.push_back(vs[node]);
        extra_ws.push_back(ws[node]);
        node /= 2;
      }

      int k = extra_vs.size();
      int64 r = 0;
      for (int bits = 0; bits < 1 << k; bits++) {
        int64 extra_v = 0;
        int64 extra_w = 0;
        for (int b = 0; b < k; b++) {
          if (bits & (1 << b)) {
            extra_v += extra_vs[b];
            extra_w += extra_ws[b];
          }
        }
        if (extra_w > q_weights[q_index]) continue;
        UpdateMax(r, dp[node][q_weights[q_index] - extra_w] + extra_v);
      }
      return r;
    }();
    cout << ans << endl;
  }
}

Measured memory_bytes: 410816
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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


vector<ll> getDivisorsList(ll n)
{
    vector<ll> ret;

    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }

    return ret;
}

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

    int N;
    cin >> N;

    map<int, int> m;
    rep(i, N)
    {
        int a;
        cin >> a;
        m[a]++;
    }

    ll ans = 0;

    for(auto n : m)
    {
        auto lst = getDivisorsList(n.first);

        bool flg = true;
        for (auto x : lst)
        {
            if (x == n.first)
            {
                if (n.second == 1) continue;
            }
            else
            {
                if (m.count(x) == 0) continue;   
            }

            flg = false;
            break;
        }

        if (flg) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12992
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long ans = 1;
    for(int i = 0; i < n; i++) {
      long t = sc.nextLong();
      long u = gcd(t, ans);
      ans = t * (ans / u);
    }
    
    System.out.println(ans);
  }
  
  public static long gcd(long a, long b) {
    if(b == 0) return a;
    return gcd(b, a % b);
  }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int i,j,y,u,q,w,H,W,flag;
	char a[60][60];
	while(~scanf("%d%d",&H,&W))
	{
		for(i=1;i<=H;i++)
		{
			for(j=1;j<=W;j++)
			{
				scanf(" %c",&a[i][j]);
			}
		}
		for(i=1;i<=H;i++)
		{
			for(j=1;j<=W;j++)
			{
				if(a[i][j]=='.')
				{
					flag=0;
					for(y=i-1;y<=i+1;y++)
					{
						for(u=j-1;u<=j+1;u++)
						{
							if(a[y][u]=='#')
							{
								flag=flag+1;
							}
						}
					}
					printf("%d",flag);
				}
				if(a[i][j]=='#')
				{
					printf("#");
				}
			}
			printf("\n");
		}
	}
}


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

using namespace std;

int main(void) {
	int n, x;
	cin >> n >> x;
	vector<int>m(n);
	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> m[i];
		x -= m[i];
		count++;
	}
	sort(m.begin(), m.end());
	while (x - m[0] >= 0) {
		x -= m[0];
		count++;
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
 
using namespace std;
 
int main(){

    string s;
    cin >> s;

    int a=0,b=0,c=0,d=0;
    for(auto x:s){
        if(x == 'N') a = 1;
        if(x == 'S') b = 1;
        if(x == 'E') c = 1;
        if(x == 'W') d = 1;
    }
    if(a == b && c == d) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include<complex>
#include<iostream>
using namespace std;
typedef complex<double> P;

int cross(P a, P b, P c, P d);

int main(){
    int n;
    cin >>n;
    for(int i = 0; i < n; i++){
        P a, b, c, d;
        cin >>a.real() >>a.imag() >>b.real() >>b.imag() >>c.real() >>c.imag() >>d.real() >>d.imag();
        if(cross(a, b, c, d)){
            cout <<"YES" <<endl;
        } else{
            cout <<"NO" <<endl;
        }
    }
    return 0;
}
int cross(P a, P b, P c, P d){
    P x = a - b, y = c - d;
    int ret;
    if(!(x.real() * y.imag() - x.imag() * y.real())){
        ret = 1;
    } else{
        ret = 0;
    }
    return ret;
}

Measured memory_bytes: 0
s=input()
s= s[::-1]

S=[0,]
cnt=[0]*2019
cnt[0]=1
d=1
num=0
for i in range(len(s)):
    num += int(s[i])*d
    num %= 2019
    d *= 10
    d%= 2019
    # S.append((int(S[i]) + int(s[i]) * 10**i) % 2019)
    cnt[num]+=1

ans=0
for i in cnt:
    ans += i*(i-1) //2

print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  if (s == "abc"){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
)

func main() {
	N := ReadInt()
	adjM := make([][]int, N)
	for i := 0; i < N; i++ {
		adjM[i] = make([]int, N)
		for j := 0; j < N; j++ {
			adjM[i][j] = -1
		}
	}
	for i := 0; i < N; i++ {
		A := ReadInt()
		for j := 0; j < A; j++ {
			x, y := ReadInt()-1, ReadInt()
			adjM[i][x] = y
		}
	}

	ans := 0
	for S := 1; S < 1<<N; S++ {
		ok := true
		for i := 0; i < N; i++ {
			if S>>i&1 == 0 {
				continue
			}
			for j := 0; j < N; j++ {
				if i == j {
					continue
				}
				if adjM[i][j] == -1 {
					continue
				}
				if adjM[i][j] != S>>j&1 {
					ok = false
					break
				}
			}
		}
		if ok && bits.OnesCount(uint(S)) > ans {
			ans = bits.OnesCount(uint(S))
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1L<<61);

double dist(double x1, double x2, double y1, double y2) {
  return sqrt(pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0));
}

int main() {
  int n; cin >> n;
  vector<double> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];
  vl ord(n);
  iota(all(ord), 0);
  double sum = 0, count = 0;
  do {
    REP(i,1,n) {
      sum += dist(x[ord[i]], x[ord[i-1]], y[ord[i]], y[ord[i-1]]);
    }
    count++;
  } while (next_permutation(all(ord)));
  printf("%.10lf\n", sum/count);
  return 0;
}


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

int main() 
{
	int n;
	cin >> n;
	int h[n + 1];
	for (int i = 1; i <= n; i++) cin >> h[i];
	int count = 0;
	for (int i = 1; i <= n; i++)
		{
			bool c = 1;
			for (int j = 1; j < i; j++)
				if (h[i] < h[j]) c = 0;
			if (c) count++;
		}
	cout << count;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  ll ans=0;
  if(k==0){
    cout<<n*n<<endl;
    return 0;
  }
  for(ll i=k+1;i<=n; i++){
    ans+=(n/i)*(i-k);
    ll a=(n%i)-k+1;
    if(a>0) ans+=a;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int n;
  int res = 0;
  cin>>n;
  VI h;
  RE (i, 2 * n) {
    int a;
    cin>>a;
    h.PB(a);
  }
  sort(ALL(h));
  REP (i, n) {
    res += h[2 * i];
  }
  cout<<res<<endl;

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 256
require 'set'

n, m, tax = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| line.strip.split.map(&:to_i) }
abc = abc.map {|a, b, c| [a, b, -1*(c-tax)] }

# 特殊な隣接リストを構築
graph = Array.new(n+1) { [] }
r_graph = Array.new(n+1) { [] }
abc.each do |a, b, c|
  graph[a] << [b, c]
  r_graph[b] << [a, c]
end

# スタートとゴールから到達可能なノードを列挙
from_1 = Set.new
from_1.add(1)
q = [1]
until q.empty?
  c = q.shift
  graph[c].each do |to, _|
    next if from_1.include?(to)
    from_1 << to
    q.push(to)
  end
end

from_n = Set.new
from_n.add(n)
q = [n]
until q.empty?
  c = q.shift
  r_graph[c].each do |to, _|
    next if from_n.include?(to)
    from_n << to
    q.push(to)
  end
end

available_nodes = from_1 & from_n
available_roads = abc.select {|a, b, _| available_nodes.include?(a) || available_nodes.include?(b) }

# ベルマンフォードで経路探索、最短経路を算出
INF = 10**13
dist=Array.new(n+1, INF)
dist[1]=0
updated=false

available_nodes.each do
  updated=false
  available_roads.each do |from, to, cost|
    if dist[from] != INF && dist[to] > dist[from] + cost
      dist[to] = dist[from] + cost
      updated = true
    end
  end
  break unless updated
end

if updated
  p -1
  exit
end

#p abc
#p [from_1, from_n]
#p available_roads
#p dist
p [-1*dist[n], 0].max



Measured memory_bytes: 5244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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

int main()
{
    int n,k; cin >> n >> k;
    vector<ll> dp(n+1000,INF);
    vector<ll> h(n+1000,0);
    for(int i=0;i<n;i++) cin >> h[i];
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            chmin(dp[i+j],dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef long long ll;
struct edge{
  int to;
  ll cost;
};
typedef pair<int, int> P;
const ll INF = 1e15;
const int MAX_V = 301;

vector<edge> G[MAX_V];
ll d[MAX_V];
int V;

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  rep(i, V+1) d[i] = INF;
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    rep(i, G[v].size()){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  cin >> V;
  ll a[V+1][V+1];
  for(int i = 1; i <= V; i++){
    for(int j = 1; j <= V; j++) cin >> a[i][j];
  }
  vector<tuple<ll, int, int>> vec;
  for(int i = 1; i <= V; i++){
    for(int j = i + 1; j <= V; j++) vec.push_back(make_tuple(a[i][j], i, j));
  }
  sort(vec.begin(), vec.end());
  ll ans = 0;
  bool can = true;
  rep(i, vec.size()){
    ll c = get<0>(vec[i]);
    int t = get<1>(vec[i]), s = get<2>(vec[i]);
    dijkstra(s);
    if(d[t] == INF || d[t] > a[s][t]) {
      edge e1, e2;
      e1.to = t , e1.cost = c, e2.to = s , e2.cost = c;
      G[s].push_back(e1), G[t].push_back(e2);
      ans += c;
    } else {
      if(d[t] < a[s][t]) {
        can = false;
        break;
      }
    }
  }
  if(can) cout << ans << endl;
  else cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        StringBuilder s = new StringBuilder(scanner.next());
        StringBuilder left = new StringBuilder();
        StringBuilder right = new StringBuilder();
        final long q = scanner.nextLong();
        int rev = 0;
        String qi;
        int fi;
        for (int i = 0; i < q; i++) {
            qi = scanner.next();
            if (qi.equals("1")) {
                rev++;
            } else {
                fi = scanner.nextInt();
                if (fi == 1) {
                    if (rev % 2 == 0) {
                        left.insert(0,scanner.next());
                    } else {
                        right.append(scanner.next());
                    }
                } else {
                    if (rev % 2 == 0) {
                        right.append(scanner.next());
                    } else {
                        left.insert(0,scanner.next());
                    }
                }
            }
        }
        if (rev % 2 == 1) {
            s.reverse();
            System.out.println(right.reverse().toString() + s.toString() + left.reverse().toString());
        } else {
            System.out.println(left.toString() + s.toString() + right.toString());
        }
    }
}

Measured memory_bytes: 93896
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: i64,
        scs: [[i64; 2]; m],
    };

    let mut guess = vec![-1; n];
    let mut flag = true;

    for sc in scs {
        let s = (sc[0] - 1) as usize;
        let c = sc[1];

        if guess[s] == -1 {
            guess[s] = c
        }
        if guess[s] != c || (guess[0] == 0 && guess.len() > 1) {
            flag = false
        }

        if !flag {
            break;
        }
    }

    if !flag {
        println!("-1");
    } else {
        guess[0] = if guess.len() == 1 && guess[0] == -1 {
            0
        } else if guess[0] == -1 {
            1
        } else {
            guess[0]
        };
        for i in 1..guess.len() {
            guess[i] = std::cmp::max(guess[i], 0);
        }

        for c in guess {
            print!("{}", c);
        }
        println!("");
    }
}


Measured memory_bytes: 4352
H,W,K = map(int,input().split())

ans = "No"

for i in range(H+1):
    if H-2*i == 0:
        if K-W*i == 0:
            ans = "Yes"
        else:
            continue
    if (K-W*i) % (H-2*i) != 0:
        continue
    j = (K-W*i) // (H-2*i)
    if 0 <= j <= W:
        ans = "Yes"
        break

print(ans)

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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,b,a)     for(int i=b;i>=a;i--)

int n,temp,sum=0,maxi;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    

    cin>>n;
    rep(i,1,n)
    {
        cin>>temp;
        if(i==1)
            maxi=temp;
        else
            if(temp>=maxi)
                maxi=temp;
        sum+=temp;
    }
    sum-=maxi;
    if(sum>maxi)
        cout<<"Yes";
    else
        cout<<"No";
}



Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define INF (1<<29)
#define f(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

ll GCD(ll a, ll b) {
	if (b == 0)return a;
	return GCD(b, a%b);
}

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

ll mypow(ll a, ll b, ll c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	else return mypow(a, b / 2, c)*mypow(a, b / 2, c) % c;
}

signed main() {
	int a, b;
	cin >> a >> b;
	string s[100];
	map<int, string> m;
	f(i, a) {
		cin >> s[i];
		int x = 1;
		f(j, i) {
			f(k, b) {
				if (m[j][k] > s[i][k]) {
					for (int l = i; l > j; l--) {
						m[l] = m[l - 1];
					}
					m[j] = s[i];
					x = 0;
					goto mutu;
				}
				if (m[j][k] < s[i][k]) break;
			}
		}
		mutu:;
		if (x) m[i] = s[i];
	}
	f(i, a) cout << m[i];
	cout << endl;
	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 256
N = int(input())
SP = []
for i in range(N):
    S, P = input().split()
    SP.append([S, int(P), i + 1])
# SP = [[input().split(), i] for i in range(N)]
SP.sort(key=lambda x: (x[0], -x[1]))
num = list(zip(*SP))[-1]
for i in num:
    print(i)


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

template <long long MOD> class modint {
  long long x;
  long long norm(long long v) {
    v %= MOD;
    return (v+MOD)%MOD;
  }
public:
  modint(long long v = 0) : x(norm(v)) {
  }

  modint operator+(modint other) {
    return norm(x+other.x);
  }

  modint& operator+=(modint other) {
    x = (*this + other).x;
    return *this;
  }

  modint operator-(modint other) {
    return norm(x-other.x);
  }

  modint& operator-=(modint other) {
    x = (*this - other).x;
    return *this;
  }

  modint operator*(modint other) {
    return norm(x*other.x);
  }

  modint operator*=(modint other) {
    x = (*this - other).x;
    return *this;
  }

  /*
    modint operator/(modint other) {
    return x*mod_pow(other.x, MOD-2)%MOD;
    }

    moding operator/=(modint other) {
    x = (*this / other).x;
    return *this;
    }
  */

  modint operator^(long long b) {
    if (b == 0) return 1;
    modint ret = *this ^ (b/2);
    ret = ret * ret;
    if (b % 2 == 1) ret = *this * ret;
    return ret;
  }

  long long value() {
    return x;
  }

  friend istream& operator>>(istream& in, modint& a) {
    long long x; in >> x;
    a = modint(x);
    return in;
  }

  friend ostream& operator<<(ostream& out, modint a) {
    out << a.x;
    return out;
  }
};

const ll MOD = 1000'000'007;

typedef modint<MOD> mint;

ll n,k;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n >> k;

  vl f;
  for (int i = 1; i*i <= n; i++) {
    f.push_back(i);
    f.push_back(n/i);
  }

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

  f.erase(unique(f.begin(),f.end()),f.end());

  vl cnt;

  int m = f.size();

  forn(i,m-1) {
    cnt.push_back(n/f[i]-n/f[i+1]);
  }
  cnt.push_back(1);
  reverse(cnt.begin(),cnt.end());

  map<int,int> idx;
  forn(i,m) idx[f[i]] = i;

  vector<vector<mint>> dp(k+1, vector<mint>(m,0));

  dp[0][0] = 1;

  for (int i = 0; i < k; i++) {
    forn(j,m-1) {
      dp[i][j+1] += dp[i][j];
    }
    forn(j,m) {
      int l = idx[n/f[j]];
      dp[i+1][j] += dp[i][l]*cnt[j];
    }
  }

  mint res = accumulate(dp[k].begin(),dp[k].end(),mint(0LL));

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 54776
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

string s[55];

void solve(int x, int y) {
  char cur = s[x][y];
  if (cur == '#') { cout << '#'; return ; }
  int sum = 0;
  for (int i = x-1; i <= x+1; i++) {
    for (int j = y-1; j <= y+1; j++) {
      if (i < 0 || j < 0) continue;
      if (i==x && j==y) continue;
      if (s[i][j] == '#') sum++;
    }
  }
  cout << sum;
  return ;
}

int main() {
  int h,w; cin >> h >> w;
  REP(i,h) cin >> s[i];
  REP(i,h) {
    REP(j,w) solve(i,j);
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int Q = sc.nextInt();
        int[] l = new int[Q+1];
        int[] r = new int[Q+1];
        int rmax = Integer.MIN_VALUE;
        for(int i=1;i<=Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            rmax = Math.max(rmax,r[i]);
        }
        boolean[] primeRecord = new boolean[rmax+2];
        primeRecord[2]=true;
        for(int i=3;i<=rmax+1; i++){
            if((i&1)==0||(!isPrime(i)))continue;
            primeRecord[i] = true;
        }
        int[] rec2017 = new int[rmax+2];
        for(int i=3;i<=rmax+1; i++){
            if((i&1)==1&&primeRecord[i]&&primeRecord[(i+1)/2]){
                rec2017[i] =rec2017[i-1]+1;
            }
            else rec2017[i] = rec2017[i-1];
        }
        for(int i=1; i<=Q; i++){
            int ans;
            int left = l[i];
            int right = r[i];
            if((left&1)==0) left++;
            if((right&1)==0) right--;
            if(right<left) ans = 0;
            else{
                ans = rec2017[right]-rec2017[left-1];
            }
            System.out.println(ans);
        }
    }
    private static boolean isPrime(int target){
        int upper = (int) Math.sqrt(target)+1;
        for(int i=2; i<= upper; i++){
            if(target%i==0) return false;
        }
        return true;
    }
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s1; cin >> s1;
  int n = SZ(s1);
  int c = n, f = -1;
  for(int i=0;i<SZ(s1);++i) {
    if(s1[i] == 'C') {
      c = min(c, i);
    } else if(s1[i] == 'F') {
      f = max(f, i);
    }
  }
  cout << (c < f ? "Yes": "No") << endl;
}


Measured memory_bytes: 256