akhauriyash/Code-Regression huggingface dataset:
-- B
local function each_char(s)
    local f = function(_, i)
        i = i + 1
        if i <= #s then
            return i, string.sub(s, i, i)
        end
    end
    return f, nil, 0
end
local N,_ = io.read("n", "l")
local s = io.read("l")
local b,r = 0,0
for k,c in each_char(s) do
    if c == 'R' then
        r = r + 1
    else
        b = b + 1
    end
end
print(r>b and 'Yes' or 'No')

Measured memory_bytes: 888
n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
blue = [list(map(int, input().split())) for _ in range(n)]

red.sort(reverse=True, key=lambda x: x[1])
blue.sort()

ans = 0
for i in range(len(blue)):
    c, d = blue[i]
    for j in range(len(red)):
        a, b = red[j]
        if a < c and b < d:
            del red[j]
            ans += 1
            break
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if ((i + 1) % 2)
        {
            if (!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D'))
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            if (!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D'))
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

char u[] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
int v[] =  {1, 5, 10, 50, 100, 500, 1000};

int value_of (char c) {
  rep (i, 7) {
    if (c == u[i]) return v[i];
  }
}

int max_u(string s) {
  int ac = -1;
  int r = -1;
  rep (i, s.size()) {
    int vl = value_of(s[i]);
    if (ac < vl) {
      ac = vl;
      r = i;
    }
  }
  return r;
}

int read(string s) {
  if (s == "") return 0;
  int idx = max_u(s);
  int x = value_of(s[idx]);
  string t1 = s.substr(0, idx);
  string t2 = s.substr(idx + 1, s.size() - idx - 1);
  return -read(t1) + x + read(t2);
}

int main() {

  for (string s; cin >> s, cin; ) {
    cout << read(s) << endl;
  }

  return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>
int main(void)
{
	int h, w, n, max;
	scanf("%d", &h);
	scanf("%d", &w);
	scanf("%d", &n);
	max = h > w ? h : w;
	if (n % max) printf("%d", n / max + 1);
	else printf("%d", n / max);
}

Measured memory_bytes: 128
n, m = map(int, input().split())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return upper_divisors + lower_divisors[::-1]
m_divisor = make_divisors(m)
for i in m_divisor:
    if i <= m / n:
        print(i)
        exit()

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    ll ans;
    
    if (N >= M)
    {
        if (N == 1 && M == 1) 
            ans = 1;
        else if (M == 1)
            ans = N - 2;
        else 
            ans = (N - 2) * (M - 2);
    }
    else
    {
        if (N == 1)
            ans = M - 2;
        else 
            ans = (N - 2) * (M - 2);
    }
    
    cout << ans << endl;
}


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

int main () {
	long long h, w; cin >> h >> w;
    if (h > 1 && w > 1) cout << ((h * w + 1) >> 1);
    if (h == 1 || w == 1) cout << 1;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        long A=a/x;
        if(a%x==0)A--;
        long B=b/x;
        long ans = B-A;
        System.out.println(ans);
    }
}


Measured memory_bytes: 9808
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int n, m, k; cin >> n >> m >> k;
    ll a[n], b[m];
    ll sumA[n + 1], sumB[m + 1];//sum 0 < x < i
    sumA[0] = 0; sumB[0] = 0;
    rep(i, n) cin >> a[i], sumA[i + 1] = sumA[i] + a[i];
    rep(i, m) cin >> b[i], sumB[i + 1] = sumB[i] + b[i];
    int ans = 0;
    rep(i, n + 1) {
        if(sumA[i] > k) continue;
        int key = upper_bound(sumB, sumB + (m + 1), k - sumA[i]) - sumB;
        ans = max(i + key - 1, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 9824
n,c,k=map(int,input().split())
t=sorted([int(input()) for i in range(n)])
ans=0
j=0
e=0
for i in t:
    if j==0:
        j=1
        e=i+k
        ans+=1
    elif e<i:
        j=1
        e=i+k
        ans+=1
    else:
        j+=1
    if j==c:
        j=0
print(ans)


Measured memory_bytes: 8280
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
    int n, a;
    cin >> n >> a;

    n %= 500;
    if(n > a) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;

    vector<vector<int>> table(n, vector<int>(10));
    for (auto& row : table)
    {
        for (auto& elem : row)
        {
            cin >> elem;
        }
    }

    vector<vector<int64_t>> price(n, vector<int64_t>(11));
    for (auto& row : price)
    {
        for (auto& elem : row)
        {
            cin >> elem;
        }
    }

    int64_t best_cost = std::numeric_limits<int64_t>::min();

    for (int i = 1; i < (1 << 10); i++)
    {
        int64_t cost = 0;
        for (int j = 0; j < n; j++)
        {
            int cj = 0;
            for (int k = 0; k < 10; k++)
            {
                if (table[j][k] == 1 && ((i & (1 << k)) != 0))
                {
                    cj++;
                }
            }
            cost += price[j][cj];
            // cerr << cj << " " << cost << endl;
        }
        best_cost = std::max<int64_t>(best_cost, cost);
    }
    cout << best_cost << endl;
}


Measured memory_bytes: 256
a, b, k = map(int, input().split())

flag = True
for i in range(k):
    if flag:
        if a % 2 == 1:
            a -= 1
        b += a // 2
        a = a // 2
        flag = False
    else:
        if b % 2 == 1:
            b -= 1
        a += b // 2
        b = b // 2
        flag = True
print(a, b)

Measured memory_bytes: 61640
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) {
		cout << "Left" << endl;
	}
	else if (a + b == c + d) {
		cout << "Balanced" << endl;
	}
	else cout << "Right" << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 998244353
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	inp(n) inp(s)
	inpa(a,n)
	vector<vector<int>> dp(n+1,vector<int>(s+1));
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		fo(j,s+1)
			dp[i][j]=(dp[i-1][j]*2)%mod;
		for(int j=0;j+a[i-1]<=s;j++)
		{
			dp[i][j+a[i-1]]+=dp[i-1][j];
			dp[i][j+a[i-1]]%=mod;
		}
	}
	cout<<dp[n][s]<<'\n';
	printclock;
}

