akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int MAX = 200200, MOD = 1000000007;
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;
    }
}

long long COM(int n, int k){
    if (n < 0 || k < 0 || n < k) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

template<class Monoid>
struct Rerooting {
    // 問題ごとに書き換える
    const Monoid UNITY = make_pair(1,0);    
    function<Monoid(Monoid, Monoid)> merge = [](Monoid a, Monoid b) {
        return make_pair(a.first * b.first % MOD * COM(a.second + b.second, b.second) % MOD, a.second + b.second); 
    };
    function<Monoid(Monoid)> add = [](Monoid a) { return make_pair(a.first, a.second + 1); };

    struct Edge { int from, to, cost; };
    vector<vector<Edge>> G;
    vector<vector<Monoid>> dp; // dp[v][i]: vから出るi番目の有向辺に対応する部分木のDP
    vector<Monoid> ans; // ans[v]: 頂点vを根とする木の答え
 
    Rerooting(int n) { G.resize(n); dp.resize(n); ans.resize(n); } 
    void add_edge(int a, int b, int c = 1) { G[a].push_back({a,b,c}); G[b].push_back({b,a,c}); }
    void build() { COMinit(); dfs(0); bfs(0, UNITY); }
 
    Monoid dfs(int v, int p = -1) {
        Monoid num = UNITY;
        for (auto nv : G[v]) {
            if (nv.to == p) dp[v].push_back(UNITY);
            else {
                Monoid save = dfs(nv.to, v);
                dp[v].push_back(save);
                num = merge(num, save);
            }
        }
        return add(num);
    }

    void bfs(int v, const Monoid &num, int p = -1) {
        int deg = (int)G[v].size();
        for (int i = 0; i < deg; i++) if (G[v][i].to == p) dp[v][i] = num;

        vector<Monoid> left(deg+1, UNITY), right(deg+1, UNITY);
        for (int i = 0; i < deg; i++) left[i+1] = merge(left[i], dp[v][i]);
        for (int i = deg; i > 0; i--) right[i-1] = merge(right[i], dp[v][i-1]);
 
        ans[v] = add(right[0]);
 
        for (int i = 0; i < deg; i++) {
            int nv = G[v][i].to;
            if (nv != p) bfs(nv, add(merge(left[i], right[i+1])), v);
        }
    }
};
 
int main() {
    int n; cin >> n;
    Rerooting<pair<long,long>> reroot(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v; u--, v--;
        reroot.add_edge(u, v);
    }
    reroot.build(); 
    for (int i = 0; i < n; i++) cout << reroot.ans[i].first << endl;
    return 0;
}

Measured memory_bytes: 44480
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
int x=0,n1=n;
while(n1)
{
	x=x*10+n1%10;
	n1/=10;
}
if(x==n)ol("Yes");
else ol("No");
return 0;
}



Measured memory_bytes: 256
N,K = map(int,input().split())

ans = 0
prob = 1
pow2 = 1
for i in range(N,0,-1):
    if i*pow2 >= K:
        ans += prob/N 
    else:
        while(1):
            prob = prob/2
            pow2 = pow2*2
            if i*pow2 >= K:
                ans += prob/N
                break
print(ans)


Measured memory_bytes: 39280
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (a + b == 15) {
    cout << "+" << endl;
  } else if (a * b == 15) {
    cout << "*" << endl;
  } else {
    cout << "x" << endl;
  }
}


Measured memory_bytes: 256
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

x = [0]*(H*W+1)
p = [[] for _ in range(H*W+1)]

for h in range(H):
    for w in range(W):
        p[A[h][w]] = [h, w]

for i in range(D+1, H*W+1):
    x[i] = x[i-D]+abs(p[i][0]-p[i-D][0])+abs(p[i][1]-p[i-D][1])

for _ in range(int(input())):
    l, r = map(int, input().split())
    print(x[r]-x[l])

