akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
const int N = 100007;
int n , k ,x , b , c;
map<ll , ll> m;
vector<pll> opr;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    cin >> n >> k;
    for(int i = 1;i <= n ; i++){
        cin >> x;
        m[x]++;
    }
    for(int i = 0 ; i < k ; i++){
        cin >> b >> c;
        m[c] += b;
    }
    for(auto it : m){
        opr.pb(it);
    }
    reverse(all(opr));
    ll taken = 0;
    ll sum = 0;
    for(auto it : opr){
        if(it.S + taken >= n){
            sum += it.F*(n-taken);
            break;
        }
        else
        {
            sum += it.F*it.S;
            taken += it.S;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 18928
#include<bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> point;
namespace std{
    bool operator < (const point& a, const point& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}
double cross(const point& a, const point& b) {
    return imag(conj(a)*b);
}
double dot(const point& a, const point& b) {
    return real(conj(a)*b);
}

int main()
{
    double xp1, yp1, xp2, yp2;
    scanf("%lf %lf %lf %lf", &xp1, &yp1, &xp2, &yp2);
    point p1(xp1,yp1), p2(xp2,yp2);
    int q;
    scanf("%d", &q);
    vector<point> List;
    for(int i = 0; i < q; ++i) {
        double qx, qy;
        scanf("%lf %lf", &qx, &qy);
        List.push_back(point(qx, qy));
    }

    for(int i = 0; i < q; ++i) {
        point tmp = dot(p2 - p1, List[i] - p1)/dot(p2-p1, p2-p1)*(p2-p1)+p1;
        printf("%.12lf %.12lf\n", tmp.real(), tmp.imag());
    }
    return 0;
}


Measured memory_bytes: 3280
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define T ll t = 1; cin>>t; while(t--)
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define F first
#define S second
#define I insert
#define pb push_back
#define ppb pop_back
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())

const ll maxs = 3e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
inline ll add(ll a, ll b) {
    return (mod + a + b) % mod;
}
inline ll sub(ll a, ll b) {
    return (a - b + mod) % mod;
}
inline ll mul(ll a, ll b) {
    return (1ll * a * b) % mod;
}

//POWER
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) {
        if(y & 1)
            res = (res * x) % mod; 
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

//MODULAR INVERSE
ll inv(ll x) {
    return fastpow(x, mod - 2);
}

//     ll n;
//     ll a[maxs];
//     ll tree[maxs];
bool vis[maxs];
vector < ll > graph[maxs];
//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
//ALWAYS RETURN WHEN ST == ED CONDITION IN SEGMENT TREES

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,k;
    ll cnt = 0;
    cin >> a >> b >> c >> k;
    if(k >= a)
        cnt += a;
    else
    {
        cout << k;
        return 0;
    }
    k -= a;
    if(k >= b)
    {
        
    }
    else{
        cout << cnt;
        return 0;
    }
    k -= b;
    if(k)
    cnt += -1 * k;
    cout << cnt;
        
}



Measured memory_bytes: 10668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int (i) = (a); (i) < (b); ++(i))
#define per(i, a, b) for (int (i) = (a); (i) >= (b); --(i))
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define ff first
#define ss second
#define sz(x) ((int) x.size())
#define rd(type, ...) type __VA_ARGS__; sc(__VA_ARGS__)
#define rda(a, n) rep(i, 0, n) cin >> a[i];
#define rdaa(a, n, m) rep(i, 0, n) rep(j, 0, m) cin >> a[i][j];
#define rdv(type, v, n) vector<type> v(n); rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) vector<vector<type>> v(h, vector<type>(w)); rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
#define rdv2(type, n, ...)std::vector<type> __VA_ARGS__;MACRO_rdv2_Init(n, __VA_ARGS__); for(int w_=0; w_<n; ++w_){MACRO_rdv2_Scan(w_, __VA_ARGS__);}
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "] : ", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
void solve();
signed main() {ios::sync_with_stdio(false); cin.tie(0);
  cout << fixed; cout.precision(20); solve(); return 0;}