Measured memory_bytes: 73688
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd( T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
template<typename T>T lcm(T a, T b){return a * b / gcd(a, b);}
static const double pi = 3.141592653589793;
lint power(lint N, lint P, lint M){if(P==0) return 1;if(P%2==0){lint t = power(N, P/2, M);return t*t % M;}return N * power(N, P-1, M);}
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**/int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位

class unionfind{
public:
	vector<int> table;
	vector<int> wod;
	void init(int size){
		table.resize(size);
		wod.resize(size);
		rep(i,size)table[i]=i,wod[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(12);
	int a,b,c;
	in(a,b,c);
	if(a<b&&b<c)out("Yes");
	else out("No");
	return 0;
}



Measured memory_bytes: 3224
using namespace std;

#include <bits/stdc++.h>

int main(){
    int N;
    cin >> N;
    int previous = -2;
    int A[N + 7];
    int B[N + 7];
    int C[N + 7];
    int ans = 0;
    for ( int i = 0; i < N; i ++ ){
        int k;
        cin >> k;
        A[i] = k - 1;
    }
    for ( int i = 0; i < N; i ++ ){
        cin >> B[i];
    }
    for ( int i = 0; i < N - 1; i ++ ){
        cin >> C[i];
    }
    for ( int i = 0; i < N; i ++ ){
        ans += B[A[i]];
        if ( A[i] == previous + 1 ) ans += C[A[i] - 1];
        previous = A[i];
    }
    cout << ans;
}


Measured memory_bytes: 256
# ?§£?????????????????????????????????????????????

a, b = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

ans = 0
b.times do |i|
  len = 0
  as.each do |n|
    if n == bs[i]
      i += 1
      len += 1
    end
  end

  ans = [len, ans].max
end

puts ans

Measured memory_bytes: 8968
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int a;
	cin>>a;
	if(a<1200) cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;
return 0;
}


Measured memory_bytes: 256
import numpy as np
n,m,x = map(int, input().split())
costs = []
understnding = []
ans = 10 ** 20

for _ in range(n):
    tmp = list(map(int, input().split()))
    costs.append(tmp[0])
    understnding.append(tmp[1:])
    
costs = np.array(costs)
understnding = np.array(understnding)

for i in range(1, 2**n):
    row = str(bin(i)).split("0b")[1]
    row = '0'*(n - len(row))+row
    one_index = [j for j in range(len(row)) if row[j] =="1"]
    cost_sum = np.sum(costs[one_index])
    under_sum = np.sum(understnding[one_index], axis=0)
    if np.all(under_sum >= x) and cost_sum < ans:
        ans = cost_sum
    
if ans == 10 ** 20:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 27404
#include <bits/stdc++.h>
#define pb(a)           push_back(a)
#define ll              long long int
#define scd(a)          scanf("%d",&a)
#define mp(a,b)         make_pair(a,b)
#define scl(w)          scanf("%I64d",&w)
#define scdd(a,b)       scanf("%d %d",&a,&b)
#define srt(a)          sort(a.begin(),a.end())
#define rsrt(a)         sort(a.rbegin(),a.rend())
#define scll(a,b)       scanf("%I64d %I64d",&a,&b)
///4direction ->        int del_x[]={-1,0,1,0},del_y[]={0,1,0,-1};
#define input(v,n)      for (int i=0;i<n;i++){int a;cin >> a;v.push_back(a);}
#define inputll(v,n)    for (ll i=0;i<n;i++){ll a;cin >> a;v.push_back(a);}
#define vii             vector < int >
#define vll             vector < ll >
#define pii             pair < int , int >
#define pll             pair < ll , ll >
#define mk              make_pair
#define inf8            100000008
#define inf18           1000000000000000018
#define MAX             10000001

using namespace std;
 int main()
 {
     ll x,s=0,y;
     cin>>x;
     y=x;
     while(x!=0){
        s+=x%10;
        x/=10;
     }
     if(y%s==0){
        cout<<"Yes"<<endl;
     }
     else{
        cout<<"No"<<endl;
     }

 }


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

const int INF = 0x3f3f3f3f;
const int MAXN = 112345;

int n, k;
int a[MAXN], b[MAXN], c[MAXN];
int pd[MAXN][3];

int rec(int cur, int last)
{
	if(cur>=n)
		return 0;

	if(pd[cur][last])
		return pd[cur][last];

	if(last==0)
		return pd[cur][last] = max(b[cur]+rec(cur+1,1), c[cur]+rec(cur+1,2));

	if(last==1)
		return pd[cur][last] = max(c[cur]+rec(cur+1,2), a[cur]+rec(cur+1,0));

	if(last==2)
		return pd[cur][last] = max(b[cur]+rec(cur+1,1), a[cur]+rec(cur+1,0));

	return max(b[cur]+rec(cur+1,1), max(c[cur]+rec(cur+1,2), a[cur]+rec(cur+1,0)));
}

int main() {
	// memset(pd, -1 , sizeof(pd));

	cin >> n;

	for(int i=0; i<n; i++)
		cin >> a[i] >> b[i] >> c[i];

	cout << rec(0, -1) << endl;

	return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>

#define MAXN 100005

using namespace std;

vector<int> adj[MAXN];
int dp[MAXN];

int lp(int u) {
    if(dp[u] != -1) {
        return dp[u];
    }
    dp[u] = 0;
    for(int v : adj[u]) {
        dp[u] = max(dp[u], lp(v) + 1);
    }
    return dp[u];
}

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

    int n, m, u, v;
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        cin >> u >> v;
        adj[u].push_back(v);
    }
    memset(dp, -1, sizeof(dp));
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        ans = max(ans, lp(i));
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 11520
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))

    ans = X
    tmp = INF
    for n in range(X, 102):
        if abs(X-n) < tmp and not n in p:
            ans = n
            tmp = abs(X-n)
            break
    for n in reversed(range(-1, X)):
        if abs(X-n) <= tmp and not n in p:
            ans = n
            break
    
    print(ans)


