akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define LL long long
const int maxn = 1000 + 100;
struct Node {
    int x, y;
    Node() {}
    Node(int xx, int yy) {
        x = xx;
        y = yy;
    }
};

bool operator<(const Node &a, const Node &b) {
    if(a.x == b.x) {
        return a.y < b.y;
    }
    return a.x < b.x;
}

int n, ans;
Node a[maxn], b[maxn];
set<int> st;
set<int>::iterator it;

int main() {
    #ifdef LOCAL
    freopen("test.txt", "r", stdin);
//        freopen("out.txt", "w", stdout);
    #endif // LOCAL
    ios::sync_with_stdio(false);

    while(scanf("%d", &n) != EOF) {
        st.clear();
        ans = 0;
        for(int i = 0; i < n; ++i) {
            scanf("%d%d", &a[i].x, &a[i].y);
        }
        for(int i = 0; i < n; ++i) {
            scanf("%d%d", &b[i].x, &b[i].y);
        }
        sort(a, a + n);
        sort(b, b + n);
        int Index = n - 1;
        for(int i = n - 1; i >= 0; --i) {
            while(b[Index].x > a[i].x) {
                st.insert(b[Index].y);
                --Index;
            }
            it = st.upper_bound(a[i].y);
            if(it != st.end()) {
                ++ans;
                st.erase(it);
            }
        }
        printf("%d\n", ans);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e18);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n,cnt = 0;
    cin >> n;
    vector<ll> a(n + 1);
    ll c = 1;
    rep0(i, n + 1){
        cin >> a[i];
        if(c <= a[i] && i != n){
            pf(-1);
            return 0;
        }
        c -= a[i];
        if(c <= 1e9)c *= 2;
        cnt += a[i];
    }
    ll ans = 0,cnts = 1;
    rep0(i, n + 1){
        ans += cnts;
        cnt -= a[i];
        cnts -= a[i];
        if(cnts < 0){
            pf(-1);
            return 0;
        }
        cnts = min(cnts * 2,cnt);
    }
    pf(ans);
    return 0;
}


Measured memory_bytes: 4056
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

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

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




// ***************************************


int main(){

    int N;
    string S;

    cin >> N >> S;

    ll r, g, b;
    r = g = b = 0;
    for(auto c: S){
        if (c == 'R') r++;
        else if (c == 'G') g++;
        else b++;
    }

    ll all = r * g * b;
    ll sub = 0;

    REP(i, N){
        FOR(j, i + 1, N){
            ll k = 2 * j - i;
            if (k >= N) continue;

            if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) sub++;
        }
    }

    cout << all - sub << endl;

    return 0;
}


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

int parse(string a) {
	int l, r;
	l = r = 0;
	for (int b = 0; b < 4; b++) {
		l *= 10;
		l += a[b] - 48;
	}
	int b = 3;
	for (; b>-1; b--) {
		if (a[b] != '0')break;
	}
	for (int c = b; c!=-1; c--) {
		r *= 10;
		r += a[c] - 48;
	}
	return r - l;
}
int main() {
	while (1) {
		string a;
		cin >> a;
		if (a == "0000")break;
		if (a[0] == a[1] && a[1] == a[2] && a[2] == a[3]) { cout << "NA" << endl; continue; }
		for (int b = 0;; b++) {
			if (a == "6174") { cout << b << endl; break; }
			sort(a.begin(), a.end());
			a = to_string(parse(a));
		}
	}
}

Measured memory_bytes: 3276
#include <stdio.h>

