akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fir first
#define sec second
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

typedef double db;
const db pi = acos(-1);
const int N = 800010;
int rev[N];
void prework(int n) {
  rev[0] = 0;
  rep (i, 1, n-1)
    if (i&1) rev[i] = rev[i^1] | (n >> 1);
    else rev[i] = rev[i >> 1] >> 1;
}
struct cpl {
  db x,y;
  cpl(db x=0,db y=0): x(x), y(y) {}
  cpl operator + (const cpl& a) const {
    return cpl(x + a.x, y + a.y);
  }
  cpl operator - (const cpl& a) const {
    return cpl(x - a.x, y - a.y);
  }
  cpl operator * (const cpl& a) const {
    return cpl(x * a.x - y * a.y, x * a.y + y * a.x);
  }
  cpl operator / (const db& a) const {
    return cpl(x / a, y / a);
  }
};
void dft(cpl* a,int n,int sgn) {
  rep (i, 0, n-1) if (rev[i] < i)
    swap(a[i], a[rev[i]]);
  cpl w, wp, u, v;
  for (int s = 2; s <= n; s <<= 1) {
    wp = cpl(cos(2 * pi / s), sin(2 * pi / s));
    if (sgn) wp.y = -wp.y;
    for (int k = 0; k < n; k += s) {
      w = cpl(1, 0);
      for (int j = 0; j < (s >> 1); ++ j) {
        u = a[k + j];
        v = a[k + j + (s >> 1)] * w;
        a[k + j] = u + v;
        a[k + j + (s >> 1)] = u - v;
        w = w * wp;
      }
    }
  }
  if (sgn) {
    rep (i, 0, n-1) a[i] = a[i] / n;
  }
}

const int MOD = 200003, G = 5;
int power(int a,int b) {
  int ret = 1;
  while (b) {
    if (b&1) ret = (ll)ret * a % MOD;
    a = (ll)a * a % MOD;
    b >>= 1;
  }
  return ret;
}
int n, val[N], key[MOD + 10], num[N];
ll tnum[N];
cpl ta[N];
ll ans;
int main() {
  read(n);
  rep (i, 1, n) read(val[i]);
  for (int i = 0, j = 1; i < MOD - 1; ++ i, j = (ll)j * G % MOD)
    key[j] = i;
  rep (i, 1, n) if (val[i] != 0) {
    ++ num[key[val[i]]];
    // cerr << key[val[i]] << endl;
  }
  int l = 1;
  while (l < 2 * MOD) l <<= 1;
  prework(l);
  rep (i, 0, MOD - 2) ta[i] = cpl(num[i], 0);
  dft(ta, l, 0);
  rep (i, 0, l-1) ta[i] = ta[i] * ta[i];
  dft(ta, l, 1);
  rep (i, 0, l-1) tnum[i] = (ll)(ta[i].x + 0.5);
  rep (i, 0, 2 * MOD) if (tnum[i]) {
    ans += power(G, i) * tnum[i];
    // cerr << i << ' ' << tnum[i] << endl;
  }
  rep (i, 1, n) ans -= (ll)val[i] * val[i] % MOD;
  ans /= 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 24864
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  cout << S[0];
  cout << S.size()-2;
  cout << S[S.size()-1] << endl;
}

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

// Generate all primes till 1000000 //
const int N = 1e6 + 5 ;
ll arrPrime[5761555], sz ;
bool prime[N + 1] ;

void SieveOfEratosthenes()
{
    for (ll p = 3; p * p <= N; p += 2) {
        if (!prime[p]) {
            for(ll i = p * p; i <= N; i += (p << 1) ) {
                prime[i] = true;
            }
        }
    }

    ll i = 0 ;
    arrPrime[i++] = 2 ;
    for (ll p = 3; p <= N; p += 2) {
        if(!prime[p]) arrPrime[i++] = p ;
    }
    sz = i ;
}

map <int, int> mp ;

int main()
{
    SieveOfEratosthenes() ;
    int val = 1 ;
    mp[val] = 1 ;
    for (int i = 2; i <= 45; i++) {
        val += i ;
        mp[val] = i ;
    }
    ll n, limit, ans = 0 ;
    cin >> n ;
    limit = sqrt(n) ;
    for (int i = 0; i < sz and arrPrime[i] <= limit; i++) {
        if (n % arrPrime[i] == 0) {
            ll cnt = 0, val ;
            while (n % arrPrime[i] == 0) {
                n /= arrPrime[i] ;
                cnt++ ;
            }
            for (auto it = mp.begin(); it != mp.end(); it++) {
                if (it->first <= cnt) {
                    val = it->second ;
                }
            }
            ans += val ;
        }
    }
    if (n != 1) ans++ ;
    cout << ans ;


    return 0 ;
}


Measured memory_bytes: 5268
use std::io;

