akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <cmath>
#include <complex>
#include <cstdio>

using namespace std;

inline int getInt(){ int s; scanf("%d", &s); return s; }

// sizeof v must be 2 ^ n
template<class T>
void fft_core(vector<complex<T> > &v, bool rev = false){
  const int n = v.size();

  for(int i = 0; i < n; i++){
    int k = 0;
    int b = (n >> 1);
    int a = 1;

    while(b >= a){
      if(b & i) k |= a;
      if(a & i) k |= b;
      b >>= 1;
      a <<= 1;
    }

    if(i < k) swap(v[i], v[k]);
  }

  int m = 2;

  while(m <= n){
    double arg = -2.0 * M_PI / m;
    complex<T> w(cos(arg), sin(arg));
    if(rev) w = 1.0 / w;

    for(int i = 0; i < n; i += m){
      complex<T> ww(1.0);

      for(int j = 0; j < m / 2; j++){
	int a = i + j;
	int b = i + j + m / 2;
	complex<T> t = ww * v[b];

	v[b] = v[a] - t;
	v[a] = v[a] + t;

	ww *= w;
      }
    }
    m *= 2;
  }

  if(rev){
    double s = (double)n;
    for(int i = 0; i < n; i++)
      v[i] /= s;
  }
}

template<class T> inline void  fft(vector<T> &v){ fft_core(v); }
template<class T> inline void ifft(vector<T> &v){ fft_core(v, true); }

int next(int n){
  int i = 1;
  while(i < n) i *= 2;
  return i;
}


int main(){
  int n  = getInt();
  int m  = next(n + 1);
  int mm = m * 2;
  vector<complex<double> > p(mm, 0.0);
  double prev = 0.0;
  p[0] = 1.0;
  
  for(int i = 1; i <= n; i++){
    if(i < 51){
      fft(p);

      for(int j = mm - 1; j >= 0; j--){
	p[j] = p[j] * p[j];
      }
      
      ifft(p);

      for(int j = mm - 1; j >= 1; j--){
	p[j] = p[j - 1];
      }
      p[0] = 1.0;
      for(int j = 1; j < mm / 2; j++)
	p[j] /= j;
      for(int j = mm / 2; j < mm; j++)
	p[j] = 0.0;
      
      double ans = n >= p.size() ? 0.0 : p[n].real();
      double pans = (ans - prev);
      if(ans > 1e-10) pans += 0.000007;
      printf("%.7f\n", max(0.0, pans) + 1e-10);
      prev = ans;
    }else{
      printf("%.7f\n", 0.0 + 1e-10);
    }
  }

  return 0;
}