int main() {

	int t[3];
	int p, q, r, i, min=300;

	scanf("%d", &p);
	scanf("%d", &q);
	scanf("%d", &r);

	t[0] = p + q;
	t[1] = q + r;
	t[2] = p + r;

	for (i = 0; i < 3; i++) {
		if (min > t[i])
			min = t[i];
	}

	printf("%d", min);

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,m;cin>>n>>m;
    vector<ll> edges[n];
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--;b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    bool selected[n]={}; 
    queue<pair<ll,ll> > que;
    deque<ll> res;
    res.push_front(0);
    selected[0]=true;
    res.push_front(edges[0][0]);
    que.push(make_pair(edges[0][0], 0));
    selected[edges[0][0]]=true;
    if(edges[0].size()>1){
        res.push_back(edges[0][1]);
        que.push(make_pair(edges[0][1],1));
        selected[edges[0][1]]=true;
    }
    while(!que.empty()){
        ll cur,front;
        cur = que.front().first;
        front = que.front().second;
        que.pop();
        for(auto x:edges[cur]){
            if(!selected[x]){
                DEBUG{
                    cout << "now : " << cur << " x : " << x << endl;
                    cout << "front : "<< front << endl;
                }
                if(front){
                    res.push_back(x);
                }else{
                    res.push_front(x);
                }
                que.push(make_pair(x, front));
                selected[x]=true;
                break;
            }
        }
    }
    cout << res.size() << endl;
    while(!res.empty()){
        ll tmp=res.front();
        res.pop_front();
        cout << (tmp+1);
        if(!res.empty()){
            cout<<" ";
        }else{
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 6948
N, Q = map(int, input().split())
S = str(input())
i = [0] * (N + 1)
j = 1
while j < N:
    i[j+1] = i[j] 
    if (S[j-1] == 'A' and S[j] == 'C'):
        i[j+1] += 1
    j += 1
k = 0
#print (i)
while k < Q:
    l, r = map(int, input().split())
    ans = i[r]-i[l]
    k += 1
    print (ans)

Measured memory_bytes: 6132
n=int(input())
s=input()
dp=[0]*(n+1)

for i in range(1,n+1):
  if s[i-1]==".":
    cnt=0
  else:
    cnt=1
  dp[i]=dp[i-1]+cnt
ans=n
for i in range(n+1):
  ans=min(ans,dp[i]+(n-i)-(dp[n]-dp[i]))
print(ans)

Measured memory_bytes: 76356
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORL(i,a,b) for(LL i=(a);i<(b);++i)
#define REPL(i,n)  FORL(i,0,n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

template<typename T>
T gcd(T a, T b) {
    if(a > b) swap(a, b);
    if(a == 0) return b;
    else return gcd(b%a, a);
}

template<typename T>
T lcm(T a, T b) {
    return (a / gcd(a, b)) * b;
}

template<typename T>
map<T, T> prime_list(T n) {
    map<T, T> ret;
    for(T i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            ret[i] = 0;
            while(n % i == 0) {
                n /= i;
                ret[i]++;
            }
        }
    }
    if(n != 1) ret[n]++;
    return ret;
}

#define MOD 1000000007

LL mypow(LL a, LL n) {
    if(n == 1) return a % MOD;
    if(n % 2 == 1) return (a * mypow(a, n-1)) % MOD;
    LL t = mypow(a, n/2);
    return (t * t) % MOD; 
}

int n, m;
VVI v;
bool ans;

void dfs(int i) {
    if(i == 0) {
        REP(j, v[0].size()) {
            dfs(v[0][j]);
        }
    } else {
        REP(j, v[i].size()) {
            if(v[i][j] == n-1) {
                ans = true;
                break;
            }
        }
    }
}

int main(void) {
    cin >> n >> m;
    v = VVI(n);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].push_back(b);
    }
    ans = false;
    dfs(0);
    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 8576
// ABC118_B
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    ll N;
    cin >> N;
    vector<ll> vec(N);
    REP(i, N) cin >> vec[i];
    
    // calculation
    if ((SUM(vec) - *MAX(vec)) > *MAX(vec)) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 764
# input
read N
read -a A

# check if there is 0 in A
declare flag=false

for (( i = 0; i < N; i++ )); do
  if [ ${A[i]} -eq 0 ]; then flag=true; break; fi
done

if "$flag"; then echo "0"; exit 0; fi

# calculate
declare -i ans=1

for (( i = 0; i < N; i++ )); do
  if [ $ans -gt $(( 10**18 / A[i] )) ]; then echo "-1"; exit 0; fi
  ans=$(( ans * A[i] ))
done

echo $ans

Measured memory_bytes: 24048
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

bool isSameSign(int a, int b) {
    if (a == 0 && b == 0) return true;
    if ((a > 0 && b > 0) || (a < 0 && b < 0)) return true;
    return false;
}

long calc(int[] a) {

    long _calc(int sign) {
        long ans = 0;
        int s = sign;
        int sum = 0;
        foreach (x; a) {
            sum += x;
//            writeln("sum ", sum, " s ", s);
            if (!isSameSign(sum, s)) {
                int y = sum * -1 + s;
                x = y;
//                writeln("y = ", y);
                ans += abs(x);
                sum += y;
            }
            s *= -1;
        }
//        writeln(">>> ", ans);
        return ans;
    }

    return min(_calc(1), _calc(-1));
}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}


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

