akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long int n,sum;
    cin>>n>>sum;
    vector<pair<int,int>> vp;
    long long int i,j,k;
    long long int a,b;
    for(i=0;i<n;i++)
    {
       cin>>a>>b;
       vp.push_back(make_pair(a,b));
    }
    long long int total = 0;
    for(i=0;i<n;i++)
    {
        total = total + vp[i].second;
    }
    sort(vp.begin(),vp.end());
    long long int dp[total+1];
    for(i=0;i<=total;i++)
    {
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    for(i=0;i<n;i++)
    {
       for(j = total-vp[i].second;j>=0;j--)
       {
           dp[j+vp[i].second] = min(dp[j+vp[i].second],dp[j]+vp[i].first);
       }
    }
    
    long long int ans = 0;
    for(i=1;i<=total;i++)
    {
        if(dp[i]<=sum)
        {
            ans = i;
        }
    }
    cout<<ans<<endl;
	// your code goes here
	return 0;
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl
#define rad_to_deg(x) ((double)(x) * 180 / PI)

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  double a, b, x;
  in(a, b, x);
  double ans;
  if (x < (a * a * b) / 2) {
    double depth = x / (a * b);
    ans = 90 - rad_to_deg(atan(depth / (b / 2)));
  } else {
    double depth = x / (a * a);
    ans = rad_to_deg(atan((b - depth) / (a / 2)));
  }
  printf("%.10f", ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	char c; cin >> c;
	switch(c){
		case 'A' : cout << "T" << endl; break;
		case 'C' : cout << "G" << endl; break;
		case 'G' : cout << "C" << endl; break;
		case 'T' : cout << "A" << endl; break;
	
	}
	
	
	
	
	
    return 0;
}

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


int main(){
  
  int n;
  cin >> n;
  int a[3][n+1];
  for(int i=1; i<3; i++){
  	for(int j=1; j<=n; j++){
    	cin >> a[i][j];
    }
  }
  int dp[3][n+1];
  int j=1;
  while(j<=n){
    if(j==1) dp[1][1]=a[1][1];
  	if(j>1)dp[1][j]=dp[1][j-1]+a[1][j];
    j++;
  }
  
   j=1;
   while(j<=n){
    if(j==1) dp[2][1]=dp[1][1]+a[2][1];
  	if(j>1) dp[2][j]=max(dp[2][j-1]+a[2][j],dp[1][j]+a[2][j]);
    j++;
  }              
    cout << dp[2][n] << endl;
}

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

vector<int> g[100005];
int v[100005];

bool check(int x)
{
	for (int i = 0; i < g[x].size(); i++)
	{
		if( v[x] <= v[g[x][i]] ) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> v[i];
	}
	for (int i = 1; i <= m; i++)
	{
		int a,b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);  
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if( check(i) ) ans ++;
	}
	cout << ans << '\n';
	return 0;
	
}


Measured memory_bytes: 8700
def main():
    N, K = map(int, raw_input().split())
    H = list(map(int, raw_input().split()))
    
    # dp[i] := 足場iにいくまでの最低コスト
    dp = [float('inf')] * N
    dp[0] = 0
    
    for i in range(N):
        for k in range(K + 1):
            if i - k < 0:
                break
            dp[i] = min(dp[i], dp[i - k] + abs(H[i] - H[i - k]))
    
    print(dp[-1])
    
main()


