akhauriyash/Code-Regression huggingface dataset:
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let pair_l = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d %d %d " (fun a b c -> a,b,c)) in

  let rec aux cur = function
      [] -> "Yes"
    | hd :: tl -> 
      let ct,cx,cy = cur in
      let nt,nx,ny = hd in
      let a = abs (cx-nx) in
      let b = abs (cy-ny) in
      let c = nt-ct in
      if a+b <= c && (c-(a+b)) mod 2 = 0 then aux (nt,nx,ny) tl else "No"
  in

  Printf.printf "%s\n" @@
  aux (0,0,0) pair_l


Measured memory_bytes: 8448
//{{{
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef LOCAL
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int n, x, t;
int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (cin >> n >> x >> t)
    {
        int d = n / x;
        if (n % x != 0) d++;
        int ans = d * t;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3580
#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)

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

const int N_MAX = 100000;

int N, a, b;
int x[N_MAX];
int y[N_MAX];

int d;
P z[N_MAX];
P w[N_MAX];
ll c[N_MAX];
set<P> sz;
set<P> sw;

void dfs(int u, int v) {
  sz.erase(P(u, v)); sw.erase(P(v, u));
  while (true) {
    auto it = sz.lower_bound(P(u + d, v - d));
    if (it == sz.end()) break;
    int u2 = it->first, v2 = it->second;
    if (u2 > u + d || v2 > v + d) break;
    // printf("u: %d, v: %d (r) u2: %d, v2: %d\n", u, v, u2, v2);
    dfs(u2, v2);
  }
  while (true) {
    auto it = sz.lower_bound(P(u - d, v - d));
    if (it == sz.end()) break;
    int u2 = it->first, v2 = it->second;
    if (u2 > u - d || v2 > v + d) break;
    // printf("u: %d, v: %d (l) u2: %d, v2: %d\n", u, v, u2, v2);
    dfs(u2, v2);
  }

  while (true) {
    auto it = sw.lower_bound(P(v + d, u - d));
    if (it == sw.end()) break;
    int v2 = it->first, u2 = it->second;
    if (v2 > v + d || u2 > u + d) break;
    // printf("u: %d, v: %d (t) u2: %d, v2: %d\n", u, v, u2, v2);
    dfs(u2, v2);
  }
  while (true) {
    auto it = sw.lower_bound(P(v - d, u - d));
    if (it == sw.end()) break;
    int v2 = it->first, u2 = it->second;
    if (v2 > v - d || u2 > u + d) break;
    // printf("u: %d, v: %d (b) u2: %d, v2: %d\n", u, v, u2, v2);
    dfs(u2, v2);
  }
}

void solve() {
  d = abs(x[a] - x[b]) + abs(y[a] - y[b]);
  REP(i, N) {
    int u = x[i] + y[i], v = x[i] - y[i];
    z[i] = P(u, v); w[i] = P(v, u);
    sz.insert(z[i]); sw.insert(w[i]);
  }
  sort(z, z + N); sort(w, w + N);
  REP(i, N) {
    int u = z[i].first;
    int v = z[i].second;
    int r1 = lower_bound(z, z + N, P(u + d, v + d)) - z;
    int r2 = lower_bound(z, z + N, P(u + d, v - d)) - z;
    int l1 = upper_bound(z, z + N, P(u - d, v + d)) - z;
    int l2 = upper_bound(z, z + N, P(u - d, v - d)) - z;
    int t1 = upper_bound(w, w + N, P(v + d, u + d)) - w;
    int t2 = upper_bound(w, w + N, P(v + d, u - d)) - w;
    int b1 = lower_bound(w, w + N, P(v - d, u + d)) - w;
    int b2 = lower_bound(w, w + N, P(v - d, u - d)) - w;
    // printf("u: (%d)-(%d)-(%d), v: (%d)-(%d)-(%d)\n", u - d, u, u + d, v - d, v, v + d);
    // printf("r:(%d,%d), l:(%d,%d), t:(%d,%d), b:(%d,%d)\n",
    //   r1, r2, l1, l2, t1, t2, b1, b2);
    c[i] = (r1 - r2) + (l1 - l2) + (t1 - t2) + (b1 - b2);
    // printf("c: %lld\n", c[i]);
  }
  dfs(x[a] + y[a], x[a] - y[a]);
  ll ans = 0;
  REP(i, N) if (sz.count(z[i]) == 0) ans += c[i];
  printf("%lld\n", ans / 2);
}

void input() {
  scanf("%d%d%d", &N, &a, &b);
  a--; b--;
  REP(i, N) scanf("%d%d", x + i, y + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 17408
import itertools
import math

n = int(input())
points = []
for _ in range(n):
    x, y = map(int, input().strip().split())
    points.append((x, y))


total = 0
for perm in itertools.permutations(points):
    for i in range(n - 1):
        p1 = perm[i]
        p2 = perm[i + 1]
        dist = math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
        total += dist

avg = total / math.factorial(n)


print(avg)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<int> a(n), cnt(n + 1, 0);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        ++cnt[a[i]];
    }
    ll sum = 0;
    for(int i = 1; i <= n; ++i){
        sum += (ll)cnt[i] * (cnt[i] - 1) / 2;
    }
    for(int i = 0; i < n; ++i){
        ll ans = sum;
        int k = a[i];
        ans -= (ll)cnt[k] * (cnt[k] - 1) / 2;
        ans += (ll)(cnt[k] - 1) * (cnt[k] - 2) / 2;
        cout << ans << '\n';
    }
}

Measured memory_bytes: 4224
n = int(input())
A = list(map(int, input().split()))
A.sort()
amin = A[0]
amax = A[-1]
B = A[1:-1]
action = []
for b in B:
    if b < 0:
        action.append((amax, b))
        amax -= b
    else:
        action.append((amin, b))
        amin -= b
action.append((amax, amin))
score = amax - amin
print(score)
for x, y in action:
    print('{} {}'.format(x, y))

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

int main(){
  int A, V, B, W, T;

  cin >> A >> V;
  cin >> B >> W;
  cin >> T;

  bool success = false;
  if (V == W){
    // 同じ速度では捕まえられない
    ;
  }else if (V < W){
    // 鬼が遅いので捕まえられない
    ;
  }else{
    int dV = V - W;	// 秒あたりに詰められる距離
    if (dV < 0){
      dV = -dV;
    }
    int dD = A - B;	// 初期位置の差
    if (dD < 0){
      dD = -dD;
    }
    for (int t = 0; t < T; t++){
      dD -= dV;
      if (dD <= 0){
	success = true;
	break;
      }
    }
  }

  cout << (success ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3636
def main()
        stdin = gets.chomp.split('')
        f = (stdin[0]+stdin[1]).to_i
        b = (stdin[2]+stdin[3]).to_i
        frag_f = 13>f && f>0 ? true : false
        frag_b = 13>b && b>0 ? true : false
        
        if frag_f
                if frag_b # t t
                        print "AMBIGUOUS"
                else # t f
                        print "MMYY"
                end
        else
                if frag_b # f t
                        print "YYMM"
                else # f f
                        print "NA"
                end
        end

end
main()

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,A,B; cin >> N >> A >> B;
    if((B - A) % 2 ==0 )
    {
        cout << "Alice" << endl;
    }
    else
    {
        cout << "Borys" << endl;
    }
}

Measured memory_bytes: 256
import copy

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



N=int(input())
a=spaceinput()

count4=0
count2=0
countodd=0
for sa in a:
    if sa%4==0:
        count4+=1
    elif sa%2==0:
        count2+=1
    else:
        countodd+=1



x=["o","e4"]*count4
if count2>0:
    x.extend(["e2"]*count2)
else:
    x.extend(["o"])
#print(count4,count2)
#print(x)
#print(len(x),N)
if len(x)>=N:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long k = sc.NextLong();

        bool ok = (n + 1) / 2 >= k;

        string answer = ok ? "YES" : "NO";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

{
	int b[3][3],t,k,r,s;
	set<int>p;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
		{
			cin>>b[i][j];
		}
		cin>>t;
		while(t--)
		{
			cin>>k;
			p.insert(k);
		}
		for(int i=0;i<3;i++)
		{
			r=0;
			for(int j=0;j<3;j++)
			{
				s=p.count(b[i][j]);
				if(s==1)
				r++;
			}
			if(r==3)
			{
				cout<<"Yes";
				break;
			}
		}
		if(r!=3)
		{
			for(int j=0;j<3;j++)
		{
			r=0;
			for(int i=0;i<3;i++)
			{
				s=p.count(b[i][j]);
				if(s==1)
				r++;
			}
			if(r==3)
			{
				cout<<"Yes";
				break;
			}
		}
		}
		if(r!=3)
		{
			r=0;
			for(int j=0,i=0;j<3;i++,j++)
		{
			
			s=p.count(b[i][j]);
				if(s==1)
				r++;
		}
			if(r==3)
			{
				cout<<"Yes";
			}
		}
		if(r!=3)
		{r=0;
			for(int j=0,i=2;j<3;j++,i--)
		{
			
			s=p.count(b[i][j]);
				if(s==1)
				r++;
		}	
			if(r==3)
			{
				cout<<"Yes";
			}
		}
		if(r!=3)
		cout<<"No";
		
}


Measured memory_bytes: 256
N = int(input())
A = []
B = []
for i in range(N):
    a = int(input())
    A.append(a)
    B.append(a)
B.sort()
maxA = B[-1]
max2A = B[-2]

for j in range(N):
    if A[j] == maxA:
        print(max2A)
    else:
        print(maxA)


Measured memory_bytes: 14096
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int a,b,h;
    cin >> a >> b >> h;

    cout << (a+b)*h / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
int main()
{
  int a[4];
  int i = 0;
  while (i < 4)
  {
    scanf("%d\n",&a[i]);
    //if (i % 2 == 0 && i != 0)
    i++;
  }
  a[0] -= a[1];
  printf("%d",a[0] % a[2]);
}

Measured memory_bytes: 128
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ----------- debug ---------- */

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p);

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

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

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

template <typename T>
T iceil(T n, T d) {
    return (n + d - 1) / d;
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int N, h[100];

int rec(int l, int r) {
    if (l == r) return 0;

    for (int i = l; i < r; ++i) --h[i];

    int ret = 1;
    int pre = l;
    for (int i = l; i < r; ++i) {
        if (h[i] == 0) {
            ret += rec(pre, i);
            pre = i + 1;
        }
    }
    ret += rec(pre, r);

    return ret;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }

    int ans = 0, pre = 0;
    for (int i = 0; i < N; ++i) {
        if (h[i] == 0) {
            ans += rec(pre, i);
            pre = i + 1;
        }
    }
    ans += rec(pre, N);

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


Measured memory_bytes: 256
import random
class Dice:
    def __init__(self,top,front,right,left,back,bottom):
        self.top, self.bottom=top,bottom
        self.right, self.left=right,left
        self.front, self.back=front,back
    def turn(self,order):
        if order=="N":
            self.top,self.front,self.bottom,self.back=self.front,self.bottom,self.back,self.top
        if order=="S":
            self.top,self.front,self.bottom,self.back=self.back,self.top,self.front,self.bottom
        if order=="E":
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        if order=="W":
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
def same(a,b):
    if ((a.top,a.bottom,a.right,a.left,a.front,a.back)==(b.top,b.bottom,b.right,b.left,b.front,b.back)):
        return True
    else:
        return False
n=input()
dicelist=[]
dice=[]
for i in range(n):
    dicelist.append(map(int,raw_input().split()))
for i in range(n):
    dice.append(Dice(dicelist[i][0],dicelist[i][1],dicelist[i][2],dicelist[i][3],dicelist[i][4],dicelist[i][5]))
flg=0
for i in range(1,n):
    if flg==1:
        break
    for j in range(1000):
        if flg==1:
            break
        d="NSWE"[random.randint(0,3)]
        dice[i].turn(d)
        for k in range(i):
            if same(dice[k],dice[i]):
                print "No"
                flg=1
                break
if flg==0:
    print "Yes"


Measured memory_bytes: 6732
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
    int A[3][3];
    rep(i,3) rep(j,3) cin >> A[i][j];
    int n;
    cin >> n;
    rep(i,n){
        int b;
        cin >> b;
        rep(i,3) rep(j,3){
            if(A[i][j] == b){
                A[i][j] = -1;
            }
        }
    }
    int ans = 0;
    rep(i,3){
        if(A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1){
            ans++;
        }
    }
    rep(i,3){
        if(A[0][i] == -1 && A[1][i] == -1 && A[2][i] == -1){
            ans++;
        }
    }
    if(A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1){
        ans++;
    }
    if(A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1){
        ans++;
    }
    if(ans) cout <<"Yes"<< endl; else cout <<"No"<<endl;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/
	
	int n[3];
	cin >> n[0] >> n[1] >> n[2];

	sort(n, n + 3);

	int d = n[2] * 2 - n[1] - n[0];
	int ans = d / 2;
	if (d % 2 == 1) ans += 2;

	out(ans);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
      cout<<c<<endl;
    }else if(a==c){
      cout<<b<<endl;
    }else{
      cout<<a<<endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;


//---------------------------------------------------------------
template<int MOD> struct ModInt { int x;
    explicit operator bool() const { return !!x; }
    ModInt(int v = 0) : x(v % MOD) { if (x < 0) x += MOD; }
    ModInt(long long v) : x(v % MOD) { if (x < 0) x += MOD; }
    ModInt &operator+=(const ModInt &r) { if ((x += r.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt &r) { if ((x += MOD - r.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(const ModInt &r) { x = 1LL * x * r.x % MOD; return *this; }
    ModInt &operator/=(const ModInt &r) { return *this *= r.inv(); }
    ModInt operator-() const { return x ? ModInt(MOD - x) : ModInt(x); }
    ModInt operator+(const ModInt &r) const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt &r) const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt &r) const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt &r) const { return ModInt(*this) /= r; }
    ModInt inv() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u); } // x.pow(MOD-2)
    ModInt pow(long long k) const { ModInt r(1), a(x);
        while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
    bool operator==(const ModInt r) const { return x == r.x; }
    bool operator!=(const ModInt r) const { return x != r.x; }
    bool operator< (const ModInt r) const { return x <  r.x; }
    friend ostream& operator<<(ostream &os, const ModInt<MOD>& a) { return os << a.x; }
    friend istream& operator>>(istream &is, ModInt<MOD>& a) { return is >> a.x; }
};
template<typename T, int SZ> struct Comb { vector<T> _fac, _ifac, _inv;
    Comb() : _fac(SZ + 1), _ifac(SZ + 1), _inv(SZ + 1) {
        _fac[0] = _ifac[SZ] = _inv[0] = 1;
        for (int i = 1; i <= SZ; i++) _fac[i] = _fac[i - 1] * i;
        _ifac[SZ] /= _fac[SZ];
        for (int i = SZ - 1; i >= 0; i--) _ifac[i] = _ifac[i + 1] * (i + 1);
        for (int i = 1; i <= SZ; i++) _inv[i] = _ifac[i] * _fac[i - 1]; }
    T inv(int n) { return n < 0 ? T(0) : _inv[n]; }
    T fac(int n) { return n < 0 ? T(0) : _fac[n]; }
    T ifac(int n) { return n < 0 ? T(0) : _ifac[n]; }
    T P(int a, int b) { return (b < 0 || a < b) ? T(0) : _fac[a] * _ifac[a - b]; }
    T C(int a, int b) { return b < 0 ? T(0) : P(a, b) * _ifac[b]; }
    T H(int n, int k) { if (n < 0 || k < 0) return T(0);
        return k == 0 ? T(0) : C(n + k - 1, k); }
};
typedef ModInt<MOD> mint;
//---------------------------------------------------------------


int main() {
    Comb<mint, 250000> com;
    int n, k; cin >> n >> k;
    cout << com.H(k, n) << endl;
    return 0;
}


Measured memory_bytes: 5568
#include<stdio.h>
int main(void)
{
	int a, i;
	char s[11];
	scanf("%d %s", &a, s);
	if(a >= 3200) {
		for(i = 0; s[i] != '\0'; ++i) {
			printf("%c", s[i]);
		}
	}
	else puts("red");
	return 0;
}

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

int main(){
  int n,h,w;
  cin>>n>>h>>w;
  vector<int> a(n),b(n);
  
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  int count=0;
  
  for(int i=0;i<n;i++){
    if(a[i]>=h&&b[i]>=w)
      count++;
  }
  cout<<count<<endl;
}


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

#define INF             1e9
#define INFL            1e19
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cout << endl;
#define HOISE           cerr << "hoise" << endl
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << endl
#define READ            freopen("alu.txt", "r", stdin)
#define WRITE           freopen("vorta.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

#define MASK(x)         for(int i = 0; i < 8; i++){ if(x&(1<<i)){ cout << i << " "; } } cout << endl;

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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


const int MAX = 2e5 + 2;
const int MAXLOG = log2(MAX) + 2;
const int MAXN = 1e6 + 2;
const int MOD = 1000000007;

int main()
{
    FASTIO;

    int a[] = {0, 300000, 200000, 100000, 0};
    int x, y;
    cin >> x >> y;
    x = min(x, 4);
    y = min(y, 4);
    int ans = a[x] + a[y];
    if(x==1 and y==1) ans += 400000;
    cout << ans;

    return 0;
}


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

using namespace std;
using ll = long long;

void solve(){
	int a,b,k;
	cin >> a >> b >> k;
	vector<int> st;
	for(int i=1;i<=min(a,b);++i){
		if(a%i == 0 && b%i == 0){
			st.push_back(i);
		}
	}

	for(int i=st.size()-1;i>=0;--i){
		//cout << st[i] << '\n';
		--k;
		if(k == 0) cout << st[i] << '\n';
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){ 
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0; i<n/2; i++)
    {
        if(s[i]==s[n-1-i])continue;
        else {cout<<"No"; return 0;}
    }
    int mid=n/2;
    for(int i=0; i<mid/2; i++)
    {
        if(s[i]==s[mid-1-i])continue;
         else {cout<<"No"; return 0;}
    }
    for(int i=mid+1; i<n; i++)
    {
        if(s[i]==s[n-1-i])continue;
        else {cout<<"No"; return 0;}
    }
    cout<<"Yes";

}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> liked(n, vector<bool>(m, false));
  rep(i, n) {
    int k;
    cin >> k;
    rep(j, k) {
      int a;
      cin >> a;
      a--;
      liked[i][a] = true;
    }
  }
  int ans = 0;
  rep(i, m) {
    bool isall = true;
    rep(j, n) {
      if (!liked[j][i]) isall = false;
    }
    if (isall) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> X(N);
  for (auto &it : X)
    cin >> it;
  ll ans = 0;
  for (int i = 1; i < N; i++)
  {
    if (A * (X[i] - X[i - 1]) <= B)
      ans += A * (X[i] - X[i - 1]);
    else
      ans += B;
  }
  cout << ans << endl;
  return 0;
}

// まず，AとBの比較　


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 int main(){
   string s;
   cin >> s;
   int  n = s.size();
   long long int ans = 0;
   
   for(int mask = 0;mask < (1 << n - 1);++mask){
     long long int sum_t = 0;
     long long int t = s[0] - '0';
     for(int i = 0;i < n - 1;++i){
       if(mask & (1 << i)){
         sum_t += t;
         t = 0;
       }
       t *= 10;
       t += s[i + 1] - '0';
       if(i + 1 == n - 1){
         sum_t += t;
       }
     }
     ans += sum_t;
   }
   if(n == 1) ans = s[0] - '0';
   cout << ans << endl;
   return 0;
 }

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

using namespace std;
int main() {
	int h, n;
	cin >> h >> n;

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

	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}
	if (h <= sum)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3696
// D - Handstand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int N, K;
	string S;
	cin >> N >> K;
	cin >> S;

	vector<int> one;
	vector<int> zero;
	bool counting_one = true;
	int cnt = 0;
	for (int i=0; i<N; i++) {
		if (counting_one) {
			if (S[i] == '1') {
				cnt++;
			} else {
				one.push_back(cnt);
				cnt = 0;
				counting_one = false;
				i--;
			}
		} else {
			if (S[i] == '0') {
				cnt++;
			} else {
				zero.push_back(cnt);
				cnt = 0;
				counting_one = true;
				i--;
			}
		}
	}

	if (one.size() == 0 || zero.size() == 0) {
		cout << N << endl;
		return 0;
	}

	if (S[N-1] == '0') {
		one.push_back(0);
		zero.push_back(cnt);
	} else {
		one.push_back(cnt);
	}

	/*
	// **** debug ****
	for (int o : one) { cout << o << " "; }
	cout << endl;
	for (int z : zero) { cout << z << " "; }
	cout << endl;
	*/

	int t = one[0];
	int l = 0;
	int r = 1;

	// initialize
	while(1) {
		t += zero[r-1];
		t += one[r];
		if (r == one.size() - 1) break;
		if (r == K) break;
		r++;
	}

	int ans = 0;
	while(1) {
		ans = max(ans, t);
		//cout << r << " " << t << endl; // **** debug ****

		t -= one[l];
		t -= zero[l];
		l++;

		if (r == one.size() - 1) break;

		r++;
		t += zero[r-1];
		t += one[r];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int,int> >
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1<<30;
const double eps = 1e-13;

LL getv(int a,int b){
	LL ans=0;
	REP(i,a)ans=(ans*10+9);
	REP(i,b)ans*=10;
	return ans;
}

int main(){
	LL n,ans=0;
	scanf("%lld",&n);
	REPP(d,2,19){//up to 19 digits!
		int h=d/2;
		int bmax=1<<(d/2);
		REP(bm,bmax){
			//printf("BM: %d\n",bm);
			LL x=n;
			LL modv=1;
			vector<int> digits;
			REP(i,h){
				LL cv=getv(d-1-2*i,i);
				modv*=10;
				LL xmod=x%modv;
				LL curd=-xmod/(modv/10);
				if(curd>0)curd-=10;
				//printf("X %lld CV %lld XMOD %lld MODV %lld CURD %lld\n",x,cv,xmod,modv,curd);
				if(bm&(1<<i)){
					digits.PB(curd);
					x-=cv*curd;
				}
				else{
					if(curd==0){x=n;break;}
					digits.PB(curd+10);
					x-=cv*(curd+10);
				}
			}
			if(x==0){
				//puts("Yes");
				//for(int i:digits)printf("%d ",i);puts("");
				LL ways=1;
				REP(i,h){
					ways*=(10-(i==0&&(digits[i]>=0))-abs(digits[i]));
				}
				if(d%2)ways*=10;
				ans+=ways;
			}
		}
	}
	printf("%lld",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int a,b,x;
  cin >> a >> b >> x;
  if(x >= a && x <= b+a) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Bitset I - Bit Operation I
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_10_A&lang=jp

"""
x = int(input())
print(f'{x:032b}')
print(f'{x:032b}'.translate(str.maketrans('01', '10')))
print(f'{x<<1:032b}'[-32:])
print(f'{x>>1:032b}')



Measured memory_bytes: 5640
N, *V = map(int, open(0).read().split())
xs = V[0::3]
ys = V[1::3]
hs = V[2::3]
MAX = 101
high_cand = int()

for y in range(MAX):
  for x in range(MAX):
    high_cand = -1
    for i in range(N):
      # 最初に高さ > 0 の場合を調べる
      if(hs[i] > 0):
        tmp = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
        if(high_cand == -1):
          high_cand = tmp
        else:
          if(high_cand != tmp):
            high_cand = -2
      # その結果矛盾していれば次を見る
      if(high_cand == -2):
        continue;
    # 高さ 0 の場合を調べる
    for i in range(N):
      if(hs[i] == 0):
        a = hs[i] + abs(xs[i] - x) + abs(ys[i] - y)
        if(high_cand > a):
          high_cand = -2
          break
    # その結果矛盾していれば次を見る
    if(high_cand == -2):
      continue;
    # ここまで矛盾なければその値を出力して終了
    print(str(x) + ' ' + str(y) + ' ' + str(high_cand))

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
    long n;
    long long hold, min, max, sum;
    sum = 0;
    max = -1000000;
    min = 1000000;
    scanf("%ld", &n);
    for(int i=0; i < n; i++){
      scanf("%lld", &hold);
      if(hold<min)min=hold;
      if(hold>max)max=hold;
      sum += hold;
    }
    printf("%lld %lld %lld\n", min, max, sum);
  return 0;
}

Measured memory_bytes: 1852
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    ll n;
    cin>>n;
    ll ans = 1e13;
    for (ll i = 1ll; i * i <= n; ++i) {
        if (n % i == 0)
            MIN(ans,i + (n/i));
    }
    cout<<ans-2<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    var (n, k) = listOfInt()
    val dd = listOfInt()

    while (true) {
        var sn = n.toString()
        if (sn.all { it.toString().toInt() !in dd }) {
            println(n)
            return
        }
        n++
    }
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 40808
#include <stdio.h>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

// Self settings
// clang-format off
#define MAX_N 20000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
// clang-format on

int N;
int a[MAX_N], b[MAX_N], c[MAX_N];

typedef pair<int, int> P;
vector<int> G[MAX_N];
map<int, int> deg;
int res[MAX_N];
bool used[MAX_N];
vector<P> edge;

int main(void)
{
  priority_queue<P, vector<P>, less<P>> q;
  cin >> N;
  fill(used, used + N, false);

  for (int i = 0; i < N - 1; ++i) {
    int v1, v2;
    cin >> v1 >> v2;
    G[v1].push_back(v2);
    G[v2].push_back(v1);
    deg[v1]++;
    deg[v2]++;
    edge.push_back(P(v1, v2));
  }
  REP(i, N) cin >> c[i];

  sort(c, c + N, greater<int>());

  for (map<int, int>::iterator i = deg.begin(); i != deg.end(); ++i) {
    q.push(P(i->first, i->second));
  }

  int ci = 0;
  priority_queue<P> ve;
  while (!q.empty()) {
    P p = q.top();
    q.pop();
    int v1 = p.first;
    if (used[v1]) continue;
    used[v1] = true;
    res[v1] = c[ci++];
    // 次数順で入れる
    for (int i = 0; i < G[v1].size(); ++i) ve.push(P(G[v1][i], deg[G[v1][i]]));
    while (!ve.empty()) {
      P p2 = ve.top();
      ve.pop();
      int v2 = p2.first;
      if (used[v2]) continue;
      used[v2] = true;
      res[v2] = c[ci++];
      for (int i = 0; i < G[v2].size(); ++i)
        ve.push(P(G[v2][i], deg[G[v2][i]]));
    }
  }

  long long sum = 0;
  for (int i = 0; i < edge.size(); ++i) {
    P pp = edge[i];
    sum += min(res[pp.first], res[pp.second]);
  }
  cout << sum << endl;
  for (int i = 0; i < N; ++i) {
    cout << res[i + 1];
    if (i != N - 1) cout << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
namespace imzzy{
	#define endl '\n'
	#define ccf std::cout<<"phi**k"<<endl
	#define rgi register int
	#define ll long long
	class fastin{private:int _ch,_f;
	public:inline fastin&operator>>(char&c){c=getchar();return*this;}
	template<typename _Tp>inline fastin&operator>>(_Tp&_x){
	_x=0;while(!isdigit(_ch))_f|=(_ch==45),_ch=getchar();
	while(isdigit(_ch))_x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
	_f&&(_x=-_x,_f=0);return*this;}fastin(){_ch=_f=0;}
	}fin;class fastout{private:int _num[32],_head;
	public:inline fastout&operator<<(char c){putchar(c);return*this;}
	template<typename _Tp> inline fastout&operator<<(_Tp _x){
	_Tp _k;if(_x==0){putchar('0');return *this;}if(_x<0)putchar('-'),_x=-_x;
	while(_x>0)_k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
	while(_head>0)putchar(_num[_head]),--_head;return*this;}fastout(){_head=0;}
	}fout;inline void P_INIT(){
	#ifdef D_STDOUT_UNBUFFERED
	setbuf(stdout,NULL);
	#endif
}}using namespace imzzy;
// ----------------------------
// #define int ll
// using namespace std;
const int maxn=100004;
const int mod=1000000007,inf=1201201201;

bool book[maxn];
int cnt[maxn];
signed main()
{P_INIT();
	// freopen("yy.in","r",stdin);
	// freopen("yy.out","w",stdout);
	int n,m,u,v,ans=0;
	fin>>n>>m;
	book[1]=1; for(rgi i=1;i<=n;++i) cnt[i]=1;
	for(rgi i=1;i<=m;++i) {
		fin>>u>>v;
		--cnt[u],++cnt[v];
		book[v]|=book[u];
		if(cnt[u]==0) book[u]=0;
	} for(rgi i=1;i<=n;++i) ans+=book[i]; fout<<ans;
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 4028
#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 << "Left" << endl;
    } else if (A + B < C + D) { 
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
}

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

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

    double w, h, x, y;
    cin >> w >> h >> x >> y;

    printf("%.19f", w*h/2);
    if(2*x == w && 2*y == h) puts(" 1");
    else puts(" 0");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  int count=0;
  for(int i=1;i<=N;i++){
    if(S[i-1]=='1'){
      count++;
    }
    else{
      count--;
    }
    //cout << count;
  }
  cout << N - abs(count) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
int prime[N];
int cond[N];
int cumu[N];
void Fill()
{
    memset(prime,1,sizeof(prime));
    prime[0] = prime[1] = 0;
    for(int i = 2; i <= N; i++)
    {
        if(prime[i])
        {
            for(int j = i+i; j <= N; j+=i)
            {
                prime[j] = 0;
            }
        }
    }
}
void build()
{
    for(int i = 0; i < N; i++)
    {
        if((i % 2 != 0) && (prime[i]) && (prime[(i + 1) / 2]))
        {
            cond[i] = 1;
        }else
        {
            cond[i] = 0;
        }
    }

    for(int i = 0; i < N; i++)
    {
        if(i == 0)
        {
            cumu[i] = cond[i];
        }else
        {
            cumu[i] = cumu[i - 1] + cond[i];
        }
    }

}
int main()
{
    Fill();
    build();
    int q , l , r;
    cin >> q;


    for(int i = 0; i < q; i++)
    {
        cin >> l >> r;
        cout << cumu[r] - cumu[l - 1] << endl;
    }
    return 0;
}


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

constexpr long long INF = 2e18;

int main() {
    int N; cin >> N;
    vector<long long> A(N); for (auto &x : A) cin >> x;
    long long sum = 0;
    for (int i = 0; i < N; i++) sum += A[i];
    if (N % 2 == 0) {
        vector<vector<long long>> memo(2, vector<long long>(N, -INF));
        memo[0][0] = A[0];
        for (int i = 2; i < N; i += 2) memo[0][i] = A[i] + memo[0][i-2];
        memo[1][1] = A[1]; memo[1][2] = A[2];
        for (int i = 3; i < N; i++) memo[1][i] = max(memo[0][i-3] + A[i], memo[1][i-2] + A[i]);
        cout << max(memo[0][N-2], memo[1][N-1]) << endl;
    } else {
        vector<vector<long long>> memo(3, vector<long long>(N, -INF));
        memo[0][0] = A[0];
        for (int i = 2; i < N; i += 2) memo[0][i] = A[i] + memo[0][i-2];
        memo[1][1] = A[1]; memo[1][2] = A[2];
        for (int i = 3; i < N; i++) memo[1][i] = max(memo[0][i-3] + A[i], memo[1][i-2] + A[i]);
        memo[2][2] = A[2];
        for (int i = 4; i < N; i++) memo[2][i] = max({memo[0][i-4] + A[i], memo[1][i-3] + A[i], memo[2][i-2] + A[i]});
        cout << max({memo[0][N-3], memo[1][N-2], memo[2][N-1]}) << endl;
    }
}


Measured memory_bytes: 11152
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for ai in range(A+1):
    for bi in range(B+1):
        for ci in range(C+1):
            if 500*ai + 100*bi + 50*ci == X:
                ans += 1

print(ans)

Measured memory_bytes: 3064
x,n= map(int, input().split())
if n!=0:
    p = list(map(int, input().split()))
else:
    p=[]
def func(x,n,p):
    if n==0:
        print(x)
        return
    if x not in p:
        print(x)
        return
    current = x
    for d in range(1,101,1):
        if current-d not in p:
            print(current-d)
            return
        elif current+d not in p:
            print(current+d)
            return
    print(x-101)
    return
func(x,n,p)

Measured memory_bytes: 9236
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((a+d-1)/d >= (c+b-1)/b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

ll power(ll  a, ll b){
   ll  ans = 1;
   while(b){
      if(b&1){
         ans *= a;
      }
      a *= a;
      b /= 2;
   }
   return ans;
}

ll nCr[52][52];

ll pre(){
   for(ll i = 0; i <= 50; i++){
       nCr[i][0] = 1;
       nCr[i][i] = 1;
       nCr[i][1] = i;
   }
   for(int n = 2; n <= 50; n++){
       for(int r = 1; r < n; r++){
           nCr[n][r] = nCr[n-1][r]+nCr[n-1][r-1];
           //cout << nCr[n][r] << endl;
       }
   }
}

ll a[123], arr[123];

int main()
{

    ll n, p;
     ll nodd = 0, ne = 0;
     cin >> n >> p;
     p = p%2;
     for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i]%2 == 1) nodd++;
            else ne++;
     }
        ll  ans;
        if(nodd == 0){
            if(!p)
            ans = power(2, ne);
            else ans = 0;
        }
        else{
            ans = power(2, ne)*power(2, nodd-1);
        }

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int N,M,Lx=0,Rx=1000000000,r=0;
    cin>>N>>M;
    vector<int>L(M),R(M);
    for(int i=0;i<M;i++){
        cin>>L.at(i)>>R.at(i);
        Lx=max(L.at(i),Lx);
        Rx=min(R.at(i),Rx);
    }
    for(int i=Lx;i<=Rx;i++){
        r++;
    }
    cout<<r<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
typedef pair<int , int > pii;
#define MOD 1000000007
#define MOD1 998244353
#define ff first
#define ss second
#define bn cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define sz(a) int((a).size())
#define o(a) cout << a
#define MAX6 1000006
#define int ll
#define all(x) x.begin(), x.end()
#define ppii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define viii vector<ppii>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define MAX5 300005
#define MAX7 10000007
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,b,a)  for (__typeof((b)) i=(b);i>=(a);i--)
#define mem(a) memset(a,0,sizeof(a))
#define memneg(a) memset(a,-1,sizeof(a))
//#define se second
#define LN 14
#define LIM 22
#define MAX_ALPHA 26
const long long INF64 = 1e18;
const ll INF = 1e9;
const double PI = acos(-1);
#define ld long double
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
inline void max_self(ll &a, ll b)
{
  a = max(a,b);
}
 
inline void min_self(ll &a,ll b)
{
  a = min(a,b);
}
 
inline void add_self(ll &a, ll b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
inline void sub_self(ll &a, ll b) {
  a -= b;
  if (a < 0) a += MOD;
}
 
inline int mul(int a, int b) {
  return (int) ((long long) a * b % MOD);
}
 
 
ll gcd(ll a,ll b)
{
  if(b == 0)
    return a;
  else 
    return gcd(b, a%b);
}
 
 
int countDigits(int x)
{
  int cnt = 0;
  while(x)
  {
    x /= 10;
    cnt++;
  }
  return cnt;
}
 
 
ll binExpo(ll a,ll b)
{
  ll res = 1;
  while(b)
  {
    if(b&1)
      res = (res * a)%MOD;
    a = (a * a)%MOD;
    b /= 2;
  }
  return res%MOD;
}
 
int sum(int a) {
    int result = 0;
    while (a > 0) {
        result += a % 10;
        a /= 10;
    }
    return result;
}

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

  int n;
  cin>>n;
  int dp[n+1];
  int h[n];
  for(int i = 0;i < n;i++){
    cin>>h[i];
    dp[i] = INF64;
  }
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for(int i = 2;i < n;i++)
  {
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    
    long A = 1;
    long B = 1;
    for (int i = 0; i < n; i++) {
      long t = sc.nextInt();
      long a = sc.nextInt();
      long x = Math.max((A + t - 1) / t, (B + a - 1) / a);
      A = x * t;
      B = x * a;
    }

    System.out.println(A + B);
    
  }
}

Measured memory_bytes: 24660
#include<bits/stdc++.h>
#define int long long
#define vin vector<int>
#define vcn vector<char>
#define ver pair<int,int>
#define ld long double
#define pb push_back
#define x first
#define y second
#define blush fflush(stdout);fflush(stdin);
#define $(a) (int)a.size()
#define scanf ;
#define printf ;
using namespace std;
void i_love_misaka_mikoto();
int32_t main(){
    #ifdef RNS
        freopen("input.txt","r",stdin);
        #ifndef DBG
        freopen("output.txt","w",stdout);
        #endif
    #else
        ios_base::sync_with_stdio(false);
    #endif
    i_love_misaka_mikoto();
    #ifdef RNS
        cout<<'\n'<<(ld)clock()/CLOCKS_PER_SEC<<" セクンド\n";
    #endif
    return 0;
}
vin g[(int)1e5+1];
int sp[(int)1e5+1];
int sppr(int v){
    if(sp[v]!=-1)
        return sp[v];
    if($(g[v])==0)
        return sp[v]=0;
    int res=0;
    for(auto&i:g[v])
        res=max(res, sppr(i));
    return sp[v]=res+1;
}
void i_love_misaka_mikoto(){
    int n, m;
    cin>>n>>m;
    memset(sp, 255, sizeof sp);
    for(int i=0;i<m;i++){
        int x, y;
        cin>>x>>y;
        g[y].pb(x);
    }
    for(int i=1;i<=n;i++)
        if(sp[i]==-1)sppr(i);
    sort(sp+1, sp+1+n);
    cout<<sp[n];
}

Measured memory_bytes: 11008
#include <iostream>

using namespace std;

int main(){
  int n,b[100000];
  while(cin >> n,n ){
      int ans = 0;
      for(int i = 0 ; i < n ; i++)cin >> b[i];
    while(1){
      bool f = true;
      for(int i = 0 ; i < n ; i++)if(b[i] != i + 1 )f = false;
      if(f){
	cout << ans << endl;
	break;
      } else if(ans >= 10000){
	cout << "-1" << endl;
	break;
      }
      ans++;

      for(int i = 0 ; i < n ; i++){
	b[i]--;
      }
      int p = 0;
      for(int i = 0 ; i < n ; i++)if(b[i])b[p++] = b[i];
      b[p++] = n;
      n = p;
    }
  }
  return 0;
}

Measured memory_bytes: 1172