akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#include<math.h>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;
double const PI = 3.1415926535;

struct edge
{
	long long to; long long cost;
	bool operator<(const edge& rhs) const {
		return cost > rhs.cost;
	}
};

ll const MAX = 800005; //4倍に取っておく
ll segtree[MAX];
ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	return (x + y + MOD) % MOD;
}
ll mod_m(ll x, ll y) {
	return x * y%MOD;
}

//演算
ll op(ll x, ll y) {
	return mod_p(x, y);
}
//init valueの変更を忘れない
ll const INIT_VALUE = 0;
ll n_ = 1;

void init(ll n) {
	while (n_ <= n) {
		n_ *= 2;
	}
	REP(i, 1, n_ * 2) {
		segtree[i] = INIT_VALUE;
	}
}

//k番目をxでupdate
void update(ll k, ll x) {
	k += n_;
	segtree[k] = mod_p(segtree[k], x);
	while (k >= 1) {
		k /= 2;
		segtree[k] = op(segtree[k * 2], segtree[k * 2 + 1]);
	}
}

ll val_o(ll a, ll b, ll k, ll l, ll r) {
	if (a <= l && r <= b) {
		return segtree[k];
	}
	else if (r <= a || b <= l) {
		//ここの値注意
		return 0;
	}
	else {
		ll x1 = val_o(a, b, k * 2, l, (l + r) / 2);
		ll x2 = val_o(a, b, k * 2 + 1, (l + r) / 2, r);
		return op(x1, x2);
	}

}

//[a,b)のvalueを求める
ll val(ll a, ll b) {
	return val_o(a, b, 1, 0, n_);
}



ll n;
ll a[MAX];
ll b[MAX];
vll l;
vll r;
ll g[MAX];

bool ord(ll x, ll y) {
	if (l[x] != l[y]) {
		return l[x] < l[y];
	}
	else {
		return r[x] > r[y];
	}
}
ll t[MAX];

ll f() {
	ll ans = 0;
	REP(i, 1, n) {
		if (i > 1 && g[i - 1] == g[i] && t[i - 1] == t[i]) {
			continue;
		}
		ll x = val(0, g[i]);
		//cout << g[i] << " " << x << endl;
		ans = mod_p(ans, x + 1);
		update(g[i], x + 1);
	}
	
	return mod_p(ans,1);
}

ll compression[MAX];
void compress(ll u[MAX], ll n) {
	map<ll, ll> mp;
	REP(i, 1, n) {
		compression[i] = u[i];
	}
	sort(compression + 1, compression + 1 + n);
	ll x = UNIQUE_ARRAY(compression, n);
	REP(i, 1, x) {
		mp[compression[i]] = i;
	}
	REP(i, 1, n) {
		u[i] = mp[u[i]];
	}
}

int main() {
	ll m;
	cin >> n >> m;
	REP(i, 1, n) {
		cin >> a[i];
	}
	REP(i, 1, m) {
		cin >> b[i];
	}
	REP(i, 1, n) {
		ll x = lower_bound(b + 1, b + m + 1, a[i]) - b;
		if (x == 1 || x == m + 1) {
			continue;
		}
		else {
			l.push_back(a[i] - b[x - 1]);
			r.push_back(b[x] - a[i]);
		}
	}
	n = l.size();
	REP(i, 1, n) {
		g[i] = i - 1;
	}
	SORT_O(g, n, ord);
	REP(i, 1, n) {
		t[i] = l[g[i]];
		g[i] = r[g[i]];
	}
	compress(t, n); compress(g, n);
	init(n);
	ll ans = f();
	cout << ans << endl;
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n;
    cin >> n;
    while(1){
        string s = to_string(n);
        int c = s[0];
        bool flag = true;
        for(auto& x : s){
            if(x != c)
                flag = false;
        }
        if(flag){
            cout << n << endl;
            return 0;
        }
        ++n;
    }
}


Measured memory_bytes: 256
// AOJ 0234: Aizu Buried Treasure
// 2018.1.19 bal4u

#include <stdio.h>
#include <string.h>

#define QMAX 10000
typedef struct { int y, x, o, c, s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].c < que[i].c) min = l; else min = i;
	if (r < qsize && que[r].c < que[min].c) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int y, int x, int o, int c, int s)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].y = y, que[i].x = x, que[i].o = o, que[i].c = c, que[i].s = s;
	while (i > 0 && que[min = PARENT(i)].c > que[i].c) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x30303030