int key[10000];
char alpha[100];
int main(){
  int n,j;
  int i;
  string s;
  for(i=0;i<52;i++){
    if(i>=26)
      alpha[i] = 'A'+i+6;
    else  alpha[i] = 'A'+i;
  }
  while(cin>>n,n){
    string ans;
    j = 0;
    for(i = 0;i<n;i++)cin>>key[i];
    cin>>s;
    int k = s.length();
    for(i = 0;i<k;i++){
      if(s[i]>='a')
	s[i] -= 'a'-'Z'-1;
      if(s[i]-key[j]-'A'>=0)
	s[i] = alpha[s[i] - key[j]-'A'];
      else{
	s[i] = alpha[s[i]-key[j]-'A'+52];
      }
      if(j >= n-1) j = 0;
      else j++;
    }
    cout<<s;
    cout<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    string S, T;
    cin >> S >> T;

    ll A, B;
    cin >> A >> B;

    string U;
    cin >> U;

    map<string, ll> mp;

    mp[S] = A;
    mp[T] = B;

    mp[U]--;

    cout << mp[S] << " " <<  mp[T] << endl;

    // if(ans){
    //     cout << "Yes" << endl;
    // }else{
    //     cout << "No" << endl;
    // }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(a >= k) cout << k << endl;
    else if(a+b >= k) cout << a << endl;
    else{
        int m = k-a-b;
        cout << a-m << endl;
    }
}

Measured memory_bytes: 3624
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
l, r, d = gets_i_list

count = 0
l.upto(r) do |i|
  if i % d == 0
    count += 1
  end
end

puts count


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

/*Range Add Min(Max) Query*/
/*区間加算、区間Min,区間Max*/

class RSAQ{
public: 
  typedef long long ll;

  //マージ可能な主データ型
  struct D{
    ll value;
    D():value(0){} /*適切な値にする!!!!!!*/
    D(ll value):value(value){}
    bool operator < (D a)const {return value < a.value;}
  };

  //遅延用の型  
  struct T{
    int type; //0 - empty   , 1 - update
    ll value;
    T():type(0),value(0){}
    T(int type,ll value):type(type),value(value){}
  };

  
  int n, n_;
  vector<D> dat;
  vector<T> td;
  D returnD = D(0); // 範囲外の時に返す値。
  
  RSAQ(){n=-1;}
  RSAQ(int n_):n_(n_){
    n=1;
    while(n < n_) n *= 2;
    td.resize(2*n-1,T());
    dat.resize(2*n-1,D());
  }
  
  inline D merge(const D a,const D b)const{return a.value + b.value;}
  
  void delay(int k,int len){
    if(td[k].type==0) return;
    ll type = td[k].type;
    ll v = td[k].value;
    td[k].type = 0;
    td[k].value = 0;
    len /= 2;
    {
      int l = k*2+1;
      dat[l].value += v * len;
      td[l].type = type;
      td[l].value += v;
    }
    {
      int r = k*2+2;
      dat[r].value += v * len;
      td[r].type = type;
      td[r].value += v;
    }
  }

  D write(int k, D x, int len){
    dat[k].value += x.value * len;
    td[k].type = 1;
    td[k].value += x.value;
    return dat[k];
  }
  
  D dfs(int a, int b, D x, bool flag, int k, int l, int r){
    if(r <= a||b <= l) return flag? dat[k]:returnD;
    if(a <= l && r <= b) return flag? write(k, x, r - l):dat[k];
    delay(k, r - l);
    D vl = dfs(a, b, x, flag, k*2+1, l, (l+r)/2);
    D vr = dfs(a, b, x, flag, k*2+2, (l+r)/2, r);
    return flag? (dat[k] = merge(vl, vr)):merge(vl, vr);
  }

  //[l,r)の値をx変更　query(l,r,x)
  void add(int l,int r,ll x){
    assert(l <= r);
    assert(0 <= l && l <= n);
    assert(0 <= r && r <= n);
    dfs(l, r, D(x), true, 0, 0, n);
  }
  
  //[l,r)の合計値を得る　find(a,b);
  ll get(int l,int r){
    assert(l <= r);
    assert(0 <= l && l <= n);
    assert(0 <= r && r <= n);
    D res = dfs(l, r, D(), false, 0, 0, n);
    return res.value;
  }
};


signed main(){
  int n,q;
  cin>>n>>q;
  
  RSAQ rsaq(n);

  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      int s,t,x;
      cin>>s>>t>>x;
      rsaq.add(s-1,t,x);
    }
    
    if(cmd == 1){
      int s,t;
      cin>>s>>t;
      cout<<rsaq.get(s-1,t)<<endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 8892
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) (v).erase( unique(all(v), (v).end() );
#define SZ(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

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

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return true;}return false;}

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    ll n, d;
    cin >> n >> d;
    ll cnt = 0;
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d) {
            cnt += 1;
        }
    }

    cout << cnt << newl;

    return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include<vector>