template<typename T> void chmin(T &a, T b) {if (a > b) a = b;}
template<typename T> void chmax(T &a, T b) {if (a < b) a = b;}
template<typename T> void MACRO_rdv2_Init(int n, T& t) { t.resize(n); }
template<typename First, typename... Rest> void MACRO_rdv2_Init(int n, First& first, Rest& ...rest) { first.resize(n); MACRO_rdv2_Init(n, rest...); }
template<typename T> void MACRO_rdv2_Scan(int p, T& t) { std::cin >> t[p]; }
template<typename First, typename... Rest> void MACRO_rdv2_Scan(int p, First& first, Rest& ...rest) { std::cin >> first[p]; MACRO_rdv2_Scan(p, rest...); }
template<typename T> void wrv(const vector<T> &v) {rep(__ii, 0, sz(v)) {if (__ii) cout << ' '; cout << v[__ii];} cout << '\n';} 
template<typename T> void wrm(const vector<vector<T>> &v) {rep(__ii, 0, sz(v)) {rep(__jj, 0, v[__ii].size()) {if (__jj) cout << ' '; cout << v[__ii][__jj];} cout << '\n';}}
template<typename T> void sc(T& x) {cin >> x;}
template<typename Head, typename... Tail> void sc(Head& head, Tail&... tail) {cin >> head; sc(tail...);}
template<typename T> void wr(const T& x) {cout << x << '\n';}
template<typename Head, typename... Tail> void wr(const Head& head, const Tail&... tail) {cout << head << ' '; wr(tail...);}
template<typename T> void wrf(const T& x) {cout << x << endl;}
template<typename Head, typename... Tail> void wrf(const Head& head, const Tail&... tail) {cout << head << ' '; wrf(tail...);}
template<typename T> void debug_out(const T& x) {cerr << x << '\n';}
template<typename Head, typename... Tail> void debug_out(const Head& head, const Tail&... tail) {cerr << head << ' '; debug_out(tail...);}
template<typename... T> void err(const T&... cod) {wr(cod...); exit(0);}

void solve() {
  #define int ll
  rd(int, n, k);
  rdv(int, a, n);
  sort(all(a));
  while (sz(a) && k > 0) {
    a.pop_back();
    --k;
  }
  int ans = 0;
  rep(i, 0, sz(a)) ans += a[i];
  wr(ans);
}

Measured memory_bytes: 1792
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    if (listOf(a, b, c).sorted().equals(listOf(5, 5, 7))) println("YES")
    else println("NO")
}