Measured memory_bytes: 24668
#include<bits/stdc++.h>
using namespace std;
char s[200005];
int len, l, r;
bool pd;
int main(){
	scanf("%s",&s);
	len=strlen(s);
	for(int i=0;i<len;++i){
		if(s[i]=='A'&&pd==0){
			l=i,pd=1;
		}
		if(s[i]=='Z') r=i;
	}
	printf("%d",r-l+1);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

struct Node {
    int x, y, id;
}p[N];
bool cmp1(Node a, Node b) {
    return a.x < b.x;
}
bool cmp2(Node a, Node b) {
    return a.y < b.y;
}
struct Edge {
    int u, v, w;
    bool operator < (const Edge &t) const {
        return w < t.w;
    }
}e[N << 1];
int fa[N];

inline int getFa(int u) {
    return fa[u] == 0 ? u : fa[u] = getFa(fa[u]);
}

int main() {
#ifdef purple_bro
    freopen("in.txt", "r", stdin);
#endif // purple_bro
    int n;

    scanf("%d", &n);

    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &p[i].x, &p[i].y);
        p[i].id = i;
    }

    sort(p + 1, p + 1 + n, cmp1);

    int tot = 0;

    for (int i = 1; i < n; i++)
        e[++tot] = {p[i].id, p[i + 1].id, p[i + 1].x - p[i].x};

    sort(p + 1, p + 1 + n, cmp2);

    for (int i = 1; i < n; i++)
        e[++tot] = {p[i].id, p[i + 1].id, p[i + 1].y - p[i].y};

    sort(e + 1, e + 1 + tot);

    LL ans = 0;
    int cnt = 0;

    for (int i = 1; i <= tot; i++) {
        int u = e[i].u;
        int v = e[i].v;
        int w = e[i].w;
        int du = getFa(u);
        int dv = getFa(v);
        if (du != dv) {
            fa[du] = dv;
            cnt++;
            ans += w;
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 2000000000
#define MAX 100001
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define IFY(con) if((con)){YES;}else{NO;}
#define IFy(con) if((con)){Yes;}else{No;}

signed main(){ INIT
    VAR(string, s);
    int p = 0;
    REP(i, s.size()) if(s[i] == 'p') p++;
    OUTL(s.size()/2 - p)
RET;}


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

#define pb push_back
#define fst first
#define snd second
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
using namespace std;

int main() {FIN;
    int n; cin>>n;
    vector<vector<int>> a(n, vector<int> (3));
    fore(i,0,n) fore(j,0,3) cin>>a[i][j];
    int dp[n][3];
    dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2];
    fore(i,1,n){
        fore(j,0,3){
            dp[i][j] = 0;
            fore(k,0,3){
                if(j != k) dp[i][j] = max(dp[i][j], dp[i-1][k]+a[i][j]);
            }
        }
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<"\n";
    return 0;
}


Measured memory_bytes: 9752
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int N_MAX=200000;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int main()
{
  int n,q,d,i,qq;
  P p;
  PP s[N_MAX];
  priority_queue<P,vector<P>,greater<P>> que;
  cin >> n >> q;
  for(i=0;i<n;i++){
    cin >> s[i].first >> s[i].second.first >> s[i].second.second;
    s[i].first-=s[i].second.second;
    s[i].second.first-=s[i].second.second;
  }
  sort(s,s+n);
  i=0;
  for(qq=0;qq<q;qq++){
    cin >> d;
    for(;i<n;i++)
      if(s[i].first<=d){
        que.emplace(s[i].second.second,s[i].second.first);
      }else{
        break;
      }
    while(!que.empty()){
      p=que.top();
      if(p.second>d){
        cout << p.first << endl;
        break;
      }else{
        que.pop();
      }
    }
    if(que.empty())
      cout << "-1" << endl;
  }
  return 0;
}

Measured memory_bytes: 7640
def main
  prime = Array.new(50100,true)
  for i in 2..prime.length ** 0.5
    if prime[i]
      for j in 2..50100 / i
        prime[i * j] = false
      end
    end
  end
  prime[0], prime[1] = false, false
  while n = gets
    n = n.to_i
    m = n - 1
    until prime[m]
      m -= 1
    end
    print m.to_s + " "
    m = n + 1
    until prime[m]
      m += 1
    end
    print m.to_s + "\n"
  end
end
main

Measured memory_bytes: 6564
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    V = []
    for a, b in zip(A, B):
        V.append((a + b, a, b))

    V.sort(reverse=True)
    takahashi = 0
    aoki = 0
    for i in range(N):
        if i % 2 == 0:
            takahashi += V[i][1]
        else:
            aoki += V[i][2]

    print(takahashi - aoki)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23456
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int M,N;
		Character[][] A = new Character [50][50];
		Character[][] B = new Character [50][50];
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();

		for(int i = 0; i < N; i++) {
			String str = sc.next();
			for(int j = 0; j < N; j++) {
				Character k = str.charAt(j);
				A[i][j] = k;
			}
		}

		for(int i = 0; i < M; i++) {
			String str = sc.next();
			for(int j = 0; j < M; j++) {
				Character k = str.charAt(j);
				B[i][j] = k;
			}
		}

		boolean exist = false;

		for(int i = 0; i < (N - M + 1); i++) {
			for(int j = 0; j < (N - M + 1); j++) {

				boolean match = true;

				for(int k = 0; k < M; k++) {
					for(int l = 0; l < M; l++) {
						if(B[k][l] != A[k + i][l + j]) {
							match = false;
							break;
						}
					}
					if(!match) {
						break;
					}
				}
				if(match) {
					exist = true;
					break;
				}
			}
			if(exist) {
				System.out.println("Yes");
				System.exit(0);
			}
		}

		System.out.println("No");

		sc.close();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int k;
  	cin >> k;
  	vector<long long> a;
    // push_back使う時はi=0から入っていくのに注意
  	for(int i=1;i<=9;i++) a.push_back(i);
  	while (1) {
      // 新しく作った配列aのサイズが、減っていくk以上になるようにしていく
      if (k <= a.size()) {
          cout << a[k-1] << endl;
          // 出力したらプログラム終了
    	  return (0);
      }
      // kの方が大きい場合は古いaのサイズ分減らす
      k -= a.size();
      vector<long long> old;
      swap(a, old);
      // 古いaをもとに新しいlunlun数を空の配列にいれていく
      for (long long x : old) {
          for(int i=-1;i<=1;i++) {
              int d = x%10 + i;
              if (d < 0 || 9 < d) continue;
              long long nx = 10*x + d;
              //cout << nx << endl;
              a.push_back(nx);
          }
      }
	}
  
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        int n; cin >> n;
        if (n == 0) break;
        vector<double> s(n); for (int i = 0; i < n; i++) cin >> s[i];
        double sum = 0;
        for (int i = 0; i < n; i++) sum += s[i];
        double ave = sum / (double) n;
        double bun = 0;
        for (int i = 0; i < n; i++) {
            bun += pow(s[i] - ave, 2);
        }
        bun /= (double) n;
        double sta = sqrt(bun);
        printf("%.8f\n", sta);
    }
    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e6;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll a[101];

int main()
{
    fast_io;
    ll n, i, v, s = 0;
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] % 2 && i % 2) s++;
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
	int n,k,ans=0;
	cin >> n >> k;
	vec(a,n);
	REP(i,n){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	REP(i,k){
		ans += a[i];
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<utility>
using namespace std;

int n, m;
int d[30][30];
int c[500][500];
pair<int, int> cost[3][30];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &d[i][j]);
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%d", &c[i][j]);
            for (int k = 0; k < m; k++) {
                cost[(i + j + 2) % 3][k].first += d[c[i][j] - 1][k];
            }
        }
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < m; j++) {
            cost[i][j].second = j;
        }
    }
    for (int i = 0; i < 3; i++) sort(cost[i], cost[i] + m);
    
    int ans = 1e9;
    for (int i = 0; i < 27; i++) {
        int j = i / 9;
        int k = (i % 9) / 3;
        int l = i % 3;
        if (cost[0][j].second == cost[1][k].second
         || cost[1][k].second == cost[2][l].second
         || cost[2][l].second == cost[0][j].second) continue;
        ans = min(ans, cost[0][j].first + cost[1][k].first + cost[2][l].first);
    }
    
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1152
from collections import Counter