int n,q,k,a;
using namespace std;
int main(){
	vector<int> point(100006,0);cin >> n >> k >> q;
	for (int j = 0; j < q; j++) {
		cin >> a;++point[a - 1];
	}
	for (int i = 0; i < n; i++) {
		if (point[i] - q+k> 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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


int main()
{
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    
    sort(a.begin(),a.end());
    if(a[n-1]==a[n-2]){
        for(int i=0;i<n;i++)cout<<a[n-1]<<endl;
    }else{
        for(int i=0;i<n;i++){
            if(b[i]==a[n-1])cout<<a[n-2]<<endl;
            else cout<<a[n-1]<<endl;
        }
    }
    return 0;
}


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

int chk(int small, int big){
	int a1,cnt=0;
	for(a1=small;a1<=big;a1=a1*small){
		cnt+=(big/a1);
	}
	return cnt;
}

int main(){
	vector <int> prime;
	vector <int> cnt;
	int a1,a2,ans=0,n;
	cin>>n;
	for(a1=2;a1<=47;++a1){
		int pos=1;
		for(a2=2;a2*a2<=a1;++a2){
			if(a1%a2==0) {pos=0;break;}
		}
		if(pos) prime.push_back(a1);
	}

	int sz=prime.size();

	for(a1=0;a1<sz;++a1){
		cnt.push_back(chk(prime[a1],n));
		// cout<<cnt[a1]<<" ";

	}
	// cout<<"\n";

	for(a1=0;a1<sz;++a1) if(cnt[a1]>=74) ++ans;
	// cout<<ans<<"\n";

	int one=0,two=0,three=0;
	for(a1=0;a1<sz;++a1){
		if(cnt[a1]>=2) ++one;
		if(cnt[a1]>=24) ++two;
	}
	ans+=(two*(one-1));
	// cout<<ans<<"\n";

	one=0,two=0,three=0;
	for(a1=0;a1<sz;++a1){
		if(cnt[a1]>=4) ++one;
		if(cnt[a1]>=14) ++two;
	}
	ans+=(two*(one-1));
	// cout<<ans<<"\n";

	one=0,two=0,three=0;
	for(a1=0;a1<sz;++a1){
		if(cnt[a1]>=2) ++one;
		if(cnt[a1]>=4) ++two;
	}
	ans+=((two*(two-1))/2*(one-2));
	// cout<<ans<<"\n";

	cout<<ans;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
signed main () {
  double a,b,x,k,v,r;cin>>a>>b>>x;
  k=b/a;v=a*a*b;r=x/v;
  printf("%f",180/M_PI*atan(2*r<1 ? k/2/r : 2*k*(1-r)));}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<math.h>
using namespace std;

int main(){
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    
    int charge1, charge2, charge3;
    charge1=X*A+Y*B;
    charge2=max(X,Y)*2*C;
    int m=0;
    if(X>=Y){
        m=A;
    }else{
        m=B;
    }
    charge3=(max(X,Y)-min(X,Y))*(m) + min(X,Y)*2*(C);
    cout << min(charge1,min(charge2,charge3)) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 aa, bb, cc;
	cin >> aa >> bb >> cc;
	cout << (aa + bb + cc >= 22 ? "bust" : "win") << endl;
	return 0;
}

Measured memory_bytes: 3620
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int m=scn.nextInt();
		char [][]arr =new char[n][m];
		int sr =scn.nextInt();
		int sc =scn.nextInt();
		sr--;
		sc--;
		int dr =scn.nextInt();
		int dc=scn.nextInt();
		dr--;
		dc--;
		int cnt=0;
		while(cnt<n){
			String s =scn.next();
			arr[cnt]=s.toCharArray();
			cnt++;
		}
		System.out.println(find(sr,sc,arr,dr,dc));

	}
	// I have 5 choices either go any direction and if any one is block use the power...
	public static long find(int sr ,int sc , char[][]arr ,int dr ,int dc){
		PriorityQueue<pair>pq =new PriorityQueue<>();
		pq.add(new pair(sr,sc,0));
		int [][]arr1 =new int[arr.length][arr[0].length];
		int []r={0,0,1,-1};
		int []c={1,-1,0,0};
		int [][]dir={{-2,-2},{-2,-1},{-2,0},{-2,1},{-2,2},
					{-1,-2},{-1,-1},{-1,0},{-1,1},{-1,2},
					 {0,-2},{0,-1},{0,0},{0,1},{0,2},
					 {1,-2},{1,-1},{1,0},{1,1},{1,2},
					 {2,-2},{2,-1},{2,0},{2,1},{2,2}
					 };
		while(pq.size()>0){
			pair p1 =pq.remove();
			if(p1.r==dr&& p1.c==dc){
				return p1.cost;
			}
			if(arr1[p1.r][p1.c]==1){
				continue;
			}
			arr1[p1.r][p1.c]=1;
			// I have 4 directions choice and a magic choice
			for(int i=0;i<4;i++){
				int nr =p1.r+r[i];
				int nc=p1.c+c[i];
				if(isvalid(nr,nc,arr,arr1)){
					pq.add(new pair(nr,nc,p1.cost));
				}
			  
			}
			// using the power boom......
			for(int i=0;i<dir.length;i++){
			  int nr= dir[i][0]+p1.r;
			  int nc=dir[i][1]+p1.c;
			  if(isvalid(nr,nc,arr,arr1)){
					pq.add(new pair(nr,nc,p1.cost+1));
				}
			}
			 
		}
		
		return -1;
	}
	public static boolean isvalid(int r ,int c, char [][]arr ,int [][]arr1){
		if(r<0 || r>=arr.length ||c>=arr[0].length || c<0 || arr[r][c]=='#' ||arr1[r][c]==1 ){
			return false;
		}
		return true;
	}
	
	public static class pair implements Comparable<pair>{
		int r;
		int c;
		 long cost;
		 public pair(int r ,int c , long cost){
			 this.r=r;
			 this.c=c;
			 this.cost=cost;
			 
		 }
		 public int compareTo(pair o){
			 return (int)(this.cost - o.cost);
		 }
	}

}

Measured memory_bytes: 68656
#include <cstdio>
#include <cmath>
#include <complex>
#include <vector>
using namespace std;

typedef complex<double> point;
typedef const point &rpoint;

inline double cross(rpoint va, rpoint vb){
	return real(va) * imag(vb) - imag(va) * real(vb);
}

point intersect(rpoint pa1, rpoint pa2, rpoint pb1, rpoint pb2){
	point da12 = pa2 - pa1;
	point db21 = pb1 - pb2;
	point dab1 = pb1 - pa1;

	double t = cross(dab1, db21) / cross(da12, db21);
	return pa1 + t * da12;
}

double area(const vector<point> &p){
	double s = 0.0;
	for(int i = 2; i < p.size(); ++i){
		s += cross(p[i] - p[0], p[i-1] - p[0]);
	}
	
	return 0.5 * abs(s);
}

point a[32], b[32], c[32], d[32];
point intr[32][32];

int main(){
	int n;
	double ax, bx, cy, dy;
	
	a[0] = c[0] = point(0.0, 0.0);
	b[0] = point(0.0, 1.0);
	d[0] = point(1.0, 0.0);

	while( scanf("%d", &n), n != 0 ){
		for(int i = 1; i <= n; ++i){
			scanf("%lf", &ax);
			a[i] = point(ax, 0.0);
		}
		for(int i = 1; i <= n; ++i){
			scanf("%lf", &bx);
			b[i] = point(bx, 1.0);
		}
		for(int i = 1; i <= n; ++i){
			scanf("%lf", &cy);
			c[i] = point(0.0, cy);
		}
		for(int i = 1; i <= n; ++i){
			scanf("%lf", &dy);
			d[i] = point(1.0, dy);
		}

		a[n + 1] = point(1.0, 0.0);
		b[n + 1] = d[n + 1] = point(1.0, 1.0);
		c[n + 1] = point(0.0, 1.0);

		for(int i = 0; i <= n + 1; ++i){
			for(int j = 0; j <= n + 1; ++j){
				intr[i][j] = intersect(a[i], b[i], c[j], d[j]);
			}
		}
		
		double ans = 0.0;
		for(int i = 0; i <= n; ++i){
			for(int j = 0; j <= n; ++j){
				vector<point> p(4);
				p[0] = intr[i][j];
				p[1] = intr[i+1][j];
				p[2] = intr[i+1][j+1];
				p[3] = intr[i][j+1];
				
				ans = max(ans, area(p));
			}
		}
		printf("%f\n", ans);
	}
}

Measured memory_bytes: 1104
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		long N = sc.nextLong();
		long X = sc.nextLong();

		long a = X;
		long b = N - X;
		if (a < b) {
			long tmp = a;
			a = b;
			b = tmp;
		}

		long ans = N + f(a, b) - alast;
		System.out.println(ans);
	}

	private static long alast = 0;

	private static long f(long x, long y) {
		if (y == 0) {
			return 0;
		}
		alast = y;
		long ret = (x / y) * y * 2 + f(y, x % y);
		return ret;
	}
}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 8020
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