Measured memory_bytes: 34252
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
using namespace std;
int main(void){

	int n, v, j;
	int a[100];
	cin >> n;
	for( int i = 0; i < n; i++ ){
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if( i < n - 1 ){
			cout << " ";
		}
	}
	cout << endl;
	for( int i = 1; i < n; i++ ){
		v = a[i];
		j = i - 1;
		while( j >= 0 && a[j] > v ){
			a[j + 1] = a[j];
			j--;
		}
		a[j+1] = v;
		for (int i = 0; i < n; i++) {
			cout << a[i];
			if( i < n - 1 ){
				cout << " ";
			}
		}
	cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int a,b;
    cin>>a>>b;
    if (a>=13)
        cout<<b;
    else if (a>=6&&a<=12)
        cout<<b/2;
    else
        cout<<0;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
def ac():
    for h in range(1,3501):
        for w in range(1,3501):
            try:
                num=(n*h*w)/(4*h*w-n*w-n*h)
                if (num).is_integer() and num>0:
                    print("{} {} {}".format(h,w,int(num)))
                    return
            except:
                pass
ac()

Measured memory_bytes: 39024
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
#include <utility>
#include <iomanip>

const double rad60 = 60 * M_PI / 180;

void koch_curve(std::pair<double, double> p1, std::pair<double, double> p2, int n) {
    if (n == 0) return;
    
    std::pair<double, double> s, t, u;
    
    s.first = (2.0 * p1.first + 1.0 * p2.first) / 3.0;
    s.second = (2.0 * p1.second + 1.0 * p2.second) / 3.0;
    t.first = (1.0 * p1.first + 2.0 * p2.first) / 3.0;
    t.second = (1.0 * p1.second + 2.0 * p2.second) / 3.0;
    u.first = (t.first - s.first) * std::cos(rad60) - (t.second - s.second) * std::sin(rad60) + s.first;
    u.second = (t.first - s.first) * std::sin(rad60) + (t.second - s.second) * std::cos(rad60) + s.second;
    
    koch_curve(p1, s, n-1);
    std::cout << s.first << " " << s.second << std::endl;
    koch_curve(s, u, n-1);
    std::cout << u.first << " " << u.second << std::endl;
    koch_curve(u, t, n-1);
    std::cout << t.first << " " << t.second << std::endl;
    koch_curve(t, p2, n-1);
}

int main() {
    std::pair<double, double> p1, p2;
    // starting point
    p1.first = 0.0f; p1.second = 0.0f;
    // ending point
    p2.first = 100.0f; p2.second = 0.0f;
    
    std::cout << std::fixed << std::setprecision(8);
    
    int n;
    std::cin >> n;
    
    std::cout << p1.first << " " << p1.second << std::endl;
    koch_curve(p1, p2, n);
    std::cout << p2.first << " " << p2.second << std::endl;
}


Measured memory_bytes: 3288
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  int x;
	      	  cin >> x;

	      	  cout << (2*x)/60 << ' ' << (2*x)%60 << endl;


	          return 0;
}

Measured memory_bytes: 3184
#%%
n = int(input())
a, b, c = [0] * n, [0] * n, [0] * n
for i in range(n-1):
    a[i], b[i], c[i] = map(int, input().split())

q, k = map(int, input().split())

l = [[] for _ in range(n+1)]
for i in range(n-1):
    l[a[i]].append([b[i],c[i]])
    l[b[i]].append([a[i],c[i]])

d = [0] * (n+1)
check = [0] * (n+1)
check[k] = 1
que = [k]
count = 1

while len(que) > 0:
    tmp = que.pop(0)
    for i in l[tmp]:
        if check[i[0]] == 0:
            que.append(i[0])
            check[i[0]] = 1
            d[i[0]] = d[tmp] + i[1]
            count += 1
        else:
            pass
    if count >= n:
        break

x, y = [0] * q, [0] * q
for i in range(q):
    x[i], y[i] = map(int, input().split())
    print(d[x[i]] + d[y[i]])

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

int main(){
    long long n, m;
    cin >> n >> m;
    long long l[m], r[m];
    for(long long i = 0; i < m; i++){
        cin >> l[i] >> r[i];
    }
    long long mi =  0, ma = 100001;
    for(long long i = 0; i < m; i++){
        mi = max(mi, l[i]);
        ma = min(ma, r[i]);
    }
    int ans = 0;
    for(long long i = 1; i <= n; i++){
        bool chk = false;
        if(i < mi || i > ma) chk = true;
        if(chk == false) ans++;
    }
    // cout << mi <<  " " << ma << endl;
    cout << ans << endl;
    return 0;
}

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

long long int ans = 0;
char s[100010];
long long int le;
char gp[2] = {'g', 'p'};

main(){
    scanf("%s", s);
    le = strlen(s);
    for(int i = 0; i < le; i++){
        if(s[i] == gp[i % 2]) continue;
        else if(i % 2) ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<stack>
#include<list>
#define MAX 10000
#define NIL -1


typedef long long ll;

using namespace std;

struct node{
	int p;
	int l;
	int r;
};

node T[MAX+10];

void preTr(int u){
	if(u == NIL)
		return;
	printf(" %d",u);
	preTr(T[u].l);
	preTr(T[u].r);
}

void inTr(int u){
	if(u == NIL)
		return;
	inTr(T[u].l);
	printf(" %d",u);
	inTr(T[u].r);
}

void postTr(int u){
	if(u == NIL)
		return;
	postTr(T[u].l);
	postTr(T[u].r);
	printf(" %d",u);
}

int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i = 0 ; i<n ; i++){
		T[i].p = NIL;
	}
	
	for(int i = 0 ; i<n ; i++){
		int v,l,r;
		cin>>v>>l>>r;
		T[v].l = l;
		T[v].r = r;
		if(l!=NIL)
			T[l].p = v;
		if(r!=NIL)
			T[r].p = r; 
	}
	int root;
	for(int i = 0 ; i<n ; i++){
		if(T[i].p == NIL){
			root = i;
			break;
		}
	}
	
	printf("Preorder\n");
	preTr(root);
	printf("\n");
	
	printf("Inorder\n");
	inTr(root);
	printf("\n");
	
	printf("Postorder\n");
	postTr(root);
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 3152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int dish[] = new int[5];

		for(int i = 0; i < 5; i++) {
			dish[i] = scan.nextInt();
		}

		int sum = 0;
		int max = 0;

		for(int i = 0; i < 5; i++) {
			int d = (dish[i] + 9) / 10 * 10;
			sum += d;
			max = Math.max(max, d - dish[i]);
		}
		System.out.println(sum - max);
	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double eps = 1e-10;
  
int main() {
  int x,a,b;
  cin >> x >> a >> b;
  int A=abs(a-x),B=abs(b-x);
  if(A < B) {
    cout << "A" << endl;
  } else if(A > B) {
    cout << "B" << endl;
  }
  return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;

string str;
vector<string> ans;

void solve(string s){
  int m=s.length();
  if(m==str.length()){
    ans.push_back(s);
    return;
  }
  char c=str[m];
  bool e=0;
  for(int i=0; i<m; i++){
    if(s[i]==c){
      e=1;
      break;
    }
  }
  if(e==1 || c=='a'){
    s+=c;
    solve(s);
    s.erase(s.end()-1);
  }
  if(c=='z') return;
  c++;
  e=0;
  for(int i=0; i<m; i++){
    if(s[i]==c){
      e=1;
      break;
    }
  }
  if(e==0){
    s+=c;
    solve(s);
    s.erase(s.end()-1);
  }
  return;
}

int main()
{
	while(1){
      str.clear();
      cin>>str;
      if(str=="#") return 0;
      string s;
      ans.clear();
      solve(s);
      printf("%d\n", ans.size());
      if(ans.size()<=10){
        for(int i=0; i<ans.size(); i++){
          cout<<ans[i]<<endl;
        }
      }else{
        for(int i=0; i<5; i++){
          cout<<ans[i]<<endl;
        }
        for(int i=ans.size()-5; i<ans.size(); i++){
          cout<<ans[i]<<endl;
        }
      }
    }
	return 0;
}



Measured memory_bytes: 4544
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
double tank;
int start[90000];
int end[90000];
double use[90000];

double calc(double speed, double ini) {
  if (ini < 0.0) { return -1.0; }
  int time = 0;
  double water = ini;
  REP(i, n) {
    water += (start[i] - time) * speed;
    water = min(water, tank);
    water += (end[i] - start[i]) * (speed - use[i]);
    water = min(water, tank);
    if (water < 0.0) { return -1.0; }
    time = end[i];
  }
  return water;
}

int main() {
  while (scanf("%d %lf", &n, &tank), n) {
    REP(i, n) { scanf("%d %d %lf", &start[i], &end[i], &use[i]); }
    start[n] = 86400;
    end[n] = 86400;
    use[n] = 0;
    n++;
    double l = 0;
    double r = 1e+6;
    REP(iter, 200) {
      double m = (l + r) / 2.0;
      double first = calc(m, tank);
      double second = calc(m, first);
      if (second > 0 && first - second < EPS) {
        r = m;
      } else {
        l = m;
      }
    }
    printf("%.6lf\n", l);
  }
}

Measured memory_bytes: 2288
#include<iostream>
using namespace std;
int gcd(int a,int b,int c)
{
	while(a!=b)
	{
		if(a>b)
			a=a-b;
		else 
			b=b-a;
	}
	while(a!=c)
	{
		if(a>c)
			a=a-c;
		else 
			c=c-a;

	}
	return c;
}
int main()
{
	long long n,i,j,k;
	cin>>n;
	long long sum=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				sum=sum+gcd(i,j,k);

			}
		}
	}
	cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <map>
#include <vector>

using namespace std;

bool is_contradiction(int N, map<int, vector<map<string, int>>>& T,vector<int>& honest_flag) {
    for (int i = 1; i <= N; i++) {
        if (honest_flag.at(i) == false) continue;

        for (auto a : T[i]) {
            if (a["y"] != honest_flag.at(a["x"])) {
                return false;
            }
        }
    }

    return true;
}

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

    map<int, vector<map<string, int>>> T;
    for (int i = 1; i <= N; i++) {
        int A;
        cin >> A;

        vector<map<string, int>> a;
        for (int j = 1; j <= A; j++) {
            map<string, int> t;
            cin >> t["x"];
            cin >> t["y"];
            a.push_back(t);
        }
        T[i] = a;
    }

/*
    // test for input
    for (int i = 1; i <= N; i++) {
        cout << i << " : ";
        for (auto a : T[i]) {
            cout << a["x"] << " " << a["y"];
        }
        cout << endl;
    }
*/

    // 総当たりで矛盾がないか調べる
    int ans = 0;
    vector<int> honest_flag(N + 1);
    for (int bits = 1; bits < (1 << N); bits++) {
        int num_honest = 0;
        for (int i = 0; i < N; i++) {
            if (bits >> i & 1) {
                honest_flag.at(i + 1) = 1;
                num_honest++;
            } else {
                honest_flag.at(i + 1) = 0;
            }
        }

        // **** debug ****
        /*
        for (int i = 1; i <= N; i++) {
            cout << honest_flag.at(i) << ' ';
        }
        cout << endl;
        */

        if (num_honest <= ans) continue;

        if (is_contradiction(N, T, honest_flag)) {
            ans = num_honest;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,l,r) for(ll i=(l); i<(r); i++)
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 ll INF = 1LL << 60;
const int inf = 1001001001;
const ll mod = 1000000007;
using pp=pair<ll,ll>;
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
   }
   void init(ll sz_) {
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x) { // 根の検索
      while (par[x] != x) {
           x = par[x] = par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y) {
       x = root(x);
       y = root(y);
       if (x == y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x] < siz[y]) swap(x, y);
       siz[x] += siz[y];
       par[y] = x;
       return true;
  }
 
  bool same(ll x, ll y) { // 連結判定
       return root(x) == root(y);
  }
 
  ll size(ll x) { // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll n) {
   x = x%mod;
   if(n==0) return 1;  //再帰の終了条件
 
   else if(n%2==1) {
       return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
   }
   else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
 
ll com(ll n, ll k) {
   ll x = 1;
   for(int i=n-k+1; i<=n; i++) {
      x = x*i%mod;
   }
 
   ll y = 1;
   for(int i=1; i<=k; i++) {
       y = y*i%mod;
   }
   y = modpow(y, mod-2);
 
   return x*y%mod;
}
 
bool is_prime(const unsigned n){
   switch(n){
       case 0: // fall-through
       case 1: return false;
       case 2: // fall-through
       case 3: return true;
  } // n > 3 が保証された
 
   if(n % 2 == 0 || n % 3 == 0) return false;
   // n は 2 と 3 のいずれの倍数でもないことが保証された
   // これより n は (6の倍数)-1 か (6の倍数)+1 である
 
   // 6の倍数前後の数を使って試し割りをする
   for(unsigned i = 5; i * i <= n; i += 6) {
       if(n % i     == 0) return false; // (6の倍数)-1
       if(n % (i+2) == 0) return false; // (6の倍数)+1
   }
 
   return true;
}
 
int digsum(int n) {
   int res = 0;
   while(n > 0) {
       res += n%10; //ここをres++;に変えたら桁数を求める関数になる
       n /= 10;
   }
   return res;
}
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(ret.begin(),ret.end());
   return ret;
}
 
int main(){

    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if(a<=b){
    if(a+v*t>=b+w*t) cout << "YES" << endl;
    else cout << "NO" << endl;
    }
    else{
        if(a-v*t<=b-w*t) cout << "YES" << endl;
    else cout << "NO" << endl;
    }
 
}

Measured memory_bytes: 3628
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline
INF = float("inf")


@nb.njit("i8(i8,i8,i8[:])")
def solve(N, K, h):
    dp = np.zeros(N, dtype=np.int64)
    for i in range(1, N):
        min_cost = INF
        for k in range(1, min(K + 1, i + 1)):
            cost = dp[i - k] + abs(h[i] - h[i - k])
            if cost < min_cost:
                min_cost = cost
        dp[i] = min_cost
    return dp[-1]


def main():
    N, K = map(int, input().split())
    h = np.array(input().split(), dtype=np.int64)

    ans = solve(N, K, h)
    print(ans)


if __name__ == "__main__":
    main()


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

using ll = long long;
using ull = unsigned long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define bzero(p, n) memset(p, 0, n)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

template <typename T> T gcd(T a, T b) {
	T r; while ((r = a % b) != 0) a = b, b = r;
	return b;
}
template <typename T> T lcm(T a, T b) {
	return a/gcd(a, b) * b;
}

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

    ll N; cin >> N;
    vector<ll> T(N); cin >> T;

    ll ans = T[0];
    rep1(i, N) {
        ans = lcm(T[i], ans);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main {
  def main(args:Array[String]) = {
    var cnt = 0
    var n = 0
    while( { n = 1000-readInt; n} != 1000) {
      cnt = 0
      while(n>=500) { n -=500; cnt += 1 }
      while(n>=100) { n -=100; cnt += 1 }
      while(n>=50) { n -=50; cnt += 1 }
      while(n>=10) { n -=10; cnt += 1 }
      while(n>=5) { n -=5; cnt += 1 }
      while(n>=1) { n -=1; cnt += 1 }
      println(cnt)
    }
  }
}

Measured memory_bytes: 43624
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    bool flag = false;
    rep(i,n-1) {
        if(s[i] != s[i+1] && (i == 0 || (flag == false))) {
            ans++;
            flag = true;
        } else flag = false;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3304
#include "bits/stdc++.h"
using namespace std;
// #define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=0;



void solve(){
	int a,b;
	cin>>a>>b;
	if(b > a) swap(a,b);
	
	long long prod = 1LL * a * b - 1;
	
	int ans = 2*b - 2;
	
	int L = b, U = a - 1;
	
	if(U - L < 1){
		while(L < U){
			int his = prod / L;
			if(his > U) his = U;
			if(his > b){
				U = his - 1;
				ans++;
			}
			else{
				cout<<ans<<"\n";
				return;
			}
			L++;
		}
		
		int U2 = a - 1;
		
		rep(x,b+1,U+1){
			int his = prod / x;
			if(his > U2) his = U2;
			if(his < L){
				cout<<ans<<"\n";
				return;
			}
			U2 = his - 1;
			ans++;
		}
		cout<<ans<<"\n";
	}
	else{
		int x;
		while(L <= U){
			int m = (L+U)/2;
			if(1LL*m*m >= prod + 1){
				x = m;
				U = m - 1;
			}
			else{
				L = m + 1;
			}
		}
		
		ans += x - b;
		
		int k = prod / x;
		
		ans += k - b;
		
		cout<<ans<<"\n";
	}
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 3656
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
const int maxn=1000010;
vector<int>G[maxn];
int u,v,n,have[maxn],s[maxn],cnt=1;
inline void dfs(int u,int f) {
	for(unsigned i=0;i<G[u].size();i++) {
		int v=G[u][i];
		if(v==f)
			continue;
		if(s[v]<s[u]) {
			if(have[v]==-1)
				dfs(v,u);
			if(have[v]==0) {
				have[u]=1;
				return;
			}
		}
	}
	have[u]=0;
}
int main() {
	read(n);
	for(int i=1;i<=n;i++)
		read(s[i]);
	for(int i=1;i<n;i++) {
		read(u);
		read(v);
		G[u].push_back(v);
		G[v].push_back(u); 
	}
	memset(have,-1,sizeof have);
	for(int i=1;i<=n;i++) {
		if(have[i]==-1)
			dfs(i,0);
		if(have[i])
			printf("%d ",i);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 29568
N = gets.to_i
S = gets.chomp.chars

lc = Array.new(N, 0)
rc = Array.new(N, 0)

c = 0
S.each_with_index do |s, i|
  if s == 'W'
    c += 1
  end
  lc[i] += c
end

c = 0
(S.size-1).downto(0) do |i|
  s = S[i]
  if s == 'E'
    c += 1
  end
  rc[i] += c
end

ans = 10 ** 20
(0..S.size-1).each do |i|
  ans = [ans, lc[i] + rc[i]].min
end
puts ans - 1

Measured memory_bytes: 32140
#include <iostream>

using namespace std;

int main () {
  string s_number;
  long long int number;

  int count = 0;

  cin >> s_number;

  number = stoi(s_number);

  for(char &letter : s_number) {
    count += letter - 48;
  }

  cout << (number % count == 0 ? "Yes" : "No") << endl;

  return 0;
}


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

typedef long long ll;
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(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
ll gcd(ll a,ll b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  ll A,B,K;
  cin >> A >> B >> K;
  ll x = gcd(A,B);
  vector<ll> v = divisor(x);
  cout << v.at(v.size() - K) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String... args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    StringBuilder f = new StringBuilder(s);
    StringBuilder b = new StringBuilder(s);

    if(s.length()%2 == 0){
      f.delete(s.length()/2, s.length());
      b.delete(0, s.length()/2).reverse();
    }else{
      f.delete(s.length()/2+1, s.length());
      b.delete(0, s.length()/2).reverse();
    }

    int cnt = 0;
    for(int i = 0; i < f.length(); i++){
      if(f.charAt(i) != b.charAt(i)){
        f.setCharAt(i, b.charAt(i));
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}


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

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

  vector<int> ans;
  ans.push_back(X);
  for (int i = 1; i < K; i++) {
    int d1 = X - i;
    int d2 = X + i;
    ans.push_back(d1);
    ans.push_back(d2);
  }

  sort(ans.begin(), ans.end());

  for (auto d : ans) {
    cout << d << " ";
  }
  cout << endl;

  return 0;
}


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

struct union_find{
	int N;
	vector<int> parent;
	vector<int> siz;

	union_find(int N) : parent(N), siz(N, 1){
		for (int i = 0; i < N; i++) parent[i] = i;
	}

	int root(int x){
		if(parent[x] == x) return x;
		else return parent[x] = root(parent[x]);
	}

	void merge(int x, int y){
		x = root(x), y = root(y);
		if(x == y) return;
		if(siz[x] < siz[y]) swap(x, y);
		parent[y] = x;
		siz[x] += siz[y];
		siz[y] = 0;
	}

	bool are_same(int x, int y){
		return root(x) == root(y);
	}

	int size(int x){
		return siz[root(x)];
	}
};

int main(){
	int N, M, K, i;
	scanf("%d%d%d", &N, &M, &K);
	vector<int> count(N, 0);
	union_find uf(N);
	for(i = 0; i < M; i++){
		int A, B;
		scanf("%d%d", &A, &B);
		A--;
		B--;
		count[A]++;
		count[B]++;
		uf.merge(A, B);
	}
	for(i = 0; i < K; i++){
		int C, D;
		scanf("%d%d", &C, &D);
		C--;
		D--;
		if(uf.are_same(C, D)){
			count[C]++;
			count[D]++;
		}
	}
	for(i = 0; i < N; i++){
		printf("%d ", uf.size(i) - count[i] - 1);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
static const int INFTY = (1<<29);
int dp[50010];
int main(void){
    int n,m,c[20];
    int i,j;

    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++){
	scanf("%d",&c[i]);
    }

    dp[1]=1;
    for(i=2;i<=n;i++) dp[i]=INFTY;

    for(i=0;i<m;i++){
	for(j=0;j+c[i]<=n;j++){
	    if(dp[j]+1<dp[j+c[i]]) dp[j+c[i]]=dp[j]+1;
	}
    }

    printf("%d\n",dp[n]);

    return 0;
}

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

int main() {
	long long l,r;cin>>l>>r;
	if(r-l>=2019){
		cout<<0<<endl;
		return 0;
	}
	long long ans=2019;
	for(long long i=l;i<r;i++){
		for(long long j=i+1;j<=r;j++){
			ans=min(ans,(i*j)%2019);
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

ans = 2000000000
for a in range(1, n):
	b = n-a
	X = str(a)
	Y = str(b)
	s = sum([int(a) for a in X])
	s += sum([int(a) for a in Y])
	ans = min(ans, s)
print (ans)


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

using namespace std;

const int N=4e3+10;


int n,pos[2][N];
int psum[2][N][N];

int f[N][N];
void prepare(){
        cin>>n;
        for(int i=1;i<=2*n;i++){
                char ch;
                int x;
                cin>>ch>>x;
                pos[ch=='W'][x]=i;
        }
        for(int type=0;type<=1;type++){
                for(int i=1;i<=n;i++){
                        for(int j=0;j<=n*2;j++){ 
                                psum[type][i][j]=psum[type][i-1][j]+(j>=pos[type][i]);
                                }
                }
        }
}

int DP(int p1,int p2){
        if (p1==0||p2==0) return 0;
        int& ans=f[p1][p2];
        if (ans!=-1) return ans;
        ans=min(DP(p1-1,p2)+p2-psum[1][p2][pos[0][p1]],
                DP(p1,p2-1)+p1-psum[0][p1][pos[1][p2]]);
        return ans;
}
int solve(){
        int ans=0;
        for(int type=0;type<=1;type++)
                for(int i=1;i<=n;i++) ans+=i-1-psum[type][i-1][pos[type][i]]; 
        memset(f,-1,sizeof(f));
        return DP(n,n)+ans;        
}
int main(){
        prepare();
        cout<<solve();
}


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

import fractions
lcm = a[0]
for ai in a:
    lcm = lcm * ai // fractions.gcd(lcm, ai)
    #lcm =  fractions.gcd(lcm, ai)
ans = 0
for ai in a:
    ans += (lcm-1)%ai
print(ans)


Measured memory_bytes: 5280
import java.util.Arrays;
import java.util.Scanner;

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();
		}
		Arrays.sort(A);

		int[] num = new int[1000001];
		for(int i = 0;i < n;i++){
			num[A[i]]++;
		}
		int sum = 0;
		int twonum = 0;
		for(int i = 0;i <= 100000;i++){

			if(num[i] > 0){
				if(num[i] % 2 == 1){
					num[i] = 1;
				}else{
					num[i] =  2;
				}
				sum++;
			}
			if(num[i] == 2){
				twonum++;
			}

//		System.out.println("i " + i + " num "+num[i]);
		}
		if(twonum % 2 == 1){
			System.out.println(sum-1);
		}else{
			System.out.println(sum);
		}



	}
}


class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 50780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a[100], b[100], dst[100][100], d[100][100];
bool at[100][100];

void warshall_floid(){
	for(ll k = 0; k <= 50; k++)
		for(ll i = 0; i <= 50; i++)
			for(ll j = 0; j <= 50; j++)
				dst[i][j] = min(dst[i][k]+dst[k][j], dst[i][j]);
}

bool g(){
	bool res = true;
	zep(i, 0, n){if(!at[i][b[i]]){res = false;}}
	return res;
}

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

	zep(i, 0, 100){zep(j, 0, 100){dst[i][j] = (1LL << 60);}}
	rep(i, 0, 50){rep(j, 1, 50){dst[i][i%j] = min((1LL << j), dst[i][i%j]);}}
	warshall_floid();

	memset(d, -1, sizeof(d));
	rep(i, 0, 50){
		rep(j, 0, 50){
			rep(k, 0, 50){
				if((dst[i][j] & (1LL << k))){d[i][j] = max(k, d[i][j]);}
				if(d[i][j] >= 60){d[i][j] = -1;}
			}
		}
	}

	cin >> n;
	zep(i, 0, n){cin >> a[i];}
	zep(i, 0, n){cin >> b[i];}
	zep(i, 0, n){if(a[i] < b[i] || d[a[i]][b[i]] < 0){print(-1) return 0;}}
	
	memset(at, 0, sizeof(at));
	zep(i, 0, n){at[i][a[i]] = true;}
	
	ll ans = 0;
	
	while(!g()){
		ll iat, jat;
		ll lng = -INF;
		
		zep(i, 0, n){
			ll jbuf;
			ll lngbuf = INF;
			
			if(!at[i][b[i]]){
				rep(j, b[i]+1, a[i]){
					if(at[i][j] && d[j][b[i]] > 0 && d[j][b[i]] < lngbuf){
						lngbuf = d[j][b[i]];
						jbuf = j;
					}
				}
				
				if(lngbuf > lng){
					lng = lngbuf;
					iat = i;
					jat = jbuf;
				}
			}	
		}
		
		ll kk =  d[jat][b[iat]];
		//cout << iat << jat << d[jat][b[iat]] << endl;
		//if(kk < 0){print(-1); return 0;}
		
		ans |= (1LL << kk);
		
		zep(i, 0, n){
			if(!at[i][b[i]]){
				rep(j, b[i]+1, a[i]){
					if(at[i][j]){at[i][j%kk] = true;}
				}
			}
		}
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

        int koma = scanner.nextInt();
        int zahyou = scanner.nextInt();

        int[] zahyou_array = new int[zahyou];
        for(int i = 0;i<zahyou;i++) {
        	zahyou_array[i] = scanner.nextInt();
        }

        Arrays.sort(zahyou_array);

        int[] dist_array = new int[zahyou-1];
        int tmp = 0;
        for(int j=0;j<zahyou;j++) {
        	if(j!=0) {
        		dist_array[j-1] = zahyou_array[j] - tmp;
        	}
        	tmp = zahyou_array[j];
        }

        Arrays.sort(dist_array);

        int sum = 0;
        for(int k=0;k<((zahyou-1)-(koma-1));k++) {
        	sum+=dist_array[k];
        }

        System.out.println(sum);

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

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

ll dp[102][100002];

ll knapsack(ll *we,ll *v,ll w,ll n)
{
	if(n==0||w==0)
	{
	return	dp[n][w]=0;
	}
	if(dp[n][w]!=-1)
	{
		return  dp[n][w];
	}
	if(we[n-1]<=w)
	{
		return dp[n][w]=max(v[n-1]+knapsack(we,v,w-we[n-1],n-1),knapsack(we,v,w,n-1));
	}
	else
	{
	  return dp[n][w]=knapsack(we,v,w,n-1);
	}
}
int main()
{
	for(ll i=0;i<102;i++)
{
	for(ll j=0;j<100002;j++)
	{
		dp[i][j]=-1;
	}
}
	ll n,w;
	cin>>n>>w;
	ll v[n],we[n];
	for(int i=0;i<n;i++)
	{
		cin>>we[i]>>v[i];
	}
	
	cout<<knapsack(we,v,w,n)<<endl;

}

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

const int maxn=1e6+5;

vector<pair<int,int> >e[maxn];//二维数组，第一维是点的序号，第二维是该点所连接的点的数量
//first是该点连接的点的序号，second是该点到所连接点的权值

int n,m,dis[maxn];

void init()
{
    for(int i=0;i<maxn;i++)e[i].clear();
    for(int i=0;i<maxn;i++)dis[i]=1e9;
}

void dij(int s)
{
    priority_queue<pair<int,int> >q;
    dis[s]=0;
    q.push(make_pair(-dis[s],s));
    while(!q.empty())
    {
        int now=q.top().second;//当前离起点最近的点（最短路已经确定的点）
        q.pop();
        for(int i=0;i<e[now].size();i++)
        {
            int v=e[now][i].first;//更新该点所连接的所有点
            if(dis[v]>dis[now]+e[now][i].second)
            {
                dis[v]=dis[now]+e[now][i].second;
                q.push(make_pair(-dis[v],v));//更新成功则入队
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    while(cin>>n>>m)
    {
        init();
        for(int i=0;i<m;i++)
        {
            int x,y,z;
            cin>>x>>y;
            e[x].push_back(make_pair(y,1));
            e[y].push_back(make_pair(x,1));
        }
        dij(1);
        if(dis[n]==2)cout<<"POSSIBLE"<<endl;
        else cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

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

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;

signed main()
{

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n)
    {
        cin >> s[i];
    }

    unordered_map<string, int> ans;
    rep(i, n)
    {
        ans[s[i]] = 1;
    }

    cout << ans.size() << endl;
}


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

// Shortcut

#define int long long
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << ' ';
#define PrintVl(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << endl;
#define PrintA(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << ' ';
#define PrintAl(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a));
#define mmset(a) memset(a, 0x3f, sizeof(a));
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5, mod = 1e9 + 7, inf = 1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    ForE(i, 1, 10){
        cout << a * c - b << endl;
        c = a * c - b;
    }
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256
N,Q = gets.split.map(&:to_i)
STX = N.times.map{
	s,t,x = gets.split.map(&:to_i)
	next s-x,t-x,x
}.sort_by!{|s,| s }
D = Q.times.map{ gets.to_i }

min = []

puts D.map{|d|
	while ! STX.empty? && STX[0][0] <= d
		_,t,x  = STX.shift
		i = min.bsearch_index{|_,xm| x<xm }||min.size
		j = min.bsearch_index{|tm,| t<tm }||min.size
		min[i...j] = i<=j ? [[t,x]] : []
	end
	min.shift(min.index{|tm,| d<tm }||min.size)
	next min.empty? ? -1 : min[0][1]
}


Measured memory_bytes: 35536
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
  std::string s;
  std::cin >> s;

  if (s == "RRR") {
    std::cout << 3 << std::endl;
  } else if (s == "RRS" || s == "SRR") {
    std::cout << 2 << std::endl;
  } else if (s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR") {
    std::cout << 1 << std::endl;
  } else {
    std::cout << 0 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3244