fn main() {
    let s = read_one::<String>();
    let b = read_one::<String>();

    let s = s.clone() + &s.as_str();

    if s.contains(&b) { println!("Yes"); }
    else { println!("No"); }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <inttypes.h>

#define MOD_BY 1000000007

int add(int a, int b) {
	return a + b - MOD_BY * (a + b >= MOD_BY);
}

int sub(int a, int b) {
	return b == 0 ? a : add(a, MOD_BY - b);
}

int mul(int a, int b) {
	return (int)((int64_t)a * b % MOD_BY);
}

int power(int a, int b) {
	int r = 1;
	while (b) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

int inv(int a) {
	return power(a, MOD_BY - 2);
}

int waru(int a, int b) {
	return b == 0 ? 0 : mul(a, inv(b));
}

int cache[3333333];

int mizuhasu[3333333];

int asumisu[3333333];

int main(void) {
	int r1, c1, r2, c2;
	int i;
	int hoge, fuga;
	int kotae;
	cache[0] = 1;
	for (i = 1; i < 3333333; i++) {
		cache[i] = mul(cache[i - 1], i);
	}
	if (scanf("%d%d%d%d", &r1, &c1, &r2, &c2) != 4) return 1;
	for (i = c1; i <= c2; i++) {
		mizuhasu[i] = waru(waru(cache[r1 + i], cache[r1]), cache[i]);
	}
	hoge = r2 - r1;
	fuga = c2 - c1;
	for (i = 0; i <= fuga + 1; i++) {
		asumisu[i] = waru(waru(cache[hoge + i], cache[hoge]), cache[i]);
	}
	kotae = 0;
	for (i = c1; i <= c2; i++) {
		kotae = add(kotae, mul(mizuhasu[i], asumisu[c2 - i + 1]));
	}
	for (i = r1 + 1; i <= r2; i++) {
		int a = waru(waru(cache[i + c1 - 1], cache[i]), cache[c1 - 1]);
		int b = waru(waru(cache[(r2 - i + 1) + (fuga + 1)], cache[r2 - i + 1]), cache[fuga + 1]);
		kotae = add(kotae, mul(a, sub(b, 1)));
	}
	printf("%d\n", kotae);
	return 0;
}

/*

対象範囲の一番下がa, b, cのとき、和 (別にx, yも後で足す)

y a aab aaabbc
x a ab  abc
  a b   c

下から上に行った時、合計でa, b, cをそれぞれ何個足すか

  10 4  1
  6  3  1
  3  2  1
  1  1  1

これは右下から左上に向かう組み合わせになっている！

そして、xを足す数は、aを足す数-1
yを足す数も、上に行く数を減らせば同様に求まる

*/


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
const int mod = 1e9 + 7;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), [](int a, int b) {return abs(a) > abs(b); });

    ll res = 1;
    int sign = 1;
    bool eqzero = false;
    for (int i = 0; i < k; ++i) {
        res *= a[i];
        if (a[i] < 0) sign *= -1;
        if (a[i] == 0) eqzero = true;
        res %= mod;
    }

    if (sign > 0 || eqzero){
        res += mod;
        res %= mod;
        cout << res << endl;
        return 0;
    }

    res = 1;
    ll lpos = INF;
    ll lneg = INF;
    ll rpos = INF;
    ll rneg = INF;
    for (int i = k - 1; i >= 0; --i) {
         if (a[i] >= 0){
             lpos = a[i];
             break;
         }
    }
    for (int i = k - 1; i >= 0; --i) {
        if (a[i] < 0){
            lneg = a[i];
            break;
        }
    }
    for (int i = k; i < n; ++i) {
        if (a[i] >= 0){
            rpos = a[i];
            break;
        }
    }
    for (int i = k; i < n; ++i) {
        if (a[i] < 0){
            rneg = a[i];
            break;
        }
    }

    if ((lpos == INF || rneg == INF) && (lneg == INF || rpos == INF)){
    //if(lpos == INF && rpos == INF){
        reverse(a.begin(), a.end());
        for (int i = 0; i < k; ++i) {
            res *= a[i];
            res %= mod;
        }
        res += mod;
        res %= mod;
        cout << res << endl;
        return 0;
    }

    int out, in;
    if (lpos != INF && rpos != INF && lneg != INF && rneg != INF){
        if (lneg * rneg > lpos * rpos) {
            out = lpos;
            in = rneg;
        } else {
            out = lneg;
            in = rpos;
        }
    } else if (lneg != INF && rpos != INF){
        out = lneg;
        in = rpos;
    } else{
        out = lpos;
        in = rneg;
    }

    bool flag = true;
    for (int i = 0; i < k; ++i) {
        if (a[i] == out && flag){
            res *= in;
            res %= mod;
            flag = false;
            continue;
        }
        res *= a[i];
        res %= mod;
    }

    res += mod;
    res %= mod;
    cout << res << endl;
}

Measured memory_bytes: 4024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;

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