int w, h;
int air[10][10], cost[10][10];
int mv[3][2] = {{0,-1},{1,0},{0,1}};
char mk[10][10][50][1024];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();

	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}

	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int dijkstra(int f, int m, int o)
{
	int i, x, y, c, s, x2, y2, o2, c2, s2;

	memset(mk, 0, sizeof(mk));
	qsize = 0;
	for (x = 0; x < w; x++) enq(-1, x, o, 0, 1 << x);
	while (qsize) {
		x = que[0].x, y = que[0].y, o = que[0].o, c = que[0].c, s = que[0].s, deq();
		if (y == h-1) return c;

		for (i = 0; i < 3; i++) {
			y2 = y + mv[i][0], x2 = x + mv[i][1];
			if (y2 < 0 || x2 < 0 || x2 >= w || o <= 1) continue;
			c2 = c, o2 = o-1;
			if (i == 1) s2 = 1 << x2;
			else        s2 = s | (1 << x2);
			if (i == 1 || s2 != s) {
				c2 += cost[y2][x2];
				o2 += air[y2][x2]; if (o2 > m) o2 = m;
			}
			if (c2 > f) continue;
			if (mk[y2][x2][o2][s2]) continue;
			mk[y2][x2][o2][s2] = 1;
			enq(y2, x2, o2, c2, s2);
		}
	}
	return -1;
}