if __name__ == '__main__':
    main()

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

int main( ) {
  string s,t;
  cin >> s >> t;
  
  // cout << s << " " << t << endl;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<int>());
  // cout << s << " " << t << endl;
  
  if(s < t) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100008][4];

/*int maxi(char a, int n)
{
	if(ca=='a')
		return max((n-1)+
*/
int s[100008][4];
int maxx(int n, int a)
{
	int b, c;
	if(a==1)
		{b=2, c=3;}
	else if(a==2)
		{b=1,c=3;}
	else
		b=1,c=2;

	if(n==1)
		return s[1][a];

	else if(dp[n][a]!=-1)
		return dp[n][a];
	//cout<<"YEET: "<<n<<" "<<a<<" "<<b<<" "<<c<<endl;

	return dp[n][a]=max(maxx(n-1,b), maxx(n-1,c))+s[n][a];
}

int main()
{
	int n;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=3; j++)
			cin>>s[i][j];
	}

	for(int i=1; i<=n; i++)
		for(int j=1; j<=3; j++)
			dp[i][j]=-1;

		//cout<<maxx(n,1);
	cout<<max(maxx(n,1),max(maxx(n,2),maxx(n,3)))<<endl;

	// for(int i=1; i<=n; i++)
	// 	{for(int j=1; j<=3; j++)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<endl;}

	//	cout<<maxx(,1);
		//cout<<max(maxx(3,2),maxx(3,3))+s[4][1];
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
void SRAND(){auto duration = std::chrono::system_clock::now().time_since_epoch();auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();srand(millis);}