int main()
{
	int i, j;
	ll a, b;
	scanf("%lld %lld", &a, &b);
	if (a < b) swap(a, b);
	ll g = gcd(a, b);
	printf("%lld", a*b / g);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d = {}
for i in range(n):
  dd = {}
  for ch in input():
    dd[ch] = dd.get(ch, 0) + 1
  if i:
    for v in d:
      d[v] = min(d[v], dd.get(v,0))
  else:
    d = dd
for v in sorted(d.keys()):
  print(v*d[v], end = "")
print()  

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

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

struct b_tree{
	int left;
	int right;
	int sibling;
	int parent;
};

int getDepth(b_tree* array, int index){
	if(index == -1) return 0;
	if(array[index].left == -1 && array[index].right == -1)return 0;

	int right = getDepth(array, array[index].right);
	int left = getDepth(array, array[index].left);

	return (right > left ? right : left) + 1;
}

void preorder(b_tree* array, int index){
	cout << " " << index;
	if(array[index].left != -1)preorder(array, array[index].left);
	if(array[index].right != -1)preorder(array, array[index].right);
	return;
}
void inorder(b_tree* array, int index){
	if(array[index].left != -1)inorder(array, array[index].left);
	cout << " " << index;
	if(array[index].right != -1)inorder(array, array[index].right);
	return;
}

void postorder(b_tree* array, int index){
	if(array[index].left != -1)postorder(array, array[index].left);
	if(array[index].right != -1)postorder(array, array[index].right);
	cout << " " << index;
	return;
}


int main(){
	ios_base::sync_with_stdio(false);

	int numOfNode;
	cin >> numOfNode;
	b_tree* array = new b_tree[numOfNode];

	rep(i,numOfNode){
		int index;
		cin >> index;
		cin >> array[index].left;
		cin >> array[index].right;
		array[index].parent = -1;
		array[index].sibling = -1;
	}

	int rootIndex;
	
	rep(i, numOfNode){
		array[array[i].left].parent = i;
		array[array[i].right].parent = i;
		array[array[i].left].sibling = array[i].right;
		array[array[i].right].sibling = array[i].left;
	}

	rep(i, numOfNode){
		if(array[i].parent == -1)rootIndex = i; 
	}

	cout << "Preorder" << endl;
	preorder(array, rootIndex); 
	cout << endl;
	

	cout << "Inorder" << endl;
	inorder(array, rootIndex); 
	cout << endl;

	cout << "Postorder" << endl;
	postorder(array, rootIndex); 
        cout << endl;

	return 0;
}

Measured memory_bytes: 1204
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
N=II()
AS=LI()
BS=LI()

sm = 0
for i in range(N):
    rest = BS[i]
    taosu = min(AS[i], rest)
    AS[i] -= taosu
    rest -= taosu
    sm += taosu

    taosu2 = min(AS[i+1], rest)
    AS[i+1] -= taosu2
    rest -= taosu2
    sm += taosu2

print(sm)


Measured memory_bytes: 81892
import itertools
import sys

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


N, M = read_int_list()
a = list()
b = list()
edges = set()
for i in range(1, M + 1):
    s = input()
    l = s.split()
    u = int(l[0])
    v = int(l[1])
    a.append(u)
    b.append(v)
    edges.add((u, v))
    edges.add((v, u))
# print(edges)

t = range(1, N + 1)
res = 0
for p in itertools.permutations(t):
    if p[0] != 1:
        break
    c = 0
    for j in range(0, N - 1):
        if (p[j], p[j + 1]) in edges:
            c += 1
    if c == N - 1:
        res += 1
print(res)


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a+b == c+d)cout << "Balanced" << endl;
  else if(a+b > c+d)cout << "Left" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 3588
import itertools

def main():
    a = list(map(int, input().split()))
    min_cost = None

    for order in itertools.permutations([0, 1, 2]):
        c = cost(a, order)
        if min_cost is None:
            min_cost = c
        else:
            min_cost = min(min_cost, c)
    print(min_cost)

def cost(a, order):
    c = 0

    for i, j in zip(order, order[1:]):
        c += abs(a[j] - a[i])
    
    return c

main()

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