int main()
{
	int f, m, o, x, y, t, ans;

	while (w = in()) {
		h = in();
		f = in(), m = in(), o = in();
		for (y = 0; y < h; y++) for (x = 0; x < w; x++) {
			t = in();
			if (t >= 0) air[y][x] = t, cost[y][x] = 0;
			else        air[y][x] = 0, cost[y][x] = -t;
		}
		ans = dijkstra(f, m, o);
		if (ans < 0) puts("NA");
		else printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 6904
/**
*    author:  y_takano
*    created: 18.06.2020 16:33:26
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int tmp;
  vector<int> arr;

  for (;;)
  {
      cin >> tmp;
      if (tmp != 0)
      {
         arr.push_back(tmp);
      }
      else
      {
          break;
      }
  }
  
  for (int i = 0; i < arr.size(); i++)
  {
      cout << "Case " << i + 1 << ": " << arr[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ll = long long;
const int MM = 1e5+5;

int X, Y, A, B, C, v;
vector<ll> va, vb, vc;

int main(){
    scan(X, Y, A, B, C);
    while(A--){
        scan(v);
        va.emplace_back(v);
    }
    while(B--){
        scan(v);
        vb.emplace_back(v);
    }while(C--){
        scan(v);
        vc.emplace_back(v);
    }
    sort(all(va));
    sort(all(vb));
    sort(all(vc));
    reverse(all(va));
    reverse(all(vb));
    reverse(all(vc));
    va.resize(X);
    vb.resize(Y);
    ll ans = accumulate(all(va), 0LL) + accumulate(all(vb), 0LL);
    for(int c: vc){
        if(va.empty() and vb.empty())
            break;
        if(va.empty()){
            if(vb.back() >= c)
                break;
            ans -= vb.back();
            ans += c;
            vb.pop_back();
        }
        else if(vb.empty()){
            if(va.back() >= c)
                break;
            ans -= va.back();
            ans += c;
            va.pop_back();
        }
        else{
            v = min(va.back(), vb.back());
            if(v >= c)
                break;
            if(va.back() == v){
                ans -= va.back();
                ans += c;
                va.pop_back();
            }
            else{
                ans -= vb.back();
                ans += c;
                vb.pop_back();
            }
        }
    }
    
    print(ans);
    
    return 0;
}

Measured memory_bytes: 3316
# Maximum heap

H = int(input())
*A, = map(int, input().split())
A = [0] + A


def left(i):
    return i*2


def right(i):
    return i*2+1


def max_heapify(i):
    l = left(i)
    r = right(i)

    M = l if l <= H and A[l] > A[i] else i
    M = r if r <= H and A[r] > A[M] else M

    if M != i:
        A[i], A[M] = A[M], A[i]
        max_heapify(M)


def build_max_heap():
    for i in range(H//2, 0, -1):
        max_heapify(i)


build_max_heap()
print('', *A[1:])



Measured memory_bytes: 63696
import math
import random

def is_prime3(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1

    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1:
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

def get_prime(number):
    prime_list = []
    search_list = list(range(2,number + 1))
    while search_list[0] <= math.sqrt(number):
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        search_list = [num for num in search_list if num % head_num != 0]
    prime_list.extend(search_list)
    return prime_list

l = get_prime(10**6+10)
N = int(input())
ans = 0
k = 1
i = 0
l2 = []
while(l[i]**2 <= N):
    if N % (l[i]**k) == 0:
        N //= (l[i]**k)
        l2.append(l[i]**k)
        k += 1
        ans += 1
    else:
        i += 1
        k = 1
index = 0
while(index < len(l2)):
    if N % (l2[index]) == 0:
        N //= l2[index]
    else:
        index += 1
if is_prime3(N) and N not in l2:
    ans += 1
print(ans)


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N, M, X, Y; cin >> N >> M >> X >> Y;
    vec x(N); rep(i, N) cin >> x[i];
    vec y(M); rep(i, M) cin >> y[i];

    bool flg = true;
    if(X >= Y) flg = false;
    rep(i, N){
        rep(j, M){
            if(x[i] >= y[j]) flg = false;
            if(X >= y[j]) flg = false;
            if(x[i] >= Y) flg = false;
        }
    }

    if(flg) cout << "No War" << endl;
    else cout << "War" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
//const int MAX=;

int N;
string S;
vi a;
void input(){
	cin>>N;
	cin>>S;
	rep(i, N){
		a.pb(1 + S[i] - '1');
	}
}

int func(vi a, int m){
	int n = m-1;
	int ans = 0;
	rep(r, n+1){
		if(n==(r^(n-r)) && a[r]%2) ans++;
	}
	return ans%2;
}

void solve(){
	bool alleven = true;
	vi diff(N-1);
	rep(i, N-1){
		diff[i] = abs(a[i]-a[i+1]);
		if(diff[i]%2==1){
			alleven = false;
		}
	}
	if(alleven){
		rep(i, N-1)diff[i]=diff[i]/2;
		int ans = func(diff, N-1);
		cout<<ans*2;
	}
	else{
		int ans = func(a, N);
		cout<<ans;
	}
}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 13688
#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<"["#x<<" :";printx(x);cout<<"]\n"
template <typename T> void printx(T x){ cout<<x; }
template <typename T> void printx(vector<T> &v){ for(int x:v){ cout<<x<<" ";}}
template <typename T> void printx(vector<vector<T>> &v){ for(size_t i=0;i<v.size();i++){cout<<"\t";
										for(size_t j=0;j<v[i].size();j++){cout<<v[i][j]<<" ";}if(i!=v.size()-1) cout<<endl;}}
typedef long long ll;
typedef unsigned long long ull;

void solve(){
	ull n;
	cin>>n;
	ull sum = (n*(n+1))/2;
	//print(sum);
	vector<int> mark(n+1);
	for(ull i=3;i<=n;i+=3){
		mark[i] = 1;
		sum -= i;
	}
	for(ull i=5;i<=n;i+=5){
		if(mark[i]==0){
			sum -= i;
			mark[i] = 1;
		}
	}
	cout<<sum<<endl;
}

int main(){
		std::ios::sync_with_stdio(0);
		cin.tie(0);
		solve();
		return 0;
}


Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
const int kN = 1e4 + 10;

int in[kN], dfs_clock;
int sccno[kN], scc_cnt;
stack<int> s;
vector<int> g[kN];

int dfs(int u) {
	int lowu = in[u] = ++dfs_clock;
	s.push(u);
	for(int v : g[u]) {
		if(!in[v]) lowu = min(lowu, dfs(v));
		else if(!sccno[v]) lowu = min(lowu, in[v]);
	}

	if(lowu == in[u]) {
		scc_cnt++;
		while(true) {
			int x = s.top(); s.pop();
			sccno[x] = scc_cnt;
			if(x == u) break;
		}
	}
	return lowu;
}

int main() {
	int n, m; scanf("%d%d", &n, &m);
	for(int i = 0, x, y; i < m; i++) {
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
	}
	for(int i = 1; i <= n; i++)
		if(!in[i]) dfs(i);

	int q; scanf("%d", &q);
	while(q--) {
		int x, y; scanf("%d%d", &x, &y);
		printf("%d\n", sccno[x] == sccno[y]);
	}
	return 0;
}



Measured memory_bytes: 4156
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
int n;
int arr[N];
long long f(long long x){
    long long sum = 0 ;
    for(int i = 1 ; i <= n ; i++){
        sum += abs(arr[i] - (x + i));
    }
    return sum;
}
int main (){
    scanf("%d",&n);
    for(int i = 1 ; i <= n ; i++){
        scanf("%d",&arr[i]);
    }
    long long l = -1e9, r = 1e9, zzz = 200;
    while (zzz--) {
        int z =(r - l + 1) / 3;
        long long m1 = l + z;
        long long  m2 = r - z;
       // cout << l <<' ' << r <<' ' << z <<' ' << m1 <<' ' << m2 << endl;
        long long f1 = f(m1);
        long long f2 = f(m2);
        //cout << f1 <<' ' << f2 <<' ' << m1 <<' ' << m2 << endl;
        if (f1 > f2)
            l = m1;
        else
            r = m2;
    }
    cout << min(f(l), f(r));
    return 0;
}


Measured memory_bytes: 1024
S=input()
s=list(S)

ans=0

if len(S)!=1:
    for i in range(2**(len(s)-1)):
        judge=str(bin(i))[2:].rjust(len(s)-1,"0")
        sum=0
        plus=s[0]
        #print(judge)
        for j,jud in enumerate(judge):
            if jud=="0":
                plus+=s[j+1]
                #print(plus)
            else:
                sum+=int(plus)
                plus=""
                plus+=s[j+1]
        if len(plus)!=0:
            sum+=int(plus)
            #print(plus)
        #print(sum)
        ans+=sum
else:
    ans=int(S)
print(ans)

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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back( make_pair( (a), (b) ) )

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

int main() {
    int64_t n;
    cin >> n;
    int64_t ans = 0;
    if ( 400 <= n && n <= 599 ) {
        ans = 8;
    } else if ( 600 <= n && n <= 799 ) {
        ans = 7;
    } else if ( 800 <= n && n <= 999 ) {
        ans = 6;
    } else if ( 1000 <= n && n <= 1199 ) {
        ans = 5;
    } else if ( 1200 <= n && n <= 1399 ) {
        ans = 4;
    } else if ( 1400 <= n && n <= 1599 ) {
        ans = 3;
    } else if ( 1600 <= n && n <= 1799 ) {
        ans = 2;
    } else if ( 1800 <= n && n <= 1999 ) {
        ans = 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>

using lli = long long int;
int inf = 1000000007;
using namespace std;
#define sort(X) sort(X.begin(),X.end())

int N, M;

int main()
{
	cin >> N >> M;
	vector<int> S(N);
	for (int i = 0; i < N; i++)cin >> S[i];
	vector<int> T(M);
	for (int i = 0; i < M; i++)cin >> T[i];

	vector<vector<lli>> ans(2019, vector<lli>(2019));
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++) {
			ans[i + 1][j + 1] = ans[i][j + 1] + ans[i + 1][j] - ans[i][j];
			if (S[i] == T[j]) ans[i + 1][j + 1] += ans[i][j] + 1;
			ans[i + 1][j + 1] = (ans[i + 1][j + 1] + inf) % inf;
		}
	//(),() を足す
	cout << ans[N][M] + 1 << endl;
	return 0;
}

Measured memory_bytes: 32256
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

int main(){
    int N, Q;
    ll K;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    for(int i = 0; i < Q; ++i) cin >> A[i];

    vector<int> P(N);
    for(int i = 0; i < Q; ++i) P[A[i] - 1]++;
    for(int i = 0; i < N; i++){
        if(Q - P[i] >= K) puts("No");
        else puts("Yes");
    }
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        char c = s.next().charAt(0);
        int  b = s.nextInt();
        if(c=='+') System.out.println(a+b);
        else System.out.println(a-b);
    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25348
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
public class Main {
	long N,S;

	public long f(long b,long n){
		if(n < b)return n;
		return f(b,n / b) + (n % b);
	}

	public void solve() {
		N = nextLong();
		S = nextLong();

		if(N == S){
			out.println(N + 1);
			return;
		}

		long ans = Long.MAX_VALUE;
		for(int i = 2;(long)i * i <= N;i++){
			long res = f(i,N);
			if(res == S){
				out.println(i);
				return;
			}
		}

		for(int i = 1;(long)i * i <= N - S;i++){
			long B = (N - S) / i + 1;
			if(f(B,N) == S){
				ans = Math.min(ans,B);
			}
		}
		out.println(ans == Long.MAX_VALUE ? -1 : ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

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

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 8532
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();
            if (S.charAt(0) == 'A' && S.charAt(1) == 'A' && S.charAt(2) == 'A') {
                out.println("No");
                return;
            }
            if (S.charAt(0) == 'B' && S.charAt(1) == 'B' && S.charAt(2) == 'B') {
                out.println("No");
                return;
            }
            out.println("Yes");
        }

    }
}



Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int n;

bool is_pal(string &s, int i, int j){
    --i; --j;
    while(i<=j && i<n && j>=0)
        if(s[i]!=s[j]) return false;
        else ++i, --j;
    return true;
}

int main(){
    string s;
    while(cin>>s){
        n = s.size();
        
        bool a = is_pal(s, 1, n);
        bool b = is_pal(s, 1, (n-1)/2);
        bool c = is_pal(s, (n+3)/2, n);

        if(a&b&c)
            cout<<"Yes"<<endl;
        else 
            cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i

s = []

N.times do |i|
  s <<  gets.chomp
  if i > 0 && s[i-1][-1] != s[i][0]
    puts "No"
    exit
  end

  if i > 1
    0.upto(i-1) do |j|
      if s[i].eql?(s[j])
        puts "No"
        exit
      end
    end
  end
end

puts "Yes"


Measured memory_bytes: 1788
def gcd(a,b):
    while b:
        a,b = b, a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

n = int(input())
t = list(int(input()) for i in range(n))
mxt = max(t)
ls = []
ans = 0
j = 0
mod_flag = False

for i in range(n):
    if not mxt == t[i] and not mxt % t[i] == 0:
        mod_flag = True
        ls.append(t[i])
        j+=1
    
if not mod_flag:
    ans = mxt

if ans == 0:
    ans += mxt
    for i in range(len(ls)):
        if not ans % ls[i] == 0:
            ans = lcm(ans,ls[i])
    
print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] a = new int[N];
    int max = 0;
    int min = (int)Math.pow(10, 9) + 1;
    for(int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
      max = Math.max(max, a[i]);
      min = Math.min(min, a[i]);
    }
    Arrays.sort(a);
    int[] b = new int[N];
    for(int i = 1; i < N; i++) {
      if(a[i] > a[i - 1]) min = Math.min(a[i] - a[i - 1], min);
      b[i] = a[i] - a[i - 1];
    }
    String ans = "IMPOSSIBLE";
    if(K == max) ans = "POSSIBLE";
    if(K < max) {
      boolean flg = false;
      if(min == 1) flg = true;
      for(int i = 0; i < N; i++) {
        if(a[i] % min != 0) flg = true;
        if(b[i] % min != 0) flg = true;
      }
      if(flg) ans = "POSSIBLE";
      if((min < max) && (K % min == 0)) ans = "POSSIBLE";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 51012
from collections import deque

N=int(input())

node_list = [[] for i in range(N)]

for i in range(N-1):
    u,v,w=list(map(int,input().split()))
    node_list[u-1].append([v-1,w%2])
    node_list[v-1].append([u-1,w%2])
    
color_list = [-1 for i in range(N)]

Q=deque([0])

color_list[0] = 0

while len(Q)>0:
    v1 = Q.pop()
    current_color=color_list[v1]
    for v2 in node_list[v1]:
        if color_list[v2[0]]==-1:
            if v2[1]==0:
                color_list[v2[0]]=current_color
            else:
                color_list[v2[0]]=1-current_color
            Q.appendleft(v2[0])

for i in range(N):
    print(color_list[i])

Measured memory_bytes: 42440
#include <bits/stdc++.h>
using namespace std;
char a[101][101];
char b[202][101];

int main() {
	int h, w;
	cin>>h>>w;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++){
			cin>>a[i][j];
			b[2*i+1][j]=b[2*i][j]=a[i][j];
		}
	
	for(int i=0;i<2*h;i++){
		for(int j=0;j<w;j++)
			cout<<b[i][j];
		cout<<endl;	
		}
	
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = map(int, input().split())
ones = [0] * 60

for a in A:
    i = 0
    while (1 << i) <= a:
        ones[i] += ((a >> i) & 1)
        i += 1

ans = 0
mod = 10 ** 9 + 7

for idx, one in enumerate(ones):
    ans = (ans + one * (N - one) * (1 << idx)) % mod

print(ans)


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    string s;
    cin >> n >> k >> s;
    if(s[k - 1] >= 'A' and s[k - 1] <= 'Z') {
        s[k - 1] = s[k - 1] - 'A' + 'a';
    }
    cout << s << ln;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const int MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

struct qd {
	int x, y, now;
	qd(int a, int b, int c) :
	x(a),
	y(b),
	now(c){
	}
};

int main() {
	int H,W;
	cin >> H >> W;
	vector<string> v(H);
	for (int i = 0; i < H; i++) {
		cin >> v[i];
	}
	vector<vector<bool>> check(H, vector<bool>(W, false));
	queue<qd> q;
	q.push(qd(0, 0, 1));
	while (!q.empty()) {
		auto n = q.front(); q.pop();
		if (check[n.y][n.x])continue;
		check[n.y][n.x] = true;
		if (v[n.y][n.x] == '#')continue;
		if (n.x == W - 1 && n.y == H - 1) {
			int ans = H*W;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (v[i][j] == '#')ans--;
				}
			}
			cout << ans - n.now << endl;
			return 0;
		}
		if (n.x != 0) {
			q.push(qd(n.x - 1, n.y, n.now + 1));
		}
		if (n.x != W-1) {
			q.push(qd(n.x + 1, n.y, n.now + 1));
		}
		if (n.y != 0) {
			q.push(qd(n.x, n.y-1, n.now + 1));
		}
		if (n.y != H-1) {
			q.push(qd(n.x, n.y+1, n.now + 1));
		}
	}
	cout << -1 << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <functional>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n, k;
	cin >> n >> k;
	cout << (n - k)*(k > 1);
	return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

use std::cmp;

fn find_min(x: &[u64]) -> u64 {
    let mut min: u64 = x[0];
    let mut x_iter = x.iter();
    while let Some(i) = x_iter.next() {
        min = cmp::min(*i, min);
    }
    return min
}

fn main() {
    let n: u64 = read();

    let mut capacity: Vec<u64> = Vec::new();
    for _i in 0..5 {
        let tmp: u64 = read();
        capacity.push(tmp);
    }

    let capacity_min: u64 = find_min(&capacity);

    let raised: u64 = (n + (capacity_min - n%capacity_min)%capacity_min)/capacity_min;

    println!("{}", raised + 4);
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    int n = s.size();
    int g=0,p=0;
    rep(i,n){
        if (s[i]=='g') g++;
        if (s[i]=='p') p++;
    }
    int P = n/2, G = n-n/2;
    int ans=min(P,g)-min(p,G);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    bool prime[1000001];
    for(int i=2;i<1000001;i++)prime[i]=0;
    for(int i=2;i<=sqrt(1000000);i++){
        if(prime[i]==0){
            for(int j=i+i;j<1000001;j+=i)prime[j]=1;
        }
    }
    int n,cou=0;
    while(cin>>n&&n!=0){
        for(int i=2;i<=n/2;i++)if(prime[i]==0&&prime[n-i]==0)cou++;
        cout<<cou<<endl;
    cou=0;
    }
}

Measured memory_bytes: 2132
' Imports System.Collections.Generic
' Imports System.Text
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim N As Integer = Console.ReadLine()
        Dim flg As Boolean = False
        For i As Integer = 0 To 9
            For j As Integer = 0 To 9
                If i * j = N Then
                    flg = True
                    Exit For
                End If
            Next
            If flg Then
                Exit For
            End If
        Next
        Console.WriteLine(If(flg, "Yes", "No"))
        Return
    End Sub
End Class

Measured memory_bytes: 28236
n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10**9 + 7

# dp[i][k]: i人目まで見たときにk個アメを配った場合の数
dp = [[0] * (k+1) for _ in range(n+1)]

# 始点は1、それ以外は0で初期化
dp[0][0] = 1

for i in range(1, n+1):
    # dp[i-1]の累積和をループを回しながら計算する
    # 累積和は0を含んだ0-basedの半開区間でかく (1-indexed)
    cum = [0] * (k+2)
    for j in range(k+1):
        cum[j+1] = (cum[j] + dp[i-1][j]) % mod
        dp[i][j] += cum[j+1] - cum[max(0, j-a[i-1])]
        dp[i][j] %= mod

print(dp[n][k])

Measured memory_bytes: 130328
#include <iostream>

using namespace std;

int main()
{
	int k, result = 0;
	cin >> k;

	for (int i = 1; i < k; i++) 
	{
		for (int j = i + 1; j <= k; j+=2)
		{
			result++;
		}
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9



int main() {
	ll a, b;
	cin >> a >> b;
	ll dif = b - a;
	cout << dif * (dif + 1) / 2 - b << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a,b;cin>>n>>a>>b;
  if(n==1) puts("Hello World");else print(a+b);
  return 0;
}


Measured memory_bytes: 256
def f_1(s):
    if s[0] == "A":
        return True
    else:
        return False

def f_2(s):
    s = s[2:-1]
    if "C" in s:
        i = s.index("C")
        s = s[:i] + s[i+1:]
        if "C" not in s:
            return True
        else:
            return False
    else:
        return False
def f_3(s):
    s = s[1:].replace("C","")
    if s.lower() == s:
        return True
    else:
        return False

s = input()
if f_1(s) and f_2(s) and f_3(s):
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;

map<pair<int, pii>, int> mp;
int ali[MAXN];

ll do_it(int a, int b, int c){
    if(a + b + c == n){
        return 1;
    }
    auto it = mp.find({a, {b, c}});
    if(it != mp.end()){
        //cout<<(*it).ff.ff<<" "<<(*it).ss<<endl;
        return (*it).ss;
    }
    ll cur = ali[a + b + c]; 
    ll ans = 0;
    if(cur == a){
        ans += do_it(a + 1, b, c);
        ans %= mod;
    }
    if(cur == b){
        ans += do_it(a, b + 1, c);
        ans %= mod;
    }
    if(cur == c){
        ans += do_it(a, b, c + 1);
        ans %= mod;
    }
    return mp[{a, {b, c}}] = ans;
}

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

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n;

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

    cout<<do_it(0, 0, 0)<<endl;
    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

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

int main() {
    int a,i,b;
    cin >> a;
    vector<int> v(a,0);
    for(i=0;i<a;i++){
        cin >>v.at(i);
    }
    stable_sort(v.begin(),v.end());
    b=a/2;
    cout << v.at(b)-v.at(b-1) << endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int sum = 0;
	for(int i = 0;i<n;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		sum+=abs(a-b)+1;
	}
	printf("%d\n",sum);
	return 0;
}

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

int main(){
  string s, t;
  cin >> s >> t;
  int ls = s.length();
  int lt = t.length();
  vector<vector<int>> dp(ls+1,vector<int>(lt+1,INF));
  rep(i,ls+1) dp[i][0] = i;
  rep(i,lt+1) dp[0][i] = i;
  for(int i = 1; i <= ls; i++) {
    for(int j = 1; j <= lt; j++) {
      if(s[i-1] == t[j-1]) dp[i][j] = min({dp[i-1][j-1],dp[i][j-1]+1,dp[i-1][j]+1});
      else dp[i][j] = min({dp[i-1][j-1]+1,dp[i][j-1]+1,dp[i-1][j]+1});
    }
  }
  cout << dp[ls][lt] << endl;
  return 0;
}


Measured memory_bytes: 6824
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main (void){
	int x,y;
  	cin >> x >> y;
  	if((x+y)%2==0) cout << (x+y)/2 << endl;
  	else cout << (x+y+1)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    char s;
    cin >> s;
    s++;
    cout << s << endl;
}


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

#define lld long long
#define pii pair<int,int>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Mod 1000000007

using namespace std;

int N,M; lld ans;
int a[3002],sum[3002];
int x[3002],y[3002];
lld fact[3002],inv[3002];
lld d[3002][3002];
char s[3002];

lld mul(lld x,int y){
	if(y == 0) return 1;
	lld tmp = mul(x,y/2);
	tmp *= tmp; tmp %= Mod;
	if(y%2==1){
		tmp *= x;
		tmp %= Mod;
	}
	return tmp;
}
lld comb(int n,int r){
	lld tmp = fact[n];
	tmp *= inv[n-r]; tmp %= Mod;
	tmp *= inv[r]; tmp %= Mod;
	return tmp;
}

int main(){
	scanf("%d %d",&N,&M);
	scanf("%s",s);
	fact[0] = inv[0] = 1;
	for(int i=1; i<=N; i++){
		a[i] = s[i-1]-'0';
		sum[i] = sum[i-1]+a[i];
		fact[i] = (fact[i-1]*i)%Mod;
		inv[i] = mul(fact[i],Mod-2);
	}
	int rear = 0;
	for(int i=1; i<=M; i++){
		int tx,ty;
		scanf("%d %d",&tx,&ty);
		if(x[rear] == tx) y[rear] = max(y[rear],ty);
		else{
			rear++;
			x[rear] = tx; y[rear] = ty;
		}
	}
	M = rear;
	d[0][sum[x[1]-1]] = 1;
	x[M+1] = N+1;
	int maxr = 0;
	for(int i=1; i<=M; i++){
		maxr = max(maxr,y[i]);
		for(int j=0; j<=sum[maxr]; j++){
			if(d[i-1][j] == 0) continue;
			int cnt1,cnt2,tmp = 0;
			if(maxr < x[i+1]){
				cnt1 = cnt2 = sum[maxr]-j;
				tmp = sum[x[i+1]-1]-sum[maxr];
			}else{
				if(sum[maxr]-j > maxr-x[i]+1) while(true);
				cnt1 = max(0,sum[maxr]-j-(maxr-x[i+1]+1));
				cnt2 = min(sum[maxr]-j,x[i+1]-x[i]);
			}
			for(int k=cnt1; k<=cnt2; k++){
				d[i][j+k+tmp] += d[i-1][j]*comb(min(maxr,x[i+1]-1)-x[i]+1,k);
				d[i][j+k+tmp] %= Mod;
			}
		}
	}
	for(int i=0; i<=sum[N]; i++){
		ans += d[M][i];
		ans %= Mod;
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 45696
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}

int log(int x) {
    int i;
    for(i=0;(1ll<<i)<=x;i++);
    return i;
}
 
int32_t main() {
    fio
    
    cout << fixed << setprecision(15);
    int n;
    cin >> n;
    
    int c=0;
    map<int,int> m;
    
    while(true) {
        c++;
        if(n%2==0) {
            if(m[n]==1) {
                cout << c;
                break;
            }
            m[n]=1;
            n/=2;
        }
        else {
            if(m[n]==1) {
                cout << c;
                break;
            }
            m[n]=1;
            n=(3*n)+1;
        }
        
    }
    
	return 0;
    
}

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

#define read  cin >> 
#define print cout << 
#define vec vector


int dfs (vec<vec<int>>& G, vec <int>& dp, int k)
{
    int n = G[k].size();
    if(!n) dp[k] = 1;

    if(dp[k]) return dp[k];
    
    for(int i = 0; i < n; i++)
        if(!dp[G[k][i]])
            dfs(G, dp, G[k][i]);
    
    for(int i = 0; i < n; i++)
        dp[k] = max (dp[k], dp[G[k][i]]);

    dp[k]++;
    return dp[k];
}


int main()
{
    int n, m, x, y; read n >> m;
    vec <vec <int> > G (n + 1);
    for(int i = 0; i < m; i++){ read x >> y; G[x].push_back(y);}


    vector <int> dp (n+1, 0);
    int max_ = dp[0];
    for(int i = 1; i <= n; i++)
        max_ = max(max_, dfs (G, dp, i) );
    
    print max_-1<< "\n";

    return 0;
}

Measured memory_bytes: 9472
object Main extends App {
  import scala.io.StdIn._
  val n = readLine().toInt
  val nums = (0 until n).map(_ => readLine().toInt).toArray
  if (withNext(nums, -1).forall{case (prev, now) => (now - prev) < 2}){
    println( withNext(nums, 0).map{case (prev, now) => if (now - prev == 1) 1 else now}.foldLeft(0L){_ + _})

  }else{
    println(-1)
  }
  def withNext[T](array:Array[T], first:T):Array[(T, T)] = {
    return array.zipWithIndex.map{
      case (factor, 0) => (first, factor)
      case (factor, idx) => (array(idx - 1), factor)
    }
  }

}


Measured memory_bytes: 98228
#include<iostream>
using namespace std;
int main(){
    int H,W,i,j;
    while(true){
        cin>>H>>W;
        if(H == 0)break;
        for(i=1;i<=H;i++){
            for(j=1;j<=W;j++){
                if((i+j)%2==0){
                    cout<<"#";
                }else{
                    cout<<".";
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3044