akhauriyash/Code-Regression huggingface dataset:
// B - Distance
import { readFileSync } from 'fs';
const input = readFileSync('/dev/stdin', 'utf8');

const [ND, ...XY] = input.split('\n');

const [, D] = ND.split(' ').map((value) => parseInt(value));

const xy = XY.map((value) => value.split(' ').map((val) => parseInt(val)));

let count = 0;

xy.forEach((value) => {
  const [X, Y] = value;
  const sqrted = Math.sqrt(Math.pow(X, 2) + Math.pow(Y, 2));
  if (sqrted <= D) count += 1;
});

console.log(count);


Measured memory_bytes: 94112
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
l = [0 for _ in range(n + 1)]
r = [0 for _ in range(n + 1)]

for i in range(n):
    l[i + 1] = gcd(l[i], a[i])

for i in reversed(range(n)):
    r[i] = gcd(r[i + 1], a[i])

m = [gcd(l[i], r[i + 1]) for i in range(n)]

print(max(m))


Measured memory_bytes: 16076
s = gets.strip
s1 = s[0..1].to_i
s2 = s[2..3].to_i

if s1 <= 12 && s2 <= 12 && s1 >= 1 && s2 >= 1
  print 'AMBIGUOUS'
elsif s1 <= 12 && s1 >= 1
  print 'MMYY'
elsif s2 <= 12 && s2 >= 1
  print 'YYMM'
else
  print 'NA'
end

Measured memory_bytes: 1788
# include<bits/stdc++.h>
# include<unordered_map>
# include<unordered_set>
// # include<prettyprint.hpp>
using namespace std;
# define ll long long
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n, k; cin >> n >> k;
    vector<ll> a(n+1, 0);
    for(ll i = 1; i <= n; i++) cin >> a[i];
    vector<ll> vis(n+1, 0);
    vector<ll> path;
    ll pos = 1;
    while(vis[pos] == 0){
        path.push_back(pos);
        vis[pos] = 1;
        pos = a[pos];
    }
    vector<ll> cycle;
    while (true){
        cycle.push_back(path.back());
        path.pop_back();
        if (cycle.back() == pos){
            break;
        }
    }
    if (k < path.size()){
        cout << path[k] << endl;
    }else{
        reverse(cycle.begin(), cycle.end());
        k-=path.size();
        k%=cycle.size();
        cout << cycle[k] << endl;
    }
    return 0;
}