class DisjointSet{
public:
  vector<int> rank,p;

  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);

    // rank0 n個の独立な集合を作成
    for(int i=0;i<size;i++) makeSet(i);
  }

  void makeSet(int x){
    p[x] = x;
    rank[x] = 0;
  }

  bool same(int x,int y){
    return findSet(x) == findSet(y);
  }

  void unite(int x,int y){
    link(findSet(x),findSet(y));
  }

  void link(int x,int y){
    if(rank[x] > rank[y]){
      p[y] = x;
    }else{
      p[x] = y;
      if(rank[x] == rank[y]){
        rank[y]++;
      }
    }
  }
  int findSet(int x){
    if(x != p[x]){
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
};

int main(){
  int n,a,b,q;
  int t;

  cin >> n >> q;
  DisjointSet ds = DisjointSet(n);

  for(int i=0;i<q;i++){
    cin >> t >> a >> b;
    if(t == 0) ds.unite(a,b);
    else if(t == 1){
      if(ds.same(a,b)) cout << 1 << endl;
      else cout << 0 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3196
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

m=0
for i in range(N):
  m+=B[A[i]-1]
for i in range(N-1):
  if A[i+1]==A[i]+1:
    m+=C[A[i]-1]
print(m)

Measured memory_bytes: 3064
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
int h[20];

void init()
{
}

void solve()
{
    int ans = 0;
    REP(i, N){
        bool ok = true;
        REP(j, i){
            if(h[j] > h[i]){
                ok = false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) cin >> h[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin>>n;
    vector<vector<int>> f(n,vector<int>(10)),p(n,vector<int>(11));
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin>>f[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<11;j++){
            cin>>p[i][j];
        }
    }
    ll ans=-10000000000;
    for(int bit=1;bit<(1<<10);bit++){
        vector<int> opentime(10);
        for(int i=0;i<10;i++){
            if(bit&(1<<i)){
                opentime[i]++;
            }
        }
        int prof=0;
        for(int i=0;i<n;i++){
            int cnt=0;
            for(int j=0;j<10;j++){
                if(opentime[j]==1&f[i][j]==1){
                    cnt++;
                }
            }
            prof+=p[i][cnt];
        }
        if(ans<prof){
            ans=prof;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3576
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int main() {
  const Int X = lin();

  for (Int A = -200; A <= 200; ++A) {
    for (Int B = -200; B < A; ++B) {
      Int aa = A*A*A*A*A;
      Int bb = B*B*B*B*B;
      if (aa - bb == X) {
        printf("%lld %lld\n", A, B);
        return 0;
      }
    }
  }

  return 0;
}


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

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

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

    int ans = 0;
    int sum = 0;

    // 左からi番目で下に遷移するケース
    for (int i = 0; i < n; ++i) {
        sum = 0;
        for (int j = 0; j <= i; ++j) {
            sum += a[0][j];
            if (j == i) {
                for (int k = i; k < n; ++k) {
                    sum += a[1][k];
                }
                ans = max(ans, sum);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	x=0;char c=getchar();bool f=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
	if(x<0){putchar('-'),write(-x);}
	else{if(x>9)write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=2e5+5;
int n,k,a[N],s[N],ans;
map<int,queue<int> > mp;

signed main(){
	read(n);read(k);
	for(int i=1;i<=n;i++){
		read(a[i]);
		s[i]=s[i-1]+a[i];
	}
	// mp[0].push(1);
	for(int i=1;i<=n;i++){
		int now=s[i]-i;
		now=(now%k+k)%k;
		while(!mp[now].empty()&&i-mp[now].front()>=k) mp[now].pop();
		// printf("$%d %d\n",now,mp[now].size());
		ans+=mp[now].size();
		if(s[i]%k==i) ans++;
		mp[now].push(i);
	}
	write(ans);
}


Measured memory_bytes: 147072
/*
 *　　　　　　  　　┏┓　　 　┏┓
 * 　　　　　  　　┏┛┗━━━━━━━┛┗━━━┓
 * 　　　　　  　　┃　　　　　　　┃ 　
 * 　　　　　  　　┃　　　━　　 　┃
 * 　　　　　  　　┃　＞　　　＜　┃
 * 　　　　　  　　┃　　　　　　　┃
 * 　　　　　  　　┃...　⌒　... 　┃
 * 　　　　　　  　┃              ┃
 * 　　　　　　  　┗━┓          ┏━┛
 * 　　　　　　　　　┃          ┃　Code is far away from bug with the animal protecting　　　　　　　　　　
 * 　　　　　　　　　┃          ┃   神兽保佑,代码无bug
 * 　　　　　　　　　┃          ┃　　　　　　　　　　　
 * 　　　　　　　　　┃          ┃  　　　　　　
 * 　　　　　　　　　┃          ┃
 * 　　　　　　　　　┃          ┃　　　　　　　　　　　
 * 　　　　　　　　　┃          ┗━━━┓
 * 　　　　　　　　　┃              ┣┓
 * 　　　　　　　　　┃              ┏┛
 * 　　　　　　　　　┗┓┓┏━━━━━━━━┳┓┏┛
 * 　　　　　　　　　　┃┫┫       ┃┫┫
 * 　　　　　　　　　　┗┻┛       ┗┻┛
 */ 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#include<assert.h>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 200005
#define nm 200005
#define pi 3.1415926535897931
#define mp(x,y) make_pair(x,y)
using namespace std;
const int inf=1e9;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
 


int n,m,_x,cnt,ans;
struct P{int x,y;}a[NM];
struct node{
    int x,y,s,tag;
    node*l,*r;
    node(int x,int y,node*l=0,node*r=0):x(x),y(y),l(l),r(r),s(0),tag(0){if(l)upd();else s=x-m-1;}
    void upd(){s=max(l->s,r->s);}
    void push(){
	if(tag){
	    l->s+=tag;l->tag+=tag;
	    r->s+=tag;r->tag+=tag;
	    tag=0;
	}
    }
    void mod(){
	if(y<=_x){s++;tag++;return;}
	push();if(_x>mid)r->mod();l->mod();upd();
    }
}*root;
node*build(int x,int y){return x==y?new node(x,y):new node(x,y,build(x,mid),build(mid+1,y));}


int main(){
    n=read();m=read();
    ans=max(0,n-m);
    inc(i,1,n)a[i].x=read(),a[i].y=read();
    sort(a+1,a+1+n,[](P a,P b){return a.x<b.x;});
    root=build(1,m+1);
    cnt=1;
    inc(i,0,m){
	while(cnt<=n&&a[cnt].x==i){
	    _x=a[cnt++].y;
	    root->mod();
	}
	ans=max(ans,root->s-i);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 20608
n = int(input())

if n % 2 == 1:
  print(0)

else:
  counter2 = 0
  counter5 = 0
  
  stock = n
  stock = stock//2
  
  while stock > 0:
    stock = stock//5
    counter5 += stock
    
  stock = n//2
  counter2 += stock
  while stock > 0:
    stock = stock//2
    counter2 += stock
    
  print(min(counter2, counter5))

Measured memory_bytes: 3064
N = int(input())
a = list(map(int, input().split()))

sx = 1
delcnt = 0
for i in range(N):
    if a[i] == sx:
        sx = sx + 1
    else:
        delcnt = delcnt + 1

if sx > 1:
    print(delcnt)
else:
    print(-1)


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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    int64_t N, K, tmp, ans = 0;
    cin >> N >> K;
    if (K == 0)
        cout << N * N;
    else
    {
        for (int b = K + 1; b <= N; b++)
        {
            ans += (N / b) * (b - K);
            tmp = N % b;
            if (tmp >= K)
                ans += tmp - K + 1;
        }
        cout << ans;
    }
}

Measured memory_bytes: 3632
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var fac=[],finv=[],invs=[],pow2=[];
function fset(n){
  fac.length=n+1,fac[0]=fac[1]=1;
  for(var i=2;i<=n;)fac[i]=mul(fac[i-1],i++);
  finv.length=n+1,finv[0]=finv[1]=1,finv[n]=inv(fac[n]);
  for(i=n;2<i;)finv[i-1]=mul(finv[i],i--);
  invs.length=n+1,invs[0]=invs[1]=1;
  for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
  //pow2.length=n+1,pow2[0]=1;
  //for(i=1;i<=n;i++)pow2[i]=pow2[i-1]*2%mod;
}
function inv(b){for(var a=mod,u=0,v=1,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function ncr(n,r){return mul(fac[n],finv[r],finv[n-r]);}
function npr(n,r){return mul(fac[n],finv[r]);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);
function main(){
  var r1 = next(), c1 = next(), r2 = next(), c2 = next();
  c2++;
  fset(r2+c2);
  var ans = 0, x1 = 1, x2 = 1;
  for(var i = 0; i < r1; i++){
    x1 = mul(x1,c1+i,invs[i+1]);
    x2 = mul(x2,c2+i,invs[i+1]);
  }
  for(var i = r1; i <= r2; i++){
    x1 = mul(x1,c1+i,invs[i+1]);
    x2 = mul(x2,c2+i,invs[i+1]);
    ans += x2 - x1;
  }
  return (ans%mod+mod)%mod;
}

Measured memory_bytes: 88240
#include <iostream>
using namespace std;
 
double diff(double x, double y){
  if(x-y<0){
    return y-x;
  }else{
    return x-y;
  }
}
 
int main(){
  int n;
  cin>>n;
  
  int T,a;
  cin>>T>>a;
  
  int h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  
  double t[n];
  for(int i=0;i<n;i++){
    t[i]=T-h[i]*0.006;
  }
  
  double min=diff(a,t[0]);
  int ans=1;
  for(int i=1;i<n;i++){
    if(min>diff(a,t[i])){
      min = diff(a,t[i]);
      ans = i+1;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
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) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}



vector<int> kai;

// 0 indexed
int n;
vector<int> bit(200005);
void add(int a, int w) {
  for (int x = a; x < n; x |= x + 1) bit[x] += w;
}
int sum(int a) { // [0, a)
  int ret = 0;
  for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
    ret += bit[x];
  }
  return ret;
}

int calc(vector<int> a) {
  int ret = 0;
  rep(i, n) {
    ret += (a[i] - 1 - sum(a[i])) * kai[n - 1 - i];
    add(a[i], 1);
  }
  return ret;
}

void solve() {
  cin >> n;
  vector<int> a(n);
  cin >> a;
  vector<int> b(n);
  cin >> b;


  kai.resize(10);
  kai[0] = 1;
  rep3(i, 1, 10) kai[i] = kai[i - 1] * i;

  int ans = calc(a);
  // cout << ans << endl;
  bit = vector<int>(200005, 0);
  ans -= calc(b);
  cout << abs(ans) << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 3e5 + 7;
const int maxM = 1e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;
struct node {
	int l, r;

	inline int len() const {return r - l + 1;}

	inline bool operator < (const node &v) const {
		return this->len() < v.len();
	}
}a[maxN];

namespace Fenwick {
	int c[maxM];

	inline int lb(int x) {return x & (-x);}

	inline void add(int x, int d) {
		for (; x > 0; x -= lb(x)) c[x] += d;
	}
	
	inline void ins(int l, int r) {add(r, 1), add(l-1, -1);}

	inline int get(int x) {
		int res = 0;
		for (; x <= m; x += lb(x)) res += c[x];
		return res;
	}
}

int main() {

	n = ri(), m = ri();
	rep (i, 1, n) a[i].l = ri(), a[i].r = ri();
	sort(a+1, a+n+1);

	int cur = 1, ans = n;
	rep (d, 1, m) {
		for (; cur <= n && a[cur].len() <= d; ++ cur) --ans, Fenwick::ins(a[cur].l, a[cur].r);
		int res = ans;
		for (int j = d; j <= m; j += d) res += Fenwick::get(j);
		printf("%d\n", res);
	}

	return 0;
}


Measured memory_bytes: 3584
while line = STDIN.gets
  a = line.chomp.split(' ').map { |item| item.to_i }
  b = STDIN.gets.chomp.split(' ').map { |item| item.to_i }
  has_a={}
  a.each do |e| 
    has_a[e]=1
  end
  hit=0
  blow=0
  (0...4).each do |i| 
    if a[i] == b[i] then
      hit+=1
      next
    end
    if has_a.has_key?(b[i]) then
      blow+=1
    end  
  end
  puts "#{hit} #{blow}"
end

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

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    vector<int64_t> margins;
    int64_t sum_margin = 0;
    int64_t sum_lack = 0;
    int ans = 0;
    bool all_ok = true;
    rep(i,n) {
        if (a[i] > b[i]) {
            int margin = a[i] - b[i];
            sum_margin += margin;
            margins.push_back(margin);
        }
        if (a[i] < b[i]) {
            sum_lack += b[i] - a[i];
            ans++;
            all_ok = false;
        }
    }
    sort(margins.begin(), margins.end(), greater<>());
    vector<int64_t> cumulative_sum(margins.size()+1, 0);
    rep(i,margins.size()) cumulative_sum[i+1] = cumulative_sum[i] + margins[i];
    if (sum_margin < sum_lack) ans = -1;
    else {
        ans += lower_bound(cumulative_sum.begin(), cumulative_sum.end(), sum_lack) - cumulative_sum.begin();
    }
    if (all_ok) ans = 0;
    cout << ans << endl;
}

Measured memory_bytes: 2040
#include <math.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;

int main()
{
string s;
bool t=true;
while(cin >> s)
{
for(int i=0;i<s.size();i++)
{
if(isupper(s.at(i)))s.at(i)=tolower(s.at(i));
else if(islower(s.at(i)))s.at(i)=toupper(s.at(i));
}
if(t){t=false;cout << s;}
else cout << " " << s;
}
cout << endl;
}



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


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

    int n, x, t;
    cin >> n >> x >> t;

    int res = (n + x - 1) / x;
    cout << res * t << endl;


    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{

//	vector<int> v;
	long long int k;
	long long int n,p,val;
	long long int c,cycle,dest;
	
	
	cin>>n>>k;
	long long int A[n+1][3];
	
	for(long long int i=1;i<=n;i++)
	{
		cin>>A[i][0];
		A[i][1]=0;
		A[i][2]=0;
	}
	
	dest=1;
	A[1][1]=1;
	c=0;
	int flag=0;
	while(c<=k)
	{
		c++;
		if(c>k)
		break;
		dest=A[dest][0];
		
		if(A[dest][1]==1)
		{
			cycle=c-A[dest][2];
			flag=1;
			break;
		}
		else 
		{
			A[dest][1]=1;
			A[dest][2]=c;
		}
//		cout<<dest<<" "<<c<<"	"<<A[dest][0]<<endl;
	}
	if(flag==0)
	cout<<dest<<endl;
	else
	{
			val=(k-A[dest][2])%cycle;
	
		for(long long int i=1;i<=val;i++)
		{
			dest=A[dest][0];
		}
		cout<<dest<<endl;
	}
	

}

Measured memory_bytes: 8292
#include <iostream>

int as[100000];

int main(){
  int N,L;
  std::cin>>N>>L;
  for(int i=1;i<=N;i++){
    std::cin>>as[i];
  }
  for(int i=1;i<N;i++){
    if(as[i]+as[i+1]>=L){
      std::cout<<"Possible"<<std::endl;
      for(int j=1;j<i;j++){
	std::cout<<j<<std::endl;
      }
      for(int j=N-1;j>i;j--){
	std::cout<<j<<std::endl;
      }
      std::cout<<i<<std::endl;
      return 0;
    }
  }
  std::cout<<"Impossible"<<std::endl;
  return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
using namespace std;
int main(){
  int a;string s;cin >> a >> s;
  if(a%2==1) cout << "No" << endl;
  else cout << ((s.substr(0,a/2) == s.substr(a/2,a/2)) ? "Yes":"No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n,m;
struct Node{int l,r;}a[Maxn];
bool cmp(Node a,Node b){return a.r>b.r;}
struct Seg{int l,r,lc,rc,mx,tag;}tr[Maxn<<1];
int tot=0;
void work(int x,int y){tr[x].mx+=y;tr[x].tag+=y;}
void up(int x)
{
	int lc=tr[x].lc,rc=tr[x].rc;
	tr[x].mx=max(tr[lc].mx,tr[rc].mx);
}
void down(int x)
{
	if(tr[x].tag)
	{
		int t=tr[x].tag;
		work(tr[x].lc,t);work(tr[x].rc,t);
		tr[x].tag=0;
	}
}
void build(int l,int r)
{
	int t=++tot;
	tr[t].l=l;tr[t].r=r;tr[t].tag=0;
	if(l==r){tr[t].mx=-l;return;}
	int mid=l+r>>1;
	tr[t].lc=tot+1;build(l,mid);
	tr[t].rc=tot+1;build(mid+1,r);
	up(t);
}
void add(int x,int l,int r)
{
	if(tr[x].l==l&&tr[x].r==r){work(x,1);return;}
	int lc=tr[x].lc,rc=tr[x].rc,mid=tr[x].l+tr[x].r>>1;
	down(x);
	if(r<=mid)add(lc,l,r);
	else if(l>mid)add(rc,l,r);
	else add(lc,l,mid),add(rc,mid+1,r);
	up(x);
}
int query(int x,int l,int r)
{
	if(tr[x].l==l&&tr[x].r==r)return tr[x].mx;
	int lc=tr[x].lc,rc=tr[x].rc,mid=tr[x].l+tr[x].r>>1;
	down(x);
	int re;
	if(r<=mid)re=query(lc,l,r);
	else if(l>mid)re=query(rc,l,r);
	else re=max(query(lc,l,mid),query(rc,mid+1,r));
	up(x);
	return re;
}
int main()
{
	/*4 4
	0 3
	2 3
	1 3
	3 4*/
	n=read(),m=read();
	build(0,m+1);
	for(int i=1;i<=n;i++)a[i].l=read(),a[i].r=read();
	sort(a+1,a+1+n,cmp);
//	for(int i=1;i<=n;i++)printf("%d %d\n",a[i].l,a[i].r);
	int ans=n-m;
	for(int i=1;i<=n;i++)
	{
		if(i==1||a[i].r==a[i-1].r)add(1,a[i].l,m+1);
		else
		{
			int t=query(1,0,a[i-1].r-1)-(m-a[i-1].r+1);
//			printf("# %d %d\n",i,query(1,0,a[i-1].r-1));
			ans=max(ans,t);
			add(1,a[i].l,m+1);
		}
//		printf("%d %d\n",i,ans);
	}
	int t=query(1,0,a[n].r-1)-(m-a[n].r+1);
	ans=max(ans,t);
	ans=max(ans,0);
	printf("%d",ans);
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
ll h,n; pii p[200001];
void decrement(ll x,ll y,ll dec,ll xx[],ll hh[])
{
	ll cur;
	rep(i,0,n)
	{
		cur=xx[i];
		if(cur>=x && cur<=y)
		hh[i]=max(0ll,hh[i]-dec);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,m,k,ans,a,b,g,d,x,h,l,mid;
    	cin>>n>>d>>a;
    	rep(i,0,n)
    	{
    		cin>>p[i].F>>p[i].S;
		}
		sort(p,p+n);
		ll xx[n],hh[n],payload[n];
		rep(i,0,n)
		{
			xx[i]=p[i].F; hh[i]=p[i].S; payload[i]=0;
		}
		ans=0; k=0;
		rep(i,0,n)
		{
			hh[i]=hh[i]-k;
			if(hh[i]>0)
			{
				g=(hh[i]+a-1)/a;
				ans+=g;
				k+=g*a;
				l=i; h=n;
				while(l<h)
				{
					mid=(l+h+1)/2;
					if(xx[mid]<=xx[i]+2*d)
					l=mid;
					else
					h=mid-1;
				}
				payload[l]+=g*a;
			}
			k-=payload[i];
		}
		cout<<ans;
    } 
	return 0;
}

Measured memory_bytes: 8064
import math
import fractions
import collections
import itertools
import pprint
from collections import deque
N,K=map(int,input().split())
A=list(map(int,input().split()))
plist=[]
mlist=[]
ans=1
p=10**9+7
for i in range(N):
    if A[i]>=0:
        plist.append(A[i])
    else:
        mlist.append(A[i])
if len(plist)==0:
    if K%2==1:
        A.sort(reverse=True)
    else:
        A.sort()
    for i in range(K):
        ans=(ans*A[i])%p
    print(ans%p)
elif len(plist)==1:
    #print(plist,mlist)
    mlist.sort()
    if K%2==1:
        ans=plist[0]
    for i in range(K-1):
        ans=(ans*mlist[i])%p
    print(ans%p)
else:
    ans=1
    plist.sort(reverse=True)
    mlist.sort()
    pmap=deque()
    mmap=deque()
    if K%2==1:
        ans=plist[0]%p
        plist.pop(0)
        K=K-1
    #print(plist,mlist)
    for i in range(0,len(plist)-1,2):
        pmap.append(plist[i]*plist[i+1])
    if len(plist)>0:
        pres=plist[len(plist)-1]
    if len(mlist)>0:
        mres=mlist[len(mlist)-1]
    for i in range(0,len(mlist)-1,2):
        mmap.append(mlist[i]*mlist[i+1])
    #print(K)
    mapnum=K//2
    #print(mapnum)
    #print(pmap,mmap,ans)
    for i in range(mapnum):
        if (len(pmap)>0)and(len(mmap)>0):
            pl=pmap.popleft()
            mi=mmap.popleft()
            if pl>mi:
                ans=(ans*pl)%p
                mmap.appendleft(mi)
            else:
                ans=(ans*mi)%p
                pmap.appendleft(pl)
        elif (len(pmap)==0)and(len(mmap)>0):
            mi=mmap.popleft()
            ans = (ans *mi) % p
        elif (len(mmap)==0)and(len(pmap)>0):
            pl=pmap.popleft()
            ans = (ans *pl) % p
        else:
            ans=(ans*pres*mres)%p
    print(ans)



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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#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 int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    float A, B; cin >> A >> B;
    float min_a = A / 0.08;
    float max_a = (A + 1) / 0.08;
    float min_b = B / 0.1;
    float max_b = (B + 1) / 0.1;
    int ans;
    if (max_a <= min_b || min_a >= max_b) {
        ans = -1;
    } else {
        ans = ceil(max(min_a, min_b));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3764
# AGC029
S = input()
N = len(S)
B_cnt = 0
W_cnt = 0
ans = 0
for i in range(N-1, -1, -1):
    ##print(i, S[i])
    if S[i] == "B":
        ans += W_cnt
    else:
        W_cnt += 1
print(ans)

Measured memory_bytes: 3500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] L = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int ans = 0;
        Array.Sort(L);
        for (int i = 0; i < N; i++)
        {
            ans += L[2 * i];
        }
        Console.WriteLine(ans.ToString());
    }
}


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

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

    ll ans = 0;
    rep(i, n) {
        if (i % 3 != 0 && i % 5 != 0) ans += i;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
    vector<int>a(3,0);
    cin>>a[0]>>a[1]>>a[2];

    
    sort(a.begin(), a.end());
    int b;
    b=10*a[2]+a[1];
    cout<<b+a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;


void solve()
{
    ll n,k;
    cin>>n>>k;
    ll cnt[n+1];
    clr(cnt);
    ll i,j,d,x;
    for(i=0;i<k;i++)
    {
        cin>>d;
        for(j=0;j<d;j++)
        {
            cin>>x;
            cnt[x]++;
        }
    }
    ll res=0;
    for(i=1;i<=n;i++)
    {
        if(cnt[i]==0){
           res++;
        }
    }
    cout<<res<<"\n";
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3668
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,m;
int card[2][222];
int f;
int main(void)
{
  cin >> n >> m;
  f = 0;
  for(int i = 0; i < n * 2; i++){
    card[f][i] = i+1;
  }

  for(int i = 0; i < m; i++){
    int k;
    cin >> k;
    if(k){
      int l = 0;
      for(int j = k; j < 2 * n; j++,l++){
	card[(f+1)%2][l] = card[f][j];
      }
      for(int j = 0; j < k; j++,l++){
	card[(f+1)%2][l] = card[f][j];
      }
    }else{
      int l = 0;
      for(int j = 0; j < n; j++){
	card[(f+1)%2][l++] = card[f][j];
	card[(f+1)%2][l++] = card[f][n+j];
      }
    }
    f = (f+1)%2;
  }
  for(int i = 0; i < n * 2; i++){
    printf("%d\n",card[f][i]);
  }
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include <set>

#define INF 1e12
#define DIV 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;

    vector<pair<ll, pair<int, int>>> edge(M);
    for (int i = 0; i < M; i++) {
        cin >> edge[i].second.first >> edge[i].second.second >> edge[i].first;
        edge[i].first *= -1;
        edge[i].second.first -= 1;
        edge[i].second.second -= 1;
    }
    
    vector<ll> dis(N,INF);
    dis[0] = 0;
    for (int i = 0; i < N-1; i++) {
        for (int j = 0; j < M; j++) {
            ll cost = edge[j].first;
            int from = edge[j].second.first;
            int to = edge[j].second.second;
            if (dis[from] != INF && dis[to] > dis[from] + cost) {
                dis[to] = dis[from] + cost;
            }
            //cout << "cost=" << cost << endl;
        }
        /*
        for (int k = 0; k < N; k++) {
            printf("dis[%d]=%lld\n", k, dis[k]);
        }
        */
    }
    ll ans = dis[N - 1];
    vector<bool> nega(N, false);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            ll cost = edge[j].first;
            int from = edge[j].second.first;
            int to = edge[j].second.second;
            if (dis[from] != INF && dis[to] > dis[from] + cost) {
                dis[to] = dis[from] + cost;
                nega[to] = true;
                //cout << "from=" << from << "to=" << to << endl;
            }

            if (nega[from])
                nega[to] = true;
        }
    }
    /*
    for (int i = 0; i < N; i++) {
        printf("dis[%d]=%lld\n", i, dis[i]);
    }
    */
    if (!nega[N - 1])
        cout << -ans << endl;
    else
        cout << "inf" << endl;
}



Measured memory_bytes: 256