ll n,x,c,u[N],k,ans;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	REP1(i,n+1)cin>>u[i];
	REP1(i,n){
		cin>>x;
		k=min(u[i],x);
		ans+=k;
		x-=k;u[i]-=k;
		k=min(u[i+1],x);
		ans+=k;
		x-=k;u[i+1]-=k;
	}
	cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 1024
//元の文字列と与えられたものを全て比較して数え上げる
//数え上げたやつが最も多かったやつを

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string oristr,str;
  cin >> oristr >> str;
  
  int count = 0;   //一番大きい数
  
  for (int i = 0; i < oristr.size() - str.size(); i++) {
     int precount = 0;//一時的に格納
     for (int j = 0; j < str.size(); j++) {
       if(oristr.at(i+j) == str.at(j) ){
      		precount++;
      	}
      }
      if(precount > count){
    	count = precount; 
    }
  }
  
  if(oristr.size() == str.size()){
     int precount = 0;//一時的に格納
     for (int j = 0; j < str.size(); j++) {
       if(oristr.at(j) == str.at(j) ){
      		precount++;
      	}
      }
      if(precount > count){
        count = precount; 
      }
  }
  
    cout << str.size() - count << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible" << "\n";
	else
		cout << "Impossible" << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main() {
	fast();

    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    inp(n);
    inpv(a, n);
    set <ll> s;
    ll cnt = 0;
    for(auto i:a){
        s.ins(i);
        if(s.find(i)==s.begin()){
            cnt++;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 11248
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 A, B;
    cin >> A >> B;
    if (A > 2 * B) cout << A - 2 * B << endl;
    else cout << 0 << endl;
}


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

#define LL long long
#define pa pair<int,int>
using namespace std;
const int inf = 2147483647;
const int N = 100001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

struct edge {
	int x, y, next;
} e[N]; int len, last[N];
int du[N], fa[N];

int findfa(int x) {
	if(fa[x] != x) fa[x] = findfa(fa[x]);
	return fa[x];
}

void ins(int x, int y) {
	e[++len].x = x, e[len].y = y;
	e[len].next = last[x], last[x] = len;
}

int main() {
	int n = read(), m = read();
	for(int i = 1; i <= m; i++) {
		int x = read(), y = read();
		ins(x, y), du[x]++, du[y]++;
	} for(int i = 1; i <= n; i++) if(du[i] & 1) {puts("No"); return 0;}
	for(int i = 1; i <= n; i++) if(du[i] >= 6) {puts("Yes"); return 0;}
	int sum = 0, hh;
	for(int i = 1; i <= n; i++) if(du[i] == 4) {sum++; hh = i;}
	if(sum >= 3) {puts("Yes"); return 0;}
	if(sum == 2) {
		for(int i = 1; i <= n; i++) fa[i] = i;
		for(int i = 1; i <= m; i++) if(e[i].x != hh && e[i].y != hh){
			int fx = findfa(e[i].x), fy = findfa(e[i].y);
			if(fx != fy) fa[fx] = fy;
		} int cnt = 0;
		for(int i = 1; i <= n; i++) cnt += findfa(i) == i;
		if(cnt >= 3) puts("Yes"); else puts("No");
	} else puts("No");
	return 0;
}



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

const int MAX = 200000;
int main() {
	int N, M;
	static int D[MAX], T[MAX];
	
	cin >> N;
	for (int i = 0;i < N;i ++) cin >> D[i];
	cin >> M;
	for (int i = 0;i < M;i ++) cin >> T[i];
	if (N < M) {
		cout << "NO";
		return 0;
	}
	sort(D, D+N);
	sort(T, T+M);
	for (int i = 0, j = 0;j < M && i < N;i ++) {
		if (D[i] == T[j]) {
			j ++;
			if (j >= M) {
				cout << "YES";
				return 0;
			}
		}
	}
	cout << "NO";
	return 0;
}

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




namespace contest
{

    class contest
    {


        static void Main(string[] args)
        {


      


           
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());

            var map = new int[3,3];
            map[0, 0] = a;
            map[0, 1] = b;
            map[1, 1] = c;

            
            
                
                for(int i=1; i<100; i++)
                {
                    int sum = calc(a, b, c, i);
                    map[2, 2] = sum - a - c;
                    map[0, 2] = sum - a - b;
                    map[2, 1] = sum - b - c;
                    map[1, 2] = sum - map[0, 2] - map[2, 2];
                    map[2, 0] = sum - map[0, 2] - map[1, 1];
                    map[1, 0] = sum - map[0, 0] - map[2, 0];

                    if (check(map)) break;
                }

                
            



            for(int i=0; i<3; i++)
            {
                for(int j=0; j<3; j++)
                {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }



        }

		 public static int calc(int a, int b, int c , int inc)
        {
            int mx = Math.Max(a+b, Math.Max(b+c,a+c));
            mx += inc;

            return mx;
        }

        public static bool check(int[,] map)
        {
            int tmp = 0;
            for (int i = 0; i < 3; i++) tmp += map[0,i];

            for(int i=1; i<3; i++)
            {
                int count = 0;
                for(int j=0; j<3; j++)
                {
                    count += map[i, j];
                }
                if (tmp != count) return false;
            }

            for (int i = 0; i < 3; i++)
            {
                int count = 0;
                for (int j = 0; j < 3; j++)
                {
                    count += map[j, i];
                }
                if (tmp != count) return false;
            }


            return true;
        }
        

    }


   

    
}


Measured memory_bytes: 2648
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288
 
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

int pref[1000075] ;
int main(){
    FAST_IO ;
    int D , T , S ; cin >> D >> T >> S ;
    if( S * T >= D )
        cout << "Yes" << endl ;
    else
        cout << "No" << endl ;
    return 0 ;
}
 

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt(),b = scanner.nextInt();
		if(a + b < 10){
			System.out.println((a+b));
		}else{
			System.out.println("error");
		}
	}

}