Measured memory_bytes: 42348
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 30;
const double PI = acos(-1);
int main()
{
    int a, b;
    int ans = -1;
    cin >> a >> b;
    for (int i = 0; i < 1020; i++)
    {
        if ((int)(i * 0.08) == a and (int)(i * 0.10) == b)
        {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int h,n;
    int cnt = 0;
    int b = 0;
    cin>>h>>n;
    vector<int> vec(n);
    for(int i = 0;i<n ;i++)
    {
        cin>>vec[i];
    }
    sort(vec.begin(),vec.end(),greater<int>());
    for(int i = 0 ; i < n ; i ++)
    {
        if(cnt <2)
        {
            h = h - vec[b];
            cnt = cnt +1;
            if(cnt == 1)
            {
                b = b +1;
                cnt = 0;
            }
        }
    }
    if(h > 0 )
    {
        cout<<"No"<<endl;
    }else
    {
        cout<<"Yes"<<endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
	long long  n,m,ans;
	ans = 0;
	scanf("%lld%lld",&n,&m);
	if( (n-2)>=0 || (m-2)>=0){
		ans = (n-2)*(m-2);
	}
	if( n==1){
		ans = m-2;
	}else if( n!= 1 &&m==1){
		ans = n-2;
	}
	if( ans == -1){
		ans = 1;
	}else{
	}
	printf("%lld",ans);
}


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

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

    if (N == 0)
    {
        cout << X << endl;
        return 0;
    }

    vector<int> P;
    vector<int> not_P;
    for (int i = 0; i < N; i++)
    {
        int p;
        cin >> p;
        P.push_back(p);
    }
    sort(P.begin(), P.end());
    int j = 0;
    for (int i = 0; i <= 101; i++)
    {
        if (P[j] == i)
        {
            j++;
        }
        else
        {
            not_P.push_back(i);
        }
    }

    int ans = 100;
    int min_value = 100;
    for (auto a : not_P)
    {
        if (min_value > abs(X - a))
        {
            ans = a;
            min_value = abs(X - a);
        }
    }

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

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
long long N, A[1 << 18];
 
int main() {
	cin >> N; long long S = 0;
	for (int i = 1; i <= N; i++) { cin >> A[i]; S += A[i]; }
 
	long long minx = S, sum = 0;
	for (int i = 1; i <= N; i++) {
		sum += A[i];
		minx = min(minx, abs(sum - (S - sum)));
	}
	cout << minx << endl;
	return 0;
}


Measured memory_bytes: 5192
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_c

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# greedyっぽいなぁ
# ABとなる部分を最大化したい
# *B → A*はむだ、*A→B*となる文字列はそのように連結させたほうがよい
# つまり新たにAB文字列になるのはmin(*Aの数,B*の数)
# ただしB*Aを満たす文字列に関してはどちらにもなりうるので、好きにpaddingできる

N = int(input())
cnt = end_A = start_B = both = 0
for _ in ra(N):
    s = input()
    cnt += s.count('AB')

    if s.endswith('A') and s.startswith('B'):
        both += 1
    elif s.endswith('A'):
        end_A += 1
    elif s.startswith('B'):
        start_B += 1


# 処理の順番も大事
# bothから考えると、bothは基本的にboth−1個のABをつくり,B*Aの文字列に化ける
# つぎにend_Aやstart_Bについて考える。これらによってmin(end_A,start_B)個できる。しかし、B*Aが存在する場合はこれを途中に挟まなければ最大値にならない。
# つまり以下のように処理すれば良い。
# both=0の場合→min(end_A,start_B)
# both>0の場合→ end_A=endB=0→both-1, end_A or endB=0→both, それ以外→both+min(end_A,start_B)
# ∵まずmin(end_A,start_B)個の組をつくりそのうちの一つをばらしてB*Aを挿入するのが最適、min()-1(ばらした分)+2(増える分)+both-1(B*Aの中の'AB'の数)だから


add = min(start_B, end_A)
if both > 0:
    if end_A == 0 and start_B == 0:
        add += both - 1
    else:
        add += both

# print(cnt, add)
print(cnt + add)


Measured memory_bytes: 44008
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N, A, B = li_input()

    print(min(N * A, B))


main()


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii; 

#define mp make_pair
#define F first
#define S second

const ll N = 2e5;
const ll M = 20;
const ll SQ = 320;
const ll INF = 1e16;
const ll MOD = 1e9+7;

ll n,l;
ll a[N];

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

	cin >> n >> l;
	for (int i = 0; i<n; i++)
		cin >> a[i];
	ll mx = 0 , id;
	for (int i = 0; i<n-1; i++)
		if (a[i]+a[i+1]>mx)
		{
			mx = a[i]+a[i+1];
			id = i;
		}
	if (mx<l)
	{
		cout << "Impossible\n";
	}
	else
	{
		cout << "Possible\n";
		for (int i = 0; i<id; i++)
			cout << i+1 << endl;
		for (int i = n-2; i>id; i--)
			cout << i+1 << endl;
		cout << id+1 << endl;
	}
	
	return 0;
}



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

long long gcd(long long a, long long b) {
  if(a < b) return  gcd(b, a);
  long long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    long long ans = b - b/c;
    if(c != d){
        ans -= b/d;
        long long lcm1 = c*d/gcd(c,d);
        ans += b/lcm1;
    }
    long long diff = a - a/c;
    if(c != d){
        diff -= a/d;
        long long lcm2 = c*d/gcd(c,d);
        diff += a/lcm2;
    }
    cout << ans-diff << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int c[n],s[n],f[n];
  for(int i = 0; i < n-1; i++){
    cin >> c[i] >> s[i] >> f[i];
  }
  int cost;
  for(int i = 0; i < n; i++){
    if(i != n-1) cost = s[i];
    else cost = 0;
    for(int j = i; j < n-1; j++){

      //始発の時間より前
      if(cost < s[j]) cost = s[j];

      //次の列車の時刻
      cost += ( f[j] - (cost % f[j]) ) % f[j];

      //移動のコストを加算
      cost += c[j];
    }
    cout << cost << endl;
  }
  return 0;
}


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

typedef long double ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,b,j;
	cin >> n >> m;
	k=n*m;
	long long int a=1LL*floor(n*m);
	cout << a << "\n";
	return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
template<typename T>
class fixed_point : T {
  public:
    explicit constexpr fixed_point (
        T&& t
      ) noexcept
      : T(forward<T>(t))
      {
      }
    template<typename... Args>
    constexpr decltype(auto)
    operator()(
        Args&&... args
      ) const
      {
        return T::operator()(*this, forward<Args>(args)...);
      }
};
template<typename T>
static inline constexpr decltype(auto) fix (T&& t) noexcept {
  return fixed_point<T>{forward<T>(t)};
}
template <typename T>
class ford_fulkerson {
  public:
    const T inf = numeric_limits<T>::max();
  private:
    struct edge {
      int to; T cap;
      weak_ptr<edge> rev;
      edge(int to, T cap) : to(to), cap(cap) {}
    };
    const int n, source, sink;
    vector<bool> ckd;
    vector<vector<shared_ptr<edge>>> grh;
    T dfs () {
      return fix ([&](auto dfs, int crr, int f) -> T {
        if (crr == sink) return f;
        ckd[crr] = true;
        for (auto& e : grh[crr]) {
          if (ckd[e->to] || !e->cap) continue;
          T d = dfs(e->to, min(f, e->cap));
          if (d) {
            e->cap -= d;
            e->rev.lock()->cap += d;
            return d;
          }
        }
        return 0;
      })(source, inf);
    }
  public:
    ford_fulkerson (int n, int source, int sink) :
      n(n), source(source), sink(sink), grh(n)
      {}
    void insert(int u, int v, T c) {
      auto e = make_shared<edge>(v, c);
      auto r = make_shared<edge>(u, 0);
      e->rev = r;
      r->rev = e;
      grh[u].push_back(e);
      grh[v].push_back(r);
    }
    T cal() {
      T ret = 0;
      while (true) {
        ckd.assign(n, false);
        T f = dfs();
        if (!f) return ret;
        ret += f;
      }
    }
};
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<vector<int>> grh(1 + h + w + 1);
  int source = 0, sink = 1 + h + w;
  ford_fulkerson<int> ffk(sink + 1, source, sink);
  int si, sj, ti, tj;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == 'o') {
        ffk.insert(1 + i,     1 + h + j, 1);
        ffk.insert(1 + h + j, 1 + i,     1);
      }
      if (c == 'S') {
        si = i, sj = j;
        ffk.insert(source, 1 + i,     ffk.inf);
        ffk.insert(source, 1 + h + j, ffk.inf);
      }
      if (c == 'T') {
        ti = i, tj = j;
        ffk.insert(1 + i,     sink, ffk.inf);
        ffk.insert(1 + h + j, sink, ffk.inf);
      }
    }
  }
  if (si == ti || sj == tj) {
    cout << -1 << endl;
    return 0;
  }
  auto ret = ffk.cal();
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 2944
#include <cstdio>
#define ll long long int