int main()
{
    long int H, W, N;
    cin >> H >> W >> N;
    long int a, b;
    vector<pair<long int, long int> > pairs(9*N);//黒のカウント用
    int flag=0;
    for (int i=0; i<N; i++){
        cin >> a >> b;
        for (int j=0; j<3; j++){
            for (int k=0; k<3; k++){
                if (a-j<=H-2 && a-j>=1 && b-k<=W-2 && b-k>=1){
                    pairs[flag] = make_pair(a-j, b-k);
                    flag++;
                }
            }
        }
    }
    long int max=10000000000;
    for (int c=flag; c<9*N; c++){
        pairs[c]=make_pair(max, max);
    }

    sort(pairs.begin(), pairs.end());
    
    int c_up=0;
    long int count[10];
    memset(count, 0, sizeof(count));
    int tmp=1;
    while(c_up!=flag){
        if(pairs[c_up].first==pairs[c_up+1].first && pairs[c_up].second==pairs[c_up+1].second){
            tmp++;
        }else{
            count[tmp]++;
            tmp=1;
        }
        c_up++;
    }
    count[0]=(H-2)*(W-2);
    for (int i=1; i<10; i++){
        count[0]-=count[i];
    }
    
    for (int i=0; i<10; i++){
        cout << count[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 14336
s = gets.to_i
n = gets.chomp.split("")
bw = Array.new(2,0)
ans = 10**6
s.times{|i| bw[0] += 1 if n[i] == "#"}
ans = bw[0]
for i in 1..s
  if n[-i] == "#"
    bw[0] -= 1
  else
    bw[1] += 1
  end
  ans = bw[0]+bw[1] if ans > bw[0]+bw[1]
end
puts ans


Measured memory_bytes: 16764
fn main() {
    proconio::input! {
        s: proconio::marker::Chars,
    }
    let mut min_times = std::usize::MAX;
    for &c in &s {
        let mut sdash = s.clone();
        let mut count = 0;
        loop {
            if sdash.len() == 1 || sdash.windows(2).all(|x| x[0] == x[1]) {
                break;
            }
            for i in 0..sdash.len() - 1 {
                if sdash[i + 1] == c {
                    sdash[i] = sdash[i + 1];
                }
            }
            sdash.pop();
            count += 1;
        }
        min_times = std::cmp::min(min_times, count);
    }
    println!("{}", min_times);
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 1000000000000000000

int main(void)
{
    string O, E;
    cin >> O >> E;
    for( int i = 0; i < E.length(); i++){
        cout << O[i] << E[i];
    }

    if( O.length() > E.length()) cout << O[O.length()-1];

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 文字列入力
'''
S = input()
A, B = input().split()
'''

# 文字列分解（['A', 'B', 'C']）
'''
S = list(input())
'''

# 整数入力
'''
X, Y, Z = map(int, input().split())
X, Y, Z = list(map(int, input().split()))
'''

# リストのユニーク化（順破壊）
'''
L = ['a', 'a', 'b']
L = list(set(L))
'''

# 固定長リスト最速初期化
'''
L = [None] * N
'''

# 二進数でフラグパターンを全種作成
'''
import numpy as np

N = 3
f = []

for i in range(0, 2**N):
    string = str(bin(i))[2:]
    f.append(['0'] * (N - len(string)) + list(string))

F = np.array(f)
F = (F == '1')
'''

import fractions
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)


N = int(input())
A = list(map(int, input().split()))
L = lcm(A) - 1

result = 0

for a in A:
    result += (L % a)

print(result)


Measured memory_bytes: 5564
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e8;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int f(vector<pair<int, int>> &v){
  sort(ALL(v));
  int ret = INF;
  REP(i, v.size()-1){
    if(v[i].second == 0 && v[i+1].second != 0){
      chmin(ret, v[i+1].first-v[i].first);
    }
  }
  return ret;
}
int f(map<int, vector<pair<int, int>>> &m){
  int ret = INF;
  for(auto p : m){
    chmin(ret, f(p.second));
  }
  return ret;
}

signed main() {
  int N;
  cin >> N;

  vector<int> x(N), y(N), d(N);
  REP(i, N){
    char c;
    cin >> x[i] >> y[i] >> c;
    if(c == 'U') d[i] = 0;
    if(c == 'R') d[i] = 1;
    if(c == 'D') d[i] = 2;
    if(c == 'L') d[i] = 3;
  }

  int ans = INF;
  REP(i, 4){
    {
      map<int, vector<pair<int, int>>> m;
      REP(i, N){
        if(d[i] != 0 && d[i] != 2) continue;
        m[x[i]].emplace_back(y[i], d[i]);
      }
      chmin(ans, f(m)*5);
    }
    {
      map<int, vector<pair<int, int>>> m;
      REP(i, N){
        if(d[i] != 0 && d[i] != 1) continue;
        m[x[i]+y[i]].emplace_back(y[i], d[i]);
      }
      chmin(ans, f(m)*10);
    }
    REP(i, N){
      int px = x[i], py = y[i];
      x[i] = py;
      y[i] = -px;
      d[i] = (d[i]+1)%4;
    }
  }

  if(ans == INF) cout << "SAFE" << "\n";
  else cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 29528
#include <iostream>
using namespace std;
int main()
{
	long long q,h,s,d,n,ans=0;
	cin>>q>>h>>s>>d>>n;
	if(q*2<h)h=q*2;
	if(h*2<s)s=h*2;
	if(s*2<d)d=s*2;
	n*=4;
	while(n>=8)n-=8,ans+=d;
	while(n>=4)n-=4,ans+=s;
	while(n>=2)n-=8,ans+=h;
	while(n>=1)n-=4,ans+=q;
	cout << ans<<"\n";
}

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

int main(){

	int n, cnt=0, i, j;
	int a[100000];

	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}

	for(i=0; i<n; i++){
		for(j=2; j<=sqrt(a[i]); j++){
			if(a[i]%j == 0){
				j=a[i];
			}
		}
		if(j!=a[i]+1){
			cnt++;
		}
	}

	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}


int main() {
    double r;
    cin>>r;

    cout<<fixed<<setprecision(20);
    cout<<r*6.28318530717958623200<<endl;
}



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

using namespace std;

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

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

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

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

  int n; cin >> n;
  vector<P> v(n);
  for(int i=0;i<n;++i) {
    cin >> v[i].second >> v[i].first;
  }
  sort(v.begin(), v.end());
  ll now = 0;
  bool ok = true;
  for(int i=0;i<n;++i) {
    if(now + v[i].second <= v[i].first) {
      now += v[i].second;
    } else {
      ok = false;
      break;
    }
  }
  cout << (ok ? "Yes":"No") << endl;
}


Measured memory_bytes: 1792
n = int(input())
ls = [input() for _ in range(n)]

ls_cn = [0] * 5

for i in range(n):
    if ls[i][0] == "M":
        ls_cn[0] += 1
    elif ls[i][0] == "A":
        ls_cn[1] += 1
    elif ls[i][0] == "R":
        ls_cn[2] += 1
    elif ls[i][0] == "C":
        ls_cn[3] += 1
    elif ls[i][0] == "H":
        ls_cn[4] += 1

x = 0

for j in range(2**5):
    ls_mul = []
    for k in range(n):
        if ((j >> k) & 1):
            ls_mul.append(ls_cn[k])
    
    if len(ls_mul) == 3:
        x += ls_mul[0] * ls_mul[1] * ls_mul[2]

print(x)

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


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    UnionFind uf(13);
    int a[6] = {3, 5, 7, 8, 10, 12};
    int b[3] = {6, 9, 11};
    int c[1] = {2};
    for (int i : a) uf.unite(1,i);
    for (int i : b) uf.unite(4,i);
    int x, y;
    cin >> x >> y;
    string ans = "No";
    if (uf.same(x, y)) ans = "Yes";
    cout << ans << endl;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  const lli mod = 1e9 + 7;

  lli n, m;
  while (cin >> n >> m) {
    if (1 < abs(n - m)) {
      cout << 0 << endl;
      continue;
    }

    lli x = 1;
    for (int i = 1; i <= n; ++i) {
      (x *= i) %= mod;
    }

    lli y = 1;
    for (int i = 1; i <= m; ++i) {
      (y *= i) %= mod;
    }

    if (n == m) {
      cout << (x * y * 2) % mod << endl;
    } else {
      cout << (x * y) % mod << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[]ss = S.toCharArray();
    
    int cou = 0;
    for(int i=0; i<S.length(); i++) {
    	if(i%2 == 0){
    		if(ss[i] == 'L') {
    			cou++;
    		}
    	}else {
    		if(ss[i] == 'R') {
    			cou++;
    		}
    	}
    }
   	if(cou==0) {
    		System.out.println("Yes");
    	}else {
    		System.out.println("No");
    	}
    	}
}

Measured memory_bytes: 35276
#include<iostream>
#include<cstring>
using namespace std;
char grip[3][4];
int main(){
	cin>>grip[0];cin>>grip[1];
	for(int j=0;j<3;j++)
		if(grip[0][j]!=grip[1][2-j]){cout<<"NO";return 0;}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


struct MinMonoid {
  using T = lint;
  static T op(const T& lhs, const T& rhs) { return min(lhs, rhs); }
  static constexpr T e() { return numeric_limits<T>::max(); }
};

template<class Monoid> struct SegmentTree {
  using M = Monoid;
  using T = typename M::T;

  const int n;

  SegmentTree(int n, const T& a = M::e()) : n(n), val(2 * n, a) {
    build();
  }

  template<class Itr> SegmentTree(Itr first, Itr last) :
    n(distance(first, last)), val(2 * n, M::e()) {
    copy(first, last, next(begin(val), n));
    build();
  }

  T& operator[](int i) {
    assert(0 <= i and i < n);
    return val[i + n];
  }

  void build() {
    for (int i = n - 1; i > 0; --i) {
      val[i] = M::op(val[2 * i], val[2 * i + 1]);
    }
  }

  T get(int l, int r) const {
    l = max(l, 0), r = min(r, n);
    T resl = M::e(), resr = M::e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = M::op(resl, val[l++]);
      if (r & 1) resr = M::op(val[--r], resr);
    }
    return M::op(resl, resr);
  }

  void set(int i, const T& a) {
    assert(0 <= i and i < n);
    for (val[i += n] = a, i >>= 1; i > 0; i >>= 1) {
      val[i] = M::op(val[2 * i], val[2 * i + 1]);
    }
  }

private:
  V<T> val;
};
using ST = SegmentTree<MinMonoid>;

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  V<lint> zero(n + 1), even(n + 1), odd(n + 1);
  for (int i = 0; i < n; ++i) {
    zero[i + 1] = zero[i] + a[i];
    even[i + 1] = even[i] + (a[i] == 0 ? 2 : a[i] & 1);
    odd[i + 1]  = odd[i]  + !(a[i] & 1);
  }

  ST ze(n + 1);
  for (int i = 0; i <= n; ++i) {
    ze[i] = zero[i] - even[i];
  }
  ze.build();
  ST oe(n + 1), ez(n + 1);
  for (int l = 0; l <= n; ++l) {
    ez[l] = even[l] - zero[l];
  }
  ez.build();
  for (int k = 0; k <= n; ++k) {
    oe[k] = odd[k] - even[k] + ez.get(k, n + 1);
  }
  oe.build();

  lint res = 9e18;
  for (int j = 0; j <= n; ++j) {
    lint curr = even[j] - odd[j] + ze.get(0, j + 1) + oe.get(j, n + 1) + zero[n];
    res = min(res, curr);
  }
  cout << res << '\n';
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string S;
  cin >> S;

  cout << "2018" << S.substr(4) << endl;
}

Measured memory_bytes: 3596