Measured memory_bytes: 21072
/*  -*- coding: utf-8 -*-
 *
 * 1368.cc: Quality of Check Digits
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int D = 10;
const int K = 4;

/* typedef */

/* global variables */

int xs[D][D], ps[K + 1];

/* subroutines */

int check(int n, int ps[]) {
  int c = 0;
  for (int i = 0; i < n; i++) c = xs[c][ps[i]];
  return c;
}

bool next(int ps[]) {
  int k = K - 1;
  while (k >= 0) {
    if (++ps[k] < D) break;
    ps[k--] = 0;
  }
  return (k >= 0);
}

void printps(int n, int ps[]) {
  for (int i = 0; i < n; i++) putchar('0' + ps[i]);
  putchar('\n');
}

/* main */

int main() {
  for (int i = 0; i < D; i++)
    for (int j = 0; j < D; j++) scanf("%d", &xs[i][j]);

  int cnt = 0;
  do {
    ps[K] = check(K, ps);
    //printps(K + 1, ps);

    bool ok = true;
    for (int k = 0; ok && k <= K; k++) {
      int pk = ps[k];
      for (int d = 0; ok && d < D; d++)
	if (pk != d) {
	  ps[k] = d;
	  ok = (check(K + 1, ps) != 0);
	  ps[k] = pk;
	}
    }

    for (int k = 0; ok && k < K; k++)
      if (ps[k] != ps[k + 1]) {
	swap(ps[k], ps[k + 1]);
	ok = (check(K + 1, ps) != 0);
	swap(ps[k], ps[k + 1]);
      }

    if (! ok) cnt++;
  } while (next(ps));

  printf("%d\n", cnt);
  return 0;
}



Measured memory_bytes: 3232
#include "bits/stdc++.h"

using namespace std;

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

const int ddx[] = { 0,1,1,  0,2, 1,-1,-2, 2, 2, -2,-2,1,-1,1,-1,2,2,-2,-2 };
const int ddy[] = { 2,1,-1,-2,0, 1, 1, 0,2, -2,  2,-2,2,2, -2,-2, 1,-1,1,-1 };