int main(void){
    ll A, B;
    ll K;
    scanf("%lld %lld %lld", &A, &B, &K);
    if(B-A >= 2*K){
        for(ll i = 0; i < K;i++){
            printf("%lld\n", A+i);
        }
        for(ll i = 0; i < K;i++){
            printf("%lld\n", B+i-K+1);
        }
    }else{
        for(ll i = A; i <= B; i++){
            printf("%lld\n", i);
        }

    }
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second

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


signed main(){
	
	ll n,ans = 0;
	
	cin >> n;
	
	ll a[n],b[n],c[n];
	
	rep(i,0,n)cin >> a[i];
	rep(i,0,n) cin >> b[i];
	
	rep(i,0,n){
		c[i] = a[i] - b[i];
		if(c[i] > 0) ans += c[i];
	}
	
	
	cout << ans << endl;
	
	
	return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <string>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

int A, B;

bool palid(int n) {
  string s = to_string(n);
  rep(i, (s.length() / 2) + 1) {
    if (s[i] != s[s.length() - 1 - i]) {
      return false;
    }
  }
  return true;
}

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

  int count = 0;
  FOR(i, A, B + 1) {
    if (palid(i)) count++;
  }
  printf("%d\n", count);
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    string a, b;
  cin >> a >> b;
  if(a.size() > b.size()) {
    cout << "GREATER" << endl;
    return 0;
  }
  if(a.size() < b.size()) {
    cout << "LESS" << endl;
    return 0;
  }
  if(a > b) {
    cout << "GREATER" << endl;
  } else if(a < b) {
    cout << "LESS" << endl;
  } else {
    cout << "EQUAL" << endl;
  }
    return 0;
}


Measured memory_bytes: 256
from scipy.sparse import*
i=lambda:map(int,input().split())
f=csgraph.floyd_warshall
I=9e9
n,m,l=i()
d=eval('[I]*-~n,'*-~n)
exec('a,b,c=i();d[a][b]=c;'*m)
d=f(f(d,0)<=l)
d[d>I]=I
q,=i()
while q:s,t=i();print(int(d[s,t]%I)-1);q-=1

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

using namespace std;

#define llong long long int
#define ldouble long double
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static llong MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

llong dp[210000][5];

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    bool flag = false;
    int index_left = -1, index_right = -1;
    rep(i, s.size() - 1) {
        if (s[i] == s[i + 1]) {
            index_left = i + 1;
            index_right = i + 2;
        }
    }

    rep(i, s.size() - 2) {
        if (s[i] == s[i + 2]) {
            index_left = i + 1;
            index_right = i + 3;
        }
    }

    cout << index_left << " " << index_right << endl;
    
    return 0;
}