Measured memory_bytes: 0
/**
*    created: 13.05.2020 22:23:25
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    k--;
    string s; cin >> s;
    s[k] = tolower(s[k]);
    cout << s << endl;
    return 0;
}

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

const int N = (int)2e5;

class BIT {
    int n;
    int dat[N+5];
    //
    int LSOne(int a) { return a & -a; }
public:
    int reset(int _n) {
        for (int i=0; i<+_n+3; i++) dat[i] = 0;
        return n=_n;
    }
    int add(int pos, int val=1) {
        for (int i=pos; i<=n; i+=LSOne(i)) dat[i] += val;
        return 0;
    }
    int query(int pos) {
        int res = 0;
        for (int i=pos; i>=1; i-=LSOne(i)) res += dat[i];
        return res;
    }
};

BIT ds_min;
BIT ds_max;
int dat[N+5];

int main() {
    int n,k; scanf("%d %d", &n, &k);
    for (int i=1; i<=n; i++) scanf("%d", dat+i);

    ds_min.reset(n);
    ds_max.reset(n);

    int res = 0;
    int is_original = 0;

    int inversion_count = 0;
    for (int i=1; i<=k; i++) {
        inversion_count += ds_max.query(n-dat[i]);
        ds_min.add(dat[i]+1);
        ds_max.add(n-dat[i]);
    }

    if (inversion_count == 0) {
        is_original = 1;
    } else {
        res = 1;
    }

    for (int i=k+1; i<=n; i++) {
        int ret = 0;

        int new_count_1 = inversion_count;
        new_count_1 -= ds_min.query(dat[i-k]+1) - 1;
        if (new_count_1 != inversion_count) ret = 1;

        ds_min.add(dat[i-k]+1, -1);
        ds_max.add(n-dat[i-k], -1);

        int new_count_2 = new_count_1;
        new_count_2 += ds_max.query(n-dat[i]);
        if (new_count_2 != new_count_1) ret = 1;

        ds_min.add(dat[i]+1);
        ds_max.add(n-dat[i]);

        if (new_count_2 == 0) {
            is_original = 1;
        } else if (ret == 1) {
            res += 1;
        }

        inversion_count = new_count_2;
    }

    printf("%d\n", res + is_original);
    return 0;
}


Measured memory_bytes: 2560
def main():
    N, T = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    target_list = list()
    price_buy, town_num_buy = A[N - 1], 1
    price_sell, town_num_sell = A[N - 1], 1
    for t in range(N - 2, -1, -1):
        price = A[t]
        if price < price_buy:
            price_buy = price
            town_num_buy = 1
        elif price == price_buy:
            town_num_buy += 1
        elif price == price_sell:
            town_num_sell += 1
        elif price > price_sell:
            target_list.append({
                'score': price_sell - price_buy,
                'town_num_buy': town_num_buy,
                'town_num_sell': town_num_sell
            })
            price_buy, town_num_buy = price, 1
            price_sell, town_num_sell = price, 1
    target_list.append({
        'score': price_sell - price_buy,
        'town_num_buy': town_num_buy,
        'town_num_sell': town_num_sell
    })
    max_score = max([target['score'] for target in target_list])
    ans = 0
    for target in target_list:
        if target['score'] < max_score:
            continue
        ans += min(target['town_num_buy'], target['town_num_sell'])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 24144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int E=C-A,F=D-B;
  
  cout << C-F << " " << D+E  << " " << C-F-E << " " << D+E-F  << " " << endl;
}

Measured memory_bytes: 256
def show(A):
    L = list(map(str, A))
    print(" ".join(L))

N = int(input())
A = list(map(int, input().split()))
flag = True
cnt = 0

while flag:
    flag = False
    for j in range(N-1, 0, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            flag = True
            cnt += 1

show(A)
print(cnt)


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

using namespace std;
typedef long long ll;

const int N = 100000;
const int MOD = 1e9+7;

char s[N + 1];
int have[100];

int main() {
	int n;
	scanf("%d%s", &n, s + 1);
	for (int i = 1; i <= n; ++i) have[s[i] - 'a' + 1]++;
    long long res = 1;
	for (int i = 1; i <= 26; i++) (res *= (have[i] + 1)) %= MOD;
    cout << (res + MOD - 1) % MOD << endl;
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
#include <cstdlib>
#include <cctype>
#include <random>

using namespace std;

int main() {
    int n, max_l=0, sum_l=0;
    cin >> n;
    int l;
    for (int i=0; i<n; i++) {
        cin >> l;
        max_l = max(max_l, l);
        sum_l += l;
    }
    sum_l -= max_l;

    if (max_l < sum_l) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
# coding=utf-8


class Dice(object):

    def __init__(self, label):
        self.label = label

    def _rotateS(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s5, s1, s3, s4, s6, s2]

    def _rotateN(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s2, s6, s3, s4, s1, s5]

    def _rotateE(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s4, s2, s1, s6, s5, s3]

    def _rotateW(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s3, s2, s6, s1, s5, s4]

    def _spinPos(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s1, s4, s2, s5, s3, s6]

    def _spinNeg(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s1, s3, s5, s2, s4, s6]

    def rotate(self, r):
        if r == 'S':
            self._rotateS()
        elif r == 'N':
            self._rotateN()
        elif r == 'E':
            self._rotateE()
        elif r == 'W':
            self._rotateW()
        elif r == 'SP':
            self._spinPos()
        elif r == 'SN':
            self._spinNeg()
        elif r == '2S':
            self._rotateS()
            self._rotateS()
        elif r == '2SP':
            self._spinPos()
            self._spinPos()

    def getLabel(self, i):
        return self.label[i - 1]

    def match(self, top, front):
        iTop = self.label.index(top) + 1
        topRot = {1: '', 2: 'N', 3: 'W', 4: 'E', 5: 'S', 6: '2S'}
        self.rotate(topRot[iTop])

        iFront = self.label.index(front) + 1
        frontRot = {2: '', 3: 'SN', 4: 'SP', 5: '2SP'}
        self.rotate(frontRot[iFront])


def main():
    d = Dice(map(int, raw_input().split()))
    n = input()
    for _ in xrange(n):
        top, front = map(int, raw_input().split())
        d.match(top, front)
        print d.getLabel(3)

if __name__ == '__main__':
    main()

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


int main() {
  string s, t;
  cin >> s >> t;
  reverse(rng(s));
  reverse(rng(t));
  int ssz = s.size();
  int tsz = t.size();
  rep(i,ssz) {
    rep(j,tsz) {
      if(s[i+j]!=t[j]&&s[i+j]!='?') break;
      if(j==tsz-1) {
        rep(k,tsz) {
          s[i+k]=t[k];
        }
        for(int i = 0; i<ssz; i++) {
          if(s[i]=='?') s[i]='a';
        }
        reverse(rng(s));
        cout << s << endl;
        return 0;
      }
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll L,R,d;
  cin>>L>>R>>d;
  ll ans=0;
  for(int i=L;i<=R;i++){
    if(i%d==0) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
x, y = map(int, input().split())

ret = float('inf')


def f(k):
    return k if k >= 0 else float('inf')


print(
    min(
        f(y - x),
        f(-y - x) + 1,
        f(y + x) + 1,
        f(-y + x) + 2
    )
)


Measured memory_bytes: 2940
n, m = map(int, input().split())
s = []
d = []
for i in range(n):
    x, y = map(int, input().split())
    s.append([x, y])
for i in range(m):
    x, y = map(int, input().split())
    d.append([x, y])
for i in s:
    a = 1
    c = abs(i[0] - d[0][0]) + abs(i[1] - d[0][1])
    for j in range(1, m):
        c_t = abs(i[0] - d[j][0]) + abs(i[1] - d[j][1])
        if c_t < c:
            c = min(c, c_t)
            a = j + 1
    print(a)


Measured memory_bytes: 3064
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f;
LL n, m, s, t, h, w, a[100];
vector<Pll>ans;
int main() {
	cin >> n;
	Pll mn=Pll(INF,0), mx=Pll(-INF,0);
	rep(i, n) {
		cin >> a[i];
		if (mn.fir > a[i])
			mn = Pll(a[i], i);
		if (mx.fir < a[i])
			mx = Pll(a[i], i);
	}
	if (abs(mn.fir) < abs(mx.fir)) {
		rep(i, n) {
			if (i != mx.second)
				ans.push_back(Pll(mx.second, i));
		}
		rep(i, n-1) {
			ans.push_back(Pll(i, i + 1));
		}
	}
	else {
		rep(i, n) {
			if (i != mn.second)
				ans.push_back(Pll(mn.second, i));
		}
		Rrep(i, n - 1) {
			ans.push_back(Pll(i + 1, i));
		}
	}
	cout << ans.size() << endl;
	rep(i, ans.size()) {
		cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

bool check (vi v, const vi &u)
{
    assert(sz(v) == sz(u));
    sort(ALL(v));
    assert(is_sorted(ALL(u)));
    return v == u;
}

struct fenw
{
    vi v;

    fenw (int n)
    {
        v.assign(n, 0);
    }

    void inc (int pos)
    {
        for (int i = pos; i < sz(v); i += i & (-i))
            v[i]++;
    }

    int pref (int pos)
    {
        int sum = 0;
        for (int i = pos; i > 0; i -= i & (-i))
            sum += v[i];
        return sum;
    }
};

ll cnt_invs (const vi &v)
{
    int maxx = *max_element(ALL(v));
    fenw data(maxx + 2);

    ll good = 0;
    for (int x : v)
    {
        good += data.pref(x);
        data.inc(x);
    }

    ll total = (ll)sz(v) * (ll)(sz(v) - 1) / 2LL;
    assert(0LL <= good && good <= total);
    return total - good;
}

void solve (int n)
{
    vvi a(3, vi(n));

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

    bool ok = true;
    vector<vvi> perm(2, vvi(2));
    vector<vvi> exp(2, vvi(2));

    int num = 1;
    for (int j = 0; j < n; j++)
    for (int i = 0; i < 3; i++)
    {
        perm[j % 2][i % 2].pb(a[i][j]);
        exp[j % 2][i % 2].pb(num);
        ++num;
    }

    for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
        ok &= check(perm[i][j], exp[i][j]);

    if (!ok)
    {
        cout << "No" << endl;
        return;
    }

    ok &= (cnt_invs(perm[1][0]) % 2 == cnt_invs(perm[0][1]) % 2);
    ok &= (cnt_invs(perm[1][1]) % 2 == cnt_invs(perm[0][0]) % 2);

    cout << (ok ? "Yes" : "No") << endl;
}

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

    int n;
    while (cin >> n)
        solve(n);
}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll n, m, p[100001];
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

signed main() {
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  rep(i, m) {
    ll x, y;
    cin >> x >> y;
    x--, y--;
    uf.merge(x, y);
  }
  ll cnt = 0;
  rep(i, n) {
    if (uf.issame(i, p[i])) cnt++;
  }
  cout << cnt << endl;
}

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

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int field[32][32];
int dfs(int x,int y){
  int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
  if(field[x][y]==0) return 0;
  field[x][y]=0;
  int answer=1;
  REP(i,4) answer += dfs(x+dx[i],y+dy[i]);
  return answer;
}
int main(void)
{
  for(;;){
    int w,h;
    cin >> w >> h;
    if(!w&&!h) return 0;
    REP(i,32) REP(j,32) field[i][j]=0;
    vector<string> fi;
    fi.resize(h);
    REP(i,h) cin >> fi[i];
    REP(i,h) REP(j,w) if(fi[i][j]!='#') field[i+5][j+5]=1;
    REP(i,h) REP(j,w) if(fi[i][j]=='@')
      cout << dfs(i+5,j+5) << endl;
  }
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;
const ll MAX = 1000000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(ll n, ll k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void Main() {
  int x, y;
  cin >> x >> y;
  if (2 * x < y || (2 * x - y) % 3 != 0 || 2 * y - x < 0 ||
      (2 * y - x) % 3 != 0) {
    cout << 0 << endl;
    return;
  }
  ll n = (2 * x - y) / 3;
  ll m = (2 * y - x) / 3;
  COMinit();
  cout << COM(n + m, n) << endl;
}

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


Measured memory_bytes: 23680
#include<stdio.h>

int main(void)
{
  int N,M,i;
  int id[100000][2]={0};
  
  scanf("%d%d",&N,&M);
  
  for(i=0;i<M;i++){
    scanf("%d%d",&id[i][1],&id[i][2]);
  }
  
  int min=id[0][1];
  int max=id[0][2];
  
  for(i=0;i<M-1;i++){
    if(min<id[i+1][1]){
      min=id[i+1][1];
    }
    if(max>id[i+1][2]){
      max=id[i+1][2];
    }
  }
  if(max<min){
    puts("0");
  }else{
  printf("%d",max-min+1);
  }
  
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,s,x[N];
long long p[N];
int main(){
	scanf("%d%d",&n,&s);
	for(int i=1; i<=n; ++i)scanf("%d%lld",&x[i],&p[i]);
	long long ans=0;
	for(int l=1,r=n; ; ){
		if(x[l]>s){ans+=x[r]-s; break;}
		if(x[r]<s){ans+=s-x[l]; break;}
		ans+=x[r]-x[l];
		if(p[l]>=p[r])while(p[l]>=p[r]&&l<r)p[l]+=p[r--];
		else while(p[l]<p[r]&&l<r)p[r]+=p[l++];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <string.h>
#define ll long long

using namespace std;

ll n,k;
ll arr[100009]{};
ll mem[100009]{};
ll MAX = 9223372036854775807;

ll minCost(ll i)
{
    if(i>=n)
    {
        if(i==n) return 0;
        if(i>n) return MAX;  //false calls
    }

    ll &ret = mem[i];
    if(ret!= -1)
        return ret;

    ret = MAX;
    for(int inc = 1 ; inc<= k ; inc++)
    {
        if(i+inc<n)
        ret = min(ret , abs(arr[i] - arr[i+inc]) + minCost(i+inc));
        else if(i+1==n)
            ret = min(ret , minCost(i+1));
    }

    return ret;

}
int main()
{
    cin>>n>>k;
    for(int i = 0 ; i<100009 ; i++)mem[i] = -1;
    for(int i = 0 ; i< n ; i++)cin>>arr[i];

    cout<<minCost(0)<<endl;

    return 0;
}


Measured memory_bytes: 6528
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

numbers = [0] * (10**5+2)
total = sum(A)

for a in A:
    numbers[a] += 1

for _ in range(Q):
    B, C = map(int, input().split())
    tmp = numbers[B]
    #print('tmp: ', tmp)
    diff = (C-B) * tmp
    #print('diff: ', diff)
    total += diff
    numbers[B] = 0
    numbers[C] += tmp
    print(total)
    #print()

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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>L(N);
	int sum = 0;
	int res = 0;

	for (int i = 0; i < N; i++) {
		cin >> L[i];
		sum += L[i];
		res = max(res, L[i]);
	}

	if (sum - res > res) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	int n; cin >> n;
	vector<int> p(n);
	REP(i,n) cin >> p[i];

	int ans = 0;
	FOR(i,1,n-1){
	if(p[i-1] < p[i] and p[i] < p[i+1]) ans++;
	else if(p[i+1] < p[i] and p[i] < p[i-1]) ans++;
	}
	
	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 256
'use strict'
let maxnum = 109

function countingSort(arr) {
  const sorted = []
  let tmp = Array.apply(null, { length: maxnum + 1 }).map(v => 0)
  // console.log(tmparr.length)
  for (let i in arr) {
    tmp[arr[i]]++
  }
  for (let i in tmp) {
    while (tmp[i]) {
      sorted.push(~~i)
      tmp[i]--
    }
  }
  // console.log(sorted)

  return sorted
}

function main(input) {
  input = input.split(/\n|\s/).map(v => ~~v)
  const n = input[0]
  const arr = input.slice(1, n + 1)
  const sorted = arr.slice(0).sort((a, b) => a - b) //countingSort(arr)

  const mid = sorted[n / 2]
  const mid2 = sorted[n / 2 - 1]
  // console.log(arr, sorted, mid)
  // console.log('-------')

  // console.log(mid)

  // let ans = []
  for (let i = 0; i < n; i++) {
    if (arr[i] < mid) {
      console.log(mid)
    } else {
      console.log(mid2)
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 60448
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18
 
ll n,q;
vector<ll> ar;
vector<pair<pll,ll>> queries;
ll bit[500005]={0};
vector<ll> last(500005,-1);
 
ll query(ll r)
{
    ll ans=0;
 
    for(;r>=0;r=(r&(r+1))-1)
    ans+=bit[r];
 
    return ans;
}
 
void update(ll idx,ll delta)
{
    for(;idx<n;idx|=(idx+1))
    bit[idx]+=delta;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
 
    ll test=1;
    // cin>>test;
    while(test--)
    {
        cin>>n>>q;
        
        ar.resize(n);
        queries.resize(q);
 
        for(ll i=0;i<n;i++)
        {
            ll x;
            cin>>x;
            x--;
            ar[i]=x;
        }
 
        for(ll i=0;i<q;i++)
        {
            ll x,y;
            cin>>x>>y;
 
            x--,y--;
 
            queries[i].ff.ss=x;
            queries[i].ff.ff=y;
            queries[i].ss=i;
 
        }
 
        sort(queries.begin(),queries.end());
 
        ll qcount=0;
 
        vector<ll> ans(q,0);
 
        for(ll i=0;i<n;i++)
        {
            if(last[ar[i]]!=-1)
            update(last[ar[i]],-1);
 
            update(i,1);
            last[ar[i]]=i;
 
            while(qcount<q && queries[qcount].ff.ff==i)
            {
                ans[queries[qcount].ss]=query(queries[qcount].ff.ff)-query(queries[qcount].ff.ss-1);
                qcount++;
            }
        }
 
        for(ll i=0;i<q;i++)
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 31096
#include<stdio.h>
#define MAX 1000



int main()
{
  int i,N;
  int F[MAX];

  scanf("%d",&N);
 
  F[0] = 1;
  F[1] = 1;

 
 
 
 
  if(N==0||N==1)
    {
      printf("%d\n",1);
    }
  else
    {
      for(i=2;i<=N;i++)
	{
	  F[i] = F[i-1] + F[i-2];
	}
      printf("%d\n",F[N]);
    }
  return 0;
    
}


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

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> cnt(N + 1);
  for (int i = 0; i < N; i++)
  {
    int A;
    cin >> A;
    cnt[A]++;
  }
  sort(cnt.begin(), cnt.end(), greater<int>());
  int ans = 0;
  for (int i = K; i < N; i++)
    ans += cnt[i];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

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

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

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

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

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

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

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

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

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=nii()
l=[lnii() for i in range(m)]

uf=UnionFind(n)
for a,b, in l:
  a-=1
  b-=1
  uf.union(a,b)

ans=uf.group_count()
print(ans-1)

Measured memory_bytes: 29280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
int n,a,b,c;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b>>c;
		if(a<b+c||(a-b-c)%2==1){cout<<"No\n";return 0;}
	}
	cout<<"Yes\n";
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2000 + 5;
const ll oo = 0x3f3f3f3f3f3f3f3f;
int N, M;
ll d1, d2;
int main(){
	while (cin >> N >> M){
		vector<int>a(M);
		vector<int>b(M);
		vector<ll>c(M);
		for (int i = 0; i < M; i++){
			cin >> a[i] >> b[i] >> c[i];
			a[i]--,	b[i]--;
		}
		vector<ll>d(N, -oo);
		d[0] = 0LL;
		for (int i = 0; i < 2 * N; i++){
			for (int j = 0; j < M; j++){
				d[b[j]] = max(d[b[j]], d[a[j]] + c[j]);
			}
			if (i == N - 1)d1 = d[N - 1];
			if (i == 2 * N - 1)d2 = d[N - 1];
		}
		if (d1 == d2)cout << d1 << endl;
		else cout << "inf" << endl;
	}
}

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

#define mod 1000000007

#define rep(i, n) for(ll i=0; i<n; ++i)

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	ll N, K;
	
	cin >> N >> K;
	
	vector<pair<ll, ll>> ab(N);
	
	rep(i, N)
		cin >> ab[i].first >> ab[i].second;
		
	sort(ab.begin(), ab.end());
	
	ll ans, count = 0, i = 0;
	
	while(count < K){
		if(count + ab[i].second >= K){
			ans = ab[i].first;
			break;
		}
		else{
			count += ab[i].second;
			ans = ab[i].first;
		}
		i++;
	}
	
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

#define INF (1<<30)
#define MOD 1000000007
#define ll long long

ll memo[100001][10];

string s;
int n;

int charToPhase(char c){
	if(c == 'A'){
		return 1;
	}else if(c == 'B'){
		return 2;
	}else if(c == 'C'){
		return 3;
	}else{
		return -1;
	}
}

ll dfs(int depth, int phase){
	cout << depth << " " << phase << endl;
	if(depth == n && phase == 3){
		return 1;
	}
	if(depth == n)return 0;

	ll ans = 0;
	if(s[depth] == '?'){
		if(phase == 3){
			ans+=dfs(depth+1, phase)*3;
		}else{
			ans+=dfs(depth+1, phase+1);
			ans+=dfs(depth+1, phase)*3;
		}
	}else{
		int now = charToPhase(s[depth]);
		if(phase+1 == now){
			ans+=dfs(depth+1, phase+1);
		}
		ans+=dfs(depth+1, phase);
	}
	return ans%MOD;
}

int main(){

	cin >> s;
	// s = "";
	// for(int i = 0;i < 100000;i++){
	// 	s.push_back('?');
	// }
	n = s.length();
	fill_n(*memo,100001*10,0);
	// cout << dfs(0,0) << endl;

	memo[n][3] = 1;
	memo[n][2] = 0;
	memo[n][1] = 0;
	memo[n][0] = 0;

	for(int phase = 3; phase!=-1; phase--){
		for(int d = n-1; d!=-1; d--){
			if(s[d] == '?'){
				if(phase == 3){
					memo[d][phase] += memo[d+1][phase]*3;
				}else{
					memo[d][phase] += memo[d+1][phase+1];
					memo[d][phase] += memo[d+1][phase]*3;
				}
			}else{
				int now = charToPhase(s[d]);
				if(phase+1 == now){
					memo[d][phase] += memo[d+1][phase+1];
				}
				memo[d][phase] += memo[d+1][phase];
			}
			memo[d][phase]%=MOD;
		}
	}

	cout << memo[0][0] << endl;

	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  string S, T;
  cin >> N >> S >> T;

  VI cnt1(26), cnt2(26);
  for(char c: S)
	cnt1[c-'a']++;
  for(char c: T)
	cnt2[c-'a']++;

  SORT(cnt1);
  SORT(cnt2);

  int ans = 0;
  REP(i,26) ans += abs(cnt1[i] - cnt2[i]);

  cout << ans/2 << endl;

  return 0;
}



Measured memory_bytes: 3308
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

template <class T>
struct fenwick_tree {
  using Op = function<T(const T&, const T&)>;
  Op op;
  vector<T> x;
  fenwick_tree(int n, const Op& op_)
      : x(n + 1), op(op_) {
  }
  void add(int k, T a) {
    for (++k; k < x.size(); k += k & -k) x[k] = op(x[k], a);
  }
  T sum(int k) {
    T s;
    for (; k > 0; k &= k - 1) s = op(s, x[k]);
    return s;
  }
};

using P = pair<int, ll>;

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (int& x : A) cin >> x;
    auto op = [](const P& a, const P& b) {
      return max(a, b);
    };
    fenwick_tree<P> bit(100010, op);
    P res;
    for (int x : A) {
      P p = bit.sum(x);
      P q = {p.fst + 1, p.snd + x};
      res = op(res, q);
      bit.add(x, q);
    }
    cout << res.snd << endl;
  }
  return 0;
}



Measured memory_bytes: 4668
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  for(int i=0; i<H; i++)
    cin >> A[i];
  cout << string(W+2, '#') << endl;
  for(int i=0; i<H; i++)
    cout << '#' << A[i] << '#' << endl;
  cout << string(W+2, '#') << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);


	int H, W, x, y;
	cin >> H >> W >> x >> y;

	int black;
	black = (x * W) + (y * (H - x));
	cout << H * W - black << '\n';
	return 0;
}


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

Ls.sort(reverse=True)

count = 0
for k, Lk in enumerate(Ls[:-2]):
    for j, Lj in enumerate(Ls[k+1:-1]):
        for i, Li in enumerate(Ls[k+j+2:]):
            if Lk == Lj or Lj == Li or Li == Lk:
                continue
            if Lk < Lj + Li:
                count += 1

print(count)

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N, std::vector<long long> A){
    int sum = 0;
    rep(i, N) sum += A[i];

    bitset<2020 * 2020> bits;
    bits[0] = 1;
    rep(i, N) {
        bits |= (bits << A[i]);
    }

    for(int i = (sum + 1) / 2; i <= sum; i++) {
        if (bits[i]) {
            cout << i << endl;
            return;
        }
    }
}

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<utility>
#include<bitset>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(3*n);
	for(int i=0; i<3*n; i++)
		cin >> a[i];
	sort(a.rbegin(), a.rend());
	long long ans = 0;
	for(int i=1; i<2*n; i+=2){
		ans += a[i];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void)
{
	int	cnt=0,max=0,i;
	char a[4];
	scanf("%s",a);
	for (i=0;i<3;i++){
		if(a[i]=='R'){
			cnt++;
			 if(max<=cnt){
				 max=cnt;
			 }
		}
		else {
			cnt=0;
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
string a[500];
int vis[500][500];
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
int lol[500][500];
int n,m;
int tot[2];
 
void dfs(int x,int y,int col)
{
    if(x<1||x>n||y<1||y>m)
        return ;
    if(col!=lol[x][y])
        return ;
    vis[x][y]=1;
    tot[col]++;
    for(int i=0;i<4;i++)
    {
        if(!vis[x+dx[i]][y+dy[i]])
            dfs(x+dx[i],y+dy[i],(col+1)&1);
    }
}
 
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  
 
 
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]="@"+a[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]=='#')
                lol[i][j]=1;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(!vis[i][j])
            {
                tot[0]=0;
                tot[1]=0;
                dfs(i,j,lol[i][j]);
                ans+=tot[0]*tot[1];
            }
        }
    }
    cout<<ans;
    
 
} 

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

using namespace std;
vector<int> shortest_cycle;
vector<int> a[5000];
void bfs(int x){
    int par[5000],vis[5000];
    memset(vis,0,sizeof(vis));
    queue<int> q;
    q.push(x);
    vis[x]=1;
    while(q.size()){
        int u=q.front();
        q.pop();
        
        for(auto v:a[u]){
            if(v==x){
                int k=u;
                vector<int>cycle({k});
                while(1){
                    k=par[k];
                    cycle.push_back(k);
                    if(k==x)
                        break;
                }
                if(shortest_cycle.size()==0 || shortest_cycle.size()>cycle.size()){
                    shortest_cycle=cycle;
                }
                return;
            }
                 
            if(vis[v])  continue;
            par[v]=u;
            vis[v]=1;
            q.push(v);
        }
    }
}
int main() {
    int n,m,i,j;
    cin>>n>>m;
    for(i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        a[x].push_back(y);
        
    }    
    for(i=0;i<n;i++){
        bfs(i);
    }
    if (shortest_cycle.empty()) {
        cout << -1 << endl;
    }
    else {
        cout << shortest_cycle.size() << endl;
        for (int v : shortest_cycle) {
            cout << v + 1 << endl;
        }
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<string, int> mp;
  string a, b;
  cin >> a >> b;
  int c, d;
  cin >> c >> d;
  string t;
  cin >> t;
  if (t == a) cout << --c << " " << d << '\n';
  else cout << c << " " << --d << '\n';
}


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

int main(){
  int n,m;
  cin >> n>> m;
  if(n>m){
    for(int i=0;i<n;i++){
      cout << m; 
    }
    cout << endl;
  }
  else{ for(int i=0;i<m;i++){
      cout << n; 
    }
    cout << endl;}
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
        continue
    else:
        ans += a[i]
        b[i] -= a[i]
        if a[i+1] <= b[i]:
            ans += a[i+1]
            a[i+1] = 0
        else:
            ans += b[i]
            a[i+1] -= b[i]
print(ans)


Measured memory_bytes: 18852
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl;
#define rep(i,n) for(ll i = 0;i < n;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0);

const ll INF = 1e9+7;

// 各桁の和
template<typename T>
T digit(T num){
  T sum = 0;
  while(num){
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

template<typename T>T gcd(T a,T b){
  if(b == 0)
    return a;
  return gcd(b,a%b);
}
template<typename T>T lcm(T a, T b){
  T g = gcd(a,b);
  return a/g*b; 
}

int main(){
  int n,k;cin>>n>>k;
  vector<int> a(n+1,0);
  int ans = 0;
  rep(i,n){
    int tmp;cin>>tmp;
    a[tmp]++;
  }
  
  sort(all(a));
  int num = 0;
  
  rep(i,n+1){
    if(a[i] == 0)a[i] = n + 100;
    else num++;
  }
  
  sort(all(a));
  rep(i,n+1){
    if(num > k){
      ans+=a[i];
      num--;
    }else
      break;
  }
  print(ans)
  return 0;
}


Measured memory_bytes: 1024
try:
    while True:
        n = int(input())
        count = 0
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if a+b+c+d == n:
                            count += 1
        print(count)
except:
    pass

Measured memory_bytes: 6720
N,M,X = map(int,input().split())
A = list(map(int,input().split()))

to_N = list(range(X,N))
to_0 = list(range(0,X))

to_N_count = 0
for i in to_N:
    for j in  A:
        if i == j:
            to_N_count += 1

to_0_count = 0
for i in to_0:
    for j in A:
        if i == j:
            to_0_count += 1

print(min(to_N_count,to_0_count))

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.StringTokenizer;

import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String c = sc.next();
        String c1 = String.valueOf(c.charAt(0));
        String c11=String.valueOf(Integer.parseInt(c1)+1);
        
        String c2 = c1 + c1 + c1;
        String c21 = c11 + c11 + c11;
        
        String ans = "";
        if (Integer.parseInt(c2) >= Integer.parseInt(c)) {
        	ans = c2;
        } else {
        	ans = c21;
        }
        
    	System.out.println(ans);   
    
    }
    private static String change19(String str) {
    	if ("1".equals(str)) {
    		str="9";
    	} else if ("9".equals(str)) {
    		str="1";
    	}
    	
    	return str;
    }
}

Measured memory_bytes: 22868
#include<stdio.h>
int main(){
    int W,H,x,y,r;
    scanf("%d",&W);
    scanf("%d",&H);
    scanf("%d",&x);
    scanf("%d",&y);
    scanf("%d",&r);
    if(W>=r*2&&H>=r*2&&W>=x+r&&H>=y+r&&W>0&&H>0&&x>0&&y>0&&r>0)printf("Yes\n");
    else printf("No\n");
}


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

map<int,int> mp;

int main()
{
    int N,num;
    scanf("%d",&N);
    for(int i = 0; i < N; ++i)
    {
        scanf("%d",&num);
        mp[num]++;
    }

    int res = 0;
    for(map<int,int>::iterator it = mp.begin(); it != mp.end(); ++it)
    {
        if(it->first > it->second) res += it->second;
        else res += it->second - it->first;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b, ans;
    cin >> a >> b ;
    //*/

    ans = 6 - a - b;

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    /*
    if( a * 500 >= b ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    cout << ans << endl;

    return 0; 
}


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

int main () {
  int A, B, ans = -1;
  cin >> A >> B ;
  for(int i = 0; i <= 1000; i++){
    if(int(i*0.08) == A && int(i*0.10) == B){
      ans = i ;
      break ;
    } else if ((i*0.08)/1 > A && (i*0.10)/1 > B){
      break ;
    }
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256