int main() {
	int H, W;
	cin >> H >> W;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	vector<string> S(H);
	for (int n = 0; n < H; ++n) {
		cin >> S[n];
	}

	vector<vector<int>> D(H, vector<int>(W, 1e9));//回数
	priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>> > q;
	q.push(make_pair(0, make_pair(ch, cw)));
	D[ch][cw] = 0;

	while (!q.empty()) {
		int x = q.top().second.first;
		int y = q.top().second.second;
		int z = q.top().first;
		q.pop();
		if ((x == dh) && (y == dw)) {
			cout << D[dh][dw] << endl;
			return 0;
		}
		if (D[x][y] < z) {
			continue;
		}
		//範囲内かつ0を4セット
		for (int l = 0; l < 4; ++l) {
			int x1 = x + dx[l];
			int y1 = y + dy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y]) {
					D[x1][y1] = D[x][y];
					pair<int, pair<int, int>> p = make_pair(D[x1][y1], make_pair(x1, y1));
					q.emplace(p);
				}
			}
		}
		//範囲内かつ0を20セット
		for (int l = 0; l < 20; ++l) {
			int x1 = x + ddx[l];
			int y1 = y + ddy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y]) {
					D[x1][y1] = D[x][y] + 1;
					pair<int, pair<int, int>> p = make_pair(D[x1][y1], make_pair(x1, y1));
					q.emplace(p);
				}
			}
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 16024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  string S,T;
  cin >> S >> T;

  int sz = S.size();

  //aはintで97
  bool used[26];
  fill(used,used+26,false);

  //cout << endl;
  for(int i=0;i<sz;i++){
    char s = S[i];
    char t = T[i];
    int temps = s-'a';
    int tempt = t-'a';
    if(s==t){
      used[temps] = true;
    }else{
      if(used[temps] || used[tempt]){
        cout << "No" << endl;
        return 0;
      }else{
        for(int j=i;j<sz;j++){
          if(S[j]==s) S[j]=t;
          else if(S[j]==t) S[j]=s;
          used[tempt] = true;
        }
      }
    }
    //cout << S << endl;
  }

  if(S==T){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
    int i;
    cin>>i;
    if(i==0)
    {

       cout<<1<<endl;
    }
    else
    {
       cout<<0<<endl;
    }
    return 0;
}

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

int main() {
	int N;
	int a[110];
	cin >> N;
	int i;
	for(i=0; i<N; ++i)
	{
	    cin >> a[i];
	}
	int Al=0;
	int Bo=0;
	int memo;
	for(int p=0; p<N; ++p)
	{
	 int max=0;
	 for(i=0; i<N; ++i)
	 {
	    if(max<a[i]) 
	    {
	        max=a[i];
	        memo=i;
	    }
	 }
	 a[memo]=0;
	 if(p%2==0) {Al=Al+max;}
	 else {Bo=Bo+max;}
	}
	cout << Al - Bo << endl;
	return 0;
}


Measured memory_bytes: 256
n,m,k = map(int,input().split())
al = [0 for i in range(n)]
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, a, b,l):
        x = self.find(a)
        y = self.find(b)
        l[a] -= 1
        l[b] -= 1

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(n)
for i in range(m):
    a,b = map(int,input().split())
    uf.union(a-1,b-1,al)
#print(al)
for i in range(k):
    c,d = map(int,input().split())
    if uf.find(c-1) == uf.find(d-1):
        al[c-1] -= 1
        al[d-1] -= 1
for i in range(n):
    print(uf.size(i)+al[i]-1,end=" ")

Measured memory_bytes: 8776
n=int(raw_input())
a=map(int,raw_input().split())
cnt=[0]*(max(a)+1)
for i in xrange(n):
    cnt[a[i]]+=1
for i in xrange(max(a)+1):
    while cnt[i]>=3:
        cnt[i]=cnt[i]/3+cnt[i]%3
ans=0
cnt1=0
cnt2=0
tmp=0
for i in xrange(max(a)+1):
    if cnt[i]==2:
        cnt2+=1
        tmp+=2
    if cnt[i]==1:
        cnt1+=1
if cnt2%2==1:
    print(cnt1+tmp/2-1)
else:
    print(cnt1+tmp/2)


Measured memory_bytes: 11304
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        h: [usize; n],
    }
    let mut m = 0;
    let mut cnt = 0;
    for i in (0..n-1).rev() {
        if h[i] >= h[i+1] {
            cnt+=1;
        } else {
            m = std::cmp::max(m, cnt);
            cnt=0;
        }
    }
    m = std::cmp::max(m, cnt);
    println!("{}", m);
}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int i##_to_ = (t), i = (f); i <= i##_to_; i++)
#define uptil(f, t, i)   for(int i##_to_ = (t), i = (f); i <  i##_to_; i++)
#define downto(f, t, i)  for(int i##_to_ = (t), i = (f); i >= i##_to_; i--)
#define downtil(f, t, i) for(int i##_to_ = (t), i = (f); i >  i##_to_; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 1
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '

class BIT {
    static constexpr int N = 131072/2;
    int node[N];
public:
    BIT() { times(N, i) node[i] = 0; }
    /** 0-based **/
    void set(int i, int v) {
        add(i, v - node[i]);
    }
    /** 0-based **/
    void add(int i, int v) {
        for(++i; i <= N; i += i & -i)
            node[i-1] += v;
    }
    /** [0, i) **/
    int sum(int i) {
        int s = 0;
        for(++i; i; i -= i & -i)
            s += node[i-1];
        return s;
    }
};