Measured memory_bytes: 512
from collections import Counter
N = int(input())
l = []
pql = []
for i in range(N):
        x, y = map(int, input().split())
        l.append((x,y))
l.sort()
for i in range(N-1):
        for j in range(1, N-i):
                p = int(l[i+j][0] - l[i][0])
                q = int(l[i+j][1] - l[i][1])
                pql.append((p,q))
pq = Counter(pql)
cntl = pq.most_common(1)
if N == 1:
        print(1)
else:
        cnt = cntl[0][1]
        print(N - cnt)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define so(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pa pair
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<ll,ll>> vpl;
typedef vector<vector<pair<int,int>>> vvp;




int main()
{
    
    int N;
    cin >> N;
    vs s(N);
    in(N,s);
    
    int aaa = -1;
    
    rep(k,N){
        queue<pa<int,int>> B;
        B.push({k,1});
        vi ans(N,0);
        ans[k] = 1;
        int h = -1;
        
        while (!B.empty()) {
            
            pa<int,int> a = B.front();
            B.pop();
            rep(i,N){
                if(s[a.fi][i] == '0') continue;
                if(i == a.fi) continue;
                if(ans[i] == 0){
                    ans[i] = a.se+1;
                    h = max(h,a.se+1);
                    B.push({i,a.se+1});
                }else{
                    if(abs(ans[i]-a.se) != 1){
                        out(-1);
                        return 0;
                    }
                }
                
            }
            
        }
        aaa = max(aaa,h);
        
    }
    
    out(aaa);
    
    
    return 0;
}



Measured memory_bytes: 256
a, b = map(int, input().split())
def f(x):
    if x % 4 == 0:
        return x
    if x % 4 == 1:
        return x^(x-1)
    if x % 4 == 2:
        return 1^x
    return 0
print(f(a-1)^f(b))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
Int gcd(Int a, Int b) {
 return b != 0 ? gcd(b, a % b) : a;
}//gcd

Int lcm(Int a, Int b) {
 return a / gcd(a, b)*b;
}//lcm
int main(){

  Int a,b,c,d;cin >> a >> b >> c >> d;
  Int ga=a-(a/c+a/d-(a/lcm(c,d)));
  Int gb = b-(b/c+b/d-b/(lcm(c,d)));
  if(a%c) gb++;
  cout << gb - ga << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		char[] a = str.toCharArray();
		if (a[1] == 'R') {
			System.out.println("ABC");
		} else {
			System.out.println("ARC");
		}

	}

}


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

using namespace std;

void swap(int *a, int *b){
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

int partition(int A[], int p, int r){
    int x = A[r];
    int i = p-1;
    for(int j=0;j<r;++j){
        if(A[j] <= x){
            ++i;
            swap(&(A[i]),&(A[j]));
        }
    }
    swap(&(A[i+1]), &(A[r]));
    return i+1;
}

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

    int q = partition(A,0, n-1);
    
    for(int i=0;i<n;++i){
        if(i) cout << " ";
        if(i==q) cout << "[";
        cout << A[i];
        if(i==q) cout << "]";
    }
    cout << endl;

    return 0;

}


Measured memory_bytes: 3452
#include<stdio.h>
int main()
{
	int x, y;
	int t;

	for (;;) {
		scanf("%d%d", &x, &y);
		if (x == 0 && y == 0) break;
		if (x > y) t = x, x = y, y = t;
		printf("%d %d\n", x, y);
	}
	return 0;

}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back 
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

 int N=200005;

void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U;
    int x,y;
    cin>>x>>y;
    if(y>=2*x&&y<=4*x&&(y%2==0))
    {
        cout<<"Yes";
    }
    else cout<<"No";
}


signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