Measured memory_bytes: 10756
#include<bits/stdc++.h>
using namespace std;
const int N=(1<<18)+5;
int fa[N],f[1<<9][N],v[N],w[N];
int main(){
//	freopen("in05.txt","r",stdin);
//	freopen("out05.txt","w",stdout);
	int n;cin>>n;
	for(int i=1;i<=n;++i)
		cin>>v[i]>>w[i],fa[i]=i/2;
	for(int i=1;i<(1<<9);++i){
		for(int j=1;j<=1e5;++j)
			f[i][j]=f[fa[i]][j];
		for(int j=w[i];j<=1e5;++j)
			f[i][j]=max(f[i][j],f[fa[i]][j-w[i]]+v[i]);
	}
	//cout<<"erhtyjrstyd\n";
	int q,x,l;
	cin>>q;
	while(q--){
		cin>>x>>l;
		//cout<<x<<" "<<l<<endl;
		if(x<(1<<9)){
			cout<<f[x][l]<<endl;
			continue;
		}
		vector< pair<int,int> > vec;
		while(x>=(1<<9)) vec.push_back(make_pair(v[x],w[x])),x=fa[x];
		//cout<<"dfgbtfhrteff\n";
		int cnt=vec.size(),ans=f[x][l];
		//cout<<(1<<cnt)<<" "<<cnt<<endl;
		for(int i=0;i<(1<<cnt);++i){
			int val=0,wei=0;
			for(int j=0;j<cnt;++j)
				if((i>>j)&1) val+=vec[j].first,wei+=vec[j].second;
			//cout<<i<<" "<<val<<" "<<wei<<endl;
			if(wei<=l) ans=max(ans,f[x][l-wei]+val);
		}
		//cout<<"rgerydgg\n";
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 208336
# バイナリーサーチ
ABCD=list(map(int,input()))
for i in range(2**4):
    sm = ABCD[0]
    ans = [str(sm)]
    for j in range(1,4):
        bit = i & 1
        if bit:
            sm += ABCD[j]
            ans.append('+')
            ans.append(str(ABCD[j]))
        else:
            sm -= ABCD[j]
            ans.append('-')
            ans.append(str(ABCD[j]))
        i = i >> 1
    ans.append('=7')
    if sm == 7:
        print(''.join(ans))
        exit()





Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int upper(long long *, int);
int lower(long long *, int);

int main(void){
    int N;
    cin >> N;
    long long ary[100000];
    for(int i=0; i<N; i++){
        cin >> ary[i];
    }
    int idx=0;
    int cnt=0;
    while(1){
        int a = upper(ary+idx, N-idx);
        int b = lower(ary+idx, N-idx);
        if(a < b){
            idx += b+1;
        }else{
            idx += a+1;
        }
        cnt++;
        if(idx > N-1){
            cout << cnt;
            return 0;
        }
    }


    return 0;
}

int upper(long long *a, int size){
    int i=0;
    for(; i<size-1; i++){
        if(a[i] > a[i+1]){
            return i;
        }
    }
    return i+1;
}

int lower(long long *a, int size){
    int i=0;
    for(; i<size-1; i++){
        if(a[i] < a[i+1]){
            return i;
        }
    }
    return i+1;
}

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

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

	ll k;cin >> k;
	ll n;cin >> n;
	vector<ll> a(n);
	vector<ll> sa(n);
	cin >> a[0];
	ll max = -1;
	for(int i = 1; i < n; i++){
		cin >> a[i];
		sa[i-1] = a[i] - a[i-1];
		if(max < sa[i-1]){
			max = sa[i-1];
		}
	}
	sa[n-1] = k - a[n-1] + a[0];
	if(max < sa[n-1]){
		max = sa[n-1];
	}
	ll ans = 0;
	for(int i = 0; i < n; i++){
		ans += sa[i];
	}
	ans -= max;
	cout << ans << endl;
}


Measured memory_bytes: 3456
#include <cstdio>
#include <vector>
using std::vector;

template <class T>
struct FenwickTree
{
    vector<T> dat;

    explicit FenwickTree(int size): dat(++size, 0) {}

    void add(int i, const T &v)
    { while (i < dat.size()) dat[i]+=v, i += i&-i;
    }

    T sum(int i) {
        T ret = 0;
        while (i > 0) ret+=dat[i], i -= i&-i;
        return ret;
    }
    inline T sum(int s, int t) { return sum(t) - sum(s-1); }
};

int main()
{
    int n, q;
    int com, x, y;
    scanf("%d %d", &n, &q);

    FenwickTree<int> ft(n);

    while(q--) {
        scanf("%d %d %d", &com, &x, &y);
        if (com == 0) ft.add(x, y);
        else printf("%d\n", ft.sum(x, y));
    }

}



Measured memory_bytes: 2712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;
        Integer cnt = 0;
        List<Integer> inputs = new ArrayList<>();
        while ((line = br.readLine().trim()) != null && !line.isEmpty()) {
            if (cnt == 0) {
                if("0".equals(line)) System.exit(0);
                cnt = Integer.parseInt(line);
                continue;
            }
            inputs.add(Integer.parseInt(line));
            if (--cnt == 0) {
                output(inputs.stream().sorted().collect(Collectors.toList()));
                inputs.clear();
            }
        }
    }

    public static void output(List<Integer> inputs) {
        int sum = 0;
        for(int i : inputs.subList(1, inputs.size()-1)) {
            sum+=i;
        }
        System.out.println(sum/(inputs.size()-2));
    }
}

