akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  string s;
  cin >> s;
  vector<int> rui(s.size() + 1);
  rui.back() = 0;
  int powten = 1;
  for (int i = s.size() - 1; i >= 0; i--) {
    int d = (int)(s[i] - '0');
    rui[i] = (rui[i + 1] + powten * d) % 2019;
    powten = (powten * 10) % 2019;
  }
  sort(all(rui));
  vector<pair<int, ll>> runlen;
  for (int i = 0; i < rui.size(); i++) {
    if (runlen.empty() || runlen.back().first != rui[i])
      runlen.emplace_back(rui[i], 1);
    else
      runlen.back().second++;
  }
  ll ans = 0ll;
  for (auto p : runlen) { ans += p.second * (p.second - 1ll) / 2ll; }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


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

struct data {
  long long a, b;
};

long long n;
string s;

void solve();
data calcor(int &id);
data calcand(int &id);
data calcterm(int &id);

int main() {
  cin >> s;
  n = s.size();
  solve();
  return 0;
}

void solve() {
  int id = 0;
  data res = calcor(id);
  cout << res.a << " " << res.b << endl;
}

data calcor(int &id) {
  data res = {0, (long long)1e10};
  vector<data> v;
  while(id < n) {
    v.push_back(calcand(id));
    if(s[id] == '|')
      ++id;
    else
      break;
  }
  for(int i = 0; i < v.size(); ++i) {
    res.b = min(res.b, res.a + v[i].b);
    res.a += v[i].a;
  }
  return res;
}
data calcand(int &id) {
  data res = {(long long)(1e10), 0};
  vector<data> v;
  while(id < n) {
    v.push_back(calcterm(id));
    if(s[id] == '&')
      ++id;
    else
      break;
  }
  res.a = v[0].a;
  for(int i = 0; i < v.size(); ++i) {
    res.a = min(res.a, res.b + v[i].a);
    res.b += v[i].b;
  }
  return res;
}

data calcterm(int &id) {
  data res = {1, 1};
  if(s[id] == '(') {
    res = calcor(++id);
    assert(s[id] == ')');
    ++id;
    return res;
  }
  assert(s[id] == '?');
  ++id;
  return res;
}


Measured memory_bytes: 3312
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

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

void dfs(vector<vector<int>> &G, int v, vector<bool> &visit) {
  visit[v] = true;
  int N = G.size();
  for(int j = 0; j < N; j++) {
    if (j != v && !visit[j] && G[v][j]) {
      dfs(G, j, visit);
    }
  }
}