ll mpow(ll x, ll p) {
    if (p == 0) { return 1; }
    if (p == 1) { return x % MOD; }
    if (p % 2) { return (x * mpow(x, p - 1)) % MOD; }
    ll sub = mpow(x, p / 2);
    return (sub * sub) % MOD;
}

vi sieve(int n) {
    vi primes(n + 1);
    std::iota(primes.begin(), primes.end(), 0);

    for (int i = 2; i * i <= n; ++i) {
        if (primes[i] < i) { continue; }
        for (int j = i * i; j <= n; j += i)
            if (primes[j] == j) { primes[j] = i; }
    }
    return primes;
}

void factorize(map<int, int>& LCM, const vi& primes, ll x) {
    map<int, int> fac;
    while (x > 1) {
        ++fac[primes[x]];
        x /= primes[x];
    }
    for (auto v: fac) {
        LCM[v.first] = max(LCM[v.first], v.second);
    }
    // return fac;
}

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

    int n;
    cin >> n;

    vi a(n);
    int maxv = 0;
    rep(i, 0, n) {
        cin >> a[i];
        maxv = max(maxv, a[i]);
    }

    vi primes = sieve(maxv);

    map<int, int> LCM;
    rep(i, 0, n) { factorize(LCM, primes, a[i]); }

    ll L = 1;
    for (auto v : LCM) { L = (L * mpow(v.first, v.second)) % MOD; }

    ll sum = 0;
    rep(i, 0, n) { sum = (sum + (L * mpow(a[i], MOD - 2)) % MOD) % MOD; }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4736
s = input()
se = set("".join(s))
ans = 10**10
for m in se:
    t = s
    tans = 0
    for i in range(len(s)):
        if len(set("".join(t))) == 1 and m in t:
            break
        tt = ""
        for j in range(len(t)-1):
            if t[j] == m or t[j+1] == m:
                tt += m
            else:
                tt += t[j]
        tans += 1
        t = tt
    ans = min(ans , tans)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;cout<<n*n*n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
#define ld long double
int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    bool ans=false;
    rep(i,k){
        if(a>=b) b*=2;
        else if(b>=c) c*=2;
        
        if(a<b && b<c){
        ans = true;
        }
    }
    YN(ans);
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
    int a;
    int max;
    int min;
    int b_max;
    int b_min;
    int c;
    int dif;
    cin >> a;
    if (a < 2) {
        cout << "error" << endl;
        return 1;
    }
    //int b;
    //b = a - 1;
    //vector<int> v(a);
    cin >> c;
    max = -100000;
    min = c;
    dif = max - min;
    FOR(i, 1, a){
        cin >> c;
        if (max < c) {
            max = c;
            //cout << "max is " << max << endl;
        }
        if (min > c) {
            if (i != a - 1) {
                if (dif < max - min) {
                    dif = max - min;
                }
                min = c;
                max = 0;
                //cout << "min is " << min << endl;
                //cout << "max is " << max << endl;
            } 
        }
    }
    int ans;
    ans = max - min;
    if (ans > dif) {
        cout << ans << endl;        
    }
    else {
        cout << dif << endl;
    }
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio>

#define nl '\n'

using namespace std;

int m;

int main(){

    cin >> m;

    cout << (24-m)+24;


}
 
//g++ -std=c++14 comp.cpp -o c && c.exe
//g++ -std=c++14 comp.cpp -o c; ./c.exe
//g++ -std=c++14 comp.cpp && ./a.out


//Surely this is going to AC

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {

	nextReader = newScanner()

	x := nextInt()

	c1 := x / 500
	c2 := (x - c1*500) / 5

	fmt.Println(c1*1000 + c2*5)
}

/* --------------------------------------------------------------------------
 *  std.io
 * ------------------------------------------------------------------------- */
var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 640
# サンプル3
# 6
# 6 5 4 3 2 1
# b=3で2+0+2+4+6+8 = 22 b=4で1+1+3+5+7+9=26
# わからんからコード書いて試す
n = int(input())
a = list(map(int, input().split()))
# for b in range(-10, 10):
#     tmp = 0
#     for i, v in enumerate(a):
#         tmp += abs(v - (b + i + 1))
#     print(f"b={b}, tmp={tmp}")
# でかくても小さくてもダメっぽい
# 三分探索？やったことないしやり方わからんからググる
# めぐる式にこれhttps://qiita.com/ganariya/items/1553ff2bf8d6d7789127をしただけ

ok, ng = -10**9, 10**9 + 1


def calc(b):
    ret = 0
    for i, v in enumerate(a):
        ret += abs(v - (b + i + 1))
    return ret