Measured memory_bytes: 31092
class Combination():
    # コンストラクタ
    def __init__(self, N:int, P:int):
        self.N = N
        self.P = P

        # fact[i] = (i! mod P)
        self.fact = [1, 1]   
        # factinv[i] = ((i!)^(-1) mod P)
        self.factinv = [1, 1]
        # factinv 計算用
        self.inv = [0, 1]    

        for i in range(2, N+1):
            self.fact.append((self.fact[-1] * i) % P)
            self.inv.append((-self.inv[P % i] * (P // i)) % P)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % P)
    
    # nCk (mod P)   (ただし、n<=N)
    def getComb(self, n:int, k:int):
        if (k < 0) or (n < k):
            return 0
        k = min(k, n - k)
        return self.fact[n] * self.factinv[k] * self.factinv[n-k] % self.P

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

MOD = 10**9 + 7

COMB = Combination(N, MOD)

cmb = [0] * (N - K + 1)
for i in range(N - K + 1):
    cmb[i] = COMB.getComb(i + (K - 1), K - 1)

sum_max = 0
for i in range(K - 1, N):
    sum_max = (sum_max + A[i] * cmb[i - (K - 1)]) % MOD

sum_min = 0
for i in range(N - K, -1, -1):
    sum_min = (sum_min + A[i] * cmb[(N - K) - i]) % MOD

ans = sum_max - sum_min
print(ans % MOD)

Measured memory_bytes: 22180
#include<bits/stdc++.h>
#define lb long double
#define N 100010 
using namespace std;
struct Po{lb x,y;}a[N];
int n;
lb ansn;
Po operator -(Po x,Po y){return (Po){x.x-y.x,x.y-y.y};}
lb operator *(Po x,Po y){return x.x*y.y-x.y*y.x;}
void get(Po &x){scanf("%Lf %Lf",&x.x,&x.y);}
int pa(int x){if (x>n)x-=n;return x;}
lb le(Po x){return sqrtl(x.x*x.x+x.y*x.y);}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) get(a[i]);
	for (int i=1,j=2;i<=n;i++){
		while((a[pa(i+1)]-a[i])*(a[j]-a[i])<=(a[pa(i+1)]-a[i])*(a[pa(j+1)]-a[i]))j=pa(j+1);
		ansn=max(ansn,max(le(a[j]-a[i]),le(a[j]-a[pa(i+1)])));
	}
	printf("%.10Lf\n",ansn);
	return 0;
} 


Measured memory_bytes: 5620
#include <iostream>
#define INF 1e+9
using namespace std;

typedef pair<int,int> P;

P dp[33][33][33][33];
int h,w,s,u[33][33] = {},sum = 0;

int calc(int x1,int y1,int x2,int y2){
	return u[x2][y2] - u[x1][y2] - u[x2][y1] + u[x1][y1];
}

P dfs(int x1,int y1,int x2,int y2){
	if(dp[x1][y1][x2][y2].first >= 1 || sum - calc(x1,y1,x2,y2) > s) return dp[x1][y1][x2][y2];
	for(int i = y1 + 1;i < y2;i++){
		P p1 = dfs(x1,y1,x2,i),p2 = dfs(x1,i,x2,y2),p = P(p1.first + p2.first,min(p1.second,p2.second));
		dp[x1][y1][x2][y2] = max(dp[x1][y1][x2][y2],p);
	}
	for(int i = x1 + 1;i < x2;i++){
		P p1 = dfs(x1,y1,i,y2),p2 = dfs(i,y1,x2,y2),p = P(p1.first + p2.first,min(p1.second,p2.second));
		dp[x1][y1][x2][y2] = max(dp[x1][y1][x2][y2],p);
	}
	if(dp[x1][y1][x2][y2].first <= 0) dp[x1][y1][x2][y2] = P(1,s - sum + calc(x1,y1,x2,y2));
	return dp[x1][y1][x2][y2];
}

int main(){
	while(cin >> h >> w >> s,h){
		sum = 0;
		for(int i = 1;i <= h;i++){
			for(int j = 1;j <= w;j++){
				cin >> u[i][j];
				sum += u[i][j];
				u[i][j] += u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1];
			}
		}
		for(int i = 0;i <= h;i++){
			for(int j = 0;j <= w;j++){
				for(int k = 0;k <= h;k++){
					for(int l = 0;l <= w;l++){
						dp[i][j][k][l] = P(-INF,-INF);
					}
				}
			}
		}
		dfs(0,0,h,w);
		cout << dp[0][0][h][w].first << " " << dp[0][0][h][w].second << endl;
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int x=0, y=0, z=0;  // z:4n y:2n
  rep(i,n) {
    int num;
    cin >> num;
    if (num%2) ++x;
    else if (num/2%2) ++y;
    else ++z;
  }
  if (2*z + max(1,y) >= n) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

int cnt = 0;


void solve()
{
	ll q, h, s, d; cin >> q >> h >> s >> d;
	ll n; cin >> n;
	ll mn = min(n * q * 4, n * h * 2);
	mn = min(mn, n * s);
	if (n % 2 == 0)
	{
		mn = min(mn, (n / 2LL) * d);
	}
	else
	{
		mn = min(mn, (n / 2LL) * d + min(4LL * q, min(2LL * h, s)));
	}
	cout << mn;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back



int main(){
    int n,k;cin>>n>>k; vector<int> v;int ans = 0;
    for(int i = 0; i < n; i++){
        int temp;
        cin>>temp;
        v.pb(temp);
    }
    sort(v.begin(),v.end());

    for(int i = n-1; i >=n-k; i--){
        ans += v[i];
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MN 30005
using namespace std;
int n,num,ans[MN];
int main(){
	scanf("%d",&n);
	if(n==3){puts("2 5 63");}
	else {
		ans[++num]=2;ans[++num]=4;
		for(int i=6;num+2<=n&&i+3<=30000;i+=12)ans[++num]=i-3,ans[++num]=i+3;
		for(int i=6;num+2<=n&&i+4<=30000;i+=6)ans[++num]=i+2,ans[++num]=i+4;
		for(int i=6;num+1<=n&&i<=30000;i+=6)ans[++num]=i;
		for(int i=1;i<=num;i++)printf("%d ",ans[i]);
	}
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    int n; cin>>n;
    vector<int> p(n);
    int sum=0;
    rep(i,0,n){
        cin>>p[i];
        sum+=p[i];
    }
    sort(all(p));
    reverse(all(p));
    cout<<sum-p[0]/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

ll eval(ll x) {
    if(x % 3 == 0 || x % 5 == 0) {
        return 0;
    } else {
        return x;
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll sum = 0;
    ll n;
    cin >> n;
    for(int i = 1; i <= n; i ++) {
        sum += eval(i);
    }
    cout << sum << endl;
    return 0;
}




Measured memory_bytes: 3648
//author: Harsh :)
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  ll n=0;
  cin>>n;
  ll ar[n];
  for(ll i=0;i<n;++i) cin>>ar[i];
  bool f=true;
  for(ll i=0;i<n;++i){
    if(ar[i]%2==0 and (ar[i]%3!=0 and ar[i]%5!=0)){
      f=false;
      break;
    }
  }
  if(f) cout<<"APPROVED";
  else cout<<"DENIED";
  return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

struct edge{
    int from, to; lint cost;
    edge(int f, int t, lint c) : from(f), to(t), cost(c) {}
    edge(int t, lint c) : from(-1), to(t), cost(c) {}
};

struct dijkstra{
    vector<vector<edge> > G;
    vector<lint> d;
    int V, s;
    dijkstra(vector<vector<edge> > _G, int _s) : G(_G), s(_s){
        init();
    }
    void init(){
        V = G.size();
        d = vector<lint>(V, INF);
        priority_queue<P, vector<P>, greater<P> > que; que.push(P(0, s));
        d[s] = 0;
        while(!que.empty()){
            P p = que.top(); que.pop();
            int v = p.second;
            if(d[v] < p.first) continue;
            for(int 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 dist(int t){
        return d[t];
    }
};

int main(){
    int n,m,s,t; cin>>n>>m>>s>>t;
    s--; t--;
    vector<vector<edge> > ga(n), gb(n);
    rep(i,m){
        lint u,v,a,b; cin>>u>>v>>a>>b;
        u--; v--;
        ga[u].push_back(edge(v,a));
        ga[v].push_back(edge(u,a));
        gb[u].push_back(edge(v,b));
        gb[v].push_back(edge(u,b));
    }

    dijkstra da(ga, s), db(gb, t);
    
    vector<P> vp;
    const lint L = 1e15;
    rep(i,n){
        lint c = da.d[i] + db.d[i];
        vp.push_back(P(L-c, i));
    }

    sort(all(vp), [](P& l, P& r){
        return l.fi > r.fi;
    });

    int j = 0;
    rep(i, n){
        while(vp[j].se < i){
            j++;
        }
        out(vp[j].fi);
    }
}


Measured memory_bytes: 40504
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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 (b < a) { a = b; return 1; } return 0; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;



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

	string s;
	cin >> s;

	int ans = 0;

	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
	{
		cout << 3 << endl;
	}
	else if (s[0] == 'R' && s[1] == 'R' || s[1] == 'R' && s[2] == 'R')
	{
		cout << 2 << endl;
	}
	else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
	{
		cout << 1 << endl;
	}
	else
		cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
typedef long long           ll;
typedef vector<int>         vi;
typedef vector<ll>          vll;

#define ff                  first
#define sf                  scanf
#define pf                  printf
#define ss                  second
#define ppb                 pop_back
#define pb                  push_back
#define MP                  make_pair
#define MAXN                10000
#define MOD                 100000007
#define inf                 0x3f3f3f3f
#define PI                  (2.0*acos(0.0))
#define INF                 0x3f3f3f3f3f3f3f3f
#define rev(v)              reverse(all(v))
#define all(v)              v.begin(), v.end()
#define __lcm(x, y)         (x * y) / __gcd(x, y)
#define FOR(i, x, y)        for(int i = x; i < y; i++)
#define RFOR(i, x, y)       for(int i = x; i >= y; i--)
#define MEM(arr, val)       memset(arr, val, sizeof(arr));
#define unq(v)              (v).resize(unique(all(v)) - v.begin())
#define READ()              freopen("input.txt", "r", stdin)
#define WRITE()             freopen("output.txt", "w", stdout)
#define si(n)               scanf("%d", &n)
#define sl(n)               scanf("%lld", &n)
#define sii(a, b)           scanf("%d %d", &a, &b)
#define sll(a, b)           scanf("%lld %lld", &a, &b)
#define siii(a, b, c)       scanf("%d %d %d", &a, &b, &c)
#define slll(a, b, c)       scanf("%lld %lld %lld", &a, &b, &c)
#define siiii(a, b, c, d)   scanf("%d %d %d %d", &a, &b, &c, &d)
#define sllll(a, b, c, d)   scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define vout(v)             for(int i = 0; i < v.size(); i++) {cout << v[i]; if(i < v.size() - 1) cout << ' '; else cout << endl;}

int main(){
        ll a, b, c, k; sllll(a, b, c, k);
        ll sum = 0;
        if(k > 0){
            sum += min(k, a);
            k -= a;
        }

        if(k > 0){
            k -= b;
        }

        if(k > 0){
            sum -= min(k, c);
        }
        cout << sum << endl;



    return 0;
}

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

typedef tuple<int,int> P;

signed main(){
  
  int N;
  cin>>N;
  
  vector<P> V;

  for(int i=0;i<N;i++){
    int a, b;
    cin>>a>>b;
    V.push_back(P(b,a));
  }
  
  sort(V.begin(),V.end());
  
  int t = 0;
  
  for(int i=0;i<N;i++){
    
    int a, b;
    tie(b,a) = V[i];
    
    t += a;
    
    if( t > b ){
      cout<<"No"<<endl;
      return 0;
    }
    
  }

  cout<<"Yes"<<endl;
  
  return 0;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,flag=1;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int num;
		cin >> num;
		if(num%2==0)
		{
			if(num%3==0||num%5==0) continue;
			else flag=0;
		}
	}
	if(!flag) cout<<"DENIED\n";
	else cout<<"APPROVED\n";
	return 0;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
# import itertools
N = int(input())
K = int(input())

L = list(str(N))
leng = len(L)
st = int(L[0])
cnt = 0

#N(3003)と左桁数(0)をもらってOKな桁数(3)とその数値を返す
def keta(n,l):
    for i in range(l,leng):
        d = n[i]
        if d=='0':
            continue
        else:
            return (i,int(d))
    return -1,-1

if K==1:
    cnt += st
    cnt += 9*(leng-1)
elif K==2:
    i,d = keta(L,1)
    if not i==-1:
        cnt += d + 9*(leng-i-1)

    cnt += (st-1)*9*(leng-1) + 9*9*(leng-1)*(leng-2)//2
else:
    i_1,d_1 = keta(L,1)
    i_2,d_2 = keta(L,i_1+1)
    if not i_1==-1:
        a = (leng-i_1-1)
        cnt += (d_1-1)*9*a
        cnt += 9*9*(a*(a-1)//2)
    if not i_2==-1:
        cnt += d_2 + 9*(leng-i_2-1)
    cnt += (st-1)*9*9*(leng-1)*(leng-2)//2 + (9**3)*(leng-1)*(leng-2)*(leng-3)//6
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;

int main(){
    string N;
    cin>>N;
    int n=stoi(N);
    int size=N.size();
    int sum=0;
    rep(i,size){
        sum+=N[i]-48;
    }
    if(n==(int)pow(10,size-1)){
        cout<<10<<endl;
    }else{
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
x,y,a,b,c = list(map(int, input().split()))
r = sum(sorted(sorted(list(map(int, input().split())), reverse = True)[:x] + sorted(list(map(int, input().split())), reverse = True)[:y] + list(map(int, input().split())), reverse = True)[:x+y])
# g = sorted(list(map(int, input().split())), reverse = True)[:y]
# c = sorted(list(map(int, input().split())))
# rc = 0
# gc = 0
# for i in range(x+y):
#     if(r[0]<g[0]):
#         if(rc<x):
#             if(r[0]<)
print(r)

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

using namespace std;
using i64 = int64_t;
#define int i64
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const i64 INFL = (1LL << 62);
const i64 MOD = 1000000007;

#undef int
int main() {
#define int i64
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 1001) {
    int c1 = i / 100;
    int c2 = i / 10 % 10;
    int c3 = i % 10;
    int c1_index = -1;
    rep(j, n) {
      if (s[j] == (c1 + '0')) {
        c1_index = j;
        break;
      }
    }
    if (c1_index == -1) continue;
    int c2_index = -1;
    for (int j = c1_index + 1; j < n; ++j) {
      if (s[j] == (c2 + '0')) {
        c2_index = j;
        break;
      }
    }
    if (c2_index == -1) continue;
    int c3_index = -1;
    for (int j = c2_index + 1; j < n; ++j) {
      if (s[j] == (c3 + '0')) c3_index = j;
    }
    if (c3_index == -1) continue;
    ans++;
  }
  cout << ans << endl;

  return 0;
}

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


int main() {
    long long n;
    long long a;
    long long b;
    double x;
    cin >> n;
    long long min = n;
    x = sqrt(n);
    for(long long i = 1; i <= x; i++) {
         if(n % i == 0) {
             b = n / i;
            min = ((i + b - 2 < min)?  i + b - 2 : min);
         }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAX=100001;

int parent(int i) {
  return i/2;
}
int left(int i) {
  return 2*i;
}
int right(int i) {
  return 2*i+1;
}
int main() {
  int H;
  cin>>H;
  int A[MAX];
  for (int i=1; i<=H; i++) {
    cin>>A[i];
  }
  for (int i=1; i<=H; i++) {
    cout<<"node "<<i<<": key = "<<A[i]<<", "<<flush;
    if (parent(i)>=1) {
      cout<<"parent key = "<<A[parent(i)]<<", "<<flush;
    }
    if (left(i)<=H) {
      cout<<"left key = "<<A[left(i)]<<", "<<flush;
    }
    if (right(i)<=H) {
      cout<<"right key = "<<A[right(i)]<<", "<<flush;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
char m[55][55];

int main(){
  int h,w;
  cin >> h >> w;
  rep(i,h) cin >> m[i];
  rep(i,h) rep(j,w){
    if(m[i][j]=='#'){
    if(i>0&&m[i-1][j]=='#') continue;
    else if(i<h-1&&m[i+1][j]=='#') continue;
    else if(j>0&&m[i][j-1]=='#') continue;
    else if(j<w-1&&m[i][j+1]=='#') continue;
    else{cout << "No" << endl; return 0;}
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string S;
    cin >> S;
    if(S=="zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }
    map<char,int> m,m2;
    rep(i,S.size()){
        m[S[i]]++;
    }
    if(m.size()<26){
        string ans = S;
        for(char c='a';c<='z';c++){
            if(m[c]==0){
                ans+=c;
                cout << ans << endl;
                return 0;
            }
        }
    }else{
        for(int i=25;i>0;i--){
            if(S[i]>S[i-1]){
                string ans = S.substr(0,i-1);
                rep(i,ans.size()){
                    m2[ans[i]]++;
                }
                for(char c=S[i-1]+1;c<='z';c++){
                    if(m2[c]==0){
                        ans+=c;
                        break;
                    }
                }
                cout << ans << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

using namespace std;

string a[7]={"SUN","MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main()
{
    string str;
    cin>>str;
    for(int i = 0;i<7;i++)
    {
        if(a[i]==str)cout<<7-i;
    }
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
count = 0
end_flg = 0

while end_flg == 0:
    for i in range(N):
        if(A[i]%2 == 0):
            A[i] = A[i]//2
        else:
            end_flg = 1
            break

    count+=1

print(count-1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <array>
using namespace std;

int main(void){
    int N, M; cin >> N >> M;
    bool c[8][8] = {0};
    array<int, 8> arr;
    for(int i = 0; i < M; i++){
        int a, b; cin >> a >> b;
        c[--a][--b] = true; c[b][a] = true;
    }
    for(int i = 0; i < N; i++) arr[i] = i;

    int res = 0;
    do{
        // cout << "permutation: ";
        // for_each(arr.begin(), arr.begin()+N, [](auto x){cout << x << ' ';});
        // cout << '\n';

        for(int i = 0; i < N-1; i++){
            // cout << "---" << arr[i] << ' ' << arr[i+1] << '\n';
            if(not c[arr[i]][arr[i+1]]) break;
            if(i == N-2){
                res++;
                // cout << "res is incremented\n";
            }
        }
    }while(next_permutation(arr.begin()+1, arr.begin()+N));

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX_V 1000000
int prime[MAX_V+1];
int main(){
	int i,k,v;
	for(i=2;i<=MAX_V;i++){
		prime[i]=1;
	}
	for(i=2;i*i<=MAX_V;i++){
		if(prime[i]){
			for(k=2*i;k<=MAX_V;k+=i){
				prime[k]=0;
			}
		}
	}
	for(i=2;i<=MAX_V;i++){
		prime[i]+=prime[i-1];
	}
	while(scanf("%d",&v)!=EOF){
		printf("%d\n",prime[v]);
	}	
	return 0;
}

Measured memory_bytes: 5664
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
//cout << fixed << setprecision(8) << a << endl;
//cout << "Case " << ca << ": " << ans << endl;
#define Fast_Input ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define MX 100005
#define infinity 20000000
#define pb push_back
#define ll long long int
int main()
{
    ll n,i,j;
    cin >> n;
    map < ll,ll>m;
    vector < ll > v;

    for(i=1; i<=n; i++)
    {
        ll x;
        cin >> x;
        v.push_back(x);
        m[x]++;
    }
    ll sum=0;
    for(auto x: m)
    {
        ll z;
        z=x.second;
        z--;
        ll ans=((z*(z+1))/2);
        sum+=ans;
    }

    for(i=0; i<n; i++)
    {
        ll z;
        z=m[v[i]];
        if(z>1)
        {
            ll ans=((z*(z-1))/2);
            ll now=sum-ans;
            z=z-2;
            now+=((z*(z+1))/2);
            cout << now << endl;
        }
        
        else 
        {
            cout << sum << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 11120
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct Node{
    int l;
    int r;
}a[1000000];
int n,h,c;
bool cmp(Node p,Node q){
    return p.l>q.l;
}
int main(){
    scanf("%d%d",&n,&h);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[c++].l);
        a[c].r=1;
        scanf("%d",&a[c++].l);
    }
    stable_sort(a,a+c,cmp);
    int sum=0;
    for(int i=0;i<c;i++)
    {
        if(a[i].r==1)
        {
            sum++;
            h-=a[i].l;
            if(h<=0)
            {
                printf("%d",sum);
                return 0;
            }
        }
        else if(a[i].r!=1)
        {
            if(h%a[i].l==0) sum+=h/a[i].l;
            else sum+=h/a[i].l+1;
            printf("%d",sum);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
  if (a < b) std::swap(a, b);
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
  llong g = gcd(a, b);
  return a * b / g;
}
//ここまで共通
string S;
llong N;
llong ANS = 0;
llong A[500100] = { 0 };
int main() {
	cin >> S;
	N = S.length() + 1;
	for (llong i = 0; i < N - 1; i++) {
		if (S[i] == '<') {
			A[i + 1] = A[i] + 1;
		}
	}
	for (llong i = N - 2; i >= 0; i--) {
		if (S[i] == '>') {
			A[i] = max(A[i], A[i + 1] + 1);
		}
	}
	for (llong i = 0; i < N; i++) {
		ANS += A[i];
	}
	
	cout << ANS << endl;
}

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

int main(){
  int x, n;
  cin >> x >> n;
  int p[n];
  int dif = 1000;
  int ans;
  rep(i,n) cin >> p[i];
  for(int c = 101; c >= 0; c--) {
    bool f = true;
    rep(i,n) {
      if(c == p[i]) f = false;
    }
    if(f) {
      if(abs(x-c) <= dif) {
        dif = abs(x-c);
        ans = c;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
    int i,j,k,t;

    char str[7];

    cin >> str;

    if(str[2]==str[3] && str[4]==str[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<list>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		list<pair<int,int> >L;
		L.push_back(make_pair(-1,2e9));
		for(int i=0;i<n;i++)
		{
			char c;cin>>c;
			if(c=='W')
			{
				int s,l;cin>>s>>l;
				for(auto it=L.begin();l>0&&it!=L.end();it++)
				{
					if(it->first==-1)
					{
						if(it->second>l)
						{
							it->second-=l;
							L.insert(it,make_pair(s,l));
							break;
						}
						else
						{
							l-=it->second;
							it->first=s;
						}
					}
				}
			}
			else if(c=='R')
			{
				int l;cin>>l;
				for(auto it=L.begin();l>=0&&it!=L.end();it++)
				{
					l-=it->second;
					if(l<0)
					{
						cout<<it->first<<endl;
						break;
					}
				}
			}
			else
			{
				int l;cin>>l;
				for(auto it=L.begin();it!=L.end();it++)
				{
					if(it->first==l)it->first=-1;
				}
			}
		}
		cout<<endl;
	}
}



Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

typedef long long ll;
//typedef pair<ll, ll> P;

static const ll MOD = 1000000007;
//static const ll INF = 100000000;
//#define PI 3.14159265359


int main() {
    // input
    ll S, W;
    cin >> S >> W;

    // process
    if (S > W) {
        cout << "safe";
    } else {
        cout << "unsafe";
    }


    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;
typedef struct {
    double x, y, z;
} P;

double dot(P a, P b)
{
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

P diff(P f, P t)
{
    return P{ t.x - f.x, t.y - f.y, t.z - f.z };
}

P mul(P a, double s)
{
    return P{ a.x*s, a.y*s, a.z*s };
}

double dist(P a)
{
    return pow(dot(a, a), 0.5);
}

const double EPS = 1e-8;

int main()
{
    int n, q; cin >> n >> q;
    vector<P> p(n);
    vector<double> r(n);
    vector<ll> l(n);
    loop (n, i) cin >> p[i].x >> p[i].y >> p[i].z >> r[i] >> l[i];

    loop (q, i) {
        P s, t;
        cin >> s.x >> s.y >> s.z >> t.x >> t.y >> t.z;

        P st = diff(s, t), ts = diff(t, s);
        P n_st = mul(st, 1.0/dist(st));
        ll ans = 0;
        loop (n, j) {
            P sp = diff(s, p[j]), tp = diff(t, p[j]);
            if (dot(sp, st) < 0 || dot(tp, ts) < 0) continue;
            P n_sp = mul(n_st, dot(sp, n_st));
            double R = dist(diff(sp, n_sp));
            if (R < r[j] + EPS) ans += l[j];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=5e3+5;
char s[maxn];
ll dp[maxn][3];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin>>n;
    cin>>(s+1);
    if(n<=3)
    {
        cout<<0<<'\n';
        return 0;
    }
    //ll tol=n*(n-1)*(n-2)/6;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        dp[i][j]=dp[i-1][j];
        if(s[i]=='R')
            dp[i][0]++;
        else if(s[i]=='G')
            dp[i][1]++;
        else
            dp[i][2]++;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(s[i]==s[j])
               continue;
                char x='R'+'G'+'B'-s[i]-s[j];
                if(x=='R')
                {
                    sum+=dp[n][0]-dp[j][0];
                    if(j+j-i<=n&&s[j+j-i]=='R')
                    {
                        sum--;
                    }
                }
                else if(x=='G')
                {
                    sum+=dp[n][1]-dp[j][1];
                    if(j+j-i<=n&&s[j+j-i]=='G')
                    {
                        sum--;
                    }
                }
                else
                {
                    sum+=dp[n][2]-dp[j][2];
                    if(j+j-i<=n&&s[j+j-i]=='B')
                    {
                        sum--;
                    }
                }

        }

    }
    cout<<sum<<'\n';


}

Measured memory_bytes: 3668
def main():
  import sys
  input=sys.stdin.buffer.readline
  h,w=map(int,input().split())
  s=input()
  a=b=x=y=s[0]==35
  d=[(b,a)]
  d_add=d.append
  for i in range(1,w):
    f=s[i]==35
    b+=a^f and 1or 0
    a=f
    d_add((b,a))
  for _ in range(h-1):
    s=input()
    f=s[0]==35
    y+=x^f and 1or 0
    b=y
    a=x=f
    p=[(b,a)]
    p_add=p.append
    for i in range(1,w):
      f=s[i]==35
      b+=a^f and 1or 0
      c,g=d[i]
      c+=f^g and 1or 0
      if b>c:b=c
      a=f
      p_add((b,a))
    d=p
  print(b+1>>1)
main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

vector<int> v;


void f(int n){
  cout<<n<<':';

  FOR(i,1,v.size()){
    if(n%v[i]==0) cout<<' '<<v[i];
  }

  cout<<endl;
}


int main(){
  rep(i,45000){
    v.push_back(7*i+1);
    v.push_back(7*i+6);
  }

  rrep(i,v.size()){
    for(int j=1;v[j]*v[j]<=v[i]&&j<i;j++){
      if(v[i]%v[j]==0){
        v.erase(v.begin()+i);
        break;
      }
    }
  }


  while(1){
    int n;
    cin>>n;
    if(n==1) break;
    f(n);
  }


  return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> b(n);
    for(int i = 0; i < n; i++) cin >> b[i];
    vector<int> c(n-1);
    for(int i = 0; i < n-1; i++) cin >> c[i];
    
    for(int i = 0; i < n; i++) a[i]--;
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        //a[i]--にしていることに注意
        ans += b[a[i]];
    }
    for(int i = 0; i < n-1; i++){
        if(a[i]+1 == a[i+1]){
            ans += c[a[i]];
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
# define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	char c;
	cin>>c;
	if(isupper(c))
	cout<<'A'<<endl;
	else
	cout<<'a'<<endl;
	return 0;
}

Measured memory_bytes: 3608
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        ll n;
        cin>>n;
        cout<<n+n*n+n*n*n;
        



        cout<<'\n';
    return 0;
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Scanner.scanint[0];
            var w = Scanner.scanint;

            var min = 1 << 29;
            for(var t = 0; t < n - 1; t++)
            {
                var a = new int[n];
                var b = new int[n];
                Array.Copy(w, 0, a, 0, t + 1);
                Array.Copy(w, t + 1, b, 0, n - t - 1);
                var d = Math.Abs(a.Sum() - b.Sum());
                if (min > d) min = d;
            }
            Console.WriteLine(min);
        }
    }

    public class Scanner
    {
        public static string[] scan => Console.ReadLine().Split();
        public static int[] scanint => Array.ConvertAll(scan, int.Parse);
        public static long[] scanlong => Array.ConvertAll(scan, long.Parse);
    }
}


Measured memory_bytes: 13268
n = int(input())
nums = list(map(int, input().split()))
sum = 1
flag = 1
upper = pow(10, 18)
for num in nums:
  if num == 0:
    sum = 0
    flag = 1
    break
  if flag == 1:
    sum = sum * num
    if sum > upper:
      flag = 2

if flag == 1:
  print(sum)
elif flag == 2:
  print(-1)

Measured memory_bytes: 21776
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n){
        rep(i,n){
            double hour, mini;
            scanf("%lf%*c%lf", &hour, &mini);
            double angle1 = (hour * 300 + mini * 5);
            double angle2 = (mini * 60);
            double angle = sqrt((angle1 - angle2) * (angle1 - angle2));
            if(angle > 1800) angle = 3600 - angle;
            if(angle >= 0 && angle < 300)
                cout << "alert" << endl;
            else if(angle >= 900 && angle <= 1800)
                cout << "safe" << endl;
            else
                cout << "warning" << endl;
        }
    }
}

Measured memory_bytes: 1260
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vector<char> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int cnt = 1;
	rep(i, n - 1) {
		if (a[i + 1] != a[i])cnt++;
	}
	if (cnt == 3) {
		cout << "Three" << endl;
	}
	else {
		cout << "Four" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

int main()
{
  int n, m;
  std::map<std::string, int> cnt;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::string val;
    std::cin >> val;
    cnt[val]++;
    /*
    auto it = cnt.find(val);
    if (it == cnt.end()) {
      cnt[val] = 1;
    } else {
      cnt[val]++;
    }
    */
  }
  std::cin >> m;
  for (int i = 0; i < m; i++) {
    std::string val;
    std::cin >> val;
    cnt[val]--;
  }
  int result = 0;
  for (const auto& p : cnt) {
    result = std::max(result, p.second);
  }
  std::cout << result << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

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

    int N, K; cin >> N >> K;
    ll b = 0, x = 0;
    vector<int> f(100100, 0);
    priority_queue<LP> q;
    priority_queue<LP, vector<LP>, greater<LP>> q2;
    rep(i, N) {
        ll t, d; cin >> t >> d;
        t --;
        q.push(make_pair(d, t));
    }
    rep(i, K) {
        LP lp = q.top(); q.pop();
        b += lp.first;
        if(f[lp.second] == 0) x ++;
        f[lp.second] ++;
        q2.push(lp);
    }
    ll s = b + x * x;
    ll ans = s;
    while(!(q.empty())) {
        LP lp = q.top(); q.pop();
        if(f[lp.second]) continue;
        ll m = -1;
        while(!q2.empty()) {
            LP lp2 = q2.top(); q2.pop();
            if(f[lp2.second] > 1) {
                f[lp2.second] --;
                m = lp2.first;
                break;
            }
        }
        if(m == -1) break;
        x ++;
        f[lp.second] ++;
        b -= m;
        b += lp.first;
        s = b + x * x;
        ans = max(ans, s);
    }
    cout << ans << "\n";

    return 0;
}

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = 0;

	if (a <= b) ans += a;
	else ans += b;

	if (c <= d) ans += c;
	else ans += d;

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

Measured memory_bytes: 256