int A[48600], B[48600], C[48600];
int e0[48600], e[48600];

signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    int N; scanf("%d", &N);
    long nn = N * (N - 1) / 2;
    vector<pair<LD, int>> d0(N), d(N);

    times(N, i) {
        scanf("%d%d%d", &A[i], &B[i], &C[i]);
    }

    times(2, o) {
        times(N, i) d0[i] = make_pair((C[i] - (LD)A[i] * -1e9L) / B[i], i);
        if(debug) times(N, i) cout << d0[i].first ln;
        sort(d0.begin(), d0.end());
        if(debug) times(N, i) cout << d0[i].first ln;
        times(N, i) e0[d0[i].second] = i;
        if(debug) { times(N, i) cout << d0[i].first << "," << d0[i].second sp; cout ln; }

        LD l = -1e9L, r = 1e9L;
        times(100, oo) {
            LD m = (l + r) / 2;
            times(N, i) d[i] = {(C[i] - (LD)A[i] * m) / B[i], i};
            sort(begin(d), end(d));

            BIT bit;
            long a = 0;
            times(N, i) {
                int aj = e0[d[i].second];
                a += aj - bit.sum(aj);
                bit.add(aj, 1);
            }
            if(a < (nn + 1) / 2) l = m;
            else r = m;
        }

        cout << std::fixed << setprecision(30) << l << (o ? "\n" : " ");
        swap(A, B);
    }

    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <iomanip>

int main()
{
    int a, b;
    std::cin >> a >> b;
    std::cout << std::fixed;
    std::cout << a / b << ' '  << a % b << ' ' << std::setprecision(8) << static_cast<double>(a) / b << std::endl;
    return 0;
}



Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int maxn=100005,INF=0x3f3f3f3f,mod=1000000007;
struct QES{
	int v,d,c;
	QES(){}
	QES(int x,int y,int z){v=x;d=y;c=z;}
}qes[maxn];
int n,m,q,vis[maxn],col[maxn];
vi eg[maxn];
void dfs(QES nd){
	if(col[nd.v]==0) col[nd.v]=nd.c;
	if(nd.d==0) return;
	for(int i=0;i<eg[nd.v].size();i++){
		if(vis[eg[nd.v][i]]<nd.d-1){
			vis[eg[nd.v][i]]=nd.d-1;
			dfs(QES(eg[nd.v][i],nd.d-1,nd.c));
		}
	}
}
int main(){
	int t1,t2;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&t1,&t2);
		eg[t1].push_back(t2);
		eg[t2].push_back(t1);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++) scanf("%d%d%d",&qes[i].v,&qes[i].d,&qes[i].c);
	memset(vis,-1,sizeof(vis));
	for(int i=q-1;i>=0;i--){
		if(vis[qes[i].v]<qes[i].d){
			vis[qes[i].v]=qes[i].d;
			dfs(qes[i]);
		}
	}
	for(int i=1;i<=n;i++) printf("%d\n",col[i]);
	return 0;
}

Measured memory_bytes: 8440
N = int(input())
a = list(map(int, input().split()))
c = {1:0, 2:0, 4:0}
for i in range(N):
    if a[i] % 4 == 0:
        c[4] += 1
    elif a[i] % 2 == 0:
        c[2] += 1
    else:
        c[1] += 1
if c[2] > 0:
    c[1] += 1
if c[1] >= c[4] + 2:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 14252
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2155

#include <iostream>
#include <stdio.h>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

typedef tuple<int, int, int> data;