# なぜかTLEなるのでカウンタを設置してみた
c = 0
while c < 100:
    c += 1
    c1 = (2 * ok + ng) // 3
    c2 = (ok + 2 * ng) // 3
    b1, b2 = calc(c1), calc(c2)
    if b1 > b2:
        ok = c1 + 1  # +1のきもちは不明
    else:
        ng = c2

print(calc(ok))


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

int main () {
 long long X;
  cin >> X;
  long long Y=100;
  long long Z;
  int t = 0;
  while (Y<X) {
   Z = Y/100;
    Y += Z;
    t++;
  }
  cout << t << endl;
}

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

#define ll          long long
#define pb          push_back
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a>=1 && a<=9 && b>=1 && b<=9){
        cout<<a*b;
    }
    else cout<<-1;
    
}

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

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr <<">>>>>>"<< #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif


int main()
{
	int x[2],y[2],xx,yy,n,a;
	x[0]=0;y[0]=0;
	cin>>x[1]>>y[1]>>n;
	while(n--)
	{cin>>xx>>yy>>a;
		if(a==1)x[0]=max(x[0],xx);
			else if(a==2)x[1]=min(x[1],xx);
			else if(a==3)y[0]=max(y[0],yy);
			else y[1]=min(y[1],yy);
		
		
		
		
	}
	cout<<max(0,y[1]-y[0])*max(0,x[1]-x[0])<<endl;
	
	
}



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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define INF 1e9

int n;
PII dist[(int)(1e5+10)];
VI board[(int)(1e5+10)];
void dfs(int x, bool snukeFlag){
  int next;
  rep(i,board[x].size()){
    next = board[x][i];
    if(snukeFlag == true &&
       dist[next].first > dist[x].first + 1 ){
         dist[next].first = dist[x].first + 1;
         dfs(next,snukeFlag);
    }

    if(snukeFlag == false &&
       dist[next].second > dist[x].second + 1 ){
         dist[next].second = dist[x].second + 1;
         dfs(next,snukeFlag);
    }
  }
}
int main(){
  cin >> n;
  int to ,from;
  rep(i,n-1){
    cin >> to >> from;
    to--; from--;
    board[to].push_back(from);
    board[from].push_back(to);
  }

  //!!!!!! seoncd = Snuke
  //!!!!!! first  = Fennec

  rep(i,n) dist[i] = make_pair(INF,INF);
  dist[0].second = 0;
  dist[n-1].first = 0;


  dfs(0,false);   //Fennecc
  dfs(n-1,true);  // Snuke
  int fennec = 0;
  rep(i,n){
    if(dist[i].first >= dist[i].second ){
      fennec++;
    }
  }
  if(fennec > n - fennec) cout << "Fennec" << endl;
  else                     cout << "Snuke"  << endl;
  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll inf = 1e18;
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s , t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int ans = INT_MAX;
    int val = 0;
    for(int i = 0 ; i <= n - m ; i++){
        for(int j = 0 ; j < m ; j++){
            if(s[i+j] != t[j])
                ++val;
        }
        ans = min(ans , val);
        val = 0;
    }
    cout<<ans;
}


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

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

    int s = 0;
    int count = 0;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == 'S') s++;
        else {
            if (s) s--;
            else count++;
        }
    }

    cout << count+s << endl;

    return 0;
}