int main() {
  string S;
  cin >> S;
  for (int i = 0; i < 1 << 3; i++) {
    int now = S[0] - '0';
    for (int j = 0; j < 3; j++) {
      if (i >> j & 1) {
        now += S[j + 1] - '0';
      } else {
        now -= S[j + 1] - '0';
      }
    }
    if (now == 7) {
      cout << S[0];
      for (int j = 0; j < 3; j++) {
        if (i >> j & 1) {
          cout << "+";
        } else {
          cout << "-";
        }
        cout << S[j + 1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,y,i,j;
  scanf("%d %d",&n,&y);
  
  for(i=0;i<=n;i++){
    for(j=0;j<=(n-i);j++){
      if(10000*i+5000*j+1000*(n-i-j)==y){
        printf("%d %d %d",i,j,n-i-j);
        return 0;
      }
    }
  }
  
  printf("-1 -1 -1");
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    ll n, k, ans = 0;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }
    vector<ll> p(n, -1);
    ll t = 0, cnt = 0;
    if(n < k){
        for(int i = 0; i <= n; i++){
            if(p[t] >= 0){
                break;
            }
            p[t] = i;
            t = a[t];
            cnt++;
        }
        k -= p[t];
        k %= (cnt - p[t]);
        cnt = p[t];
    }else{
        cnt = 0;
    }
    for(int i = 0; i < cnt; i++){
        ans = a[ans];
    }
    for(int i = 0; i < k; i++){
        ans = a[ans];
    }
    ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6392
N, M = map(int, input().split())
S = input()
if N <= M:
  print(N)
  exit()
if '1'*M in S:
  print(-1)
  exit()

from collections import deque
count = deque([])
for k in range(M+1):
  if S[k] == '1':
    count.append(-1)
  else:
    count.append(k)
sgn = deque([])
k = 0
while k < N:
  k += 1
  if S[k] == '0':
    sgn.append(M)
  else:
    d = 0
    while k < N:
      if S[k] == '1':
        k += 1
        d += 1
        continue
      else:
        break
    while d > 0:
      sgn.append(M-d)
      d -= 1
    sgn.append(M)
now = M
while now < N:
  now += 1
  a = sgn.popleft()
  if S[now] == '1':
    count.append(-1)
  else:
    count.append(a)
count = list(count)  
c = 0
ans = ''
while c < N:
  ans = str(count[-1-c]) + ' ' + ans
  c += count[-1-c]

print(ans)

Measured memory_bytes: 220792
#include <bits/stdc++.h>
#define MOD 1000000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
inline ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll char_to_ll(char c) { return (int)(c - '0'); }
inline ll string_to_ll(string s) { return atoi(s.c_str()); }
inline bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    vector<int> a(5);
    rep(i,0,5) cin >> a.at(i);
    rep(i,0,5){
        if(a.at(i) == 0){
            cout << i+1 << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3592
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const ll INF = (1 << 28);
const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    ll to, cost;
};
vector<ll> value; // ノードの値を持つ配列
ll N;             // 葉の数
 
void update(ll i, ll x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = max(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}
 
ll query(ll a, ll b, ll k, ll l, ll r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return 0; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return max(c1, c2); // 左右の子の値の min を取る
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans=0;
    vector <ll> h, a;
    N = 1;
    while (N <= n) N *= 2; // 葉の数を計算（n以上の最小の2冪数）
 
    value = vector<ll>(2 * N - 1,0);
    for (ll i = 0; i < n; i++)
    {
        ll s;
        cin >> s;
        h.push_back(s);
    }
    for (ll i = 0; i < n; i++)
    {
        ll s;
        cin >> s;
        a.push_back(s);
    }
    for (ll i = 0; i < n; i++)
    {
        ll sum=query(0,h[i],0,0,N);
        //cout<<sum<<"\n";
        ans=max(sum+a[i],ans);
        update(h[i],sum+a[i]);
    }
    cout << ans << "\n";
}



Measured memory_bytes: 8944
#include <stdio.h>

int main(void) {
	int a, b;
	scanf("%d%d", &a, &b);
	if (a * b >= a + b && a * b >= a - b) printf("%d",a * b);
	else if (a + b >= a * b && a + b >= a - b) printf("%d",a + b);
	else printf("%d",a - b);
	return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i) {
            continue;
        }
        ll m = i - 1;
        if (m && n / m == n % m) {
            ans += m;
        }
        m = n / i - 1;
        if (m && n / m == n % m) {
            ans += m;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
S=list(input())
if S[0]!='A' or S[2:-1].count('C')!=1:print('WA')
else:
    S.remove('A')
    S.remove('C')
    S=sorted(set(S))
    if 'a'<=S[0] and S[-1]<='z':
        print('AC')
    else:
        print('WA')

Measured memory_bytes: 3060
#include<iostream>
#include<set>
using namespace std;
typedef long long ll;

int main(){
    int n;
    while(cin >> n, n){
        set<pair<int,pair<int,int>>> s;
        for(int i = 0; i < n; i++){
            char c; cin >> c;
            if(c == 'W'){
                int id, t;
                cin >> id >> t;
                auto it = s.begin();
                int next = 0;
                while(t > 0){
                    if(it == s.end()){
                        s.insert({next, {id, t}});
                        break;
                    }
                    if(next < it->first){
                        s.insert({next, {id, min(it->first-next, t)}});
                        t -= min(it->first-next, t);
                    }
                    next = it->first + it->second.second;
                    it++;
                }
            }else if(c == 'D'){
                int id;
                cin >> id;
                auto it = s.begin();
                while(it != s.end()){
                    if(it->second.first == id) it = s.erase(it);
                    else                       it++;
                }
            }else if(c == 'R'){
                int pos;
                cin >> pos;
                auto it = s.lower_bound({pos, {0, 0}});
                if(it != s.end() && it->first == pos){
                    cout << it->second.first << endl;
                }else if(it != s.begin()){
                    it--;
                    if(it->first+it->second.second > pos){
                        cout << it->second.first << endl;
                    }else{
                        cout << -1 << endl;
                    }
                }else{
                    cout << -1 << endl;
                }
            }
            // cout << "[" << i << "]" << endl;
            // for(auto p : s) cout << "(" << p.first << "," << p.second.first << " " << p.second.second << ") ";
            // cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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


#define pi acos(-1)
int main() {
  ll x,k,d;cin >> x >> k >> d;
  x = abs(x);
  ll res = 0;
  if (x/d >= k) res = x-k*d;
  else if (((x/d)%2) == (k%2)) res = x%d;
  else res = d-(x%d);
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<ll, ll>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

/* -- template -- */

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 {
        cout << A - (K - A - B) << endl;
    }
}


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

int main(){
    int n; cin >>n;
    vector<int> p(100000);
    for(int i=0; i<n; i++) cin >> p[i];
    int ans = 0;

    for(int i=0; i<n; i++){
        if(i==n-1 && p[i]==i+1){
            ans++;
        }
        else if(p[i]==i+1){
            ans++;
            int tmp = p[i];
            p[i] = p[i+1];
            p[i+1] = tmp; 
        }
    }
    cout << ans << endl;
    return 0;
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<string, int> mp;
  string s;
  rep(i, n) {
    cin >> s;
    mp[s]++;
  }
  cin >> n;
  rep(i, n) {
    cin >> s;
    mp[s]--;
  }
  int ans = 0;
  for(auto x : mp) {
    chmax(ans, x.second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, d = gets.chomp.split.map(&:to_i)
poss = n.times.map { gets.chomp.split.map(&:to_i) }

cnt = 0
(0...n).each do |i|
    (i+1...n).each do |j|
        dist_sq = (0...d).map { |di| (poss[i][di] - poss[j][di]) ** 2 }.reduce(:+)
        dist = Math.sqrt(dist_sq)
        cnt = cnt + 1 if dist % 1 == 0
    end
end

puts cnt


Measured memory_bytes: 1788
from collections import deque
import copy
 
def main():
  H, W = map(int, input().split())
  M = [['#' == x for x in input()] for _ in range(H)]
  que = deque([(i, j) for i in range(H) for j in range(W) if M[i][j]])
  ans = 0
  while True:
    ans += 1
    qq = deque()
    while que:
      nh, nw = que.popleft()
      if nw < W-1 and not M[nh][nw+1]:
        qq.append((nh,nw+1))
        M[nh][nw+1] = True
      if nw > 0 and not M[nh][nw-1]:
        qq.append((nh,nw-1))
        M[nh][nw-1] = True
      if nh < H-1 and not M[nh+1][nw]:
        qq.append((nh+1,nw))
        M[nh+1][nw] = True
      if nh > 0 and not M[nh-1][nw]:
        qq.append((nh-1,nw))
        M[nh-1][nw] = True
    if qq:
      que = copy.copy(qq)
    else:
      break
  print(ans-1)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 115492
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k = 1, prevtype = 1;
    string s;
    cin >> s;
    for(int i = 1; i < s.size(); i++){
        if(s[i-1] == s[i] && prevtype == 1) {
            i++;
            prevtype = 2;
        }
        else {
            if((i == s.size()-2) && s[i] == s[i+1]){
                k++;
                break;
            }
            prevtype = 1;
        } 
        k++;
    }
    cout << k ;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define MOD 1000000007;

using namespace std;
using namespace __gnu_pbds;
//typedef tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//typedef tree<TYPE, null_type, less_equal<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

long long n, cnt;

int main(){
	//IO("input.txt", "output.txt");
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	if(n % 2 == 1){
		cout << "0\n";
		return 0;
	}
	for(long long i = 10; i <= n; i *= 5) cnt += n / i;
	cout << cnt << "\n";
 	return 0;
}

Measured memory_bytes: 256
a = gets.split.map(&:to_s)
stack = []

a.each do |s|
  if s == '+'
    a = stack.pop
    b = stack.pop
    stack.push(a+b)
  elsif s == '-'
    a = stack.pop
    b = stack.pop
    stack.push(b-a)
  elsif s == '*'
    a = stack.pop
    b = stack.pop
    stack.push(a*b)
  else
    stack.push(s.to_i)
  end
end
puts stack.pop


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

int main() {
	// your code goes here
	long long a,b,k;
	cin>>a>>b>>k;
	if(a>=k)
	{
		a-=k;
	}
	else 
	{
		long long left=k-a;
		if(b>=left)
			b-=left;
		else
			b=0;
		a=0;
	}
	cout<<a<<" "<<b;
	
	return 0;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string a;
  cin >> a;
  for (char c : a){
	cout << 'x';
  }
  cout << "\n";
return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x3f3f3f3f      //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf，sscanf, getchar, fgets之类的一起使用了。
const int dr[]= {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]= {-1, 1, 0, 0, -1, 1, -1, 1};
int read()//输入外挂
{
    int ret=0, flag=0;
    char ch;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        ret = ch - '0';
    while((ch=getchar())>='0'&&ch<='9')
        ret=ret*10+(ch-'0');
    return flag ? -ret : ret;
}
const int maxn=100005;
LL dist[maxn];
bool vis[maxn];
int head[maxn];
int tot,n;
int fa[maxn];

struct node
{
    int from,to;
    LL w;
    int next;
} edge[maxn*4];
struct Point
{
    int id;
    int x,y;

} p[maxn];

void add(int u,int v,LL w)
{
    edge[tot].from=u;
    edge[tot].to=v;
    edge[tot].w=w;
    edge[tot].next=head[u];
    head[u]=tot++;
}
int Find(int x)
{
    if(x==fa[x])
        return x;
    else
        return fa[x]=Find(fa[x]);
}
bool cmp1(Point a,Point b)
{
    return a.x<b.x;
}
bool cmp2(Point a,Point b)
{
    return a.y<b.y;
}
bool cmp3(node a,node b)
{
    return a.w<b.w;
}
int main()
{
    memset(head,-1,sizeof(head));
    for(int i=1; i<=maxn; i++)
        fa[i]=i;

    scanf("%d",&n);

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

    sort(p+1,p+n+1,cmp1);
    for(int i=2; i<=n; i++)
        add(p[i-1].id,p[i].id,p[i].x-p[i-1].x);

    sort(p+1,p+n+1,cmp2);
    for(int i=2; i<=n; i++)
        add(p[i-1].id,p[i].id,p[i].y-p[i-1].y);

    sort(edge,edge+tot,cmp3);
    int cnt=0;
    LL ans=0;
    for(int i=0; i<tot; i++)
    {
        int fu=Find(edge[i].from);
        int fv=Find(edge[i].to);
        if(fu!=fv)
        {
            fa[fu]=fv;
            cnt++;
            ans+=edge[i].w;
            if(cnt==n-1)
                break;
        }
    }
    printf("%lld\n",ans);
    return 0;

}


Measured memory_bytes: 7168
#include <iostream>]
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;



int main()
{
	long long  a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({ a * c,a * d,b * c,b * d });
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if (a>b){
    printf("%d",2*a-1);
  }else if(a==b){
    printf("%d",2*a);
  }else{
    printf("%d",2*b-1);
  }
  printf("\n");
}



Measured memory_bytes: 128
using System;
using System.Linq;

namespace AGC007
{
    class A
    {
        static void Main(string[] args)
        {
            long sum = 0;
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = input[0];
            int W = input[1];
            sum = H + W - 1;
            for (int h = 0; h < H; h++)
            {
                sum -= Console.ReadLine().ToCharArray().Count(x => x == '#');
            }
            if (sum == 0) Console.WriteLine("Possible");
            else Console.WriteLine("Impossible");
        }
    }
}


Measured memory_bytes: 13396
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder_Beginner_Contest_126
{
    class Program
    {
        struct tdst
        {
            public int top;
            public int dst;            
            public tdst(int top, int dst) { this.top = top; this.dst = dst; }
        }
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NM[0];//カード数
            var M = NM[1];//式の数
            var node = new List<tdst>[N + 1];
            for(int i=0;i<=N;++i)
            { node[i] = new List<tdst>(); }
            for (int i = 0; i < M; ++i)
            {
                var XYZ = Console.ReadLine().Split().Select(int.Parse).ToArray();
                node[XYZ[0]].Add(new tdst(XYZ[1], 0));
                node[XYZ[1]].Add(new tdst(XYZ[0], 0));
            }
            var chk = new int[N + 1];

            int cnt = 0;
            for (int i = 1; i <= N; ++i)
            {
                if (0 == chk[i])
                {
                    recv(i, node, chk);
                    ++cnt;
                }
            }
            Console.WriteLine(cnt);
        }
        static void recv(int next, List<tdst>[] node, int[] chk)
        {
            foreach (var nd in node[next])
            {
                if (0 != chk[nd.top]) continue;
                chk[nd.top] = 1;
                recv(nd.top, node, chk);
            }
        }
    }
}

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

using namespace std;

#define X first
#define Y second
#define eps  1e-2
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const LL  INF  = 1<<30;
const int mod  = 1e9+7;

string s1,s2;

void solve(){
    cin>>s1>>s2;
    int len = s1.size();
    int flag = 0;
    for(int i=0;i<len;i++){
        string s3="";
        for(int j=i;j<len;j++){
            s3 += s1[j];
        }
        for(int j=0;j<i;j++){
            s3 += s1[j];
        }
     //   cout<<s3<<endl;
        if(s2==s3){flag=1;break;}
    }


    if(flag){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return;
}

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int cas = 1,t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	char s[3];
	int x = 700;
	
	scanf("%s", s);
	
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o') {
			x += 100;
		}
	}
	
	printf("%d\n", x);
	
	return 0;
}

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

int main(){
  int n, m, l;
  cin >> n >> m >> l;

  int A[n][m], B[m][l];
  long long int C[n][l];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }

  long long int sum;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      sum = 0;
      for (int k = 0; k < m; k++) {
        sum += A[i][k] * B[k][j];
      }
      C[i][j] = sum;
    }
  }

 for (int i = 0; i < n; i++) {
   for (int j = 0; j < l; j++) {
     cout << C[i][j];
     if(j == l - 1) {
       cout << "";
     } else {
      cout << " ";
     }
   }
   cout << endl;
 }

  return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, x; cin >> n >> x;
    ll gg = __gcd(n, x);
    ll ans = 3 * (n - gg);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------


//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int x,a,b;cin>>x>>a>>b;
    if(abs(x-a)<abs(x-b))
        cout<<'A'<<endl;
    else
        cout<<'B'<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define foreach(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

string itos(ll x)
{
	char s[20];
	sprintf(s,"%lld",x);
	return s;
}

ll calc(ll x)
{
	ll res=0;
	for(ll i=1,t=1;t<=x;i++,t*=10)
		res+=i*(min(x+1,t*10)-t);
	return res;
}

int main()
{
	for(int n,k;cin>>n>>k && n|k;){
		ll lo=0,hi=1e9;
		while(lo<hi){
			ll mi=(lo+hi)/2;
			if(calc(mi)>=n)
				hi=mi;
			else
				lo=mi+1;
		}
		
		ll o=n-1-calc(lo-1);
		string res;
		for(ll x=lo;(ll)res.size()-o<k;x++)
			res+=itos(x);
		cout<<res.substr(o,k)<<endl;
	}
}

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

using ll = long long;

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    ll A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <cstring>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;


int main(){
    ll a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
 
#define int long long
#define MOD 1000000007
 
using namespace std;
 
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
 

 
void solve() {
    int n, x;
    cin >> x >> n;
    int a[n];
    set<int> s;
    for(int i = 0;i < n;i ++) {
        cin >> a[i];
        s.insert(a[i]);
    }
    int k = 0;
    while(true) {
        if(s.find(x - k) == s.end()) {
            cout << x - k << endl;
            return;
        }
        if(s.find(x + k) == s.end()) {
            cout << x + k << endl;
            return;
        }
        k++;
    }
}
 
int32_t main() {
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;
typedef pair<P,int>P2;

string s[21];
int h=21,w=17,sx,sy;
int dx[]={0,1,1,1,0,-1,-1,-1};
int dy[]={-1,-1,0,1,1,1,0,-1};
bool d[21][19][1<<20];

map<pair<int,int>,int>M1;
map<int,pair<int,int> >M2;
int cnt;

int main(){
  s[0]=s[20]=".................";
  r(i,h-2){
    cin>>s[i+1];
    s[i+1]="."+s[i+1]+".";
  }
  r(i,h)r(j,w)if(s[i][j]=='O'){
    sx=j;
    sy=i;
    s[i][j]='.';
  }else if(s[i][j]=='X'){
    M2[cnt]=P(i,j);
    M1[P(i,j)]=cnt++;
  }
  queue<P2>q;
  d[sy][sx][0]=1;
  q.push(P2(P(sy*1000+sx,0),0));
  while(!q.empty()){
    P2 p=q.front();q.pop();
    int y=p.first.first/1000;
    int x=p.first.first%1000;
    int cost=p.first.second;
    int bit=p.second;
    r(i,8){
      int ny=y+dy[i];
      int nx=x+dx[i];
      int b=bit;
      if(ny<=0||nx<=0||ny>=h||nx>=w-1)continue;
      if(s[ny][nx]=='.')continue;
      if((1<<M1[P(ny,nx)])&b)continue;
      while(s[ny][nx]=='X'){
	int c=M1[P(ny,nx)];
	if((1<<c)&b)break;
	b+=(1<<c);
	ny+=dy[i];
	nx+=dx[i];
      }
      if(ny<20&&(nx==0||nx==w-1))continue;
      if(d[ny][nx][b]==1)continue;
      d[ny][nx][b]=1;
      q.push(P2(P(ny*1000+nx,cost+1),b));
      if(ny>=19){
	cout<<cost+1<<endl;
	return 0;
      }
    }
  }
  cout<<-1<<endl;
}



Measured memory_bytes: 8120
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/


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

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

int main(){
	int a, b;
	cin >> a >> b;
	if(a!=1&&b!=1)	cout << 1 << endl;
	if(a!=2&&b!=2)	cout << 2 << endl;
	if(a!=3&&b!=3)	cout << 3 << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
lst=list(map(int,input().split()))
count=0
for i in range(n-1):
    for j in range(1+i,n)[::-1]:
        if lst[j-1]>lst[j]:
            count+=1
            lst[j-1],lst[j]=lst[j],lst[j-1]
print(*lst)
print(count)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
int main(){
    int S[3];
    int maximum=0;
    for(int i=0;i<3;i++){
        cin>>S[i];
        maximum=max(maximum,S[i]);
    }
    int sa=0;
    for(int i=0;i<3;i++){
        sa=sa+(maximum-S[i]);
    }
    if(sa%2!=0){
        cout<<sa/2+2;
    }
    else{
        cout<<sa/2;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,m;
	int ans=0;
	cin >>n>>m;
	VPi data(m);
	cin >> data;
	sort(all(data));
	Pi border = mp(-INF, INF);  // left, right;
//	clog << data << endl;
	rep(i,m){
		if(border.S <= data[i].F){
			ans++;
			border = mp(-INF, INF);
		}
		chmax(border.F, data[i].F);
		chmin(border.S, data[i].S);
	//	clog << border << endl;
	}
	ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a,b,c;
    cin>>a>>b>>c;
    long long int sum=0;
    if (b>=c) {
        sum+=b+c;
    } else {
        sum+=b+b;
        c-=b;
        if (a>=c) {
            sum+=c;
        } else {
            sum+=a+1;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

vector<int> topological_sort(const vector<vector<int>>& G) {
  int N = G.size();
  vector<int> num_parents(N, 0);
  for (int i = 0; i < N; ++i) {
    for (int v : G[i]) {
      num_parents[v]++;
    }
  }

  queue<int> que;
  for (int i = 0; i < N; ++i) {
    if (num_parents[i] == 0) {
      que.push(i);
    }
  }

  vector<int> node_indices;
  while (!que.empty()) {
    int v = que.front(); que.pop();
    node_indices.push_back(v);

    for (int u : G[v]) {
      num_parents[u]--;
      if (num_parents[u] == 0) {
        que.push(u);
      }
    }
  }

  return node_indices;
}

int main() {
  int N, M; cin >> N >> M;
  vector<vector<int>> G(N);
  for (int i = 0; i < M; ++i) {
    int x, y; cin >> x >> y; --x, --y;
    G[x].push_back(y);
  }

  auto node_indices = topological_sort(G);
  vector<int> dp(N, 0);
  for (int v : node_indices) {
    for (int u : G[v]) {
      dp[u] = max(dp[u], dp[v] + 1);
    }
  }

  int vmax = 0;
  for (int v : dp) vmax = max(vmax, v);
  cout << vmax << endl;
}


Measured memory_bytes: 9776
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
#include <utility>
#include <queue>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;



int main() {
    int x, y;
    cin >> x >> y;

    for (int i=0; i < 101; i++) {
        for (int j = 0; j < 101; j++) {
            if (i + j == x && 2 * i + 4 * j == y) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);


ll modnum = 1e9+7;

const int MAX = 200000 + 5;

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % modnum;
        inv[i] = modnum - inv[modnum%i] * (modnum / i) % modnum;
        finv[i] = finv[i - 1] * inv[i] % modnum;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % modnum) % modnum;
}


int main() {
    ll n,k; cin >> n >> k;


    // 二項係数を前処理で作っておく
    COMinit();

    // N個からi個の部屋を空きにする nCi
    // 残りの部屋(N-i)にi人の人を振り分ける (n-i)Hi -> (n-i+i-1)Ci -> n-1Ci
    // 空きの部屋がkより大だったら作れないのでそこで打ち切り
    ll ans = 0;
    rep(i, k+1) {
        // 全ての部屋を空にはできない
        if(i >= n) break;
        ans += COM(n, i) * COM(n-1, i);
        ans %= modnum;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4992
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;
    
    ll n;
    cin>>n;
    ll ans=0;
    rep(i,n){
        ll a;
        cin>>a;
        ans+=a-1;
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
cy, cx = map(int, input().split())
dy, dx = map(int, input().split())
cy -= 1
cx -= 1
dy -= 1
dx -= 1

S = [input() for _ in range(H)]

worps = [[float('inf')]*W for _ in range(H)]
used = [[False]*W for _ in range(H)]
q = deque([[cy, cx]])

worp = 0
while q:
    v = {}
    while q:
        y, x = q.popleft()
        used[y][x] = True
        worps[y][x] = min(worps[y][x], worp)

        for h in range(-2+y, 3+y):
            for w in range(-2+x, 3+x):
                if 0 <= h and h < H and 0 <= w and w < W and S[h][w] == ".":
                    v[(h, w)] = True

        for h, w in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
            ny, nx = y+h, x+w
            if 0 <= ny and ny < H and 0 <= nx and nx < W:
                if not used[ny][nx] and S[ny][nx] == ".":
                    q.appendleft([ny, nx])

    worp += 1
    for h, w in v.keys():
        if not used[h][w]:
            q.appendleft([h, w])
            used[h][w] = True

ans = worps[dy][dx]
if ans != float('inf'):
    print(ans)
else:
    print(-1)


Measured memory_bytes: 151156