int main() {
  int N, M;
  while (scanf("%d%d", &N, &M) != EOF && N) {
    vector<data> V; 
    for (auto i=0; i<M; i++) {
      int t, s, d;
      scanf("%d%d%d", &t, &s, &d);
      V.push_back(make_tuple(t, s, d));
    }
    sort(V.begin(), V.end());
    bool I[20010];
    fill(I, I+20010, false);
    I[1] = true;
    int count = 1;
    for (auto i=0; i<M; i++) {
      int src = get<1>(V[i]);
      int dst = get<2>(V[i]);
      if (I[src] && !I[dst]) {
	I[dst] = true;
	count++;
	// cerr << "src = " << src << ", dst = " << dst << endl; 
      }
    }
    printf("%d\n", count);
  }
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define test ll t;cin>>t;while(t--)
#define rep(i,k,n) for(ll i=k;i<n;i++)
#define MOD 998244353
#define fast  ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define pb push_back
#define mod 1000000007
#define MAX 100000
ll inv_euclid(ll a, ll m = MOD) {ll m0 = m; ll y = 0, x = 1; if (m == 1)return 0; while (a > 1) {ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t;} if (x < 0)x += m0; return x;}
ll power(ll x, ll y, ll p)  { ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
ll max(ll a, ll b) {if (a > b)return a; return b;}
ll min(ll a, ll b) {if (a < b)return a; return b;}
ll ssum(ll n) {return (n * (n + 1)) / 2;}
ll gcd(ll a, ll b) {if (b == 0)return a; return gcd(b, a % b);}


void mult(ll a[][2] , ll b[][2]) {
	ll c[2][2];
	rep(i, 0, 2) {
		rep(j, 0, 2) {
			c[i][j] = 0;
			rep(k, 0, 2)
			c[i][j] = (c[i][j] % mod + ( a[i][k] * b[k][j]) % mod) % mod;
		}
	}
	rep(i, 0, 2)
	rep(j, 0, 2)
	a[i][j] = c[i][j];
}

ll fib(ll n, ll a, ll b) {
	ll I[2][2] = {{1, 0}, {0, 1}};
	ll A[2][2] = {{0, 0}, {1, (b / a)}};
	while (n) {
		if (n % 2)
			mult(I, A);
		mult(A, A);
		n /= 2;
	}
	return a * I[0][0] + b * I[1][0];
}



int main() {


	ll n;
	cin >> n;
	ll dp[n][3];
	cin >> dp[0][0] >> dp[0][1] >> dp[0][2];
	rep(i, 1, n) {
		ll a, b, c;
		cin >> a >> b >> c;
		dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}







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

int main(){
    int a,b,c,d,e ,i;
    cin >> a >> b >> c;
    vector<int> vec= { a, b, c};
    sort(vec.begin(), vec.end());
    std::cout <<vec[0] + vec[1] <<endl; 
return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

int gcd(int a,int b)
{
    if (b==0) return a;
    return gcd(b, a%b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    int n;
    cin >> n;
    ll ans = 0;
    REP(i,1,n+1) REP(j,1,n+1) REP(k,1,n+1)
    {
        ans += gcd(gcd(i,j),k);
    }
    cout << ans << endl;
}




Measured memory_bytes: 3640
import Control.Monad
import Control.Applicative
import Data.List
import Data.Maybe
import Data.Ratio
import Data.Int
import qualified Data.ByteString.Char8 as BS

listToTuple3 [a,b,c] = (a,b,c)
readIntBS = fst . fromJust . BS.readInt

main :: IO ()
main = do
  (n,a,b) <- listToTuple3 . map read . words <$> getLine :: IO (Int64,Int64,Int64)
  hs <- reverse . sort . map (fromIntegral . readIntBS) . BS.lines <$> BS.getContents :: IO [Int64]

  print $ solve hs a b 0 (ceiling $ (maximum hs) % b)
  
  where
    solve hs a b l r = if l+1>=r then r
      else if aux mid hs a b then solve hs a b l mid
      else solve hs a b mid r
      where
        mid = (l+r)`div`2

    aux x hs a b = (sum $ map (\y -> ceil y (a-b)) $ takeWhile (>=0) $ map (\h -> h-x*b) hs) <= x
    ceil a b = a `div` b + (if a `mod` b == 0 then 0 else 1)


Measured memory_bytes: 16764
n, x, = map(int, input().split())
m = [int(input()) for _ in range(n)]
x -= sum(m)
ans = n
while True:
    ans += (x // min(m))
    x = x % min(m)
    m.remove(min(m))
    if len(m) == 0 or x == 0:
        break
print(ans)

Measured memory_bytes: 3060
from collections import defaultdict


def num_combinations(_n):
    return _n * (_n - 1) // 2


if __name__ == '__main__':
    n = int(input())
    xs = [int(s) for s in input().split()]
    freq = defaultdict(int)

    for n in xs:
        freq[n] += 1

    total = sum([num_combinations(n) for n in freq.values()])
    for x in xs:
        print(total - (freq[x] - 1))


Measured memory_bytes: 26780
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    double mountain,high=0,low=10000;
    while(scanf("%lf",&mountain)!=EOF){
          //  cout<<mountain<<endl;
        if(mountain>high)high=mountain;
        if(mountain<low)low=mountain;
        //printf("%lf\n",high);
       // printf("%.1lf",high-low);
    }
    printf("%.1lf\n",high-low);
}

Measured memory_bytes: 1236