Measured memory_bytes: 640
"""
author : halo2halo
date : 31, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

O, E = read().decode('utf8').split()

ans = ''
for i, j in zip(O, E):
    ans += i + j

if len(O) > len(E):
    ans += O[-1]

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int scc(const VV<>& g, V<>& comp) {
  int n = g.size();
  VV<> rg(n);
  for (int v = 0; v < n; v++) {
    for (int w : g[v]) {
      rg[w].push_back(v);
    }
  }
  V<> vs;
  V<bool> vis(n);
  comp.resize(n);

  auto dfs = [&](const auto& dfs, int v) -> void {
    vis[v] = true;
    for (int w : g[v]) if (!vis[w]) {
      dfs(dfs, w);
    }
    vs.push_back(v);
  };

  auto rdfs = [&](const auto& rdfs, int v, int k) -> void {
    vis[v] = true;
    comp[v] = k;
    for (int w: rg[v]) if (!vis[w]) {
      rdfs(rdfs, w, k);
    }
  };

  for (int v = 0; v < n; v++) if (!vis[v]) {
    dfs(dfs, v);
  }
  vis.assign(n, false);
  int k = 0;
  reverse(vs.begin(), vs.end());
  for (int v : vs) if (!vis[v]) {
    rdfs(rdfs, v, k++);
  }
  return k;
}

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  VV<> g(n);
  for (int i = 0; i < n; ++i) {
    int p; cin >> p, --p;
    g[p].push_back(i);
  }
  V<> comp;
  int k = scc(g, comp);
  if (k == n) return cout << "POSSIBLE" << '\n', 0;
  VV<> h(n);
  bool first = true;
  int u0, v0;
  map<int, int> mp;
  for (int v = 0; v < n; ++v) {
    for (int w : g[v]) {
      if (comp[v] == comp[w]) {
        mp[w] = v;
        if (first) {
          u0 = v, v0 = w;
          first = false;
          continue;
        }
      }
      h[v].push_back(w);
    }
  }
  scc(h, comp);
  V<> vs(n);
  iota(begin(vs), end(vs), 0);
  sort(begin(vs), end(vs), [&](int u, int v) { return comp[u] > comp[v]; });
  V<> a(n);
  for (int v : vs) {
    set<int> se;
    for (int w : h[v]) {
      se.insert(a[w]);
    }
    int i = 0;
    while (se.count(i)) ++i;
    a[v] = i;
  }
  if (a[u0] != a[v0]) return cout << "POSSIBLE" << '\n', 0;
  while (u0 != v0) {
    set<int> se;
    for (int w : g[u0]) {
      se.insert(a[w]);
    }
    int i = 0;
    while (se.count(i)) ++i;
    a[u0] = i;
    u0 = mp[u0];
  }
  for (int w : g[v0]) {
    if (a[w] == a[v0]) return cout << "IMPOSSIBLE" << '\n', 0;
  }
  cout << "POSSIBLE" << '\n';
}

Measured memory_bytes: 45188
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

void run (void) {
  const i32 mod = 1000000007;
  i64 ans = 0;
  i64 way = 1;
  for (i32 c = getchar(); c == '0' || c == '1'; c = getchar()) {
    if (c == '1') {
      ans = (3 * ans + way) % mod;
      way = 2 * way % mod;
    } else {
      ans = 3 * ans % mod;
    }
  }
  ans = (ans + way) % mod;
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 128
s=gets.chomp.bytes.map{|b|b-97}
n=gets.to_i
(s.size-1).times{|i|
	m=(26-s[i])%26
	n>=m&&n-=m-s[i]=0
}
s[-1]=(s[-1]+n)%26
puts s.map{|e|(e+97).chr}*''

Measured memory_bytes: 7668
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll mod =1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> T maxt(T x,T y) {if (x>y) return x;else return y;}
template<class T> T mint(T x,T y) {if (x>y) return y;else return x;}
//sort(v.begin(), v.end(), [](auto& x, auto& y){return x[1] < y[1];});


//小数出力
double print_double(double d){printf("%.7f", d);}

//約数列挙
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}



// ll combination_mod(int n, int k) {
//   k = mint(k,n-k);
//   ll ans = 1;
//   if (n==0 || k ==0) return ans;
//   rep(i,k) {
//     ans = ans*(n-i)%mod;
//     ans = ans*modinv(i+1)%mod;
//   }
//   return ans;
// }

struct edge {
  int from; //出発点
  int to;   //到達点
  ll cost; //移動コスト
};

//ベルマンフォード法
vector<ll> bellman_ford (vector<edge> edges, int V, int E, int r, ll INF = 100000000000) {  
  vector<ll> cost_to(V,INF);
  cost_to[r] = 0;
  rep(i,V) {
    rep(j,E) {
      edge e = edges[j];
      if (cost_to[e.from]==INF) continue;
      if (cost_to[e.to] > cost_to[e.from] + e.cost) {
        cost_to[e.to] = cost_to[e.from] + e.cost;
        if (i==V-1) {
          printf("NEGATIVE CYCLE\n");
          return {};
        }
      }

    }
  }
  return cost_to;
}

// combination
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


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


// 木上の探索
vector<int> cnt;
void dfs(const vector<vector<int>> &G, int v, int p) {
    for (auto nv : G[v]) {
        if (nv == p) continue; // nv が親 p だったらダメ
        dfs(G, nv, v);
    }

    // 帰りがけ時に、部分木サイズを求める
    cnt[v] = 1; // 自分自身
    for (auto c : G[v]) {
        if (c == p) continue;
        cnt[v] += cnt[c]; // 子のサイズを加える
    }
}

int sdig(int d){
  int ans = 0;
  rep(i,7) if (d>>i&1) ans++;
  return ans;
}

int main() {
  ll N,K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  if (K>*max_element(A.begin(),A.end())) {
    cout << "IMPOSSIBLE\n";
    return 0;
  }
  ll tmp = A[0];
  rep2(i,1,N){
    tmp = __gcd(tmp,A[i]);
  }
  rep(i,N) {
    if ((A[i]-K)%tmp==0) {
      cout << "POSSIBLE\n";
      return 0;
    }
  }
  cout << "IMPOSSIBLE\n";
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <stack>


using namespace std;

void print(vector<int> &b);




void print(vector<int> &b) {
    for (auto i : b) {
        cout << i << " ";
    }
    cout << endl;
}


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

    int n;
    cin >> n;
    long long a = 2;
    long long b = 1;
    for (int i = 2; i <= n; ++i) {
        long long c = a + b;
        a = b;
        b = c;
    }
    cout << b;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

main(){
  int x;
  while(1){
    cin >> x;
    if(x==0) break;

    x=1000-x;
    int ans=0;
    if(x>=500){
      ans++;
      x-=500;
    }
    while(x>=100){
      ans++;
      x-=100;
    }
    if(x>=50){
      ans++;
      x-=50;
    }
    while(x>=10){
      ans++;
      x-=10;
    }
    if(x>=5){
      ans++;
      x-=5;
    }
    ans+=x;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
        cin >> a[i];
    
    vector<pair<ll, int>> b(n);
    rep(i, n)
        b[i] = make_pair(a[i], i);
    sort(b.begin(), b.end(), greater<P>());
    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));
    
    repi(i, 1, n+1) rep(j, i+1) {
        int x = j, y = i-j, m = x+y-1;
        if (x == 0) {
            int d = n - b[m].second - y;
            dp[x][y] = (d < 0 ? -INF : dp[x][y-1] + b[m].first * d);
            //cout << x << " " << y << " | > " << d << " | " << dp[x][y] << endl;
            continue;
        }
        if (y == 0) {
            int d = b[m].second - x + 1;
            dp[x][y] = (d < 0 ? -INF : dp[x-1][y] + b[m].first * d);
            //cout << x << " " << y << " | < " << d << " | " << dp[x][y] << endl;
            continue;
        }
        int dl = b[m].second - x + 1, dr = n - b[m].second - y;
        dp[x][y] = max(dp[x][y-1] + b[m].first * dr, dp[x-1][y] + b[m].first * dl);
        //cout << x << " " << y << " | " << dl << " " << dr << " | " << dp[x][y] << endl;
    }
    
    ll ans = 0;
    rep(i, n)
        chmax(ans, dp[i][n-i]);
    cout << ans << endl;
    return 0;
}


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


int main(){

    
    long long n, i;

    long long sa = 0;

    long long sb = 0;

    long long s = 0;

    long long ans = 0;

    long long ch = 0;

    vector<long long> t;


    cin >> n;


    vector<long long> a(n + 1);

    vector<long long> b(n + 1);


    for( i = 1 ; i <= n ; i = i + 1 ){

         cin >> a.at(i);

         sa += a.at(i);

         }


    for( i = 1 ; i <= n ; i = i + 1 ){

         cin >> b.at(i);

         sb += b.at(i);

         }


    if( sa < sb ){

        cout << -1 << endl;

        return 0;

        }


    for( i = 1 ; i <= n ; i = i + 1 ){

         if( a.at(i) > b.at(i) ) t.push_back( a.at(i) - b.at(i) );

         else if( a.at(i) < b.at(i) ){

                  s += ( b.at(i) - a.at(i) );

                  ans += 1;

                  }

         else ch += 1;

         }


    if( ch == n || s == 0 ){

        cout << 0 << endl;

        return 0;

        }


    sort( t.rbegin(), t.rend() );


    for( i = 0 ; i < t.size() ; i = i + 1 ){

         s -= t.at(i);

         ans += 1;

         if( s <= 0 ){

             cout << ans << endl;

             return 0;

             }

         }


    cout << -1 << endl;


    return 0;

    }


Measured memory_bytes: 2428
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		long ans = ((N - M) * 100 + M * 1900) * (long) Math.pow(2, M);
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 23508
#include<iostream>
#include<cstring>
#include<vector>
#define N 1000
#define MOD 1000000007
using namespace std;
typedef long long LL;
bool is_prime[N+1];
LL legendre(int n, int p)
{
	int ans = 0;
	int b = p;
	while(n >= b)
	{
		ans += n/b;
		b *= p;
	}
	return ans;
}
int main()
{
	int n; cin >> n;
	LL ans = 1;

	memset(is_prime,true,sizeof is_prime);
	is_prime[0] = is_prime[1] = false;
	for(int p = 2; p <= N; p++)
		if(is_prime[p])
		{
			for(int k = p*p; k <= N; k+=p)
				is_prime[k] = false;
			ans *= legendre(n,p)+1LL, ans %= MOD;
		}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	ll res = inf;
	for (ll i = 1; i <= n / 2; i++)
	{
		ll j = n - i;

		ll s = 0;
		for (ll p = i; p > 0; p /= 10)
		{
			s += p % 10;
		}

		for (ll p = j; p > 0; p /= 10)
		{
			s += p % 10;
		}

		res = min(res, s);
	}
	println(res);
}


Measured memory_bytes: 256