def main(n, s):
    c = Counter(s)
    max_count = c.most_common()[0][1]
    res = []
    for keys, count in c.most_common():
        if max_count == count:
            res.append(keys)

    print("\n".join(sorted(res)))


if __name__ == "__main__":
    n = int(input())
    s = [input() for _ in range(n)]

    main(n, s)


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int A, B, C; cin >> A >> B >> C;
    cout << max(C - (A-B), 0) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

int main(){
    long long N,M;
    long long A[100 * 2], count = 0, sum = 0;

    cin >> N >> M;
    rep(i,N){
        cin >> A[i];
        sum += A[i];
    }

    rep(i,N){
        if(A[i] >= (double)(sum / (4.0 * M))){
            count++;
        }
    }

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

Measured memory_bytes: 256
//CREATED BY TARANG KAPOOR



#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n,m,sum=0 ; cin>>n>>m;
  vector<int>v;
  for(int i=0 ; i<n ; i++){
      int x; cin>>x;
      v.push_back(x);
      sum+=v[i];
  }
  //cout<<sum;
  int count=0;
  sort(v.begin() , v.end() ,greater<int>());
 // int x=sum/(4*m);
 // cout<<x<<endl;
  for(int i=0 ; i<m ; i++){
      if((float)v[i]>=(float)sum/(4*m))
      count++;
  }
  if(count==m)
  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,maxv[105],l[105],r[105],T,tt;
double ans,las,now;
inline double v(double t){
	double ans=1e50,te;
	fo(i,0,n+1){
		te=maxv[i];
		if (t<l[i]) te=maxv[i]+l[i]-t;
		if (t>r[i]) te=maxv[i]+t-r[i];
		if (te<ans) ans=te;
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	fo(i,1,n){
		scanf("%d",&tt);
		l[i]=r[i-1];
		r[i]=l[i]+tt;
	}
	r[n+1]=l[n+1]=r[n];
	fo(i,1,n) scanf("%d",&maxv[i]);
	las=0;
	for(double t=0.5;t<=r[n];t+=0.5){
		now=v(t);
		ans+=0.25*(las+now);
		las=now;
	}
	printf("%.12f\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;



int main() {
  int A, P; cin >> A >> P;
  int S = (A * 3 + P) / 2;
  cout << S << endl;

	return 0;

}



Measured memory_bytes: 3588
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  string s, t;
  cin >> s >> t;
  vector<int> charpos[26];
  int n = s.size(), m = t.size();
  FOR(i, n) { charpos[s[i] - 'a'].push_back(i); }
  ll ans = -1;
  FOR(i, m) {
    if (charpos[t[i] - 'a'].empty()) {
      cout << -1 << endl;
      return 0;
    } else {
      int nowpad = ans % n;
      int pos = upper_bound(ALL(charpos[t[i] - 'a']), nowpad) -
                charpos[t[i] - 'a'].begin();
      if (pos == charpos[t[i] - 'a'].size()) {
        pos = 0;
        ans += n - nowpad;
        nowpad = 0;
      }
      ans += charpos[t[i] - 'a'][pos] - nowpad;
    }
  }
  cout << ans + 1 << endl;
  return 0;
}
#include <algorithm>


Measured memory_bytes: 1216
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");
	public static void main(String[] args) {
		String S=sc.next();//66 87
		long B[]=new long[S.length()];
		long b=0;
		long ans=0;
		for(int i=0;i<S.length();i++) {
			if(S.charAt(i)==66) b++;
			else if(i!=0)ans+=B[i-1];
			B[i]=b;
		}
		p(ans);
		
	}
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
}
	

Measured memory_bytes: 28720
N = int(input())
S = [input() for _ in range(N)]

l = ['M', 'A', 'R', 'C', 'H']
d = dict()
for li in l: d[li] = 0
for si in S:
    for li in l:
        if si[0] == li: d[li] += 1

ans = 0
for i in range(len(l)):
    for j in range(i+1, len(l)):
        for k in range(j+1, len(l)):
            ans += d[l[i]] * d[l[j]] * d[l[k]]
print(ans)

Measured memory_bytes: 9752
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int a1=0,a2=0,a3=0,a4=0;
    int n;
    scanf("%d", &n);
    char s[3];
    for(int i = 0; i < n; i++){
        scanf("%s", s);
        if(s[0] == 'A'){
            a1++;
        }
        else if(s[0] == 'W'){
            a2++;
        }
        else if(s[0] == 'T'){
            a3++;
        }
        else if(s[0] == 'R'){
            a4++;
        }
    }
  
    printf("AC x %d\n", a1);
    printf("WA x %d\n", a2);
    printf("TLE x %d\n", a3);
    printf("RE x %d\n", a4);
    
    return 0;
}


Measured memory_bytes: 3224
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    for(int i = a; i <= b; i++)
    {
        if(i <= a + k - 1 || i >= b - k + 1)
            cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int A, B;
    cin >> A >>B;
    if(A + B >= 10) cout << "error" << endl;
    else cout << A + B << endl;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int ans = 10000;
	for(auto&& i : a)
	{
		cin >> i;
		int cnt = 0;
		while(i % 2 == 0)
		{
			cnt++;
			i /= 2;
		}
		ans = min(ans, cnt);
	}
	cout << ans << "\n";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = long long;
using P = pair<int,int>;


int main(){
    string S,T;
    cin >> S >> T;
    int ans = 0;
    rep(i,S.size()) if(S[i] == T[i]) ans++;

    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque


S = list(input())
N = int(input())

d = deque()
d.extend(S)

# Trueであれば順方向
direction = True

for i in range(N):
    query = input()
    if query[0] == "1":
        t = int(query)
    else:
        t, f, c = query.split()
        t = int(t)
        f = int(f)

    if t == 1:
        #True-Falseの逆転
        direction = not direction

    if t == 2:
        if direction == True:
            if f == 1:
                d.appendleft(c)
            else:
                d.append(c)

        else:
            if f == 1:
                d.append(c)
            else:
                d.appendleft(c)

if direction == True:
    print(''.join(d))
else:
    print(''.join(reversed(d)))

Measured memory_bytes: 75768
from heapq import heappush, heappop
v, e, r = map(int, input().split())
G = [[] for _ in range(v)]
for _ in range(e):
    s,t,d = map(int, input().split())
    G[s].append((d, t))
    # G[t].append((d, s))

dist = [float('inf') for _ in range(v)]

prev = [(0,r)]

while len(prev):
    now = heappop(prev)
    if dist[now[1]] < now[0]:
        continue
    else:
        dist[now[1]] = now[0]
    for nxt in G[now[1]]:
        if dist[nxt[1]] > dist[now[1]] + nxt[0]:
            dist[nxt[1]] = dist[now[1]] + nxt[0]
            heappush(prev,(nxt[0]+dist[now[1]], nxt[1]))
    # print(now,prev,dist)
for i in dist:
    if i ==float('inf'):
        print("INF")
    else:
        print(i)





Measured memory_bytes: 92604
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n, m;
	while(cin >> n >> m) {
		int k;
		cin >> k;
		bool f = false;
		REP(i,n+1) REP(j,m+1){
			if(i*m+n*j-2*i*j == k) {
				f = true;
			}
		}
		if(f) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

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

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

int main() {
    int d, t, s;
    cin >> d >> t >> s;

    if (d <= t * s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

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

ll n, m, q, ans = 0;
ll a[50], b[50], c[50], d[50];
ll A[10];

void dfs(int dep, int num) {
  if (dep == n) {
    ll t = 0;
    rep(i, q) if (A[b[i]] - A[a[i]] == c[i]) t += d[i];
    ans = max(ans, t);
    return;
  }
  for (int i = num; i <= m; ++i) A[dep] = i, dfs(dep + 1, i);
}

int main() {
  cin >> n >> m >> q;
  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }

  dfs(0, 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
// https://github.com/kurokoji/.cpp-Template/wiki
#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

signed main() {
  vi v;
  REP(i,3) v.pb(in());
  sort(ALL(v));
  if ( v[0] == 5 && v[1] == 5 && v[2] == 7 )
    puts("YES");
  else
    puts("NO");
  return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

class mes {
public:
	vector<int> c;
	string s;
};

vector<mes> M;
void f(int idx, int cnt) {
	rep(i, 0, cnt)cout << ".";
	cout << M[idx].s << endl;
	rep(i, 0, M[idx].c.size()) {
		f(M[idx].c[i], cnt + 1);
	}
}

signed main() {
	int n; cin >> n;
	M = vector<mes>(n);
	rep(i, 0, n) {
		int k;
		string s;
		cin >> k >> s;
		k--;

		if (k >= 0)M[k].c.emplace_back(i);
		M[i].s = s;
	}
	f(0, 0);
	return 0;
}

Measured memory_bytes: 3408
#include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    ll a[5],n;
    int main()
    {
        while(scanf("%lld%lld%lld%lld",&a[0],&a[1],&a[2],&a[3])!=EOF)
        {
            scanf("%lld",&n);
            for(int i=1;i<4;i++) a[i]=min(a[i],2*a[i-1]);
            printf("%lld\n",n/2*a[3]+(n&1)*a[2]);
        }
        return 0;
    }

Measured memory_bytes: 256
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] sheet = new int[r + 1][c + 1];
		int sum = 0;
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		}
		sheet[r][c] = sum;

		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		}
	}
}

Measured memory_bytes: 52524
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

void solve() {
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n;
        cin >> n;
        vector<ll> p(n);
        rep(i, n) {
            cin >> p[i];
            p[i]--;
        }
        vector<ll> a(n), b(n);
        rep(i, n) {
            a[i] = n * (i + 1);
            b[i] = n * (n - i);
        }
        rep(i, n) a[p[i]] += i;
        rep(i, n) printf("%lli ", a[i]);
        printf("\n");
        rep(i, n) printf("%lli ", b[i]);

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 1152
using System;

namespace ITP_1_2_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int W = int.Parse(input[0]);
            int H = int.Parse(input[1]);
            int x = int.Parse(input[2]);
            int y = int.Parse(input[3]);
            int r = int.Parse(input[4]);
            if (x - r < 0 || y -r < 0 || x + r > W || y + r > H) Console.WriteLine("No");
            else Console.WriteLine("Yes");
            Console.ReadLine();
        }
    }
}



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

using namespace std;
using ll = long long;
const int N = 200005;

int n, a[N];

ll dp[N][5];

ll f(int i, int left) {
	if(left < 0) return (ll)-1e18;
	if(i >= n) return left <= 1 ? 0 : (ll)-1e18;
	ll &ans = dp[i][left];
	if(~ans) return ans;
	ans = f(i + 1, left - 1);
	ans = max(ans, f(i + 2, left) + a[i]);
	return ans;
}

int main() {
	memset(dp, -1, sizeof dp);
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", a + i);

	printf("%lld\n", f(0, n % 2 == 0 ? 1 : 2));
}


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

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

  int N; cin >> N;
  vector<vector<int>> g(N+1);
  for (int i = 0; i < N-1; i++) {
    int a, b; cin >> a >> b; a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  queue<int> que;
  vector<int> dist(N, -1);
  vector<vector<int>> group(2);
  que.push(0);
  dist[0] = 0;  
  group[0].push_back(0);
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int u : g[v]) {
      if (dist[u] < 0) {
        dist[u] = dist[v] + 1;
        group[dist[u] % 2].push_back(u);
        que.push(u);
      }
    }
  }

  vector<int> p(N), q = {1, 2, 3};
  if (group[1].size() <= N / 3) swap(group[0], group[1]);
  if (group[0].size() <= N / 3) {
    for (int v : group[0]) {
      p[v] = q[2]; q[2] += 3;
    }
    for (int v : group[1]) {
      if (q[2] <= N) { p[v] = q[2]; q[2] += 3; }
      else if (q[1] <= N) { p[v] = q[1]; q[1] += 3; }
      else { p[v] = q[0]; q[0] += 3; }
    }
  }
  else {
    for (int v : group[0]) {
      if (q[0] <= N) { p[v] = q[0]; q[0] += 3; }
      else { p[v] = q[2]; q[2] += 3; }
    }
    for (int v : group[1]) {
      if (q[1] <= N) { p[v] = q[1]; q[1] += 3; }
      else { p[v] = q[2]; q[2] += 3; }
    }
  }

  cout << p.front();
  for (int i = 1; i < N; i++) cout << " " << p[i];
  cout << "\n";
}

