akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 100000;
static const int INFTY = (1<<29);

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX], parent[MAX], lowest[MAX], timer;

void dfs( int current, int prev) {
	prenum[current] = lowest[current] = timer;
	timer++;

	visited[current] = true;

	int next;

	for ( int i = 0; i < G[current].size(); i++) {
		next = G[current][i];
		if (!visited[next]){
			parent[next] = current;

			dfs(next, current);
			lowest[current] = min( lowest[current], lowest[next]);
		} else if (next != prev) {
			lowest[current] = min(lowest[current], prenum[next]);
		}
	}
}

void art_points() {
	for ( int i = 0; i < N; i++) visited[i] = false;
	timer = 1;
	dfs(0, -1);// 0 == root

	set<int> ap;
	int np = 0;
	for (int i = 1; i < N; i++) {
		int p = parent[i];
		if( p == 0) np++;
		else if (prenum[p] <= lowest[i]) ap.insert(p);
	}
	if( np > 1) ap.insert(0);
	for (set<int>::iterator it = ap.begin(); it != ap.end(); it++)cout << *it << endl;
}

int main(){
	int m;
	cin >> N >> m;

	for ( int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	art_points();
	return 0;
}



Measured memory_bytes: 6952
A, B, C, K = map(int, input().split())
if K <= A:
    print(K)
    exit()

if K <= A+B:
    print(A)
    exit()

if K <= A+B+C:
    print(2*A-K+B)
    exit()

else:
    print(A-C)
    exit()

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

template<class T> bool chkmax(T & a, T b){ if(a < b){ a = b; return true;} return false;}
template<class T> bool chkmin(T & a, T b){ if(a > b){ a = b; return true;} return false;}

const int maxn = 5005;
const ll llinf = 1e18;

vector<int> adj[maxn];
int N, a[maxn];
ll h[maxn][2];
ll f[maxn][maxn][2];
int sub[maxn];

void dfs(int u, int p = -1)
{
  sub[u] = 1;
  f[u][0][0] = a[u] < 0 ? 1e18 : a[u];
  f[u][0][1] = a[u] > 0 ? 1e18 : a[u];

  for(int v : adj[u]) if (v != p) {
    dfs(v, u);
    for(int i = 0 ; i < sub[u] + sub[v] ; ++i)
      h[i][0] = 1e18,
      h[i][1] = 1e18;
    for(int i = 0 ; i < sub[u] ; ++i){
      for(int j = 0 ; j < sub[v] ; ++j){
        int k = i + j;
        h[k][0] = min(h[k][0],f[u][i][0] + f[v][j][0]);
        h[k][1] = min(h[k][1],f[u][i][0] + f[v][j][1]);
        h[k][1] = min(h[k][1],f[u][i][1] + f[v][j][0]);
        h[k][1] = min(h[k][1],f[u][i][1] + f[v][j][1]);
        if (f[v][j][0] < 1e18 || f[v][j][1] < 0)    {
          h[k + 1][0] = min(h[k + 1][0],f[u][i][0]);
          h[k + 1][1] = min(h[k + 1][1],f[u][i][1]);
        }
      }
    }
    sub[u] += sub[v];
    for(int i = 0 ; i < sub[u] ; ++i)
      f[u][i][0] = h[i][0],
      f[u][i][1] = h[i][1];
  }
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if(fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N;
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
  }
  for(int i = 1; i < N; ++i){
    int u, v; cin >> u >> v;
    adj[u].pb(v); adj[v].pb(u);
  }
  dfs(1);
  for(int i = 0; i < N; ++i){
    if(f[1][i][0] < 1e18 || f[1][i][1] < 0){
      cout << i;
      return 0;
    }
  }
}


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

    num = 1
    l = []
    s = [1]*n

    while s[num-1]:
        l.append(num)
        s[num-1] = 0
        num = a[num-1]

    if l.index(num) <= k:
        l2 = l[l.index(num):]
        kk = (k-len(set(l)-set(l2)))%len(l2)
        print(l2[kk])
    else:
        print(l[k])

main()


Measured memory_bytes: 45992
fn main() {
    let n = read::<u32>();

    if n < 10 {
        println!("{}", n);
    } else if 10 <= n && n < 10u32.pow(2){
        println!("{}", 9);
    } else if 10u32.pow(2) <= n && n < 10u32.pow(3) {
        println!("{}", 9 + (n - 100 + 1));
    } else if 10u32.pow(3) <= n && n < 10u32.pow(4) {
        println!("{}", 9 + (999 - 100 + 1));
    } else if 10u32.pow(4)<= n && n < 10u32.pow(5) {
        println!("{}", 9 + (999 - 100 + 1) + (n - 10000 + 1));
    } else if n == 10u32.pow(5) {
        println!("{}", 9 + (999 - 100 + 1) + (99999 - 10000 + 1));
    } else {
        //nop
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
import math

a, b, h, m = [int(i) for i in input().split()]

asi = h * 30 + m / 2
bsi = m * 6

sita = abs(asi - bsi)

kotae = math.sqrt( a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(abs(asi-bsi))))
print(kotae)

Measured memory_bytes: 9452
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int num[100010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,c;
    cin >> n >> c;
    vector<vp> v(c);
    rep(i,n) {
        int s,t,nc;
        cin >> s >> t >> nc;
        nc--;
        v[nc].eb(s,t);
    }
    auto add = [&](int s,int t) {
        num[s]++;
        num[t]--;
    };
    for(vp nv : v) {
        if(nv.empty()) continue;
        sort(all(nv));
        int ns,nt;
        tie(ns,nt) = nv[0];
        rep2(i,1,nv.size()) {
            if(nt == nv[i].first) nt = nv[i].second;
            else {
                add(ns-1,nt);
                ns = nv[i].first;
                nt = nv[i].second;
            }
        }
        add(ns-1,nt);
    }
    rep(i,100009) num[i+1] += num[i];
    int ans = 0;
    rep(i,100010) chmax(ans,num[i]);
    cout << ans << endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void resolve() {
    // UNRESTORABLE
    string s,t;
    cin >> s >> t;
    bool bb = false;
    int last = -1;
    REP(i,0,s.size()-t.size()+1) {
        bool b = true;
        REP(j,0,t.size()) {
            // cerr << i << " " << j << endl;
            if (s[i+j] != '?' && s[i+j] != t[j]) {
                b = false;
                break;
            }
        }
        if (b) {
            // cerr << i << endl;
            // REP(j,0,t.size()) s[i+j] = t[j];
            last = i;
            bb = true;  
        }
    }
    if (bb) {
        REP(j,0,t.size()) s[last+j] = t[j];
        REP(i,0,s.size()) if (s[i] == '?') s[i] = 'a';
        cout << s << endl;
    }
    else cout << "UNRESTORABLE" << endl;
}

int main() {
    resolve();
    
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nhw = readln.split.to!(int[]);
    auto N = nhw[0];
    auto H = nhw[1];
    auto W = nhw[2];

    int r;
    foreach (_; 0..N) {
        auto ab = readln.split.to!(int[]);
        if (ab[0] >= H && ab[1] >= W) ++r;
    }
    writeln(r);
}

Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int N, M, i, X[100005] = {}, sa[100005] = {}, sum = 0;
int main() {
	cin >> N >> M;
	for (i = 1;i <= M; i++) {
		cin >> X[i];
	}
	sort(X + 1, X + M + 1, greater<int>());
	for (i = 1;i < M;i++) {
		sa[i] = X[i] - X[i + 1];
		sum += sa[i];
	}
	sort(sa + 1, sa + M, greater<int>());
	for (i = 1;i <= N - 1;i++) {
		sum -= sa[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
numberlist = []
now = [A[0], 1]
for i in range(1, N):
	if now[0] == A[i]:
		now[1] += 1
	else:
		numberlist.append(now)
		now = [A[i], 1]
numberlist.append(now)
ans = 0
if K < len(numberlist):
	M = len(numberlist) - K
	numberlist.sort(key = lambda v: v[1])
	for i in range(0, M):
		ans += numberlist[i][1]
print(ans)

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

using namespace std;

int main() {
    string S; cin>>S;

    const int N=13;
    long long dp[N];
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    
    long long mod = 1000000007;

    long mul = 1;
    for (int i=S.length()-1; i>=0; i--) {
        // cout << "i=" << i << endl;

        long long nextDP[N];
        memset(nextDP, 0, sizeof(dp));
        
        char c = S[i];
        if (c == '?') {
            for (int k=0;k<10;k++) {
                for (int j=0;j<N;j++) {
                    nextDP[(k * mul + j) % N] += dp[j];
                    nextDP[(k * mul + j) % N] %= mod;
                }
            }
        } else {
            int k = (int)(S[i]-'0');
            for (int j=0;j<N;j++) {
                nextDP[(k * mul + j) % N] += dp[j];
                nextDP[(k * mul + j) % N] %= mod;
            }
        }

        

        mul *= 10;
        mul %= N;
        memcpy(dp, nextDP, sizeof(dp));

        // for (int i=0;i<N;i++) {
        //     cout << dp[i] << ' ';
        // }
        // cout << endl;
    }

    cout << dp[5] << endl;

    return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N;
  va.resize(N);
  rep(i, 0, N - 1) { cin >> va[i]; }
}
void solve() {
  int ans = INF;
  rep(p, 1, 100) {
    int tmp = 0;
    rep(i, 0, N - 1) { tmp += (va[i] - p) * (va[i] - p); }
    chmin(ans, tmp);
  };
  ;
  cout << ans << endl;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
from itertools import product
n, m = map(int,input().split())
canvas = []
flag = False
for i in range(n):
    canvas.append(input())
for i,j in product([num for num in range(n)],[num for num in range(m)]):
    if canvas[i][j] == '.':
        continue
    result = 0
    if i > 0 and canvas[i-1][j] == '#':
        result += 1
    if i < n-1 and canvas[i+1][j] == '#':
        result += 1
    if j > 0 and canvas[i][j-1] == '#':
        result += 1
    if j < m-1 and canvas[i][j+1] == '#':
        result += 1
    if result == 0:
        flag = True
        break
if flag:
    print('No')
else:
    print('Yes')
        
            

Measured memory_bytes: 3064
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <string.h>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
signed main() {
	int n, m;
	cin >> n >> m;
	int a[100004];
	int dp[100004] = {0};
	for (int i = 0; i < 100003; i++) { a[i] = 1;}
	dp[1] = 1;
	int x, y;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		a[x] -= 1; a[y] += 1;
		if (dp[x]) {
			if (a[x] == 0) {
				dp[x] = 0; dp[y] = 1;
			}
			else {
				dp[y] = 1;
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (dp[i])ans++;
	}cout << ans;
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a<b)
        cout<<0<<endl;
    else
        cout<<10;
}

Measured memory_bytes: 256
n, x = map(int, input().split())

x -= 1

length = [1]
n_p = [1]
for i in range(n):
    length.append(length[-1] * 2 + 3)
    n_p.append(n_p[-1] * 2 + 1)

length = length[::-1]
n_p = n_p[::-1]

ans = 0
for i in range(len(length)):

    if i == len(length) - 1:
        if x >= 0:
            ans += 1
    else:
        # print(x, ans, length[i+1])
        if x == length[i+1] + 1:
            ans += n_p[i+1] + 1
            break
        elif x == length[i+1]:
            ans += n_p[i+1]
            break
        elif x < length[i+1]:
            x -= 1
        else:
            x -= (length[i+1] + 2)
            ans += n_p[i+1] + 1

print(ans)


Measured memory_bytes: 38384
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
int G[101][101]={0};
main(){
	int n,u,v,deg;scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%d%d",&u,&deg);
		for (int j=0;j<deg;j++){
			scanf("%d",&v);
			G[u][v]=1;
		}  
	}
	for(int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			printf("%d",G[i][j]);
			if (j==n) printf("\n");
			else printf(" ");
		}
	}
}


Measured memory_bytes: 3220
#include <cstdio>
#include <cmath>
using namespace std;


int main() {
    int X;
    scanf("%d", &X);

    if(X == 1) {
        printf("1\n");
        return 0;
    }

    int ans = 0;
    for(int b = 2; b*b <= X; b++) {
        for(int p = 2; ; p++) {
            int y = pow(b, p);
            if(y <= X) {
                if(ans < y) {
                    ans = y;
                }
            }
            else {
                break;
            }
        }
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
//ehhhhh...... i hate you......

/* optimizations and other useless stuff*/
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define INF 1e14
#define ull unsigned long long int
using namespace std;
/* TYPE DEFINITIONS */
typedef     long long int   ll;
typedef     vector<ll>      vi;
typedef     pair<ll,ll>     pi;


/* Basic  Math!!! */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
ll ncr(int n, int k)  
{  
    ll res = 1;  
    if ( k > n - k )  
        k = n - k;  
    for (int i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
  
    return res;  
} 

/* MACROS */
#define  all(A)         (A).begin() , (A).end()
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).sbegin()) it = (a).begin(); it != (a).end(); it++)  
int dp[3001][3001];
string s;
void buildLCS(string s1,string s2)
{
    int l1=ln(s1);
    int l2=ln(s2);
    for(int i=1;i<=l1;i++)
    {
        for(int j=1;j<=l2;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=l1,j=l2;
    while(i>0&&j>0)
    {
        if(s1[i-1]==s2[j-1])s+=s1[i-1],i--,j--;
        else
        {
            if(dp[i-1][j]>dp[i][j-1])i--;
            else j--;
        }
    }
    /*forn(i,l1+1)
    {
        forn(j,l2+1)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;

    }*/
}
void solve()
{
    string s1,s2;
    cin>>s1>>s2;
    buildLCS(s1,s2);
    reverse(all(s));
    cout<<s<<endl;
}

int main()
{
    FastIO;
    ll c=0;
    ll t=1;
   // cin>>t;
    while(t--)
    {
        //cout<<"Case "<<++c<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int N, a[100005], b[100005];
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> N;
  rep(i, 0, N+1) cin >> a[i];
  rep(i, 0, N) cin >> b[i];
  
  int ans = 0;
  rep(i, 0, N) {
    if (b[i] - a[i] > 0) {
      if (a[i+1] - (b[i] - a[i]) < 0) {
        ans += a[i+1] + a[i];
        a[i+1] = 0;
      } else {
        a[i+1] -= (b[i] - a[i]);
        ans += b[i];
      }
    } else {
      ans += b[i];
    }
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 1792
#include <iostream>

bool isPalindrome(int n) {
    if((n % 10 == n / 10000) && ((n / 10) % 10 == (n / 1000) % 10)) {
        return true;
    } else {
        return false;
    }
}

int main() {
    int a,b,ret = 0;
    std::cin >> a >> b;
    for(int i = a; i <= b; i++){
        if(isPalindrome(i)) ret++;
    }
    std::cout << ret << std::endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input().strip())
S = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for _ in range(N):
    S[input().strip()] += 1
print(f"AC x {S['AC']}")
print(f"WA x {S['WA']}")
print(f"TLE x {S['TLE']}")
print(f"RE x {S['RE']}")


Measured memory_bytes: 9208
#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,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;



int main()
{
    ll n, p;
    cin>>n>>p;
/*
    vector<ll> prm;
    prm.push_back(2);

    ll imax = sqrt(p) + 1;
    for (ll i = 3; i < imax; i += 2) {
        int jmax = prm.size();
        bool flag = true;
        REP(j, jmax) {
            if (i % prm[j] == 0) {
                flag = false;
                break;
            }
        }
        if (flag) {
            prm.push_back(i);
        }
    }

    REPALL(i,prm) cout<<prm[i]<<" ";

    vector<int> ele(prm.size());
    int jmax = prm.size();
    REP(j, jmax) {
        while (p % prm[j] == 0) {
            ele[j]++;
            p /= prm[j];
        }
    }

    ll ans = 1;
    REP(j, jmax) {
        REP(k,ele[j]/n){
            ans *= prm[j];
        }
    }

    cout<<ans<<endl;
*/

    ll ans = 1;
    if (n == 1) {
        ans = p;
    } else if (n > p) {
        ans = 1;
    } else if (n == p) {
        if (n == 2) ans = 2;
        else ans = 1;
    } else {
        for (ll i = 2; i * i <= p; i++) {
            //cout<<i<<endl;
            bool flag = true;
            ll tmp = 1;
            REP(j,n) {
                tmp *= i;
                if (tmp > p) {
                    flag = false;
                    break;
                }
            }
            if (!flag) {
                break;
            }
            if (p % tmp == 0) {
                ans = i;
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1005];
int main()
{
	int n,k,ans;
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	ans=0;
	for (int i=1;i<=k;i++)
	{
		ans+=a[i];
	}
	cout<<ans;
	return 0;
 } 

Measured memory_bytes: 3596
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		System.out.print(a[n-1]);
		for (int i = n - 2; i >= 0; i--) {
			System.out.print(" " + a[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 26200
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    vector<int> v1, v2;
    a*=100, b*=100;
    for (int i = 0; i <= f/a; ++i) {
        v1.emplace_back(i*a);
    }
    for (int i = 0; i <= f/a; ++i) {
        for (int j = 0; j <= (f-v1[i])/b; ++j) {
            v1.emplace_back(v1[i]+j*b);
        }
    }
    sort(v1.begin(), v1.end());
    v1.erase(unique(v1.begin(), v1.end()), v1.end());
    for (int i = 0; i <= f/c; ++i) {
        v2.emplace_back(i*c);
    }
    for (int i = 0; i <= f/c; ++i) {
        for (int j = 0; j <= (f-v2[i])/d; ++j) {
            v2.emplace_back(v2[i]+j*d);
        }
    }

    sort(v2.begin(), v2.end());
    v2.erase(unique(v2.begin(), v2.end()), v2.end());
    double up = (((double)e*100)/((double)(100+e)));
    double ans = 0;
    int maxx = 0, maxy = 0;
    for (auto &&x : v1) {
        for (auto &&y : v2) {
            if(x+y != 0){
                double k = (double)100*y/(double)(x+y);
                if(ans < k && k <= up && x+y <= f ){
                    ans = k;
                    maxx = x;
                    maxy = y;
                }
            }
        }
    }
    if(maxy == 0){
        for (auto &&item : v1) {
            if(item != 0) {maxx = item; break;}
        }
    }
    cout << maxx+maxy << " " << maxy << "\n";
    return 0;
}


Measured memory_bytes: 1400
while True:
    x,y = map(int, input().split())
    if x ==0 and y ==0 :
        break
    
    ans=0
    while True:
        if y == 0:
            break
        if x < y:
            x,y= y,x
        x= x%y
        x,y = y,x
        ans+=1   
    print(x, ans)


Measured memory_bytes: 5608
N=int(input())
A = list(map(int,input().split()))
#print(A[0])
if 0 in A:
  print('0')
  exit()

ans = 1 
for i in range(N):
  ans *= A[i]
  if ans > 1e+18:
    print('-1')
    exit()
print(ans)

Measured memory_bytes: 21596
num_500 = gets.chomp.to_i
num_100 = gets.chomp.to_i
num_50 = gets.chomp.to_i
tar = gets.chomp.to_i

cnt = 0
(0..num_500).each do |a|
  (0..num_100).each do |b|
    (0..num_50).each do |c|
      result = 500 * a + 100 * b + 50 * c
      cnt += 1 if result == tar
    end
  end
end
puts cnt

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	string s;
	if( n >= 1000 ){
		s = "ABD";
	} else {
		s = "ABC";
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n+1];
		long[] b = new long[n];
		for(int i = 0; i < n+1; i++) {
			a[i] = sc.nextLong();
		}
		long ans = 0l;
		for(int i = 0; i < n; i++) {
			b[i] = sc.nextLong();
		}
		
		for(int i = 0; i < n; i++) {
			long x = Math.min(a[i], b[i]);
			ans += x;
			x = Math.min(a[i+1], b[i]-x);
			a[i+1] -= x;
			ans += x;
		}
		System.out.println(ans);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


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

int main(){
  int num;
  int max = 0;
  int sec = 0;
  int tmp = 0;
  
  cin >> num;
  vector<int> vec(num);
  vector<int> vecTmp(num);
  
  for(int i = 0; i < num; i++){
    cin >> vec.at(i);
    vecTmp.at(i) = vec.at(i);
  }
  
  sort(vecTmp.begin(), vecTmp.end());
  for(int i = 0; i < num; i++){
    if(vec.at(i) == vecTmp.at(num - 1)){
      cout << vecTmp.at(num - 2) << endl;
    }else{
      cout << vecTmp.at(num - 1) << endl;
    }
  }
}


Measured memory_bytes: 3200
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    S = SI()

    ans = int(S)
    for 文字数 in range(1, len(S)):
        for 開始位置 in range(len(S)-文字数+1):
            if 開始位置 == 0 or 開始位置+文字数 == len(S):
                ans += int(S[開始位置:開始位置+文字数]) * 2**(len(S) - 1 - 文字数)
            else:
                ans += int(S[開始位置:開始位置+文字数]) * 2**(len(S) - 1 - 文字数 -1)
    print(ans)

main()

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

#define MOD 1000000007
typedef unsigned long long ull;

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

  if (n == 1) {
    cout << 1;
  } else if (n % 2 == 0) {
    cout << 0.5;
  } else {
    float f = n / 2 + 1;
    float a = f / n;
    cout << std::setprecision(8) << a;
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5)

around = [(0,1),(1,0),(0,-1),(-1,0),(1,1),(1,-1),(-1,1),(-1,-1)]

def dfs(i,j):
    visited[i][j] = True
    for di, dj in around:
        ni = i + di
        nj = j + dj
        if not (0 <= ni < H and 0 <= nj < W):
            continue
        if C[ni][nj] and not visited[ni][nj]:
            dfs(ni,nj)

while True:
    W,H = map(int,input().split())
    if (W, H) == (0,0):
        break
    C = [list(map(int,input().split())) for _ in range(H)]

    visited = [[False]*W for _ in range(H)]
        
    ans = 0

    for i in range(H):
        for j in range(W):
            if visited[i][j]:
                continue
            if C[i][j]:
                dfs(i,j)
                ans += 1

    print(ans)


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

struct RSQ {
	using type = int;
	static const type id() { return 0; }
	static type op(const type& l, const type & r) { return l + r; }
};

const int PMAX = 3000000;

template <typename M>
class PersistentSegmentTree {
	using T = typename M::type;
	struct node {
		T val;
		node *l, *r;
		node() {}
		node(T val) : val(val), l(nullptr), r(nullptr) {}
		void init(T v, node *left, node *right) {
			val = v;
			l = left;
			r = right;
		}
	};
	const int n;
	vector<node> pool;
	int it;
	vector<node*> root;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	node *new_node(int val = 0, node *l = nullptr, node *r = nullptr) {
		pool[it].init(val, l, r);
		return &pool[it++];
	}
	node *fix(node *x, int p, T val, int lb, int ub) {
		if (p < lb || ub <= p) return x;
		if (lb + 1 == ub) return new_node(val);
		int c = (lb + ub) / 2;
		auto nl = fix(x->l, p, val, lb, c);
		auto nr = fix(x->r, p, val, c, ub);
		return new_node(M::op(nl->val, nr->val), nl, nr);
	}
	T sub(node *x, int l, int r, int lb, int ub) {
		if (ub <= l || r <= lb) return M::id();
		if (l <= lb && ub <= r) return x->val;
		int c = (lb + ub) / 2;
		return M::op(sub(x->l, l, r, lb, c), sub(x->r, l, r, c, ub));
	}
public:
	PersistentSegmentTree(int n_) : n(size(n_)), pool(PMAX) {
		for (int i = 1; i < n * 2; i++) {
			pool[i - 1].init(M::id(), i < n ? &(pool[i * 2 - 1]) : nullptr, i < n ? &(pool[i * 2]) : nullptr);
		}
		it = n * 2 - 1;
		root.push_back(&pool[0]);
	}
	void update(int p, T val, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		root.push_back(fix(root[rt], p, val, 0, n));
	}
	T find(int l, int r, int rt = -1) {
		if (rt == -1) rt = root.size() - 1;
		assert(0 <= rt && rt < (int)root.size());
		return sub(root[rt], l, r + 1, 0, n);
	}
	int getversion() {
		return root.size() - 1;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y;
	cin >> n >> q;
	PersistentSegmentTree<RSQ> st(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.find(x - 1, y - 1));
		}
		else {
			st.update(x - 1, st.find(x - 1, x - 1) + y);
		}
	}
	return 0;
}

Measured memory_bytes: 36712
n = int(input())
p = list(map(int, input().split()))
l = [0]*3
ans = 0

for i in range(0, n-2):
  l[0], l[1], l[2] = p[i], p[i+1], p[i+2]
  if sorted(l)[1] == p[i+1]:
    ans += 1

print(ans)
  

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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
#define smaller_queue_p  priority_queue <pll, vector<pll>, greater<pll> >
//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int alpha[26] = {};

    rep(i, n) {
        string p;
        cin >> p;
        alpha[(int) (p[0] - 'A')]++;
    }

    int ans = 0;
    while (1) {
        sort(alpha, alpha + 26);
        reverse(alpha, alpha + 26);

        rep(i, k) {
            if (alpha[i] == 0) goto finish;
            alpha[i]--;
        }
        ans++;
    }
finish:
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
<?php 
$N = intval(trim(fgets(STDIN)));
$tmp = trim(fgets(STDIN));
$a = array_map("intval", explode(" ", $tmp));

$l = 0;
$left = [];
$left[0] = 0;
foreach($a as $key => $value){
	$l += $value;
	array_push($left, $l);
}

$r = 0;
$right = [];
$right[0] = 0;
$r_a = array_reverse($a);
foreach($r_a as $key => $value){
	$r += $value;
	array_push($right, $r);
}
$right = array_reverse($right);

$ans = abs($right[1] - $left[1]);
for($i = 2;$i<count($right)-1;$i++){
	if($ans > abs($right[$i] - $left[$i])){
		$ans = abs($right[$i] - $left[$i]);
	}
}

echo $ans . PHP_EOL;

Measured memory_bytes: 53732
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;


int dp[5050][5050];//i人まででj人が座布団を積んだ時の枚数のmin
void solve() {
	int N; cin >> N;
	vector<int>H(N), P(N);
	vector<pii>v(N);
	REP(i, N) {
		cin >> H[i] >> P[i];
		v[i] = { H[i] + P[i],i };
	}
	VSORT(v);
	REP(i, N + 1)REP(j, N + 1)dp[i][j] = LINF;
	dp[0][0] = 0;
	REP(i, N) {
		int idx = v[i].second;
		REP(j, i+1) {
			//積まない
			chmin(dp[i + 1][j], dp[i][j]);
			//詰む
			if (dp[i][j] <= H[idx])chmin(dp[i + 1][j + 1], dp[i][j] + P[idx]);
		}
	}
	ll ans = 0;
	REP(j, N + 1)if (dp[N][j] != LINF)chmax(ans, j);
	print(ans);
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 201048
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int D, N, T[212], A[212], B[212], C[212];
int dp[212][212], ans;

int main()
{
	in >> D >> N;
	rep(i, D) { in >> T[i]; }
	rep(i, N) { in >> A[i] >> B[i] >> C[i]; }

	rep(i, D)
	{
		rep(j, N)
		{
			if (A[j] <= T[i] && T[i] <= B[j])
			{
				rep(k, N)
				{
					if (A[k] <= T[i + 1] && T[i + 1] <= B[k])
					{
						dp[i + 1][k] = std::max(dp[i + 1][k], dp[i][j] + abs(C[j] - C[k]));
					}
				}
			}
		}
	}
	rep(i, N)
	{
		ans = std::max(ans, dp[D - 1][i]);
	}

	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3232
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    append = peaks.append
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            append(upPeak)
            append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12576
#include <iostream>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <algorithm>
using namespace std;
const int MAXSIZE = 1e4+7;
struct node
{
	double x, y;
	node(double x = 0, double y = 0):x(x),y(y){}
};
typedef node Point;
struct segment
{
	node a, b;
};
typedef segment Segment;
Point operator * (Point a, double p){
	return Point(a.x * p, a.y * p);
}
Point operator - (Point a, Point b){
	return Point(a.x - b.x, a.y - b.y);
}
Point operator + (Point a, Point b){
	return Point(a.x + b.x, a.y + b.y);
}
double dot(Point a, Point b){
	return a.x * b.x + a.y * b.y;
}
double norm(Point a){
	return a.x * a.x + a.y * a.y;
}
double abs(Point a){
	return sqrt(norm(a));
}
Point project(Segment s, Point p){
	Point base = s.b - s.a;
	double r = dot(p-s.a, base) / norm(base);
	return s.a + base * r;
}
int main(){
	Segment temp;
	int n;
	scanf("%lf %lf %lf %lf",&temp.a.x, &temp.a.y, &temp.b.x, &temp.b.y);
	scanf("%d",&n);
	Point p;
	while(n--){
		scanf("%lf %lf",&p.x, &p.y);
		Point get = project(temp,p);
		printf("%0.10lf %0.10lf\n",get.x, get.y );
	}
	return 0;
}


Measured memory_bytes: 3240
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	lli h, w;
	cin >> h >> w;
	if(h%3==0 || w%3 == 0){
		cout << 0 << endl;
		return 0;
	}
	lli ans = min(h, w);

	rep(cc, 2){
		reg(i, 1, h){
			lli a, b, c;
			a = w*i;
			b = w/2 * (h-i);
			c = (w - w/2) * (h-i);
			ans = min(ans, max(a,max(b,c)) - min(a,min(b,c)));
		}
		swap(h, w);
	}
	
	cout << ans << endl;
	
	return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var x = long.Parse(Console.ReadLine());

        var k = 0L;
        var y = 100L;
        while (y < x)
        {
            var d = Math.DivRem(y, 100L, out var r);
            var years = (Math.Min(x - y, 100 - r) + d - 1) / d;
            y += years * d;
            k += years;
        }

        Console.WriteLine(k);
    }
}


Measured memory_bytes: 27392
#include <iostream>

using namespace std;
int search(int a[], int N, int key)
{
    int l=0, r=N;
    while(l<r){
        int mid=(l+r)/2;
        if(key==a[mid]) return 1;
        if(key<a[mid]) r=mid;
        else l=mid+1;
    }
    return 0;
}
int main()
{
    int n,q,key,num=0;
    int a[100000];
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    cin>>q;
    while(q--){
        cin>>key;
        if(search(a,n,key)) num++;
    }
    cout<<num<<endl;
    return 0;
}



Measured memory_bytes: 3384
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

# N = int(input())
# S = input()
L, R = map(int, input().split())
# 横
# L = [int(x) for x in input().split()]
# 縦
# A = [int(input()) for _ in range(N)]
# 多次元
# L = [[int(x) for x in input().split()] for _ in range(N)]
ans = 3000

if R - L + 1 > 2019 :
    print(0)
else :
    for i in range(L,R+1):
            for j in range(L,R+1):
                if i<j:
                    ans=min(ans,(i*j)%2019)
                
    print(ans)



Measured memory_bytes: 40940
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.ArrayBuffer
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N =sc.nextInt()
    val ans = map(N)(_ => sc.nextInt() - 1).sum

    out.println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) { f(i); i += 1 }
  }
  def rep_r(n: Int)(f: Int => Unit): Unit = {
    var i = n - 1
    while(i >= 0) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 26820