Measured memory_bytes: 16368
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];

    for i in 0..n {
        a.push(read());
    }
    let sum: i64 = a.iter().sum();
    let maxv: i64 = *a.iter().max().unwrap();

    if sum - maxv > maxv {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

d = {}
for y in range(H):
    Ay = A[y]
    for x in range(W):
        d[Ay[x]] = (y, x)

t = [[0] * ((H * W + D - 1) // D + 1) for _ in range(D)]
for i in range(D):
    ti = t[i]
    j = 0
    if i == 0:
        j = 1
    while i + (j + 1) * D <= H * W:
        y1, x1 = d[i + j * D]
        y2, x2 = d[i + (j + 1) * D]
        ti[j + 1] = abs(y1 - y2) + abs(x1 - x2)
        j += 1
    for j in range(len(ti) - 1):
        ti[j + 1] += ti[j]

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    i = L % D
    print(t[i][(R - i) // D] - t[i][(L - i) // D])


Measured memory_bytes: 28384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int n,k,l;
	int d[10];
	int dd[10];
	int ans=0;
	
	cin>>n>>k;
	l=0;
	for(int i=0;i<k;i++)
		cin>>d[i];
	for(int i=0;i<10;i++)
	{
		bool f=true;
		for(int j=0;j<k;j++)
		{
			if(d[j]==i)
			{
				f=false;
				break;
			}
		}
		if(f)
		{
			dd[l]=i;
			l++;
		}
	}

	for(int i=n;i<100000;i++)
	{
		//cerr<<i<<endl;
		int t=i;
		int mketa=0;
		int mk[5];
		while(t!=0)
		{
			mk[mketa]=t%10;
			t/=10;
			mketa++;
		}
		bool f=true;
		for(int j=0;j<mketa;j++)
		{
			for(int m=0;m<k;m++)
			{
				if(d[m]==mk[j])
				{
					f=false;
					break;
				}
			}
			if(!f)
				break;
		}
		if(f)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
N,K=map(int, input().split())
A=[0]*(N+1)
count=0
for i in range(1, N+1):
	A[i]=int(N/i)
	
for i in range(K+1,N+1):
	count += A[i]*(i-K)
	if N-A[i]*i >= K :
		if K==0:
			count += N-A[i]*i
		else:
			count += N-A[i]*i-K+1

print(count)

Measured memory_bytes: 3828
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    int h=sc.nextInt();
    int n=sc.nextInt();
    int[] a=new int[n];
    int sum=0;
    for(int i=0;i<n;++i){
      a[i]=sc.nextInt();
      sum+=a[i];
    }
    if(sum>=h){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 50212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
	ll n;
	cin>>n;
	
	ll sum=0;
	for(ll i=1; i<=n; i++){
		if(i%3!=0 && i%5!=0)
			sum+=i;
	}
	cout<<sum;
	return 0;
}



Measured memory_bytes: 3636
#include <stdio.h>

int main(void) {
    int i;
	char str[1000];
    scanf("%s",str);
    for(i = 0;str[i] != 0;i++){
         if(str[i] < 68) str[i] += 23;
         else str[i] -= 3;
    }
    printf("%s\n",str);
	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define For(i,a,b) for(long long i=a;i<b;i++)
#define pb push_back
using namespace std;
typedef long long ll;
ll power(ll x,ll y,ll p){
ll res = 1;x = x % p;
while (y > 0){
if (y & 1){res = (res*x) % p;}
y = y>>1;
x = (x*x) % p;}
return res;}
ll mcd(ll a,ll b){
    if(b>a)swap(a,b);
    if(b==0)return a;
    else return mcd(b,a%b);
}
ll t,n,m,k;
bool esprimo(ll n){
ll s=0;
for(ll i=1;i*i<=n;i++){
    if(n%i==0){s++;}}
if(s>=2){return false;}
return true;
}
ll v[1000005];
ll con(ll x){
unordered_map<ll,ll> m;
//cout<<"JAJE";
while(x!=1){
    if(m.find(v[x])==m.end()){
        m.insert({v[x],1});
        x/=v[x];
    }else{
        m.find(v[x])->se++;
        x/=v[x];
    }

}
//cout<<"valio";
unordered_map<ll,ll>::iterator it;
ll s=1;
for(it=m.begin();it!=m.end();it++){
    s*=(it->se+1);
}
m.clear();
return s;

}
int main(){
    //    cout<<fixed<<setprecision(2);
//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
memset(v,0,sizeof v);

for(int i=2;i<1000001;i++){
    if(v[i]==0){
        for(int j=1;j*i<=1000000;j++){
            if(v[j*i]==0){
                v[i*j]=i;
            }
        }
    }
}
v[1]=1;
for(int i=0;i<100;i++){
  //  cout<<v[i]<<" ";
}

cin>>n;
ll ans=0;
for(int i=n-1;i>0;i--){
    ans+=con(n-i);
}
cout<<ans<<endl;
}



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

int main(){

    int N, M;
    cin >> N >> M;

    vector<int> a(M), b(M), c(M);
    vector<vector<int> > d(N, vector<int>(N, 10000000));
    for(int i = 0; i < N; i++) d[i][i] = 0;
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }

    for(int k = 0; k < N; k++){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int count = M;
    for(int i = 0; i < M; i++){
        for(int j = 0; j < N; j++){
            if(d[j][a[i]] + c[i] == d[j][b[i]]){
                count--;
                break;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
template<class T> using V=vector<T>; 
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct edge{ll to,cost;};
vector<vector<edge>> graph;
vector<ll> d1;
int n,m;
void dijkstra(ll s){
    d1.resize(3*n);
    for(int i=0;i<3*n;i++)d1[i]=inf;//訪れていない頂点をinfで初期化
    d1[s]=0;
    priority_queue<P,vector<P>,greater<P>> q;
    q.push(P(0,s));//始点を０で置く
    while(!q.empty()){
        P a=q.top();
        q.pop();
        if(d1[a.se]<a.fi)continue;
        for(int i=0;i<graph[a.se].size();i++){
            edge e=graph[a.se][i];
            if(d1[e.to]>d1[a.se]+e.cost){
                d1[e.to]=d1[a.se]+e.cost;//訪れていないorより低いコストの経路を発見した時、値を更新
                q.push(P(d1[e.to],e.to));//コストの低いところ優先のbfs
            }
        }
    }
}
int main(){
    cin>>n>>m;
    graph.resize(3*n);
  for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      a--;b--;
      graph[a].push_back((edge){b+n,1});
      graph[a+n].push_back((edge){b+2*n,1});
      graph[a+2*n].push_back((edge){b,1});
  }
  int s,t;
  cin>>s>>t;
  s--;t--;
  dijkstra(s);
  if(d1[t]==inf)cout<<-1<<endl;
  else cout<<d1[t]/3<<endl;
}

Measured memory_bytes: 19072
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;

void solve(string s, int l=0, int m=0){
	int i;
	if(l==n){
		cout << s << endl;
		return;
	}
	for(i=0; i<m; ++i){
		solve(s+(char)('a'+i),l+1,m);
	}
	solve(s+(char)('a'+m),l+1,m+1);
}

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


Measured memory_bytes: 1536